directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r926056 - in /directory/studio/trunk/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots: BrowserViewBot.java ReferralDialogBot.java SearchResultEditorBot.java utils/ utils/JobWatcher.java
Date Mon, 22 Mar 2010 12:59:03 GMT
Author: seelmann
Date: Mon Mar 22 12:59:03 2010
New Revision: 926056

URL: http://svn.apache.org/viewvc?rev=926056&view=rev
Log:
added a job watcher with wait conditions

Added:
    directory/studio/trunk/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/utils/
    directory/studio/trunk/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/utils/JobWatcher.java
Modified:
    directory/studio/trunk/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/BrowserViewBot.java
    directory/studio/trunk/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/ReferralDialogBot.java
    directory/studio/trunk/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/SearchResultEditorBot.java

Modified: directory/studio/trunk/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/BrowserViewBot.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/BrowserViewBot.java?rev=926056&r1=926055&r2=926056&view=diff
==============================================================================
--- directory/studio/trunk/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/BrowserViewBot.java
(original)
+++ directory/studio/trunk/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/BrowserViewBot.java
Mon Mar 22 12:59:03 2010
@@ -20,7 +20,9 @@
 package org.apache.directory.studio.test.integration.ui.bots;
 
 
+import org.apache.directory.studio.ldapbrowser.core.BrowserCoreMessages;
 import org.apache.directory.studio.test.integration.ui.ContextMenuHelper;
+import org.apache.directory.studio.test.integration.ui.bots.utils.JobWatcher;
 import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
 import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
 
@@ -67,7 +69,9 @@ public class BrowserViewBot
 
     public void expandEntry( String... path )
     {
+        JobWatcher watcher = new JobWatcher( BrowserCoreMessages.jobs__init_entries_title_subonly
);
         browserBot.expandEntry( path );
+        watcher.waitUntilDone();
     }
 
 
@@ -149,7 +153,9 @@ public class BrowserViewBot
 
     public void refresh()
     {
+        JobWatcher watcher = new JobWatcher( BrowserCoreMessages.jobs__init_entries_title_subonly
);
         ContextMenuHelper.clickContextMenu( browserBot.getTree(), "Reload Entry" );
+        watcher.waitUntilDone();
     }
 
 

Modified: directory/studio/trunk/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/ReferralDialogBot.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/ReferralDialogBot.java?rev=926056&r1=926055&r2=926056&view=diff
==============================================================================
--- directory/studio/trunk/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/ReferralDialogBot.java
(original)
+++ directory/studio/trunk/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/ReferralDialogBot.java
Mon Mar 22 12:59:03 2010
@@ -20,6 +20,8 @@
 package org.apache.directory.studio.test.integration.ui.bots;
 
 
+import org.apache.directory.studio.ldapbrowser.core.BrowserCoreMessages;
+import org.apache.directory.studio.test.integration.ui.bots.utils.JobWatcher;
 import org.eclipse.swtbot.swt.finder.utils.TableCollection;
 import org.eclipse.swtbot.swt.finder.utils.TableRow;
 
@@ -35,7 +37,9 @@ public class ReferralDialogBot extends D
 
     public void clickOkButton()
     {
+        JobWatcher watcher = new JobWatcher( BrowserCoreMessages.jobs__init_entries_title_subonly
);
         super.clickButton( "OK" );
+        watcher.waitUntilDone();
     }
 
 

Modified: directory/studio/trunk/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/SearchResultEditorBot.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/SearchResultEditorBot.java?rev=926056&r1=926055&r2=926056&view=diff
==============================================================================
--- directory/studio/trunk/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/SearchResultEditorBot.java
(original)
+++ directory/studio/trunk/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/SearchResultEditorBot.java
Mon Mar 22 12:59:03 2010
@@ -26,6 +26,8 @@ import static org.eclipse.swtbot.swt.fin
 import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.withStyle;
 import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.withTooltip;
 
+import org.apache.directory.studio.ldapbrowser.core.BrowserCoreMessages;
+import org.apache.directory.studio.test.integration.ui.bots.utils.JobWatcher;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.widgets.ToolItem;
 import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
@@ -71,11 +73,13 @@ public class SearchResultEditorBot
 
     public void refresh()
     {
+        JobWatcher watcher = new JobWatcher( BrowserCoreMessages.jobs__search_name );
         //bot.toolbarButton( "Search Again (F5)" ).click();
         Matcher matcher = allOf( widgetOfType( ToolItem.class ), withTooltip( "Search Again
(F5)" ), withStyle(
             SWT.PUSH, "SWT.PUSH" ) );
         SWTBotToolbarPushButton button = new SWTBotToolbarPushButton( ( ToolItem ) bot.widget(
matcher, 0 ), matcher );
         button.click();
+        watcher.waitUntilDone();
     }
 
 }

Added: directory/studio/trunk/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/utils/JobWatcher.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/utils/JobWatcher.java?rev=926056&view=auto
==============================================================================
--- directory/studio/trunk/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/utils/JobWatcher.java
(added)
+++ directory/studio/trunk/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/utils/JobWatcher.java
Mon Mar 22 12:59:03 2010
@@ -0,0 +1,120 @@
+/*
+ *  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.bots.utils;
+
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.eclipse.core.runtime.jobs.IJobChangeEvent;
+import org.eclipse.core.runtime.jobs.IJobManager;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.core.runtime.jobs.JobChangeAdapter;
+import org.eclipse.swtbot.swt.finder.SWTBot;
+import org.eclipse.swtbot.swt.finder.waits.DefaultCondition;
+
+
+/**
+ * Helper class that watches particular job. The job is identified by its name.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class JobWatcher
+{
+
+    private final AtomicBoolean done = new AtomicBoolean();
+    private final IJobManager jobManager = Job.getJobManager();
+    private final JobChangeAdapter listener;
+    private final String jobName;
+
+
+    /**
+     * Creates a new instance of JobWatcher.
+     *
+     * @param jobName the name of the watched job
+     */
+    public JobWatcher( final String jobName )
+    {
+        this.jobName = jobName;
+
+        // register a job listener that checks if the job is finished
+        listener = new JobChangeAdapter()
+        {
+
+            public void done( IJobChangeEvent event )
+            {
+                // if the done job has the expected name we are done
+                if ( jobName.equals( event.getJob().getName() ) )
+                {
+                    done.set( true );
+                    jobManager.removeJobChangeListener( listener );
+                }
+            }
+
+        };
+        jobManager.addJobChangeListener( listener );
+    }
+
+
+    /**
+     * Waits until the watched job is done.
+     */
+    public void waitUntilDone()
+    {
+        SWTBot bot = new SWTBot();
+        bot.waitUntil( new DefaultCondition()
+        {
+
+            public boolean test() throws Exception
+            {
+                if ( done.get() )
+                {
+                    return true;
+                }
+
+                // fallback test to check if the expected job
+                // is scheduled at all, otherwise we assume it is done.
+                boolean running = false;
+                Job[] find = jobManager.find( null );
+                for ( Job job : find )
+                {
+                    if ( jobName.equals( job.getName() ) )
+                    {
+                        running = true;
+                        break;
+                    }
+                }
+                if ( !running )
+                {
+                    jobManager.removeJobChangeListener( listener );
+                    return true;
+                }
+
+                return false;
+            }
+
+
+            public String getFailureMessage()
+            {
+                return "Job run too long";
+            }
+        } );
+    }
+}



Mime
View raw message