[jbosstools-commits] JBoss Tools SVN: r23350 - in trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext: config and 1 other directories.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Fri Jul 9 11:16:42 EDT 2010


Author: lzoubek at redhat.com
Date: 2010-07-09 11:16:41 -0400 (Fri, 09 Jul 2010)
New Revision: 23350

Added:
   trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/widgets/SWTBotSection.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/SWTBotExt.java
   trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTEclipseExt.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
Log:
SWTBot Extensions: added 'runOnce' annotation, added Section widget

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-07-09 14:10:56 UTC (rev 23349)
+++ trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/RequirementAwareSuite.java	2010-07-09 15:16:41 UTC (rev 23350)
@@ -2,19 +2,18 @@
 
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map.Entry;
-
+import java.util.Set;
 import org.apache.log4j.Logger;
 import org.eclipse.swtbot.swt.finder.junit.ScreenshotCaptureListener;
+import org.jboss.tools.ui.bot.ext.config.Annotations.SWTBotTestRequires;
 import org.jboss.tools.ui.bot.ext.config.TestConfiguration;
 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.Description;
 import org.junit.runner.Runner;
-import org.junit.runner.manipulation.Filter;
-import org.junit.runner.manipulation.NoTestsRemainException;
 import org.junit.runner.notification.RunListener;
 import org.junit.runner.notification.RunNotifier;
 import org.junit.runners.BlockJUnit4ClassRunner;
@@ -106,12 +105,20 @@
 				TestConfigurator.currentConfig = this.config;
 			}
 			List<RequirementBase> reqs = TestConfigurator.getClassRequirements(klass);
-			if (reqs != null) {				
+			if (reqs != null) {
+				SWTBotTestRequires anno = klass.getAnnotation(SWTBotTestRequires.class);
+				if (anno!=null && anno.runOnce() && cleanUp.isClassPlanned(klass)) {
+					// class is already planned to run and contains annotation runOnce
+					log.info("Skipping class '" + klass.getCanonicalName()
+					+ "' - runOnce=true, class already planned");
+					return null;
+				}
 				log.info("Returning runner for class '"
 						+ klass.getCanonicalName() + "'");
 				// increment number of tests planned to run by 1 (class contains
 				// at least 1 test method)
 				cleanUp.incrPlanned();
+				cleanUp.addClass(klass);
 				return new ReqAwareClassRunner(klass, reqs, config);
 			}
 			log.info("Skipping class '" + klass.getCanonicalName()
@@ -123,7 +130,7 @@
 
 	/**
 	 * listener which listens to test runs, does some cleanup after all tests
-	 * have run
+	 * have run it also holds set of all classes which run (usefull for runOnce annotation)
 	 * 
 	 * @author lzoubek
 	 * 
@@ -155,6 +162,17 @@
 		public int getFinished() {
 			return testsFinished;
 		}
+		private Set<String> classes = new HashSet<String>();
+		/**
+		 * adds class to runList - as it is planned to run
+		 * @param klass
+		 */
+		public void addClass(Class<?> klass) {
+			classes.add(klass.getName());
+		}
+		public boolean isClassPlanned(Class<?> klass) {
+			return classes.contains(klass.getName());
+		}
 
 		@Override
 		public void testFinished(Description description) throws Exception {

Modified: trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTBotExt.java
===================================================================
--- trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTBotExt.java	2010-07-09 14:10:56 UTC (rev 23349)
+++ trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTBotExt.java	2010-07-09 15:16:41 UTC (rev 23350)
@@ -29,10 +29,12 @@
 import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable;
 import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
 import org.eclipse.ui.forms.widgets.Hyperlink;
+import org.eclipse.ui.forms.widgets.Section;
 import org.jboss.tools.ui.bot.ext.parts.SWTBotBrowserExt;
 import org.jboss.tools.ui.bot.ext.parts.SWTBotEditorExt;
 import org.jboss.tools.ui.bot.ext.parts.SWTBotHyperlinkExt;
 import org.jboss.tools.ui.bot.ext.parts.SWTBotScaleExt;
+import org.jboss.tools.ui.bot.ext.widgets.SWTBotSection;
 
 /**
  * Extended version of SWTWorkbenchBot, logging added
@@ -162,6 +164,15 @@
 	public SWTBotButton clickButton(String text) {
 		return button(text).click();
 	}
-	
+	@SuppressWarnings("unchecked")
+	public SWTBotSection section(String label) {
+		try {
+		List<Section> sections = (List<Section>)widgets(allOf(withText(label),widgetOfType(Section.class)));
+		return new SWTBotSection(sections.get(0));
+		} catch (WidgetNotFoundException ex) {
+			throw new WidgetNotFoundException(
+					"Could not find widget of type Section", ex);
+		}
+	}
 
 }

Modified: trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTEclipseExt.java
===================================================================
--- trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTEclipseExt.java	2010-07-09 14:10:56 UTC (rev 23349)
+++ trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/SWTEclipseExt.java	2010-07-09 15:16:41 UTC (rev 23350)
@@ -1132,6 +1132,30 @@
     return containsItem;
   }
   /**
+   * returns true if path composed from items exists in tree
+   * @param tree
+   * @param items
+   * @return
+   */
+  public static boolean containstInTree(SWTBotTree tree, String...items) {
+		try {			
+			SWTBotTreeItem ancestor = tree.getTreeItem(items[0]);
+			tree.expandNode(items[0]);
+			for (int i=1;i<items.length;i++) {
+				try {
+					ancestor = ancestor.expandNode(items[i]);
+				}
+				catch (WidgetNotFoundException ex) {
+					return false;
+				}				
+			}
+			return true;
+			}
+			catch (WidgetNotFoundException ex) {
+				return false;
+			}	
+  }
+  /**
    * Returns true if editor with editorLabel exists within bot
    * static version
    * @param bot

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-07-09 14:10:56 UTC (rev 23349)
+++ trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/Annotations.java	2010-07-09 15:16:41 UTC (rev 23350)
@@ -56,6 +56,14 @@
 		 * @return
 		 */
 		boolean clearProjects() default true;
+		/**
+		 * if you want your class to be run just once (among all suites and possibly multiple configurations)
+		 * set this to true, default is false. 
+		 * This is useful when testing against multiple configurations is not needed 
+		 * or for test class which would last too long and would uselessly run more than once
+		 * @return
+		 */
+		boolean runOnce() default false;
 	}
 	/**
 	 * 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-07-09 14:10:56 UTC (rev 23349)
+++ trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/TestConfigurator.java	2010-07-09 15:16:41 UTC (rev 23350)
@@ -82,11 +82,16 @@
 		}
 		// load default config by default
 		try {
+			log.info(" * Loading default configuration first");
 			currentConfig = new TestConfiguration("default", "");
+			
 		} catch (Exception e) {
 			// log only message, nothing 
 			log.error(e.getMessage());
 		}
+		finally {
+			log.info(" * Defaults loaded");
+		}
 
 	}
 	/**

Added: trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/widgets/SWTBotSection.java
===================================================================
--- trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/widgets/SWTBotSection.java	                        (rev 0)
+++ trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/widgets/SWTBotSection.java	2010-07-09 15:16:41 UTC (rev 23350)
@@ -0,0 +1,19 @@
+package org.jboss.tools.ui.bot.ext.widgets;
+
+import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
+import org.eclipse.swtbot.swt.finder.widgets.AbstractSWTBotControl;
+import org.eclipse.ui.forms.widgets.Section;
+/**
+ * this class represents Section (expandable labeled area, 
+ * section is often used as a basic building block if forms 
+ * because it provides for logical grouping of information.)
+ * @author lzoubek
+ *
+ */
+public class SWTBotSection extends AbstractSWTBotControl<Section> {
+
+	public SWTBotSection(Section w) throws WidgetNotFoundException {
+		super(w);		
+	}
+
+}


Property changes on: trunk/jst/tests/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/widgets/SWTBotSection.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain



More information about the jbosstools-commits mailing list