directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r664497 - in /directory/sandbox/seelmann/testingframework: ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/browser/ test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/
Date Sun, 08 Jun 2008 12:59:48 GMT
Author: seelmann
Date: Sun Jun  8 05:59:48 2008
New Revision: 664497

URL: http://svn.apache.org/viewvc?rev=664497&view=rev
Log:
Renamed NewConnectionWizardTest, added NewEntryWizardTest, fixed label provider

Added:
    directory/sandbox/seelmann/testingframework/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/NewConnectionWizardTest.java
      - copied, changed from r664088, directory/sandbox/seelmann/testingframework/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/ConnectionUiTest.java
    directory/sandbox/seelmann/testingframework/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/NewEntryWizardTest.java
    directory/sandbox/seelmann/testingframework/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/SWTBotUtils.java
Removed:
    directory/sandbox/seelmann/testingframework/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/ConnectionUiTest.java
Modified:
    directory/sandbox/seelmann/testingframework/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/browser/BrowserLabelProvider.java
    directory/sandbox/seelmann/testingframework/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/AutomatedSuite.java

Modified: directory/sandbox/seelmann/testingframework/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/browser/BrowserLabelProvider.java
URL: http://svn.apache.org/viewvc/directory/sandbox/seelmann/testingframework/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/browser/BrowserLabelProvider.java?rev=664497&r1=664496&r2=664497&view=diff
==============================================================================
--- directory/sandbox/seelmann/testingframework/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/browser/BrowserLabelProvider.java
(original)
+++ directory/sandbox/seelmann/testingframework/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/browser/BrowserLabelProvider.java
Sun Jun  8 05:59:48 2008
@@ -85,10 +85,7 @@
             IEntry entry = ( IEntry ) obj;
 
             StringBuffer append = new StringBuffer();
-            if ( entry instanceof IRootDSE )
-            {
-                append.append( "Root DSE" );
-            }
+           
             if ( entry.isChildrenInitialized() && ( entry.getChildrenCount() >
0 ) || entry.getChildrenFilter() != null )
             {
                 append.append( " (" ).append( entry.getChildrenCount() );
@@ -103,21 +100,24 @@
                 append.append( ")" );
             }
 
-            if ( entry instanceof ReferralBaseEntry )
+            if ( entry instanceof IRootDSE )
             {
-                return entry.getUrl().toString() + " " + append.toString();
+                return "Root DSE" + append.toString();
+            }
+            else if ( entry instanceof ReferralBaseEntry )
+            {
+                return entry.getUrl().toString() + append.toString();
             }
             else if ( entry instanceof AliasBaseEntry )
             {
-                return entry.getDn().getUpName() + " " + append.toString();
+                return entry.getDn().getUpName() + append.toString();
             }
             else if ( entry instanceof BaseDNEntry )
             {
-                return entry.getDn().getUpName() + " " + append.toString();
+                return entry.getDn().getUpName() + append.toString();
             }
             else if ( entry.hasParententry() )
             {
-
                 String label = "";
                 if ( preferences.getEntryLabel() == BrowserCommonConstants.SHOW_DN )
                 {

Modified: directory/sandbox/seelmann/testingframework/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/AutomatedSuite.java
URL: http://svn.apache.org/viewvc/directory/sandbox/seelmann/testingframework/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/AutomatedSuite.java?rev=664497&r1=664496&r2=664497&view=diff
==============================================================================
--- directory/sandbox/seelmann/testingframework/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/AutomatedSuite.java
(original)
+++ directory/sandbox/seelmann/testingframework/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/AutomatedSuite.java
Sun Jun  8 05:59:48 2008
@@ -26,7 +26,7 @@
 
 
 /**
- * TODO AutomatedSuite.
+ * Test suite to run all tests.
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
@@ -42,7 +42,8 @@
 
     public AutomatedSuite()
     {
-        addTest( new TestSuite( ConnectionUiTest.class ) );
+        addTest( new TestSuite( NewConnectionWizardTest.class ) );
+        addTest( new TestSuite( NewEntryWizardTest.class ) );
     }
 
 }
\ No newline at end of file

Copied: directory/sandbox/seelmann/testingframework/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/NewConnectionWizardTest.java
(from r664088, directory/sandbox/seelmann/testingframework/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/ConnectionUiTest.java)
URL: http://svn.apache.org/viewvc/directory/sandbox/seelmann/testingframework/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/NewConnectionWizardTest.java?p2=directory/sandbox/seelmann/testingframework/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/NewConnectionWizardTest.java&p1=directory/sandbox/seelmann/testingframework/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/ConnectionUiTest.java&r1=664088&r2=664497&rev=664497&view=diff
==============================================================================
--- directory/sandbox/seelmann/testingframework/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/ConnectionUiTest.java
(original)
+++ directory/sandbox/seelmann/testingframework/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/NewConnectionWizardTest.java
Sun Jun  8 05:59:48 2008
@@ -22,11 +22,9 @@
 
 
 import net.sf.swtbot.eclipse.finder.SWTEclipseBot;
-import net.sf.swtbot.eclipse.finder.widgets.SWTBotView;
 import net.sf.swtbot.widgets.SWTBotButton;
 import net.sf.swtbot.widgets.SWTBotCombo;
 import net.sf.swtbot.widgets.SWTBotMenu;
-import net.sf.swtbot.widgets.SWTBotTable;
 import net.sf.swtbot.widgets.SWTBotText;
 import net.sf.swtbot.widgets.SWTBotTree;
 
@@ -38,12 +36,12 @@
 
 
 /**
- * TODO ConnectionUiTest.
+ * Tests the new connection wizard.
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public class ConnectionUiTest extends AbstractServerTest
+public class NewConnectionWizardTest extends AbstractServerTest
 {
     private SWTEclipseBot bot;
 
@@ -51,15 +49,21 @@
     protected void setUp() throws Exception
     {
         super.setUp();
-
         bot = new SWTEclipseBot();
-        openLdapPerspective();
+        SWTBotUtils.openLdapPerspective( bot );
     }
 
 
     protected void tearDown() throws Exception
     {
         bot = null;
+        
+        // clear all created connections
+        ConnectionManager connectionManager = ConnectionCorePlugin.getDefault().getConnectionManager();
+        for( Connection connection : connectionManager.getConnections() )
+        {
+            connectionManager.removeConnection( connection );
+        }
         super.tearDown();
     }
 
@@ -67,16 +71,13 @@
     public void testCreateConnection() throws Exception
     {
         // Select "Connections" view, ensure no connections exists yet
-        SWTBotView view = bot.view( "Connections" );
-        view.show();
-        SWTBotTree connectionsTree = bot.tree();
+        SWTBotTree connectionsTree = SWTBotUtils.getConnectionsTree( bot );
         assertEquals( 0, connectionsTree.rowCount() );
-        
-        
+
         // open "New Connection" wizard
         SWTBotMenu newConnectionMenu = connectionsTree.contextMenu( "New Connection..." );
         newConnectionMenu.click();
-        
+
         // get buttons
         SWTBotButton backButton = bot.button( "< Back" );
         SWTBotButton nextButton = bot.button( "Next >" );
@@ -89,7 +90,7 @@
 
         // enter connection parameter
         SWTBotText connText = bot.textWithLabel( "Connection name:" );
-        connText.setText( "Simple Connection" );
+        connText.setText( "NewConnectionWizardTest" );
         SWTBotCombo hostnameCombo = bot.comboBox( "" );
         hostnameCombo.setText( "localhost" );
         SWTBotCombo portCombo = bot.comboBox( "" );
@@ -125,13 +126,14 @@
 
         // finish dialog
         finishButton.click();
+        Thread.sleep( 2000 );
 
         // ensure connection was created
         ConnectionManager connectionManager = ConnectionCorePlugin.getDefault().getConnectionManager();
         assertNotNull( connectionManager.getConnections() );
         assertEquals( 1, connectionManager.getConnections().length );
         Connection connection = connectionManager.getConnections()[0];
-        assertEquals( "Simple Connection", connection.getName() );
+        assertEquals( "NewConnectionWizardTest", connection.getName() );
         assertEquals( "localhost", connection.getHost() );
         assertEquals( ldapServer.getIpPort(), connection.getPort() );
         assertEquals( AuthenticationMethod.SIMPLE, connection.getAuthMethod() );
@@ -140,29 +142,13 @@
 
         // ensure connection is visible in Connections view
         assertEquals( 1, connectionsTree.rowCount() );
-        
+
         // close connection
-        connectionsTree.select( "Simple Connection" );
+        connectionsTree.select( "NewConnectionWizardTest" );
         SWTBotMenu contextMenu = connectionsTree.contextMenu( "Close Connection" );
         contextMenu.click();
-        
-        Thread.sleep( 2000 );
-    }
 
-
-    private void openLdapPerspective() throws Exception
-    {
-        // open "Open Perspective" dialog
-        SWTBotMenu windowMenu = bot.menu( "Window" );
-        windowMenu.click();
-        SWTBotMenu perspectiveMenu = windowMenu.menu( "Open Perspective" );
-        perspectiveMenu.click();
-        SWTBotMenu otherMenu = windowMenu.menu( "Other..." );
-        otherMenu.click();
-
-        // select "LDAP" perspective
-        SWTBotTable table = bot.table();
-        table.select( "LDAP" );
+        Thread.sleep( 1000 );
     }
 
 }

Added: directory/sandbox/seelmann/testingframework/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/NewEntryWizardTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/seelmann/testingframework/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/NewEntryWizardTest.java?rev=664497&view=auto
==============================================================================
--- directory/sandbox/seelmann/testingframework/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/NewEntryWizardTest.java
(added)
+++ directory/sandbox/seelmann/testingframework/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/NewEntryWizardTest.java
Sun Jun  8 05:59:48 2008
@@ -0,0 +1,336 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.test.integration.ui;
+
+
+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 org.apache.directory.server.unit.AbstractServerTest;
+import org.apache.directory.studio.connection.core.Connection;
+import org.apache.directory.studio.connection.core.ConnectionCorePlugin;
+import org.apache.directory.studio.connection.core.ConnectionFolder;
+import org.apache.directory.studio.connection.core.ConnectionFolderManager;
+import org.apache.directory.studio.connection.core.ConnectionManager;
+import org.apache.directory.studio.connection.core.ConnectionParameter;
+import org.apache.directory.studio.connection.core.ConnectionParameter.AuthenticationMethod;
+import org.apache.directory.studio.connection.core.ConnectionParameter.EncryptionMethod;
+
+
+/**
+ * Tests the new entry wizard.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class NewEntryWizardTest extends AbstractServerTest
+{
+    private SWTEclipseBot bot;
+
+
+    protected void setUp() throws Exception
+    {
+        super.setUp();
+        bot = new SWTEclipseBot();
+        SWTBotUtils.openLdapPerspective( bot );
+        createConnection();
+    }
+
+
+    protected void tearDown() throws Exception
+    {
+        bot = null;
+        deleteConnection();
+        super.tearDown();
+    }
+
+
+    /**
+     * Test to create a single organization entry.
+     * 
+     * @throws Exception the exception
+     */
+    public void testCreateOrganizationEntry() throws Exception
+    {
+        final SWTBotTree browserTree = SWTBotUtils.getLdapBrowserTree( bot );
+        SWTBotUtils.selectNode( browserTree, "DIT", "Root DSE", "ou=system" );
+
+        // open "New Entry" wizard
+        SWTBotMenu contextMenu = browserTree.contextMenu( "New Entry..." );
+        contextMenu.click();
+
+        // select entry creation method
+        bot.radio( "Create entry from scratch" ).click();
+        bot.button( "Next >" ).click();
+
+        // select object classes
+        bot.table( 0 ).select( "organization" );
+        bot.button( "Add" ).click();
+        bot.button( "Next >" ).click();
+
+        // specify DN
+        SWTBotCombo typeCombo = bot.comboBox( "" );
+        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()
+        {
+            public boolean test() throws Exception
+            {
+                return bot.tree( 0 ) != null;
+            }
+
+
+            public String getFailureMessage()
+            {
+                return "Could not find widget";
+            }
+        } );
+
+        // click finish to create the entry
+        bot.button( "Finish" ).click();
+
+        // wait till entry is created and selected in the tree
+        bot.waitUntil( new DefaultCondition()
+        {
+            public boolean test() throws Exception
+            {
+                return browserTree.selection().get( 0 ).get( 0 ).equals( "o=testCreateOrganizationEntry"
);
+            }
+
+
+            public String getFailureMessage()
+            {
+                return "Could not find widget";
+            }
+        } );
+    }
+
+
+    /**
+     * Test to create a single person entry.
+     * 
+     * @throws Exception the exception
+     */
+    public void testCreatePersonEntry() throws Exception
+    {
+        final SWTBotTree browserTree = SWTBotUtils.getLdapBrowserTree( bot );
+        SWTBotUtils.selectNode( browserTree, "DIT", "Root DSE", "ou=system" );
+
+        // open "New Entry" wizard
+        SWTBotMenu contextMenu = browserTree.contextMenu( "New Entry..." );
+        contextMenu.click();
+
+        // select entry creation method
+        bot.radio( "Create entry from scratch" ).click();
+        bot.button( "Next >" ).click();
+
+        // select object classes
+        bot.table( 0 ).select( "inetOrgPerson" );
+        bot.button( "Add" ).click();
+        bot.button( "Next >" ).click();
+
+        // specify DN
+        SWTBotCombo typeCombo = bot.comboBox( "" );
+        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()
+        {
+            public boolean test() throws Exception
+            {
+                return bot.tree( 0 ) != null;
+            }
+
+
+            public String getFailureMessage()
+            {
+                return "Could not find widget";
+            }
+        } );
+
+        // enter values
+        SWTBotTree tree = bot.tree( 0 );
+        tree.select( "sn" );
+        bot.text( "" ).setText( "test" );
+
+        // TODO: with SWTBot 1.2 we could use the tree.click() method! 
+        // workaround to apply the new value 
+        bot.button( "< Back" ).click();
+        bot.button( "Next >" ).click();
+        bot.waitUntil( new DefaultCondition()
+        {
+            public boolean test() throws Exception
+            {
+                return bot.button( "Finish" ).isEnabled();
+            }
+
+
+            public String getFailureMessage()
+            {
+                return "Could not find widget";
+            }
+        } );
+
+        bot.button( "Finish" ).click();
+
+        // wait till entry is created and selected in the tree
+        bot.waitUntil( new DefaultCondition()
+        {
+            public boolean test() throws Exception
+            {
+                return browserTree.selection().get( 0 ).get( 0 ).equals( "cn=testCreatePersonEntry"
);
+            }
+
+
+            public String getFailureMessage()
+            {
+                return "Could not find widget";
+            }
+        } );
+    }
+
+
+    /**
+     * Test to create multiple entries.
+     * 
+     * @throws Exception the exception
+     */
+    public void testCreateMultipleEntries() throws Exception
+    {
+        SWTBotTree browserTree = SWTBotUtils.getLdapBrowserTree( bot );
+
+        for ( int i = 0; i < 25; i++ )
+        {
+            createEntry( browserTree, "testCreateMultipleEntries" + i );
+        }
+    }
+
+
+    private void createEntry( final SWTBotTree browserTree, final String name ) throws Exception
+    {
+        SWTBotUtils.selectNode( browserTree, "DIT", "Root DSE", "ou=system" );
+
+        SWTBotMenu contextMenu = browserTree.contextMenu( "New Entry..." );
+        contextMenu.click();
+
+        bot.radio( "Create entry from scratch" ).click();
+        bot.button( "Next >" ).click();
+
+        bot.table( 0 ).select( "organization" );
+        bot.button( "Add" ).click();
+        bot.button( "Next >" ).click();
+
+        SWTBotCombo typeCombo = bot.comboBox( "" );
+        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()
+        {
+            public boolean test() throws Exception
+            {
+                return bot.tree( 0 ) != null;
+            }
+
+
+            public String getFailureMessage()
+            {
+                return "Could not find widget";
+            }
+        } );
+        bot.button( "Finish" ).click();
+
+        // wait till entry is created and selected in the tree
+        bot.waitUntil( new DefaultCondition()
+        {
+            public boolean test() throws Exception
+            {
+                return browserTree.selection().get( 0 ).get( 0 ).equals( "o=" + name );
+            }
+
+
+            public String getFailureMessage()
+            {
+                return "Could not find widget";
+            }
+        } );
+    }
+
+
+    /**
+     * Creates the test connection.
+     * 
+     * @throws Exception the exception
+     */
+    private void createConnection() throws Exception
+    {
+        SWTBotTree connectionsTree = SWTBotUtils.getConnectionsTree( bot );
+
+        ConnectionManager connectionManager = ConnectionCorePlugin.getDefault().getConnectionManager();
+        ConnectionParameter connectionParameter = new ConnectionParameter();
+        connectionParameter.setName( "NewEntryWizardTest" );
+        connectionParameter.setHost( "localhost" );
+        connectionParameter.setPort( ldapServer.getIpPort() );
+        connectionParameter.setEncryptionMethod( EncryptionMethod.NONE );
+        connectionParameter.setAuthMethod( AuthenticationMethod.SIMPLE );
+        connectionParameter.setBindPrincipal( "uid=admin,ou=system" );
+        connectionParameter.setBindPassword( "secret" );
+        Connection connection = new Connection( connectionParameter );
+        connectionManager.addConnection( connection );
+
+        ConnectionFolderManager connectionFolderManager = ConnectionCorePlugin.getDefault()
+            .getConnectionFolderManager();
+        ConnectionFolder rootConnectionFolder = connectionFolderManager.getRootConnectionFolder();
+        rootConnectionFolder.addConnectionId( connection.getId() );
+        //new OpenConnectionsJob( connection ).execute();
+
+        connectionsTree.select( "NewEntryWizardTest" );
+
+        Thread.sleep( 1000 );
+    }
+
+
+    /**
+     * Deletes the test connection.
+     */
+    private void deleteConnection()
+    {
+        ConnectionManager connectionManager = ConnectionCorePlugin.getDefault().getConnectionManager();
+        for ( Connection connection : connectionManager.getConnections() )
+        {
+            connectionManager.removeConnection( connection );
+        }
+    }
+
+}

Added: directory/sandbox/seelmann/testingframework/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/SWTBotUtils.java
URL: http://svn.apache.org/viewvc/directory/sandbox/seelmann/testingframework/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/SWTBotUtils.java?rev=664497&view=auto
==============================================================================
--- directory/sandbox/seelmann/testingframework/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/SWTBotUtils.java
(added)
+++ directory/sandbox/seelmann/testingframework/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/SWTBotUtils.java
Sun Jun  8 05:59:48 2008
@@ -0,0 +1,132 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.test.integration.ui;
+
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import net.sf.swtbot.eclipse.finder.SWTEclipseBot;
+import net.sf.swtbot.eclipse.finder.widgets.SWTBotView;
+import net.sf.swtbot.widgets.SWTBotMenu;
+import net.sf.swtbot.widgets.SWTBotTable;
+import net.sf.swtbot.widgets.SWTBotTree;
+import net.sf.swtbot.widgets.SWTBotTreeItem;
+
+
+/**
+ * Helpers for using SWTBot.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class SWTBotUtils
+{
+
+    /**
+     * Opens the LDAP perspective.
+     * 
+     * @param bot the bot
+     * 
+     * @throws Exception the exception
+     */
+    public static void openLdapPerspective( SWTEclipseBot bot ) throws Exception
+    {
+        // open "Open Perspective" dialog
+        SWTBotMenu windowMenu = bot.menu( "Window" );
+        windowMenu.click();
+        SWTBotMenu perspectiveMenu = windowMenu.menu( "Open Perspective" );
+        perspectiveMenu.click();
+        SWTBotMenu otherMenu = windowMenu.menu( "Other..." );
+        otherMenu.click();
+
+        // select "LDAP" perspective
+        SWTBotTable table = bot.table();
+        table.select( "LDAP" );
+    }
+
+
+    public static SWTBotTree getConnectionsTree( SWTEclipseBot bot ) throws Exception
+    {
+        SWTBotView view = bot.view( "Connections" );
+        view.show();
+        SWTBotTree connectionsTree = bot.tree( 0 );
+        return connectionsTree;
+    }
+
+
+    public static SWTBotTree getLdapBrowserTree( SWTEclipseBot bot ) throws Exception
+    {
+        SWTBotView view = bot.view( "LDAP Browser" );
+        view.show();
+        SWTBotTree browserTree = bot.tree( 1 );
+        return browserTree;
+    }
+
+
+    public static SWTBotTreeItem selectNode( SWTBotTree browserTree, String... path ) throws
Exception
+    {
+        List<String> pathList = new ArrayList<String>( Arrays.asList( path )
);
+        String currentPath = pathList.remove( 0 );
+
+        SWTBotTreeItem child = browserTree.getTreeItem( currentPath );
+        child.select();
+        child.expand();
+
+        if ( !pathList.isEmpty() )
+        {
+            return selectNode( child, pathList );
+        }
+        else
+        {
+            return child;
+        }
+    }
+
+
+    public static SWTBotTreeItem selectNode( SWTBotTreeItem item, List<String> pathList
) throws Exception
+    {
+        String currentPath = pathList.remove( 0 );
+
+        List<String> nodes = item.getNodes();
+        for ( String node : nodes )
+        {
+            if ( node.toUpperCase().startsWith( currentPath.toUpperCase() ) )
+            {
+                currentPath = node;
+            }
+        }
+        SWTBotTreeItem child = item.expandNode( currentPath );
+        child.select();
+        child.expand();
+
+        if ( !pathList.isEmpty() )
+        {
+            return selectNode( child, pathList );
+        }
+        else
+        {
+            return child;
+        }
+    }
+
+}



Mime
View raw message