Author: yzhishko
Date: 2009-10-16 12:15:52 -0400 (Fri, 16 Oct 2009)
New Revision: 18135
Modified:
trunk/jst/tests/org.jboss.tools.jst.ui.bot.test/src/org/jboss/tools/ui/bot/test/JBTSWTBotTestCase.java
Log:
Fix for waitForJobsAccomplished method.
Modified:
trunk/jst/tests/org.jboss.tools.jst.ui.bot.test/src/org/jboss/tools/ui/bot/test/JBTSWTBotTestCase.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.jst.ui.bot.test/src/org/jboss/tools/ui/bot/test/JBTSWTBotTestCase.java 2009-10-16
16:14:07 UTC (rev 18134)
+++
trunk/jst/tests/org.jboss.tools.jst.ui.bot.test/src/org/jboss/tools/ui/bot/test/JBTSWTBotTestCase.java 2009-10-16
16:15:52 UTC (rev 18135)
@@ -2,6 +2,8 @@
import java.io.IOException;
import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
import java.util.Properties;
import org.eclipse.core.runtime.ILogListener;
import org.eclipse.core.runtime.IStatus;
@@ -14,7 +16,7 @@
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
public abstract class JBTSWTBotTestCase extends SWTBotTestCase implements
- ILogListener{
+ ILogListener {
protected static final String BUILDING_WS = "Building workspace";
protected static final String VISUAL_UPDATE = "Visual Editor View Update";
@@ -24,52 +26,58 @@
public static final String PATH_TO_SWT_BOT_PROPERTIES = "SWTBot.properties";
protected SWTJBTBot bot = new SWTJBTBot();
private static int sleepTime = 1000;
-
- /* (non-Javadoc)
- * This static block read properties from
- * org.jboss.tools.ui.bot.test/resources/SWTBot.properties file
- * and set up parameters for SWTBot tests. You may change a number of parameters
- * in static block and their values in property file.
+
+ /*
+ * (non-Javadoc) This static block read properties from
+ * org.jboss.tools.ui.bot.test/resources/SWTBot.properties file and set up
+ * parameters for SWTBot tests. You may change a number of parameters in
+ * static block and their values in property file.
*/
-
+
static {
try {
- InputStream inputStream =
JBTSWTBotTestCase.class.getResourceAsStream("/"+PATH_TO_SWT_BOT_PROPERTIES);
+ InputStream inputStream = JBTSWTBotTestCase.class
+ .getResourceAsStream("/" + PATH_TO_SWT_BOT_PROPERTIES);
SWT_BOT_PROPERTIES = new Properties();
SWT_BOT_PROPERTIES.load(inputStream);
SWTBotPreferences.PLAYBACK_DELAY = Long
- .parseLong(SWT_BOT_PROPERTIES
- .getProperty("SWTBotPreferences.PLAYBACK_DELAY"));
+ .parseLong(SWT_BOT_PROPERTIES
+ .getProperty("SWTBotPreferences.PLAYBACK_DELAY"));
SWTBotPreferences.TIMEOUT = Long.parseLong(SWT_BOT_PROPERTIES
- .getProperty("SWTBotPreferences.TIMEOUT"));
+ .getProperty("SWTBotPreferences.TIMEOUT"));
inputStream.close();
- }
- catch (IOException e) {
- IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Can't load
properties from " + PATH_TO_SWT_BOT_PROPERTIES + " file", e);
+ } catch (IOException e) {
+ IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID,
+ "Can't load properties from " + PATH_TO_SWT_BOT_PROPERTIES
+ + " file", e);
Activator.getDefault().getLog().log(status);
e.printStackTrace();
- }
- catch (IllegalStateException e) {
- IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Property file
" + PATH_TO_SWT_BOT_PROPERTIES + " was not found", e);
+ } catch (IllegalStateException e) {
+ IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID,
+ "Property file " + PATH_TO_SWT_BOT_PROPERTIES
+ + " was not found", e);
Activator.getDefault().getLog().log(status);
e.printStackTrace();
}
-// try {
-// InputStream swtPreferenceIS =
Platform.getBundle(Activator.PLUGIN_ID).getResource(PATH_TO_SWT_BOT_PROPERTIES)
-// .openStream();
-// SWT_BOT_PROPERTIES = new Properties();
-// SWT_BOT_PROPERTIES.load(swtPreferenceIS);
-// SWTBotPreferences.PLAYBACK_DELAY = Long
-// .parseLong(SWT_BOT_PROPERTIES
-// .getProperty("SWTBotPreferences.PLAYBACK_DELAY"));
-// SWTBotPreferences.TIMEOUT = Long.parseLong(SWT_BOT_PROPERTIES
-// .getProperty("SWTBotPreferences.TIMEOUT"));
-// swtPreferenceIS.close();
-// } catch (IOException e) {
-// fail("Can't load properties from " + PATH_TO_SWT_BOT_PROPERTIES +
" file");
-// } catch (IllegalStateException e) {
-// fail("Property file " + PATH_TO_SWT_BOT_PROPERTIES + " was not
found");
-// }
+ // try {
+ // InputStream swtPreferenceIS =
+ // Platform.getBundle(Activator.PLUGIN_ID).getResource(PATH_TO_SWT_BOT_PROPERTIES)
+ // .openStream();
+ // SWT_BOT_PROPERTIES = new Properties();
+ // SWT_BOT_PROPERTIES.load(swtPreferenceIS);
+ // SWTBotPreferences.PLAYBACK_DELAY = Long
+ // .parseLong(SWT_BOT_PROPERTIES
+ // .getProperty("SWTBotPreferences.PLAYBACK_DELAY"));
+ // SWTBotPreferences.TIMEOUT = Long.parseLong(SWT_BOT_PROPERTIES
+ // .getProperty("SWTBotPreferences.TIMEOUT"));
+ // swtPreferenceIS.close();
+ // } catch (IOException e) {
+ // fail("Can't load properties from " + PATH_TO_SWT_BOT_PROPERTIES +
+ // " file");
+ // } catch (IllegalStateException e) {
+ // fail("Property file " + PATH_TO_SWT_BOT_PROPERTIES +
+ // " was not found");
+ // }
}
public void logging(IStatus status, String plugin) {
@@ -86,37 +94,42 @@
break;
}
}
-
+
/**
- * Getter method for exception that may be thrown during test
- * execution.<p>
- * You can call this method from any place of your methods
- * and verify if any exception was thrown during test executing
- * including Error Log.
+ * Getter method for exception that may be thrown during test execution.
+ * <p>
+ * You can call this method from any place of your methods and verify if any
+ * exception was thrown during test executing including Error Log.
+ *
* @return exception
* @see Throwable
*/
-
+
protected synchronized Throwable getException() {
return exception;
}
/**
- * Setter method for exception.
- * If param is not null test will fail and you will see stack trace in JUnit Error Log
- * @param e - exception, that can be frown during test executing
+ * Setter method for exception. If param is not null test will fail and you
+ * will see stack trace in JUnit Error Log
+ *
+ * @param e
+ * - exception, that can be frown during test executing
* @see Throwable
*/
-
+
protected synchronized void setException(Throwable e) {
this.exception = e;
}
/**
- * Delete .log file from junit-workspace .metadata, if it hadn't been deleted
before<p>
- * So we can catch exceptions and errors, which were thrown during current test.
+ * Delete .log file from junit-workspace .metadata, if it hadn't been
+ * deleted before
+ * <p>
+ * So we can catch exceptions and errors, which were thrown during current
+ * test.
*/
-
+
private void deleteLog() {
try {
Platform.getLogFileLocation().toFile().delete();
@@ -126,6 +139,7 @@
/**
* Make a default preconditions before test launch
+ *
* @see #activePerspective()
* @see #openErrorLog()
* @see #openPackageExplorer()
@@ -133,7 +147,7 @@
* @see #deleteLog()
* @see #delay()
*/
-
+
@Override
protected void setUp() throws Exception {
activePerspective();
@@ -143,18 +157,19 @@
}
openErrorLog();
openPackageExplorer();
-// openProgressStatus();
+ // openProgressStatus();
deleteLog();
setException(null);
Platform.addLogListener(this);
-// delay();
+ // delay();
}
/**
* Tears down the fixture. Verify Error Log.
+ *
* @see #getException()
*/
-
+
@Override
protected void tearDown() throws Exception {
Platform.removeLogListener(this);
@@ -167,20 +182,21 @@
/**
* A little delay between test's steps. Use it where necessary.
*/
-
+
protected void delay() {
bot.sleep(sleepTime);
}
-
- /** Defines which kind of perspective should be activated before tests' run.
+
+ /**
+ * Defines which kind of perspective should be activated before tests' run.
*/
-
- abstract protected void activePerspective ();
-
+
+ abstract protected void activePerspective();
+
/**
* Open and activate Error Log view if it hadn't been opened before
*/
-
+
protected void openErrorLog() {
try {
bot.viewByTitle(WidgetVariables.ERROR_LOG);
@@ -193,11 +209,11 @@
bot.button("OK").click();
}
}
-
+
/**
* Open and activate Package Explorer view if it hadn't been opened before
*/
-
+
protected void openPackageExplorer() {
try {
bot.viewByTitle(WidgetVariables.PACKAGE_EXPLORER).setFocus();
@@ -210,73 +226,91 @@
bot.button("OK").click();
}
}
-
-// protected void openProgressStatus() {
-// try {
-// bot.viewByTitle(WidgetVariables.PROGRESS_STATUS);
-// } catch (WidgetNotFoundException e) {
-// bot.menu("Window").menu("Show
View").menu("Other...").click();
-// SWTBotTree viewTree = bot.tree();
-// delay();
-// viewTree.expandNode("General").expandNode(WidgetVariables.PROGRESS_STATUS).select();
-// bot.button("OK").click();
-// }
-// }
-
+
+ // protected void openProgressStatus() {
+ // try {
+ // bot.viewByTitle(WidgetVariables.PROGRESS_STATUS);
+ // } catch (WidgetNotFoundException e) {
+ // bot.menu("Window").menu("Show
View").menu("Other...").click();
+ // SWTBotTree viewTree = bot.tree();
+ // delay();
+ //
viewTree.expandNode("General").expandNode(WidgetVariables.PROGRESS_STATUS).select();
+ // bot.button("OK").click();
+ // }
+ // }
+
/**
* Use delay() method instead
+ *
* @see #delay()
*/
- @Deprecated
- protected final void waitForJobs(){
+ @Deprecated
+ protected final void waitForJobs() {
delay();
}
-
- protected final void waitForBlockingJobsAcomplished(long timeOut, String... jobNames)
throws InterruptedException{
+
+ protected final void waitForBlockingJobsAcomplished(final long timeOut,
+ final String... jobNames) {
if (jobNames == null) {
- delay();
+ return;
} else {
- boolean isProcessStarted = false;
+ Map<String, Boolean> runningProcessesMap = new HashMap<String,
Boolean>();
+ for (int i = 0; i < jobNames.length; i++) {
+ runningProcessesMap.put(jobNames[i], false);
+ }
+ boolean isRequiredProcessesStarted = false;
long startTime = System.currentTimeMillis();
- while (!isProcessStarted) {
+ while (!isRequiredProcessesStarted) {
Job[] jobs = Job.getJobManager().find(null);
for (Job job : jobs) {
for (String jobName : jobNames) {
if (jobName.equalsIgnoreCase(job.getName())) {
- isProcessStarted = true;
+ if (!runningProcessesMap.get(jobName)) {
+ runningProcessesMap.remove(jobName);
+ runningProcessesMap.put(jobName, true);
+ }
}
}
}
- long endTime = System.currentTimeMillis();
- if (endTime-startTime>timeOut) {
- throw new InterruptedException(stringArrayToString(jobNames) + "job(s) has
never appeared or already completed");
+ isRequiredProcessesStarted = true;
+ for (String jobName : jobNames) {
+ isRequiredProcessesStarted = isRequiredProcessesStarted
+ & runningProcessesMap.get(jobName);
}
+ if (!isRequiredProcessesStarted) {
+ long endTime = System.currentTimeMillis();
+ if (endTime - startTime > timeOut) {
+ System.out.println("Next processes are already started or finished: "+
+ runningProcessesToString(jobNames)+" called in " + getName() + "
class");
+ return;
+ }
+ }
}
- while (isProcessStarted) {
- isProcessStarted = false;
+ while (isRequiredProcessesStarted) {
+ isRequiredProcessesStarted = false;
Job[] jobs = Job.getJobManager().find(null);
for (Job job : jobs) {
for (String jobName : jobNames) {
if (jobName.equalsIgnoreCase(job.getName())) {
+ isRequiredProcessesStarted = true;
delay();
- isProcessStarted = true;
}
}
}
}
}
}
-
- protected final void waitForBlockingJobsAcomplished(String... jobNames) throws
InterruptedException{
- waitForBlockingJobsAcomplished(5*1000L, jobNames);
+
+ protected final void waitForBlockingJobsAcomplished(String... jobNames) {
+ waitForBlockingJobsAcomplished(5 * 1000L, jobNames);
}
-
- private String stringArrayToString (String... strings){
- StringBuffer buffer = new StringBuffer("");
- for (String string : strings) {
- buffer.append(string+", ");
+
+ private String runningProcessesToString (String ... processes){
+ String process = "";
+ for (String processRunning : processes) {
+ process = process + processRunning + ", ";
}
- return buffer.toString();
+ return process;
}
}