Author: lzoubek(a)redhat.com
Date: 2010-04-21 07:50:54 -0400 (Wed, 21 Apr 2010)
New Revision: 21578
Added:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/requirement/SwitchPerspective.java
Modified:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/RequirementAwareSuite.java
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTOpenExt.java
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTTestExt.java
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/Annotations.java
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/TestConfigurator.java
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/requirement/AddJRE.java
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/requirement/AddSeam.java
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/requirement/AddServer.java
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/requirement/RequirementBase.java
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/requirement/StartServer.java
Log:
SWTbot extensions : improving custom annotations
Modified:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/RequirementAwareSuite.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/RequirementAwareSuite.java 2010-04-21
10:55:28 UTC (rev 21577)
+++
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/RequirementAwareSuite.java 2010-04-21
11:50:54 UTC (rev 21578)
@@ -7,9 +7,11 @@
import org.apache.log4j.Logger;
import org.jboss.tools.ui.bot.ext.config.TestConfigurator;
import org.jboss.tools.ui.bot.ext.config.Annotations.SWTBotTestRequires;
+import org.jboss.tools.ui.bot.ext.config.requirement.RequirementBase;
import org.junit.runner.Runner;
import org.junit.runners.BlockJUnit4ClassRunner;
import org.junit.runners.Suite;
+import org.junit.runners.model.InitializationError;
import org.junit.runners.model.RunnerBuilder;
/**
@@ -17,14 +19,32 @@
*
* @author lzoubek(a)redhat.com
*/
-public class RequirementAwareSuite extends Suite {
+public class RequirementAwareSuite extends Suite {
+ class ReqAwareClassRunner extends BlockJUnit4ClassRunner {
+ private final List<RequirementBase> requirements;
+ public ReqAwareClassRunner(Class<?> klass, List<RequirementBase>
requirements) throws InitializationError {
+ super(klass);
+ this.requirements = requirements;
+ }
+ @Override
+ protected Object createTest() throws Exception {
+ log.info("Fullfilling requirements before test
"+getTestClass().getJavaClass());
+ for (RequirementBase r : requirements) {
+ r.fulfill();
+ }
+ return super.createTest();
+ }
+
+ }
+
private static final Logger log = Logger.getLogger(RequirementAwareSuite.class);
private class RequirementAwareRunnerBuilder extends RunnerBuilder {
@Override
- public Runner runnerForClass(Class<?> klass) throws Throwable {
- if (TestConfigurator.canRunClass(klass)) {
+ public Runner runnerForClass(Class<?> klass) throws Throwable {
+ List<RequirementBase> reqs = TestConfigurator.getClassRequirements(klass);
+ if (reqs!=null) {
log.info("Returning runner for test class "+klass.getCanonicalName());
- return new BlockJUnit4ClassRunner(klass);
+ return new ReqAwareClassRunner(klass,reqs);
}
log.info("Skipping test class "+klass.getCanonicalName());
return null;
Modified:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTOpenExt.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTOpenExt.java 2010-04-21
10:55:28 UTC (rev 21577)
+++
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTOpenExt.java 2010-04-21
11:50:54 UTC (rev 21578)
@@ -158,6 +158,7 @@
shell.activate();
bot.table().select(perspective.getName());
bot.button("OK").click();
+ log.info("Perspective switched to
'"+perspective.getName()+"'");
}
/**
Modified:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTTestExt.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTTestExt.java 2010-04-21
10:55:28 UTC (rev 21577)
+++
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTTestExt.java 2010-04-21
11:50:54 UTC (rev 21578)
@@ -10,23 +10,15 @@
******************************************************************************/
package org.jboss.tools.ui.bot.ext;
-import java.util.List;
import java.util.Properties;
-import java.util.Vector;
-
import org.apache.log4j.Logger;
import org.eclipse.swtbot.swt.finder.SWTBotTestCase;
import org.jboss.tools.ui.bot.ext.config.ConfiguredState;
-import org.jboss.tools.ui.bot.ext.config.requirement.RequirementBase;
-import org.jboss.tools.ui.bot.ext.gen.IView;
-import org.jboss.tools.ui.bot.ext.types.IDELabel;
import org.jboss.tools.ui.bot.ext.view.ConsoleView;
import org.jboss.tools.ui.bot.ext.view.PackageExplorer;
import org.jboss.tools.ui.bot.ext.view.ProblemsView;
import org.jboss.tools.ui.bot.ext.view.ProjectExplorer;
import org.jboss.tools.ui.bot.ext.view.ServersView;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
/**
* Base class for SWTBot Tests using SWTBotExt
* @author jpeterka
@@ -50,8 +42,6 @@
// config & state
public static final ConfiguredState configuredState = new ConfiguredState();
- public static final List<RequirementBase> beforeRequirements = new
Vector<RequirementBase>();
- public static final List<RequirementBase> afterRequirements = new
Vector<RequirementBase>();
public static Properties properties;
/**
@@ -70,32 +60,5 @@
public static int TIME_5S = Timing.time5S();
public static int TIME_10S = Timing.time10S();
public static int TIME_20S = Timing.time20S();
-
- /**
- * fullfills given requirements
- * @param requirements
- */
- @BeforeClass
- public static void beforeTest() throws Exception {
- // try to close Welcome view
- open.viewClose(new IView(){
- public List<String> getGroupPath() {
- return new Vector<String>();
- }
- public String getName() {
- return IDELabel.View.WELCOME;
- }});
- log.info("Fullfilling requirements before test");
- for (RequirementBase r : beforeRequirements) {
- r.fullfill();
- }
- }
- @AfterClass
- public static void afterTest() throws Exception {
- log.info("Fullfilling requirements before test");
- for (RequirementBase r : afterRequirements) {
- r.fullfill();
- }
- }
}
Modified:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/Annotations.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/Annotations.java 2010-04-21
10:55:28 UTC (rev 21577)
+++
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/Annotations.java 2010-04-21
11:50:54 UTC (rev 21578)
@@ -10,7 +10,7 @@
public class Annotations {
/**
* annotation which defines requirement of whole test Class
- * by default all sub-annotations are optional and are
+ * by default all sub-annotations are optional and are disabled
* @author lzoubek
*
*/
@@ -22,6 +22,11 @@
*/
Server server() default @Server( required = false );
Seam seam() default @Seam( required = false );
+ /**
+ * name of perspective to run within
+ * @return
+ */
+ String perspective() default "";
}
/**
* Server requirement, by default matches all server types and versions
Modified:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/TestConfigurator.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/TestConfigurator.java 2010-04-21
10:55:28 UTC (rev 21577)
+++
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/TestConfigurator.java 2010-04-21
11:50:54 UTC (rev 21578)
@@ -4,14 +4,16 @@
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Properties;
-
import org.jboss.tools.ui.bot.ext.Activator;
import org.jboss.tools.ui.bot.ext.SWTTestExt;
import org.jboss.tools.ui.bot.ext.config.Annotations.*;
import org.jboss.tools.ui.bot.ext.config.requirement.AddSeam;
import org.jboss.tools.ui.bot.ext.config.requirement.RequirementBase;
import org.jboss.tools.ui.bot.ext.config.requirement.StartServer;
+import org.jboss.tools.ui.bot.ext.config.requirement.SwitchPerspective;
public class TestConfigurator {
@@ -112,30 +114,38 @@
return new AddSeam();
}
/**
- * returns true, if given class (Test) can run, this is done by exploring class'es
+ * returns list of requirements if given class (Test) can run, all this is done by
exploring class'es
* annotations (see {@link SWTBotTestRequires}
+ * if class cannot run returns null
*/
- public static boolean canRunClass(Class<?> klass) {
+ public static List<RequirementBase> getClassRequirements(Class<?> klass) {
+
SWTBotTestRequires requies = klass.getAnnotation(SWTBotTestRequires.class);
// all not annotated classes can run
if (requies==null) {
- return true;
+ return null;
}
+ // internal list
+ List<RequirementBase> reqs = new ArrayList<RequirementBase>();
+
if (requies.server().required()) {
RequirementBase req = getServerRequirement(requies.server());
if (req==null) {
- return false;
+ return null;
}
- SWTTestExt.beforeRequirements.add(req);
+ reqs.add(req);
}
if (requies.seam().required()) {
RequirementBase req = getSeamRequirement(requies.seam());
if (req==null) {
- return false;
+ return null;
}
- SWTTestExt.beforeRequirements.add(req);
+ reqs.add(req);
}
- return true;
+ if (!"".equals(requies.perspective())) {
+ reqs.add(new SwitchPerspective(requies.perspective()));
+ }
+ return reqs;
}
/**
* implements comparison of 2 params by given operator (in this order)
Modified:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/requirement/AddJRE.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/requirement/AddJRE.java 2010-04-21
10:55:28 UTC (rev 21577)
+++
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/requirement/AddJRE.java 2010-04-21
11:50:54 UTC (rev 21578)
@@ -19,7 +19,7 @@
this.version = version;
}
@Override
- public boolean checkFullfilled() {
+ public boolean checkFulfilled() {
return SWTTestExt.configuredState.getJreList().contains(getAddedAsName());
}
Modified:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/requirement/AddSeam.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/requirement/AddSeam.java 2010-04-21
10:55:28 UTC (rev 21577)
+++
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/requirement/AddSeam.java 2010-04-21
11:50:54 UTC (rev 21578)
@@ -6,7 +6,7 @@
public class AddSeam extends RequirementBase {
@Override
- public boolean checkFullfilled() {
+ public boolean checkFulfilled() {
return SWTTestExt.configuredState.getSeam().isConfiured;
}
Modified:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/requirement/AddServer.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/requirement/AddServer.java 2010-04-21
10:55:28 UTC (rev 21577)
+++
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/requirement/AddServer.java 2010-04-21
11:50:54 UTC (rev 21578)
@@ -88,7 +88,7 @@
fail("Unable to add server runtime, unparsable or not supported property value:
"+TestConfigurator.getProperty(TestConfigurator.Keys.SERVER));
}
@Override
- public boolean checkFullfilled() {
+ public boolean checkFulfilled() {
return SWTTestExt.configuredState.getServer().isConfigured;
}
Modified:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/requirement/RequirementBase.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/requirement/RequirementBase.java 2010-04-21
10:55:28 UTC (rev 21577)
+++
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/requirement/RequirementBase.java 2010-04-21
11:50:54 UTC (rev 21578)
@@ -29,19 +29,20 @@
* fulfills this requirement. First fulfills the dependent ones, then this.
* @throws RequirementNotFulfilledException
*/
- public void fullfill() throws RequirementNotFulfilledException {
+ public void fulfill() throws RequirementNotFulfilledException {
log.info("Fulfilling requirement
'"+this.getClass().getName()+"'");
try {
for (RequirementBase dep : getDependsOn()) {
- dep.fullfill();
+ dep.fulfill();
}
- if (!checkFullfilled()) {
+ if (!checkFulfilled()) {
handle();
- if (!checkFullfilled()) {
- throw new Exception("Requirement implementation error, checkFullfilled failed
after calling handle();");
+ if (!checkFulfilled()) {
+ throw new Exception("Requirement implementation error, checkFulfilled() failed
after calling handle();");
}
}
} catch (Exception ex) {
+ log.info("Unable to fulfill requirement
'"+this.getClass().getName()+"'");
throw new RequirementNotFulfilledException("Unable to fulfill requirement
"+this.getClass().getCanonicalName(),ex);
}
log.info("Requirement '"+this.getClass().getName()+"'
fulfilled");
@@ -51,10 +52,19 @@
* must return true if the Requirement is already fulfilled
* @return
*/
- public abstract boolean checkFullfilled();
+ public abstract boolean checkFulfilled();
/**
- * handles (should do everything to fulfill requirement), {@link
RequirementBase#checkFullfilled()}
+ * handles (should do everything to fulfill requirement), {@link
RequirementBase#checkFulfilled()}
* should return true after calling this method
*/
public abstract void handle();
+
+ @Override
+ public int hashCode() {
+ return getClass().hashCode();
+ }
+ @Override
+ public boolean equals(Object obj) {
+ return this.getClass().equals(obj.getClass());
+ }
}
Modified:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/requirement/StartServer.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/requirement/StartServer.java 2010-04-21
10:55:28 UTC (rev 21577)
+++
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/requirement/StartServer.java 2010-04-21
11:50:54 UTC (rev 21578)
@@ -14,7 +14,7 @@
}
@Override
- public boolean checkFullfilled() {
+ public boolean checkFulfilled() {
return SWTTestExt.configuredState.getServer().isRunning;
}
Added:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/requirement/SwitchPerspective.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/requirement/SwitchPerspective.java
(rev 0)
+++
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/requirement/SwitchPerspective.java 2010-04-21
11:50:54 UTC (rev 21578)
@@ -0,0 +1,33 @@
+package org.jboss.tools.ui.bot.ext.config.requirement;
+
+import java.util.List;
+import java.util.Vector;
+
+import org.jboss.tools.ui.bot.ext.SWTTestExt;
+import org.jboss.tools.ui.bot.ext.gen.IPerspective;
+
+public class SwitchPerspective extends RequirementBase {
+
+ private final String name;
+ public SwitchPerspective(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public boolean checkFulfilled() {
+ return SWTTestExt.bot.activePerspective().getLabel().equals(name);
+ }
+
+ @Override
+ public void handle() {
+ SWTTestExt.open.perspective(new IPerspective() {
+ public List<String> getGroupPath() {
+ return new Vector<String>();
+ }
+ public String getName() {
+ return name;
+ }});
+
+ }
+
+}
Property changes on:
trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/requirement/SwitchPerspective.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain