directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r683267 - in /directory/studio/trunk/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui: NewEntryWizardTest.java SWTBotUtils.java SwtResourcesTest.java
Date Wed, 06 Aug 2008 14:08:17 GMT
Author: seelmann
Date: Wed Aug  6 07:08:16 2008
New Revision: 683267

URL: http://svn.apache.org/viewvc?rev=683267&view=rev
Log:
Fixed some more race conditions in tests.

Modified:
    directory/studio/trunk/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/NewEntryWizardTest.java
    directory/studio/trunk/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/SWTBotUtils.java
    directory/studio/trunk/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/SwtResourcesTest.java

Modified: directory/studio/trunk/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/NewEntryWizardTest.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/NewEntryWizardTest.java?rev=683267&r1=683266&r2=683267&view=diff
==============================================================================
--- directory/studio/trunk/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/NewEntryWizardTest.java
(original)
+++ directory/studio/trunk/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/NewEntryWizardTest.java
Wed Aug  6 07:08:16 2008
@@ -28,7 +28,6 @@
 import net.sf.swtbot.eclipse.finder.SWTEclipseBot;
 import net.sf.swtbot.wait.DefaultCondition;
 import net.sf.swtbot.widgets.SWTBotCombo;
-import net.sf.swtbot.widgets.SWTBotMenu;
 import net.sf.swtbot.widgets.SWTBotText;
 import net.sf.swtbot.widgets.SWTBotTree;
 import net.sf.swtbot.widgets.SWTBotTreeItem;
@@ -94,8 +93,19 @@
         SWTBotUtils.selectEntry( bot, browserTree, true, "DIT", "Root DSE", "ou=system" );
 
         // open "New Entry" wizard
-        SWTBotMenu contextMenu = browserTree.contextMenu( "New Entry..." );
-        contextMenu.click();
+        SWTBotUtils.asyncClick( bot, browserTree.contextMenu( "New Entry..." ), new DefaultCondition()
+        {
+            public boolean test() throws Exception
+            {
+                return bot.shell( "New Entry" ) != null;
+            }
+
+
+            public String getFailureMessage()
+            {
+                return "Could not find dialog 'New Entry'";
+            }
+        } );
 
         // select entry creation method
         bot.radio( "Create entry from scratch" ).click();
@@ -111,10 +121,7 @@
         typeCombo.setText( "o" );
         SWTBotText valueText = bot.text( "" );
         valueText.setText( "testCreateOrganizationEntry" );
-        bot.button( "Next >" ).click();
-
-        // wait for check that entry doesn't exist yet
-        bot.waitUntil( new DefaultCondition()
+        SWTBotUtils.asyncClick( bot, bot.button( "Next >" ), new DefaultCondition()
         {
             public boolean test() throws Exception
             {
@@ -129,10 +136,7 @@
         } );
 
         // click finish to create the entry
-        bot.button( "Finish" ).click();
-
-        // wait till entry is created and selected in the tree
-        bot.waitUntil( new DefaultCondition()
+        SWTBotUtils.asyncClick( bot, bot.button( "Finish" ), new DefaultCondition()
         {
             public boolean test() throws Exception
             {
@@ -142,10 +146,9 @@
 
             public String getFailureMessage()
             {
-                return "Could not find widget";
+                return "Could not find 'o=testCreateOrganizationEntry'";
             }
         } );
-        bot.sleep( 1000 );
     }
 
 
@@ -160,8 +163,19 @@
         SWTBotUtils.selectEntry( bot, browserTree, true, "DIT", "Root DSE", "ou=system" );
 
         // open "New Entry" wizard
-        SWTBotMenu contextMenu = browserTree.contextMenu( "New Entry..." );
-        contextMenu.click();
+        SWTBotUtils.asyncClick( bot, browserTree.contextMenu( "New Entry..." ), new DefaultCondition()
+        {
+            public boolean test() throws Exception
+            {
+                return bot.shell( "New Entry" ) != null;
+            }
+
+
+            public String getFailureMessage()
+            {
+                return "Could not find dialog 'New Entry'";
+            }
+        } );
 
         // select entry creation method
         bot.radio( "Create entry from scratch" ).click();
@@ -177,10 +191,7 @@
         typeCombo.setText( "cn" );
         SWTBotText valueText = bot.text( "" );
         valueText.setText( "testCreatePersonEntry" );
-        bot.button( "Next >" ).click();
-
-        // wait for check that entry doesn't exist yet
-        bot.waitUntil( new DefaultCondition()
+        SWTBotUtils.asyncClick( bot, bot.button( "Next >" ), new DefaultCondition()
         {
             public boolean test() throws Exception
             {
@@ -203,10 +214,7 @@
         snNode.click();
 
         // click finish to create the entry
-        bot.button( "Finish" ).click();
-
-        // wait till entry is created and selected in the tree
-        bot.waitUntil( new DefaultCondition()
+        SWTBotUtils.asyncClick( bot, bot.button( "Finish" ), new DefaultCondition()
         {
             public boolean test() throws Exception
             {
@@ -216,10 +224,9 @@
 
             public String getFailureMessage()
             {
-                return "Could not find widget";
+                return "Could not find 'cn=testCreatePersonEntry'";
             }
         } );
-        bot.sleep( 1000 );
     }
 
 
@@ -237,8 +244,19 @@
         SWTBotUtils.selectEntry( bot, browserTree, true, "DIT", "Root DSE", "ou=system" );
 
         // open "New Entry" wizard
-        SWTBotMenu contextMenu = browserTree.contextMenu( "New Entry..." );
-        contextMenu.click();
+        SWTBotUtils.asyncClick( bot, browserTree.contextMenu( "New Entry..." ), new DefaultCondition()
+        {
+            public boolean test() throws Exception
+            {
+                return bot.shell( "New Entry" ) != null;
+            }
+
+
+            public String getFailureMessage()
+            {
+                return "Could not find dialog 'New Entry'";
+            }
+        } );
 
         // select entry creation method
         bot.radio( "Create entry from scratch" ).click();
@@ -254,10 +272,7 @@
         typeCombo.setText( "O" );
         SWTBotText valueText = bot.text( "" );
         valueText.setText( "testCreateOrganizationEntry" );
-        bot.button( "Next >" ).click();
-
-        // wait for check that entry doesn't exist yet
-        bot.waitUntil( new DefaultCondition()
+        SWTBotUtils.asyncClick( bot, bot.button( "Next >" ), new DefaultCondition()
         {
             public boolean test() throws Exception
             {
@@ -272,10 +287,7 @@
         } );
 
         // click finish to create the entry
-        bot.button( "Finish" ).click();
-
-        // wait till entry is created and selected in the tree
-        bot.waitUntil( new DefaultCondition()
+        SWTBotUtils.asyncClick( bot, bot.button( "Finish" ), new DefaultCondition()
         {
             public boolean test() throws Exception
             {
@@ -285,17 +297,27 @@
 
             public String getFailureMessage()
             {
-                return "Could not find widget";
+                return "Could not find 'O=testCreateOrganizationEntry'";
             }
         } );
-        bot.sleep( 1000 );
 
         // Now create a second entry under the previously created entry 
         // to ensure that the selected parent is also upper case.
 
         // open "New Entry" wizard
-        contextMenu = browserTree.contextMenu( "New Entry..." );
-        contextMenu.click();
+        SWTBotUtils.asyncClick( bot, browserTree.contextMenu( "New Entry..." ), new DefaultCondition()
+        {
+            public boolean test() throws Exception
+            {
+                return bot.shell( "New Entry" ) != null;
+            }
+
+
+            public String getFailureMessage()
+            {
+                return "Could not find dialog 'New Entry'";
+            }
+        } );
 
         // select entry creation method
         bot.radio( "Create entry from scratch" ).click();
@@ -316,10 +338,7 @@
         SWTBotText previewText = bot.text( "O=testCreateOrganizationEntry2,O=testCreateOrganizationEntry,ou=system"
);
         assertEquals( "O=testCreateOrganizationEntry2,O=testCreateOrganizationEntry,ou=system",
previewText.getText() );
 
-        bot.button( "Next >" ).click();
-
-        // wait for check that entry doesn't exist yet
-        bot.waitUntil( new DefaultCondition()
+        SWTBotUtils.asyncClick( bot, bot.button( "Next >" ), new DefaultCondition()
         {
             public boolean test() throws Exception
             {
@@ -334,10 +353,7 @@
         } );
 
         // click finish to create the entry
-        bot.button( "Finish" ).click();
-
-        // wait till entry is created and selected in the tree
-        bot.waitUntil( new DefaultCondition()
+        SWTBotUtils.asyncClick( bot, bot.button( "Finish" ), new DefaultCondition()
         {
             public boolean test() throws Exception
             {
@@ -347,10 +363,9 @@
 
             public String getFailureMessage()
             {
-                return "Could not find widget";
+                return "Could not find 'O=testCreateOrganizationEntry2'";
             }
         } );
-        bot.sleep( 1000 );
     }
 
 
@@ -369,8 +384,19 @@
         systemNode.expand();
 
         // open "New Entry" wizard
-        SWTBotMenu contextMenu = browserTree.contextMenu( "New Entry..." );
-        contextMenu.click();
+        SWTBotUtils.asyncClick( bot, browserTree.contextMenu( "New Entry..." ), new DefaultCondition()
+        {
+            public boolean test() throws Exception
+            {
+                return bot.shell( "New Entry" ) != null;
+            }
+
+
+            public String getFailureMessage()
+            {
+                return "Could not find dialog 'New Entry'";
+            }
+        } );
 
         // select entry creation method
         bot.radio( "Create entry from scratch" ).click();
@@ -388,10 +414,7 @@
         typeCombo.setText( "krb5PrincipalName" );
         SWTBotText valueText = bot.text( "" );
         valueText.setText( "kadmin/changepw@DOMAIN" );
-        bot.button( "Next >" ).click();
-
-        // wait for check that entry doesn't exist yet
-        bot.waitUntil( new DefaultCondition()
+        SWTBotUtils.asyncClick( bot, bot.button( "Next >" ), new DefaultCondition()
         {
             public boolean test() throws Exception
             {
@@ -421,10 +444,7 @@
         krbNode.click();
 
         // click finish to create the entry
-        bot.button( "Finish" ).click();
-
-        // wait till entry is created and selected in the tree
-        bot.waitUntil( new DefaultCondition()
+        SWTBotUtils.asyncClick( bot, bot.button( "Finish" ), new DefaultCondition()
         {
             public boolean test() throws Exception
             {
@@ -438,7 +458,6 @@
                 return "Could not find entry 'krb5Principal=kadmin/changepw@DOMAIN'";
             }
         } );
-        bot.sleep( 1000 );
     }
 
 }

Modified: directory/studio/trunk/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/SWTBotUtils.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/SWTBotUtils.java?rev=683267&r1=683266&r2=683267&view=diff
==============================================================================
--- directory/studio/trunk/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/SWTBotUtils.java
(original)
+++ directory/studio/trunk/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/SWTBotUtils.java
Wed Aug  6 07:08:16 2008
@@ -31,11 +31,13 @@
 import net.sf.swtbot.finder.UIThreadRunnable;
 import net.sf.swtbot.matcher.ClassMatcher;
 import net.sf.swtbot.wait.DefaultCondition;
+import net.sf.swtbot.wait.ICondition;
 import net.sf.swtbot.widgets.SWTBotButton;
 import net.sf.swtbot.widgets.SWTBotMenu;
 import net.sf.swtbot.widgets.SWTBotTable;
 import net.sf.swtbot.widgets.SWTBotTree;
 import net.sf.swtbot.widgets.SWTBotTreeItem;
+import net.sf.swtbot.widgets.TimeoutException;
 import net.sf.swtbot.widgets.WidgetNotFoundException;
 
 import org.apache.directory.studio.connection.core.Connection;
@@ -200,6 +202,76 @@
 
 
     /**
+     * Clicks a button asynchronously and waits till the given condition
+     * is fulfilled.
+     * 
+     * @param bot the SWT bot
+     * @param button the button to click
+     * @param waitCondition the condition to wait for, may be null
+     * 
+     * @throws TimeoutException 
+     */
+    public static void asyncClick( final SWTEclipseBot bot, final SWTBotButton button, final
ICondition waitCondition )
+        throws TimeoutException
+    {
+        bot.waitUntil( new DefaultCondition()
+        {
+            public boolean test() throws Exception
+            {
+                return button.isEnabled();
+            }
+
+
+            public String getFailureMessage()
+            {
+                return "Button isn't enabled.";
+            }
+        } );
+
+        UIThreadRunnable.asyncExec( bot.getDisplay(), new UIThreadRunnable.VoidResult()
+        {
+            public void run()
+            {
+                button.click();
+            }
+        } );
+
+        if ( waitCondition != null )
+        {
+            bot.waitUntil( waitCondition );
+        }
+    }
+
+
+    /**
+     * Clicks a menu item asynchronously and waits till the given condition
+     * is fulfilled.
+     * 
+     * @param bot the SWT bot
+     * @param button the button to click
+     * @param waitCondition the condition to wait for, may be null
+     * 
+     * @throws TimeoutException 
+     */
+    public static void asyncClick( final SWTEclipseBot bot, final SWTBotMenu menu, final
ICondition waitCondition )
+        throws TimeoutException
+    {
+        UIThreadRunnable.asyncExec( bot.getDisplay(), new UIThreadRunnable.VoidResult()
+        {
+            public void run()
+            {
+                menu.click();
+            }
+        } );
+
+        if ( waitCondition != null )
+        {
+            bot.waitUntil( waitCondition );
+        }
+    }
+
+
+    /**
      * Selects an entry in the browser tree and optionally expands the selected entry.
      * Takes care that all attributes and child entries are initialized so 
      * that there are no pending background actions and event notifications. 
@@ -235,7 +307,14 @@
                 entry = entry.getNode( currentPath );
             }
 
-            entry.select();
+            final SWTBotTreeItem tempEntry = entry;
+            UIThreadRunnable.asyncExec( bot.getDisplay(), new UIThreadRunnable.VoidResult()
+            {
+                public void run()
+                {
+                    tempEntry.select();
+                }
+            } );
 
             if ( !pathList.isEmpty() || expandChild )
             {

Modified: directory/studio/trunk/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/SwtResourcesTest.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/SwtResourcesTest.java?rev=683267&r1=683266&r2=683267&view=diff
==============================================================================
--- directory/studio/trunk/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/SwtResourcesTest.java
(original)
+++ directory/studio/trunk/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/SwtResourcesTest.java
Wed Aug  6 07:08:16 2008
@@ -26,7 +26,6 @@
 import net.sf.swtbot.finder.UIThreadRunnable.IntResult;
 import net.sf.swtbot.wait.DefaultCondition;
 import net.sf.swtbot.widgets.SWTBotCombo;
-import net.sf.swtbot.widgets.SWTBotMenu;
 import net.sf.swtbot.widgets.SWTBotText;
 import net.sf.swtbot.widgets.SWTBotTree;
 
@@ -130,8 +129,19 @@
     private void createAndDeleteEntry( final SWTBotTree browserTree, final String name )
throws Exception
     {
         SWTBotUtils.selectEntry( bot, browserTree, true, "DIT", "Root DSE", "ou=system" );
-        SWTBotMenu contextMenu = browserTree.contextMenu( "New Entry..." );
-        contextMenu.click();
+        SWTBotUtils.asyncClick( bot, browserTree.contextMenu( "New Entry..." ), new DefaultCondition()
+        {
+            public boolean test() throws Exception
+            {
+                return bot.shell( "New Entry" ) != null;
+            }
+
+
+            public String getFailureMessage()
+            {
+                return "Could not find dialog 'New Entry'";
+            }
+        } );
 
         bot.radio( "Create entry from scratch" ).click();
         bot.button( "Next >" ).click();
@@ -144,10 +154,7 @@
         typeCombo.setText( "o" );
         SWTBotText valueText = bot.text( "" );
         valueText.setText( name );
-        bot.button( "Next >" ).click();
-
-        // wait for check that entry doesn't exist yet
-        bot.waitUntil( new DefaultCondition()
+        SWTBotUtils.asyncClick( bot, bot.button( "Next >" ), new DefaultCondition()
         {
             public boolean test() throws Exception
             {
@@ -160,10 +167,9 @@
                 return "Finish button is not enabled";
             }
         } );
-        bot.button( "Finish" ).click();
 
-        // wait till entry is created and selected in the tree
-        bot.waitUntil( new DefaultCondition()
+        // click finish to create the entry
+        SWTBotUtils.asyncClick( bot, bot.button( "Finish" ), new DefaultCondition()
         {
             public boolean test() throws Exception
             {
@@ -176,16 +182,23 @@
                 return "Could not select 'o=" + name + "'";
             }
         } );
-        bot.sleep( 1000 );
 
         // delete the entry
         SWTBotUtils.selectEntry( bot, browserTree, false, "DIT", "Root DSE", "ou=system",
"o=" + name );
-        contextMenu = browserTree.contextMenu( "Delete Entry" );
-        contextMenu.click();
-        bot.button( "OK" ).click();
+        SWTBotUtils.asyncClick( bot, browserTree.contextMenu( "Delete Entry" ), new DefaultCondition()
+        {
+            public boolean test() throws Exception
+            {
+                return bot.shell( "Delete Entry" ) != null;
+            }
 
-        // wait till the parent ou=system is selected in the tree
-        bot.waitUntil( new DefaultCondition()
+
+            public String getFailureMessage()
+            {
+                return "Could not find dialog 'New Entry'";
+            }
+        } );
+        SWTBotUtils.asyncClick( bot, bot.button( "OK" ), new DefaultCondition()
         {
             public boolean test() throws Exception
             {



Mime
View raw message