Revision: 604
http://svn.sourceforge.net/jwebunit/?rev=604&view=rev
Author: henryju
Date: 2006-11-08 08:03:53 -0800 (Wed, 08 Nov 2006)
Log Message:
-----------
Refactor TestingEngineRegistry. Need to be tested for race condition.
Modified Paths:
--------------
branches/1.x/jwebunit-core/src/main/java/net/sourceforge/jwebunit/TestingEngineRegistry.java
branches/1.x/jwebunit-core/src/main/java/net/sourceforge/jwebunit/WebTester.java
Property Changed:
----------------
branches/1.x/jwebunit-commons-tests/
branches/1.x/jwebunit-core/
branches/1.x/jwebunit-htmlunit-plugin/
Property changes on: branches/1.x/jwebunit-commons-tests
___________________________________________________________________
Name: svn:ignore
- .classpath
.project
+ .classpath
.project
bin
target
Property changes on: branches/1.x/jwebunit-core
___________________________________________________________________
Name: svn:ignore
- .project
.classpath
+ .project
.classpath
target
Modified:
branches/1.x/jwebunit-core/src/main/java/net/sourceforge/jwebunit/TestingEngineRegistry.java
===================================================================
---
branches/1.x/jwebunit-core/src/main/java/net/sourceforge/jwebunit/TestingEngineRegistry.java
2006-11-08 15:11:27 UTC (rev 603)
+++
branches/1.x/jwebunit-core/src/main/java/net/sourceforge/jwebunit/TestingEngineRegistry.java
2006-11-08 16:03:53 UTC (rev 604)
@@ -12,57 +12,72 @@
* This will maintain a registry of known testing engines to be used by
* jWebUnit.
*
- * @author Nicholas Neuberger
* @author Julien Henry
*/
public class TestingEngineRegistry {
- // TODO Move this to a JDK1.5 typesafe enum
- public final static String TESTING_ENGINE_HTMLUNIT =
"TestingEngineHtmlUnit";
+ /**
+ * Key of HtmlUnit testing engine.
+ */
+ public final static String TESTING_ENGINE_HTMLUNIT =
"TestingEngineHtmlUnit";
- private static Hashtable testingEngineMap = null;
+ private static Hashtable testingEngineMap = new Hashtable();
- public TestingEngineRegistry() {
- }
+ static {
+ String cp = "net.sourceforge.jwebunit.htmlunit.HtmlUnitDialog";
+ // Try to load HtmlUnitDialog to check if it is present.
+ try {
+ addTestingEngine(TESTING_ENGINE_HTMLUNIT, cp);
+ } catch (ClassNotFoundException e) {
+ // HtmlUnitDialog is not present in the classpath.
Nothing to do.
+ }
+ }
- /**
- * Gets the map of testing engines defined within jwebunit.
- * Need to be synchronized for concurrent testing.
- * @return
- */
- public static synchronized Hashtable getTestingEngineMap() {
- if (testingEngineMap == null) {
- testingEngineMap = new Hashtable();
- String cp = "net.sourceforge.jwebunit.htmlunit.HtmlUnitDialog";
- //Try to load HtmlUnitDialog to check if it is present.
- try {
- Class.forName(cp);
- } catch (ClassNotFoundException e) {
- // HtmlUnitDialog is not present in the classpath. Return an
empty map.
- return testingEngineMap;
- }
- // HtmlUnitDialog was found. Add it to the map.
- testingEngineMap.put(TESTING_ENGINE_HTMLUNIT, cp);
- }
- return testingEngineMap;
- }
+ /**
+ * Gets the class based on the key of the class.
+ *
+ * @param aKey
+ * Key of the testing engine
+ * @return the testing engine class.
+ */
+ public static Class getTestingEngineClass(String aKey)
+ throws ClassNotFoundException {
+ Class theClass = (Class) testingEngineMap.get(aKey);
+ return theClass;
+ }
- /**
- * Gets the class based on the key of the class.
- *
- * @param aKey
- * @return
- */
- public static Class getTestingEngineClass(String aKey)
- throws ClassNotFoundException {
- Class theClass = Class
- .forName((String) getTestingEngineMap().get(aKey));
- if (theClass == null) {
- throw new TestingEngineRegistryException(
- "Testing Engine with Key: [" + aKey
- + "] not defined for jWebUnit.");
- }
- return theClass;
- }
+ /**
+ * Add a new testing engine.
+ *
+ * @param key
+ * A string to identify the testing engine.
+ * @param classpath
+ * The full class name.
+ * @throws ClassNotFoundException
+ * If the class is not in the classpath.
+ */
+ public static void addTestingEngine(String key, String classpath)
+ throws ClassNotFoundException {
+ Class c = Class.forName(classpath);
+ if (IJWebUnitDialog.class.isAssignableFrom(c)) {
+ testingEngineMap.put(key, c);
+ } else {
+ throw new TestingEngineRegistryException(classpath
+ + " is not an instance of
IJWebUnitDialog");
+ }
+ }
+ /**
+ * Get first available testing engine key.
+ *
+ * @return key of a testing engine, or null is none is available.
+ */
+ public static String getFirstAvailable() {
+ if (testingEngineMap.isEmpty()) {
+ return null;
+ } else {
+ return (String) testingEngineMap.keys().nextElement();
+ }
+ }
+
}
Modified:
branches/1.x/jwebunit-core/src/main/java/net/sourceforge/jwebunit/WebTester.java
===================================================================
---
branches/1.x/jwebunit-core/src/main/java/net/sourceforge/jwebunit/WebTester.java
2006-11-08 15:11:27 UTC (rev 603)
+++
branches/1.x/jwebunit-core/src/main/java/net/sourceforge/jwebunit/WebTester.java
2006-11-08 16:03:53 UTC (rev 604)
@@ -2151,9 +2151,10 @@
List cookies = getDialog().getCookies();
for (Iterator i = cookies.iterator(); i.hasNext();) {
Cookie c = (Cookie) i.next();
- System.out.println("Name="+c.getName() + "; Value=" +
c.getValue() + "; Domain="
- + c.getDomain() + "; Comment=" +
c.getComment() + "; MaxAge="
- + c.getMaxAge() + "; Path=" +
c.getPath() + "; Version=" + c.getVersion());
+ System.out.println("Name=" + c.getName() + "; Value="
+ + c.getValue() + "; Domain=" +
c.getDomain() + "; Comment="
+ + c.getComment() + "; MaxAge=" +
c.getMaxAge() + "; Path="
+ + c.getPath() + "; Version=" +
c.getVersion());
}
}
@@ -2235,17 +2236,16 @@
/**
* Gets the Testing Engine Key that is used to find the proper testing
- * engine class (HttpUnitDialog / JacobieDialog) for the tests.
+ * engine class (HtmlUnitDialog / SeleniumDialog) for the tests.
*
* @return Returns the testingEngineKey.
*/
public String getTestingEngineKey() {
if (testingEngineKey == null) {
// use first available dialog
- if (TestingEngineRegistry.getTestingEngineMap().keys()
- .hasMoreElements()) {
- setTestingEngineKey((String)
TestingEngineRegistry
-
.getTestingEngineMap().keys().nextElement());
+ String key = TestingEngineRegistry.getFirstAvailable();
+ if (key != null) {
+ setTestingEngineKey(key);
} else {
throw new RuntimeException(
"TestingEngineRegistry contains
no dialog. Check you put at least one plugin in the classpath.");
@@ -2270,18 +2270,18 @@
* Exemple: <br/>
*
* <pre>
- * <FORM
action="http://my_host/doit" method="post">
- * <P>
- * <SELECT multiple
size="4" name="component-select">
- * <OPTION selected
value="Component_1_a">Component_1</OPTION>
- * <OPTION selected
value="Component_1_b">Component_2</OPTION>
- *
<OPTION>Component_3</OPTION>
- *
<OPTION>Component_4</OPTION>
- *
<OPTION>Component_5</OPTION>
- * </SELECT>
- * <INPUT type="submit"
value="Send"><INPUT type="reset">
- * </P>
- * </FORM>
+ * <FORM
action="http://my_host/doit" method="post">
+ * <P>
+ * <SELECT multiple
size="4" name="component-select">
+ * <OPTION selected
value="Component_1_a">Component_1</OPTION>
+ * <OPTION selected
value="Component_1_b">Component_2</OPTION>
+ *
<OPTION>Component_3</OPTION>
+ *
<OPTION>Component_4</OPTION>
+ *
<OPTION>Component_5</OPTION>
+ * </SELECT>
+ * <INPUT type="submit"
value="Send"><INPUT type="reset">
+ * </P>
+ * </FORM>
* </pre>
*
* Should return [Component_1, Component_2, Component_3, Component_4,
Property changes on: branches/1.x/jwebunit-htmlunit-plugin
___________________________________________________________________
Name: svn:ignore
- .project
.classpath
+ .project
.classpath
bin
target
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Jwebunit-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jwebunit-development