You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by se...@apache.org on 2009/02/27 15:21:09 UTC
svn commit: r748537 [2/2] -
/directory/studio/trunk/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/
Modified: directory/studio/trunk/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/ReferralDialogTest.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/ReferralDialogTest.java?rev=748537&r1=748536&r2=748537&view=diff
==============================================================================
--- directory/studio/trunk/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/ReferralDialogTest.java (original)
+++ directory/studio/trunk/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/ReferralDialogTest.java Fri Feb 27 14:21:08 2009
@@ -20,6 +20,7 @@
package org.apache.directory.studio.test.integration.ui;
+
import org.apache.directory.server.core.entry.DefaultServerEntry;
import org.apache.directory.server.core.entry.ServerEntry;
import org.apache.directory.server.unit.AbstractServerTest;
@@ -34,226 +35,223 @@
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
+
/**
* Tests the referral dialog.
*
- * @author <a href="mailto:dev@directory.apache.org">Apache Directory
- * Project</a>
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev$, $Date$
*/
-public class ReferralDialogTest extends AbstractServerTest {
- private SWTEclipseBot bot;
- private Connection connection;
-
- protected void setUp() throws Exception {
- super.setUp();
- bot = new SWTEclipseBot();
- SWTBotUtils.openLdapPerspective(bot);
- connection = SWTBotUtils.createTestConnection(bot,
- "ReferralDialogTest", ldapService.getPort());
- }
-
- protected void tearDown() throws Exception {
- SWTBotUtils.deleteTestConnections();
- bot = null;
- super.tearDown();
- }
-
- /**
- * Test for DIRSTUDIO-343.
- *
- * Follows a continuation reference.
- *
- * @throws Exception
- * the exception
- */
- public void testBrowseAndFollowContinuationReference() throws Exception {
- // ensure that referrals handling method is FOLLOW
- int referralsHandlingMethodOrdinal = connection
- .getConnectionParameter()
- .getExtendedIntProperty(
- IBrowserConnection.CONNECTION_PARAMETER_REFERRALS_HANDLING_METHOD);
- assertEquals(ReferralHandlingMethod.FOLLOW.ordinal(),
- referralsHandlingMethodOrdinal);
-
- // create the referral entry
- createReferralEntry();
-
- final SWTBotTree browserTree = SWTBotUtils.getLdapBrowserTree(bot);
-
- // select ou=system, don't expand yet
- final SWTBotTreeItem systemNode = SWTBotUtils.selectEntry(bot,
- browserTree, false, "DIT", "Root DSE", "ou=system");
-
- // expand ou=system, that reads the referral and opens the referral
- // dialog
- UIThreadRunnable.asyncExec(bot.getDisplay(), new VoidResult() {
- public void run() {
- systemNode.expand();
- }
- });
- bot.sleep(1000);
-
- // click OK in the referral dialog
- bot.button("OK").click();
- SWTBotUtils.selectEntry(bot, browserTree, true, "DIT", "Root DSE",
- "ou=system");
-
- // ensure that the referral URL and target is visible
- SWTBotTreeItem referralNode = systemNode.getNode("ldap://localhost:"
- + ldapService.getPort() + "/ou=users,ou=system");
- assertNotNull(referralNode);
- SWTBotUtils.selectEntry(bot, browserTree, false, "DIT", "Root DSE",
- "ou=system", "ldap://localhost:" + ldapService.getPort()
- + "/ou=users,ou=system");
-
- }
-
- /**
- * Test for DIRSTUDIO-343.
- *
- * Does not follow a continuation reference by clicking the cancel button in
- * the referral dialog.
- *
- * @throws Exception
- * the exception
- */
- public void testBrowseAndCancelFollowingContinuationReference()
- throws Exception {
- // ensure that referrals handling method is FOLLOW
- int referralsHandlingMethodOrdinal = connection
- .getConnectionParameter()
- .getExtendedIntProperty(
- IBrowserConnection.CONNECTION_PARAMETER_REFERRALS_HANDLING_METHOD);
- assertEquals(ReferralHandlingMethod.FOLLOW.ordinal(),
- referralsHandlingMethodOrdinal);
-
- // create the referral entry
- createReferralEntry();
-
- final SWTBotTree browserTree = SWTBotUtils.getLdapBrowserTree(bot);
-
- // select ou=system, don't expand yet
- final SWTBotTreeItem systemNode = SWTBotUtils.selectEntry(bot,
- browserTree, false, "DIT", "Root DSE", "ou=system");
-
- // expand ou=system, that reads the referral and opens the referral
- // dialog
- UIThreadRunnable.asyncExec(bot.getDisplay(), new VoidResult() {
- public void run() {
- systemNode.expand();
- }
- });
- bot.sleep(1000);
-
- // click Cancel in the referral dialog
- bot.button("Cancel").click();
- SWTBotUtils.selectEntry(bot, browserTree, true, "DIT", "Root DSE",
- "ou=system");
-
- // ensure that the referral URL and target is not visible
- SWTBotTreeItem referralNode = null;
- try {
- referralNode = systemNode.getNode("ldap://localhost:"
- + ldapService.getPort() + "/ou=users,ou=system");
- } catch (WidgetNotFoundException wnfe) {
- // that is expected
- }
- assertNull(referralNode);
- }
-
- /**
- * Tests ignore referral by setting the connection property to IGNORE.
- *
- * @throws Exception
- * the exception
- */
- public void testBrowseAndIgnoreReferral() throws Exception {
- // ensure that referrals handling method is IGNORE
- connection
- .getConnectionParameter()
- .setExtendedIntProperty(
- IBrowserConnection.CONNECTION_PARAMETER_REFERRALS_HANDLING_METHOD,
- ReferralHandlingMethod.IGNORE.ordinal());
- int referralsHandlingMethodOrdinal = connection
- .getConnectionParameter()
- .getExtendedIntProperty(
- IBrowserConnection.CONNECTION_PARAMETER_REFERRALS_HANDLING_METHOD);
- assertEquals(ReferralHandlingMethod.IGNORE.ordinal(),
- referralsHandlingMethodOrdinal);
-
- // create the referral entry
- createReferralEntry();
-
- // expand ou=system, the referral must be ignored, no referral dialog
- // expected
- SWTBotTree browserTree = SWTBotUtils.getLdapBrowserTree(bot);
- SWTBotTreeItem systemNode = SWTBotUtils.selectEntry(bot, browserTree,
- true, "DIT", "Root DSE", "ou=system");
-
- // ensure that the referral entry is not visible
- SWTBotTreeItem referralNode1 = null;
- try {
- referralNode1 = systemNode.getNode("ldap://localhost:"
- + ldapService.getPort() + "/ou=users,ou=system");
- } catch (WidgetNotFoundException wnfe) {
- // that is expected
- }
- assertNull(referralNode1);
- SWTBotTreeItem referralNode2 = null;
- try {
- referralNode2 = systemNode.getNode("cn=referralDialogTest");
- } catch (WidgetNotFoundException wnfe) {
- // that is expected
- }
- assertNull(referralNode2);
- }
-
- /**
- * Tests manage referral entry by setting the connection property to MANAGE.
- *
- * @throws Exception
- * the exception
- */
- public void testBrowseAndManageReferralEntry() throws Exception {
- // ensure that referrals handling method is MANAGE
- connection
- .getConnectionParameter()
- .setExtendedIntProperty(
- IBrowserConnection.CONNECTION_PARAMETER_REFERRALS_HANDLING_METHOD,
- ReferralHandlingMethod.MANAGE.ordinal());
- int referralsHandlingMethodOrdinal = connection
- .getConnectionParameter()
- .getExtendedIntProperty(
- IBrowserConnection.CONNECTION_PARAMETER_REFERRALS_HANDLING_METHOD);
- assertEquals(ReferralHandlingMethod.MANAGE.ordinal(),
- referralsHandlingMethodOrdinal);
-
- // create the referral entry
- createReferralEntry();
-
- // expand ou=system, the referral is managed, no referral dialog
- // expected
- SWTBotTree browserTree = SWTBotUtils.getLdapBrowserTree(bot);
- SWTBotTreeItem systemNode = SWTBotUtils.selectEntry(bot, browserTree,
- true, "DIT", "Root DSE", "ou=system");
-
- // ensure that the referral entry is visible
- SWTBotTreeItem referralNode = systemNode
- .getNode("cn=referralDialogTest");
- assertNotNull(referralNode);
- SWTBotUtils.selectEntry(bot, browserTree, false, "DIT", "Root DSE",
- "ou=system", "cn=referralDialogTest");
- }
-
- private void createReferralEntry() throws Exception {
- ServerEntry entry = new DefaultServerEntry(rootDSE
- .getDirectoryService().getRegistries());
- entry.setDn(new LdapDN("cn=referralDialogTest,ou=system"));
- entry.add("objectClass", "top", "referral", "extensibleObject");
- entry.add("cn", "referralDialogTest");
- entry.add("ref", "ldap://localhost:" + ldapService.getPort()
- + "/ou=users,ou=system");
- rootDSE.add(entry);
- }
+public class ReferralDialogTest extends AbstractServerTest
+{
+ private SWTEclipseBot bot;
+ private Connection connection;
+
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ bot = new SWTEclipseBot();
+ SWTBotUtils.openLdapPerspective( bot );
+ connection = SWTBotUtils.createTestConnection( bot, "ReferralDialogTest", ldapService.getPort() );
+ }
+
+
+ protected void tearDown() throws Exception
+ {
+ SWTBotUtils.deleteTestConnections();
+ bot = null;
+ super.tearDown();
+ }
+
+
+ /**
+ * Test for DIRSTUDIO-343.
+ *
+ * Follows a continuation reference.
+ *
+ * @throws Exception
+ * the exception
+ */
+ public void testBrowseAndFollowContinuationReference() throws Exception
+ {
+ // ensure that referrals handling method is FOLLOW
+ int referralsHandlingMethodOrdinal = connection.getConnectionParameter().getExtendedIntProperty(
+ IBrowserConnection.CONNECTION_PARAMETER_REFERRALS_HANDLING_METHOD );
+ assertEquals( ReferralHandlingMethod.FOLLOW.ordinal(), referralsHandlingMethodOrdinal );
+
+ // create the referral entry
+ createReferralEntry();
+
+ final SWTBotTree browserTree = SWTBotUtils.getLdapBrowserTree( bot );
+
+ // select ou=system, don't expand yet
+ final SWTBotTreeItem systemNode = SWTBotUtils.selectEntry( bot, browserTree, false, "DIT", "Root DSE",
+ "ou=system" );
+
+ // expand ou=system, that reads the referral and opens the referral
+ // dialog
+ UIThreadRunnable.asyncExec( bot.getDisplay(), new VoidResult()
+ {
+ public void run()
+ {
+ systemNode.expand();
+ }
+ } );
+ bot.sleep( 1000 );
+
+ // click OK in the referral dialog
+ bot.button( "OK" ).click();
+ SWTBotUtils.selectEntry( bot, browserTree, true, "DIT", "Root DSE", "ou=system" );
+
+ // ensure that the referral URL and target is visible
+ SWTBotTreeItem referralNode = systemNode.getNode( "ldap://localhost:" + ldapService.getPort()
+ + "/ou=users,ou=system" );
+ assertNotNull( referralNode );
+ SWTBotUtils.selectEntry( bot, browserTree, false, "DIT", "Root DSE", "ou=system", "ldap://localhost:"
+ + ldapService.getPort() + "/ou=users,ou=system" );
+
+ }
+
+
+ /**
+ * Test for DIRSTUDIO-343.
+ *
+ * Does not follow a continuation reference by clicking the cancel button in
+ * the referral dialog.
+ *
+ * @throws Exception
+ * the exception
+ */
+ public void testBrowseAndCancelFollowingContinuationReference() throws Exception
+ {
+ // ensure that referrals handling method is FOLLOW
+ int referralsHandlingMethodOrdinal = connection.getConnectionParameter().getExtendedIntProperty(
+ IBrowserConnection.CONNECTION_PARAMETER_REFERRALS_HANDLING_METHOD );
+ assertEquals( ReferralHandlingMethod.FOLLOW.ordinal(), referralsHandlingMethodOrdinal );
+
+ // create the referral entry
+ createReferralEntry();
+
+ final SWTBotTree browserTree = SWTBotUtils.getLdapBrowserTree( bot );
+
+ // select ou=system, don't expand yet
+ final SWTBotTreeItem systemNode = SWTBotUtils.selectEntry( bot, browserTree, false, "DIT", "Root DSE",
+ "ou=system" );
+
+ // expand ou=system, that reads the referral and opens the referral
+ // dialog
+ UIThreadRunnable.asyncExec( bot.getDisplay(), new VoidResult()
+ {
+ public void run()
+ {
+ systemNode.expand();
+ }
+ } );
+ bot.sleep( 1000 );
+
+ // click Cancel in the referral dialog
+ bot.button( "Cancel" ).click();
+ SWTBotUtils.selectEntry( bot, browserTree, true, "DIT", "Root DSE", "ou=system" );
+
+ // ensure that the referral URL and target is not visible
+ SWTBotTreeItem referralNode = null;
+ try
+ {
+ referralNode = systemNode.getNode( "ldap://localhost:" + ldapService.getPort() + "/ou=users,ou=system" );
+ }
+ catch ( WidgetNotFoundException wnfe )
+ {
+ // that is expected
+ }
+ assertNull( referralNode );
+ }
+
+
+ /**
+ * Tests ignore referral by setting the connection property to IGNORE.
+ *
+ * @throws Exception
+ * the exception
+ */
+ public void testBrowseAndIgnoreReferral() throws Exception
+ {
+ // ensure that referrals handling method is IGNORE
+ connection.getConnectionParameter().setExtendedIntProperty(
+ IBrowserConnection.CONNECTION_PARAMETER_REFERRALS_HANDLING_METHOD, ReferralHandlingMethod.IGNORE.ordinal() );
+ int referralsHandlingMethodOrdinal = connection.getConnectionParameter().getExtendedIntProperty(
+ IBrowserConnection.CONNECTION_PARAMETER_REFERRALS_HANDLING_METHOD );
+ assertEquals( ReferralHandlingMethod.IGNORE.ordinal(), referralsHandlingMethodOrdinal );
+
+ // create the referral entry
+ createReferralEntry();
+
+ // expand ou=system, the referral must be ignored, no referral dialog
+ // expected
+ SWTBotTree browserTree = SWTBotUtils.getLdapBrowserTree( bot );
+ SWTBotTreeItem systemNode = SWTBotUtils.selectEntry( bot, browserTree, true, "DIT", "Root DSE", "ou=system" );
+
+ // ensure that the referral entry is not visible
+ SWTBotTreeItem referralNode1 = null;
+ try
+ {
+ referralNode1 = systemNode.getNode( "ldap://localhost:" + ldapService.getPort() + "/ou=users,ou=system" );
+ }
+ catch ( WidgetNotFoundException wnfe )
+ {
+ // that is expected
+ }
+ assertNull( referralNode1 );
+ SWTBotTreeItem referralNode2 = null;
+ try
+ {
+ referralNode2 = systemNode.getNode( "cn=referralDialogTest" );
+ }
+ catch ( WidgetNotFoundException wnfe )
+ {
+ // that is expected
+ }
+ assertNull( referralNode2 );
+ }
+
+
+ /**
+ * Tests manage referral entry by setting the connection property to MANAGE.
+ *
+ * @throws Exception
+ * the exception
+ */
+ public void testBrowseAndManageReferralEntry() throws Exception
+ {
+ // ensure that referrals handling method is MANAGE
+ connection.getConnectionParameter().setExtendedIntProperty(
+ IBrowserConnection.CONNECTION_PARAMETER_REFERRALS_HANDLING_METHOD, ReferralHandlingMethod.MANAGE.ordinal() );
+ int referralsHandlingMethodOrdinal = connection.getConnectionParameter().getExtendedIntProperty(
+ IBrowserConnection.CONNECTION_PARAMETER_REFERRALS_HANDLING_METHOD );
+ assertEquals( ReferralHandlingMethod.MANAGE.ordinal(), referralsHandlingMethodOrdinal );
+
+ // create the referral entry
+ createReferralEntry();
+
+ // expand ou=system, the referral is managed, no referral dialog
+ // expected
+ SWTBotTree browserTree = SWTBotUtils.getLdapBrowserTree( bot );
+ SWTBotTreeItem systemNode = SWTBotUtils.selectEntry( bot, browserTree, true, "DIT", "Root DSE", "ou=system" );
+
+ // ensure that the referral entry is visible
+ SWTBotTreeItem referralNode = systemNode.getNode( "cn=referralDialogTest" );
+ assertNotNull( referralNode );
+ SWTBotUtils.selectEntry( bot, browserTree, false, "DIT", "Root DSE", "ou=system", "cn=referralDialogTest" );
+ }
+
+
+ private void createReferralEntry() throws Exception
+ {
+ ServerEntry entry = new DefaultServerEntry( rootDSE.getDirectoryService().getRegistries() );
+ entry.setDn( new LdapDN( "cn=referralDialogTest,ou=system" ) );
+ entry.add( "objectClass", "top", "referral", "extensibleObject" );
+ entry.add( "cn", "referralDialogTest" );
+ entry.add( "ref", "ldap://localhost:" + ldapService.getPort() + "/ou=users,ou=system" );
+ rootDSE.add( entry );
+ }
}
Modified: directory/studio/trunk/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/RenameEntryDialogTest.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/RenameEntryDialogTest.java?rev=748537&r1=748536&r2=748537&view=diff
==============================================================================
--- directory/studio/trunk/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/RenameEntryDialogTest.java (original)
+++ directory/studio/trunk/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/RenameEntryDialogTest.java Fri Feb 27 14:21:08 2009
@@ -20,61 +20,68 @@
package org.apache.directory.studio.test.integration.ui;
+
import org.apache.directory.server.unit.AbstractServerTest;
import org.eclipse.swtbot.eclipse.finder.SWTEclipseBot;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
+
/**
* Tests the rename entry dialog.
*
- * @author <a href="mailto:dev@directory.apache.org">Apache Directory
- * Project</a>
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev$, $Date$
*/
-public class RenameEntryDialogTest extends AbstractServerTest {
- private SWTEclipseBot bot;
-
- protected void setUp() throws Exception {
- super.setUp();
- super.loadTestLdif(true);
- bot = new SWTEclipseBot();
- SWTBotUtils.openLdapPerspective(bot);
- SWTBotUtils.createTestConnection(bot, "RenameEntryDialogTest",
- ldapService.getPort());
- }
-
- protected void tearDown() throws Exception {
- SWTBotUtils.deleteTestConnections();
- bot = null;
- super.tearDown();
- }
-
- /**
- * Test for DIRSTUDIO-318.
- *
- * Renames a multi-valued RDN by changing both RDN attributes.
- *
- * @throws Exception
- * the exception
- */
- public void testRenameMultiValuedRdn() throws Exception {
- final SWTBotTree browserTree = SWTBotUtils.getLdapBrowserTree(bot);
-
- SWTBotUtils.selectEntry(bot, browserTree, false, "DIT", "Root DSE",
- "ou=system", "ou=users", "cn=Barbara Jensen+uid=bjensen");
-
- bot.sleep(2000);
- SWTBotMenu contextMenu = browserTree.contextMenu("Rename Entry...");
- contextMenu.click();
-
- bot.text("Barbara Jensen").setText("Babs Jensen");
- bot.text("bjensen").setText("babsjens");
- bot.button("OK").click();
-
- // ensure that the entry with the new name exists
- SWTBotUtils.selectEntry(bot, browserTree, false, "DIT", "Root DSE",
- "ou=system", "ou=users", "cn=Babs Jensen+uid=babsjens");
- }
+public class RenameEntryDialogTest extends AbstractServerTest
+{
+ private SWTEclipseBot bot;
+
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ super.loadTestLdif( true );
+ bot = new SWTEclipseBot();
+ SWTBotUtils.openLdapPerspective( bot );
+ SWTBotUtils.createTestConnection( bot, "RenameEntryDialogTest", ldapService.getPort() );
+ }
+
+
+ protected void tearDown() throws Exception
+ {
+ SWTBotUtils.deleteTestConnections();
+ bot = null;
+ super.tearDown();
+ }
+
+
+ /**
+ * Test for DIRSTUDIO-318.
+ *
+ * Renames a multi-valued RDN by changing both RDN attributes.
+ *
+ * @throws Exception
+ * the exception
+ */
+ public void testRenameMultiValuedRdn() throws Exception
+ {
+ final SWTBotTree browserTree = SWTBotUtils.getLdapBrowserTree( bot );
+
+ SWTBotUtils.selectEntry( bot, browserTree, false, "DIT", "Root DSE", "ou=system", "ou=users",
+ "cn=Barbara Jensen+uid=bjensen" );
+
+ bot.sleep( 2000 );
+ SWTBotMenu contextMenu = browserTree.contextMenu( "Rename Entry..." );
+ contextMenu.click();
+
+ bot.text( "Barbara Jensen" ).setText( "Babs Jensen" );
+ bot.text( "bjensen" ).setText( "babsjens" );
+ bot.button( "OK" ).click();
+
+ // ensure that the entry with the new name exists
+ SWTBotUtils.selectEntry( bot, browserTree, false, "DIT", "Root DSE", "ou=system", "ou=users",
+ "cn=Babs Jensen+uid=babsjens" );
+ }
}
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=748537&r1=748536&r2=748537&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 Fri Feb 27 14:21:08 2009
@@ -20,6 +20,7 @@
package org.apache.directory.studio.test.integration.ui;
+
import static org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable.syncExec;
import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.widgetOfType;
import static org.hamcrest.Matchers.anything;
@@ -60,433 +61,490 @@
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
+
/**
* Helpers for using SWTBot.
*
- * @author <a href="mailto:dev@directory.apache.org">Apache Directory
- * Project</a>
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev$, $Date$
*/
-public class SWTBotUtils {
+public class SWTBotUtils
+{
- /**
- * Opens the LDAP perspective.
- *
- * @param bot
- * the bot
- *
- * @throws Exception
- * the exception
- */
- public static void openLdapPerspective(final SWTEclipseBot eBot)
- throws Exception {
- // optimization: only open LDAP perspective if not yet opened
- try {
- if (eBot.view("Connections") != null) {
- // LDAP perspective already opened
- return;
- }
- } catch (Exception e) {
- // no 'Connections' view, continue to open the LDAP perspective
- }
-
- // open "Open Perspective" dialog
- SWTBotMenu windowMenu = eBot.menu("Window");
- windowMenu.click();
- SWTBotMenu perspectiveMenu = windowMenu.menu("Open Perspective");
- perspectiveMenu.click();
- SWTBotMenu otherMenu = windowMenu.menu("Other...");
- otherMenu.click();
-
- // select "LDAP" perspective
- SWTBotTable table = eBot.table();
- table.select("LDAP");
-
- // press "OK"
- SWTBotButton okButton = eBot.button("OK");
- okButton.click();
-
- // wait till Connections view become visible
- eBot.waitUntil(new DefaultCondition() {
- public boolean test() throws Exception {
- return eBot.view("Connections") != null;
- }
-
- public String getFailureMessage() {
- return "Could not find widget";
- }
- });
-
- // close welcome view, if it is there
- try {
- eBot.view("Welcome").close();
- } catch (Exception e) {
- }
- }
-
- /**
- * Creates the test connection.
- *
- * @param bot
- * the bot
- * @param name
- * the name of the connection
- * @param port
- * the port to use
- *
- * @return the connection
- *
- * @throws Exception
- * the exception
- */
- public static Connection createTestConnection(SWTEclipseBot bot,
- String name, int port) throws Exception {
- SWTBotTree connectionsTree = getConnectionsTree(bot);
-
- ConnectionManager connectionManager = ConnectionCorePlugin.getDefault()
- .getConnectionManager();
- ConnectionParameter connectionParameter = new ConnectionParameter();
- connectionParameter.setName(name);
- connectionParameter.setHost("localhost");
- connectionParameter.setPort(port);
- 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());
-
- connectionsTree.select(name);
- // new OpenConnectionsJob( connection ).execute();
-
- Thread.sleep(1000);
- return connection;
- }
-
- /**
- * Deletes the test connection.
- */
- public static void deleteTestConnections() {
- ConnectionManager connectionManager = ConnectionCorePlugin.getDefault()
- .getConnectionManager();
- for (Connection connection : connectionManager.getConnections()) {
- connectionManager.removeConnection(connection);
- }
- }
-
- /**
- * Gets the connections tree.
- *
- * @param bot
- * the bot
- *
- * @return the connections tree
- *
- * @throws Exception
- * the exception
- */
- public static SWTBotTree getConnectionsTree(SWTEclipseBot bot)
- throws Exception {
- SWTBotView view = bot.view("Connections");
- view.show();
-
- Tree tree = (Tree) bot.widget(widgetOfType(Tree.class), view
- .getWidget());
- return new SWTBotTree(tree);
- }
-
- /**
- * Gets the ldap browser tree.
- *
- * @param bot
- * the bot
- *
- * @return the ldap browser tree
- *
- * @throws Exception
- * the exception
- */
- public static SWTBotTree getLdapBrowserTree(SWTEclipseBot bot)
- throws Exception {
- SWTBotView view = bot.view("LDAP Browser");
- view.show();
-
- Tree tree = (Tree) bot.widget(widgetOfType(Tree.class), view
- .getWidget());
- return new SWTBotTree(tree);
- }
-
- /**
- * Gets the entry editor tree.
- *
- * @param bot
- * the bot
- *
- * @return the entry editor tree
- *
- * @throws Exception
- * the exception
- */
- public static SWTBotTree getEntryEditorTree(final SWTEclipseBot bot)
- throws Exception {
- Tree tree = UIThreadRunnable.syncExec(new WidgetResult<Tree>() {
- public Tree run() {
- IWorkbench workbench = PlatformUI.getWorkbench();
- IWorkbenchWindow activeWorkbenchWindow = workbench
- .getActiveWorkbenchWindow();
- IWorkbenchPage[] pages = activeWorkbenchWindow.getPages();
- for (int i = 0; i < pages.length; i++) {
- IWorkbenchPage page = pages[i];
- IEditorReference[] editorReferences = page
- .getEditorReferences();
- for (int j = 0; j < editorReferences.length; j++) {
- IEditorReference editorReference = editorReferences[j];
- if (editorReference.getName().equals("Entry Editor")) {
- DummyEditor editor = new DummyEditor(
- editorReference, bot);
- Tree tree = (Tree) bot.widget(
- widgetOfType(Tree.class), editor.widget);
- return tree;
-
- }
- }
- }
- throw new WidgetNotFoundException(
- "Could not find Entry Editor tree");
- }
- });
- return new SWTBotTree(tree);
- }
-
- static class DummyEditor extends SWTBotWorkbenchPart<IEditorReference> {
- public Widget widget;
-
- public DummyEditor(IEditorReference editorReference, SWTEclipseBot bot) {
- super(editorReference, bot);
- widget = findWidget(anything());
- }
-
- public void setFocus() {
- syncExec(new VoidResult() {
- public void run() {
- ((Control) widget).setFocus();
- }
- });
- }
-
- public boolean isActive() {
- return true;
- }
- }
-
- /**
- * 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 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 VoidResult() {
- public void run() {
- menu.click();
- }
- });
-
- if (waitCondition != null) {
- bot.waitUntil(waitCondition);
- }
- }
-
- /**
- * Clicks a tree item asynchronously and waits till the given condition is
- * fulfilled.
- *
- * @param bot
- * the SWT bot
- * @param item
- * the tree item to click
- * @param waitCondition
- * the condition to wait for, may be null
- *
- * @throws TimeoutException
- * the timeout exception
- */
- public static void asyncClick(final SWTEclipseBot bot,
- final SWTBotTreeItem item, final ICondition waitCondition)
- throws TimeoutException {
- UIThreadRunnable.asyncExec(bot.getDisplay(), new VoidResult() {
- public void run() {
- item.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.
- * This is necessary to avoid race conditions.
- *
- * @param bot
- * the SWT bot
- * @param tree
- * the browser tree
- * @param expandChild
- * true to expand the child entry
- * @param path
- * the path to the entry
- *
- * @return the selected entry as SWTBotTreeItem
- *
- * @throws Exception
- * the exception
- */
- public static SWTBotTreeItem selectEntry(final SWTEclipseBot bot,
- final SWTBotTree tree, final boolean expandChild,
- final String... path) throws Exception {
- List<String> pathList = new ArrayList<String>(Arrays.asList(path));
- SWTBotTreeItem entry = null;
-
- while (!pathList.isEmpty()) {
- String currentPath = pathList.remove(0);
-
- if (entry == null) {
- entry = tree.getTreeItem(currentPath);
- } else {
- // adjust current path, because the label is decorated with the
- // number of children
- currentPath = adjustNodeName(entry, currentPath);
- entry = entry.getNode(currentPath);
- }
-
- final SWTBotTreeItem tempEntry = entry;
- UIThreadRunnable.asyncExec(bot.getDisplay(), new VoidResult() {
- public void run() {
- tempEntry.select();
- }
- });
-
- if (!pathList.isEmpty() || expandChild) {
- // expand entry and wait till
- // - children are displayed
- // - next child is visible
- final String nextName = !pathList.isEmpty() ? pathList.get(0)
- : null;
- expandEntry(bot, entry, nextName);
- }
-
- }
- return entry;
- }
-
- /**
- * Expands the entry. Takes care that all attributes and child entries are
- * initialized so that there are no pending background actions and event
- * notifications. This is necessary to avoid race conditions.
- *
- * @param bot
- * the bot
- * @param entry
- * the entry to expand
- * @param nextName
- * the name of the entry that must become visible, may be null
- *
- * @throws Exception
- * the exception
- */
- public static void expandEntry(final SWTEclipseBot bot,
- final SWTBotTreeItem entry, final String nextName) throws Exception {
- UIThreadRunnable.asyncExec(bot.getDisplay(), new VoidResult() {
- public void run() {
- entry.expand();
- }
- });
-
- bot.waitUntil(new DefaultCondition() {
- public boolean test() throws Exception {
- if (nextName != null) {
- String adjustedNodeName = nextName != null ? adjustNodeName(
- entry, nextName)
- : null;
- SWTBotTreeItem node = entry.getNode(adjustedNodeName);
- if (node == null) {
- return false;
- }
- }
- return !entry.getNodes().contains("Fetching Entries...");
- }
-
- public String getFailureMessage() {
- return "Could not find entry " + entry.getText() + " -> "
- + nextName;
- }
- });
- }
-
- private static String adjustNodeName(SWTBotTreeItem child, String nodeName) {
- List<String> nodes = child.getNodes();
- for (String node : nodes) {
- if (node.toUpperCase().startsWith(nodeName.toUpperCase())) {
- return node;
- }
- }
- return null;
- }
+ /**
+ * Opens the LDAP perspective.
+ *
+ * @param bot
+ * the bot
+ *
+ * @throws Exception
+ * the exception
+ */
+ public static void openLdapPerspective( final SWTEclipseBot eBot ) throws Exception
+ {
+ // optimization: only open LDAP perspective if not yet opened
+ try
+ {
+ if ( eBot.view( "Connections" ) != null )
+ {
+ // LDAP perspective already opened
+ return;
+ }
+ }
+ catch ( Exception e )
+ {
+ // no 'Connections' view, continue to open the LDAP perspective
+ }
+
+ // open "Open Perspective" dialog
+ SWTBotMenu windowMenu = eBot.menu( "Window" );
+ windowMenu.click();
+ SWTBotMenu perspectiveMenu = windowMenu.menu( "Open Perspective" );
+ perspectiveMenu.click();
+ SWTBotMenu otherMenu = windowMenu.menu( "Other..." );
+ otherMenu.click();
+
+ // select "LDAP" perspective
+ SWTBotTable table = eBot.table();
+ table.select( "LDAP" );
+
+ // press "OK"
+ SWTBotButton okButton = eBot.button( "OK" );
+ okButton.click();
+
+ // wait till Connections view become visible
+ eBot.waitUntil( new DefaultCondition()
+ {
+ public boolean test() throws Exception
+ {
+ return eBot.view( "Connections" ) != null;
+ }
+
+
+ public String getFailureMessage()
+ {
+ return "Could not find widget";
+ }
+ } );
+
+ // close welcome view, if it is there
+ try
+ {
+ eBot.view( "Welcome" ).close();
+ }
+ catch ( Exception e )
+ {
+ }
+ }
+
+
+ /**
+ * Creates the test connection.
+ *
+ * @param bot
+ * the bot
+ * @param name
+ * the name of the connection
+ * @param port
+ * the port to use
+ *
+ * @return the connection
+ *
+ * @throws Exception
+ * the exception
+ */
+ public static Connection createTestConnection( SWTEclipseBot bot, String name, int port ) throws Exception
+ {
+ SWTBotTree connectionsTree = getConnectionsTree( bot );
+
+ ConnectionManager connectionManager = ConnectionCorePlugin.getDefault().getConnectionManager();
+ ConnectionParameter connectionParameter = new ConnectionParameter();
+ connectionParameter.setName( name );
+ connectionParameter.setHost( "localhost" );
+ connectionParameter.setPort( port );
+ 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() );
+
+ connectionsTree.select( name );
+ // new OpenConnectionsJob( connection ).execute();
+
+ Thread.sleep( 1000 );
+ return connection;
+ }
+
+
+ /**
+ * Deletes the test connection.
+ */
+ public static void deleteTestConnections()
+ {
+ ConnectionManager connectionManager = ConnectionCorePlugin.getDefault().getConnectionManager();
+ for ( Connection connection : connectionManager.getConnections() )
+ {
+ connectionManager.removeConnection( connection );
+ }
+ }
+
+
+ /**
+ * Gets the connections tree.
+ *
+ * @param bot
+ * the bot
+ *
+ * @return the connections tree
+ *
+ * @throws Exception
+ * the exception
+ */
+ public static SWTBotTree getConnectionsTree( SWTEclipseBot bot ) throws Exception
+ {
+ SWTBotView view = bot.view( "Connections" );
+ view.show();
+
+ Tree tree = ( Tree ) bot.widget( widgetOfType( Tree.class ), view.getWidget() );
+ return new SWTBotTree( tree );
+ }
+
+
+ /**
+ * Gets the ldap browser tree.
+ *
+ * @param bot
+ * the bot
+ *
+ * @return the ldap browser tree
+ *
+ * @throws Exception
+ * the exception
+ */
+ public static SWTBotTree getLdapBrowserTree( SWTEclipseBot bot ) throws Exception
+ {
+ SWTBotView view = bot.view( "LDAP Browser" );
+ view.show();
+
+ Tree tree = ( Tree ) bot.widget( widgetOfType( Tree.class ), view.getWidget() );
+ return new SWTBotTree( tree );
+ }
+
+
+ /**
+ * Gets the entry editor tree.
+ *
+ * @param bot
+ * the bot
+ *
+ * @return the entry editor tree
+ *
+ * @throws Exception
+ * the exception
+ */
+ public static SWTBotTree getEntryEditorTree( final SWTEclipseBot bot ) throws Exception
+ {
+ Tree tree = UIThreadRunnable.syncExec( new WidgetResult<Tree>()
+ {
+ public Tree run()
+ {
+ IWorkbench workbench = PlatformUI.getWorkbench();
+ IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow();
+ IWorkbenchPage[] pages = activeWorkbenchWindow.getPages();
+ for ( int i = 0; i < pages.length; i++ )
+ {
+ IWorkbenchPage page = pages[i];
+ IEditorReference[] editorReferences = page.getEditorReferences();
+ for ( int j = 0; j < editorReferences.length; j++ )
+ {
+ IEditorReference editorReference = editorReferences[j];
+ if ( editorReference.getName().equals( "Entry Editor" ) )
+ {
+ DummyEditor editor = new DummyEditor( editorReference, bot );
+ Tree tree = ( Tree ) bot.widget( widgetOfType( Tree.class ), editor.widget );
+ return tree;
+
+ }
+ }
+ }
+ throw new WidgetNotFoundException( "Could not find Entry Editor tree" );
+ }
+ } );
+ return new SWTBotTree( tree );
+ }
+
+ static class DummyEditor extends SWTBotWorkbenchPart<IEditorReference>
+ {
+ public Widget widget;
+
+
+ public DummyEditor( IEditorReference editorReference, SWTEclipseBot bot )
+ {
+ super( editorReference, bot );
+ widget = findWidget( anything() );
+ }
+
+
+ public void setFocus()
+ {
+ syncExec( new VoidResult()
+ {
+ public void run()
+ {
+ ( ( Control ) widget ).setFocus();
+ }
+ } );
+ }
+
+
+ public boolean isActive()
+ {
+ return true;
+ }
+ }
+
+
+ /**
+ * 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 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 VoidResult()
+ {
+ public void run()
+ {
+ menu.click();
+ }
+ } );
+
+ if ( waitCondition != null )
+ {
+ bot.waitUntil( waitCondition );
+ }
+ }
+
+
+ /**
+ * Clicks a tree item asynchronously and waits till the given condition is
+ * fulfilled.
+ *
+ * @param bot
+ * the SWT bot
+ * @param item
+ * the tree item to click
+ * @param waitCondition
+ * the condition to wait for, may be null
+ *
+ * @throws TimeoutException
+ * the timeout exception
+ */
+ public static void asyncClick( final SWTEclipseBot bot, final SWTBotTreeItem item, final ICondition waitCondition )
+ throws TimeoutException
+ {
+ UIThreadRunnable.asyncExec( bot.getDisplay(), new VoidResult()
+ {
+ public void run()
+ {
+ item.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.
+ * This is necessary to avoid race conditions.
+ *
+ * @param bot
+ * the SWT bot
+ * @param tree
+ * the browser tree
+ * @param expandChild
+ * true to expand the child entry
+ * @param path
+ * the path to the entry
+ *
+ * @return the selected entry as SWTBotTreeItem
+ *
+ * @throws Exception
+ * the exception
+ */
+ public static SWTBotTreeItem selectEntry( final SWTEclipseBot bot, final SWTBotTree tree,
+ final boolean expandChild, final String... path ) throws Exception
+ {
+ List<String> pathList = new ArrayList<String>( Arrays.asList( path ) );
+ SWTBotTreeItem entry = null;
+
+ while ( !pathList.isEmpty() )
+ {
+ String currentPath = pathList.remove( 0 );
+
+ if ( entry == null )
+ {
+ entry = tree.getTreeItem( currentPath );
+ }
+ else
+ {
+ // adjust current path, because the label is decorated with the
+ // number of children
+ currentPath = adjustNodeName( entry, currentPath );
+ entry = entry.getNode( currentPath );
+ }
+
+ final SWTBotTreeItem tempEntry = entry;
+ UIThreadRunnable.asyncExec( bot.getDisplay(), new VoidResult()
+ {
+ public void run()
+ {
+ tempEntry.select();
+ }
+ } );
+
+ if ( !pathList.isEmpty() || expandChild )
+ {
+ // expand entry and wait till
+ // - children are displayed
+ // - next child is visible
+ final String nextName = !pathList.isEmpty() ? pathList.get( 0 ) : null;
+ expandEntry( bot, entry, nextName );
+ }
+
+ }
+ return entry;
+ }
+
+
+ /**
+ * Expands the entry. Takes care that all attributes and child entries are
+ * initialized so that there are no pending background actions and event
+ * notifications. This is necessary to avoid race conditions.
+ *
+ * @param bot
+ * the bot
+ * @param entry
+ * the entry to expand
+ * @param nextName
+ * the name of the entry that must become visible, may be null
+ *
+ * @throws Exception
+ * the exception
+ */
+ public static void expandEntry( final SWTEclipseBot bot, final SWTBotTreeItem entry, final String nextName )
+ throws Exception
+ {
+ UIThreadRunnable.asyncExec( bot.getDisplay(), new VoidResult()
+ {
+ public void run()
+ {
+ entry.expand();
+ }
+ } );
+
+ bot.waitUntil( new DefaultCondition()
+ {
+ public boolean test() throws Exception
+ {
+ if ( nextName != null )
+ {
+ String adjustedNodeName = nextName != null ? adjustNodeName( entry, nextName ) : null;
+ SWTBotTreeItem node = entry.getNode( adjustedNodeName );
+ if ( node == null )
+ {
+ return false;
+ }
+ }
+ return !entry.getNodes().contains( "Fetching Entries..." );
+ }
+
+
+ public String getFailureMessage()
+ {
+ return "Could not find entry " + entry.getText() + " -> " + nextName;
+ }
+ } );
+ }
+
+
+ private static String adjustNodeName( SWTBotTreeItem child, String nodeName )
+ {
+ List<String> nodes = child.getNodes();
+ for ( String node : nodes )
+ {
+ if ( node.toUpperCase().startsWith( nodeName.toUpperCase() ) )
+ {
+ return node;
+ }
+ }
+ return null;
+ }
}
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=748537&r1=748536&r2=748537&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 Fri Feb 27 14:21:08 2009
@@ -20,6 +20,7 @@
package org.apache.directory.studio.test.integration.ui;
+
import org.apache.directory.server.unit.AbstractServerTest;
import org.eclipse.swt.graphics.DeviceData;
import org.eclipse.swtbot.eclipse.finder.SWTEclipseBot;
@@ -30,163 +31,187 @@
import org.eclipse.swtbot.swt.finder.widgets.SWTBotText;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
+
/**
* Tests allocation of SWT Resources.
*
- * @author <a href="mailto:dev@directory.apache.org">Apache Directory
- * Project</a>
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev$, $Date$
*/
-public class SwtResourcesTest extends AbstractServerTest {
- private SWTEclipseBot bot;
-
- protected void setUp() throws Exception {
- super.setUp();
- bot = new SWTEclipseBot();
- SWTBotUtils.openLdapPerspective(bot);
- SWTBotUtils.createTestConnection(bot, "SwtResourcesTest", ldapService
- .getPort());
- }
-
- protected void tearDown() throws Exception {
- SWTBotUtils.deleteTestConnections();
- bot = null;
- super.tearDown();
- }
-
- /**
- * Test for DIRSTUDIO-319.
- *
- * Creates multiple entries using the New Entry wizard. Checks that we don't
- * allocate too much SWT resources during the run.
- *
- * @throws Exception
- * the exception
- */
- public void testSwtResourcesDelta() throws Exception {
- SWTBotTree browserTree = SWTBotUtils.getLdapBrowserTree(bot);
-
- // run the new entry wizard once to ensure all SWT resources are created
- createAndDeleteEntry(browserTree, "testSwtResourcesDelta" + 0);
-
- // remember the SWT objects before the run
- int beforeObjectCount = getSwtObjectCount();
-
- // now lets run the new entry wizard it several times
- for (int i = 1; i < 25; i++) {
- createAndDeleteEntry(browserTree, "testSwtResourcesDelta" + i);
- }
-
- // get the SWT objects after the run
- int afterObjectCount = getSwtObjectCount();
-
- // we expect not more than 10 additional SWT objects
- assertTrue(
- "Too many SWT resources were allocated in testSwtResourcesDelta: before="
- + beforeObjectCount + ", after=" + afterObjectCount,
- afterObjectCount - beforeObjectCount < 10);
- }
-
- /**
- * Ensure that we have not allocated more the 1000 SWT resources during the
- * complete test suite.
- *
- * 1000 is not a fix number but it is a good starting point.
- *
- * @throws Exception
- * the exception
- */
- public void testSwtResourcesCount() throws Exception {
- int swtObjectCount = getSwtObjectCount();
- assertTrue("Too many SWT resources were allocated: " + swtObjectCount,
- swtObjectCount < 1000);
- }
-
- private int getSwtObjectCount() {
- return UIThreadRunnable.syncExec(bot.getDisplay(), new IntResult() {
- public Integer run() {
- DeviceData info = bot.getDisplay().getDeviceData();
- if (!info.tracking) {
- fail("To run this test options 'org.eclipse.ui/debug' and 'org.eclipse.ui/trace/graphics' must be true.");
- }
- return info.objects.length;
- }
- });
- }
-
- private void createAndDeleteEntry(final SWTBotTree browserTree,
- final String name) throws Exception {
- SWTBotUtils.selectEntry(bot, browserTree, true, "DIT", "Root DSE",
- "ou=system");
- 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();
-
- 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);
- SWTBotUtils.asyncClick(bot, bot.button("Next >"),
- new DefaultCondition() {
- public boolean test() throws Exception {
- return bot.button("Finish").isEnabled();
- }
-
- public String getFailureMessage() {
- return "Finish button is not enabled";
- }
- });
-
- // click finish to create the entry
- SWTBotUtils.asyncClick(bot, bot.button("Finish"),
- new DefaultCondition() {
- public boolean test() throws Exception {
- return browserTree.selection().get(0).get(0)
- .startsWith("o=" + name);
- }
-
- public String getFailureMessage() {
- return "Could not select 'o=" + name + "'";
- }
- });
-
- // delete the entry
- SWTBotUtils.selectEntry(bot, browserTree, false, "DIT", "Root DSE",
- "ou=system", "o=" + name);
- SWTBotUtils.asyncClick(bot, browserTree.contextMenu("Delete Entry"),
- new DefaultCondition() {
- public boolean test() throws Exception {
- return bot.shell("Delete Entry") != null;
- }
-
- public String getFailureMessage() {
- return "Could not find dialog 'New Entry'";
- }
- });
- SWTBotUtils.asyncClick(bot, bot.button("OK"), new DefaultCondition() {
- public boolean test() throws Exception {
- return browserTree.selection().get(0).get(0).startsWith(
- "ou=system");
- }
-
- public String getFailureMessage() {
- return "Could not select 'ou=system'";
- }
- });
- }
+public class SwtResourcesTest extends AbstractServerTest
+{
+ private SWTEclipseBot bot;
+
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ bot = new SWTEclipseBot();
+ SWTBotUtils.openLdapPerspective( bot );
+ SWTBotUtils.createTestConnection( bot, "SwtResourcesTest", ldapService.getPort() );
+ }
+
+
+ protected void tearDown() throws Exception
+ {
+ SWTBotUtils.deleteTestConnections();
+ bot = null;
+ super.tearDown();
+ }
+
+
+ /**
+ * Test for DIRSTUDIO-319.
+ *
+ * Creates multiple entries using the New Entry wizard. Checks that we don't
+ * allocate too much SWT resources during the run.
+ *
+ * @throws Exception
+ * the exception
+ */
+ public void testSwtResourcesDelta() throws Exception
+ {
+ SWTBotTree browserTree = SWTBotUtils.getLdapBrowserTree( bot );
+
+ // run the new entry wizard once to ensure all SWT resources are created
+ createAndDeleteEntry( browserTree, "testSwtResourcesDelta" + 0 );
+
+ // remember the SWT objects before the run
+ int beforeObjectCount = getSwtObjectCount();
+
+ // now lets run the new entry wizard it several times
+ for ( int i = 1; i < 25; i++ )
+ {
+ createAndDeleteEntry( browserTree, "testSwtResourcesDelta" + i );
+ }
+
+ // get the SWT objects after the run
+ int afterObjectCount = getSwtObjectCount();
+
+ // we expect not more than 10 additional SWT objects
+ assertTrue( "Too many SWT resources were allocated in testSwtResourcesDelta: before=" + beforeObjectCount
+ + ", after=" + afterObjectCount, afterObjectCount - beforeObjectCount < 10 );
+ }
+
+
+ /**
+ * Ensure that we have not allocated more the 1000 SWT resources during the
+ * complete test suite.
+ *
+ * 1000 is not a fix number but it is a good starting point.
+ *
+ * @throws Exception
+ * the exception
+ */
+ public void testSwtResourcesCount() throws Exception
+ {
+ int swtObjectCount = getSwtObjectCount();
+ assertTrue( "Too many SWT resources were allocated: " + swtObjectCount, swtObjectCount < 1000 );
+ }
+
+
+ private int getSwtObjectCount()
+ {
+ return UIThreadRunnable.syncExec( bot.getDisplay(), new IntResult()
+ {
+ public Integer run()
+ {
+ DeviceData info = bot.getDisplay().getDeviceData();
+ if ( !info.tracking )
+ {
+ fail( "To run this test options 'org.eclipse.ui/debug' and 'org.eclipse.ui/trace/graphics' must be true." );
+ }
+ return info.objects.length;
+ }
+ } );
+ }
+
+
+ private void createAndDeleteEntry( final SWTBotTree browserTree, final String name ) throws Exception
+ {
+ SWTBotUtils.selectEntry( bot, browserTree, true, "DIT", "Root DSE", "ou=system" );
+ 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();
+
+ 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 );
+ SWTBotUtils.asyncClick( bot, bot.button( "Next >" ), new DefaultCondition()
+ {
+ public boolean test() throws Exception
+ {
+ return bot.button( "Finish" ).isEnabled();
+ }
+
+
+ public String getFailureMessage()
+ {
+ return "Finish button is not enabled";
+ }
+ } );
+
+ // click finish to create the entry
+ SWTBotUtils.asyncClick( bot, bot.button( "Finish" ), new DefaultCondition()
+ {
+ public boolean test() throws Exception
+ {
+ return browserTree.selection().get( 0 ).get( 0 ).startsWith( "o=" + name );
+ }
+
+
+ public String getFailureMessage()
+ {
+ return "Could not select 'o=" + name + "'";
+ }
+ } );
+
+ // delete the entry
+ SWTBotUtils.selectEntry( bot, browserTree, false, "DIT", "Root DSE", "ou=system", "o=" + name );
+ SWTBotUtils.asyncClick( bot, browserTree.contextMenu( "Delete Entry" ), new DefaultCondition()
+ {
+ public boolean test() throws Exception
+ {
+ return bot.shell( "Delete Entry" ) != null;
+ }
+
+
+ public String getFailureMessage()
+ {
+ return "Could not find dialog 'New Entry'";
+ }
+ } );
+ SWTBotUtils.asyncClick( bot, bot.button( "OK" ), new DefaultCondition()
+ {
+ public boolean test() throws Exception
+ {
+ return browserTree.selection().get( 0 ).get( 0 ).startsWith( "ou=system" );
+ }
+
+
+ public String getFailureMessage()
+ {
+ return "Could not select 'ou=system'";
+ }
+ } );
+ }
}