Author: julien(a)jboss.com
Date: 2007-10-14 08:05:55 -0400 (Sun, 14 Oct 2007)
New Revision: 8642
Added:
modules/test/trunk/unit/src/main/org/jboss/unit/driver/impl/composite/
modules/test/trunk/unit/src/main/org/jboss/unit/driver/impl/composite/CompositeTestDriver.java
Modified:
modules/test/trunk/remote/src/main/org/jboss/unit/remote/driver/RemoteTestDriverClient.java
modules/test/trunk/remote/src/main/org/jboss/unit/remote/driver/RemoteTestDriverServer.java
modules/test/trunk/unit/src/main/org/jboss/test/unit/runner/GenericTestRunnerTests.java
modules/test/trunk/unit/src/main/org/jboss/unit/Failure.java
modules/test/trunk/unit/src/main/org/jboss/unit/driver/DriverContext.java
modules/test/trunk/unit/src/main/org/jboss/unit/driver/impl/pojo/POJOTestSuiteDriver.java
modules/test/trunk/unit/src/main/org/jboss/unit/driver/impl/pojo/SimpleDriverContext.java
modules/test/trunk/unit/src/main/org/jboss/unit/runner/impl/TestRunnerContextSupport.java
modules/test/trunk/unit/src/main/org/jboss/unit/runner/impl/driver/TestDriverRunner.java
modules/test/trunk/unit/src/main/org/jboss/unit/runner/impl/generic/GenericTestRunner.java
modules/test/trunk/unit/src/main/org/jboss/unit/runner/impl/pojo/POJOTestRunner.java
modules/test/trunk/unit/src/main/org/jboss/unit/runner/model/ModelBuilder.java
modules/test/trunk/unit/src/main/org/jboss/unit/runner/model/TestSuiteDef.java
modules/test/trunk/unit/src/main/org/jboss/unit/runner/model/generic/GenericTestSuiteDef.java
modules/test/trunk/unit/src/resources/jboss-unit-jar/org/jboss/unit/runner/model/jboss-unit_1_0.xsd
modules/test/trunk/unit/src/resources/test/org/jboss/test/unit/runner/model/f2.xml
Log:
add support for property definition at generic test suite level
Modified:
modules/test/trunk/remote/src/main/org/jboss/unit/remote/driver/RemoteTestDriverClient.java
===================================================================
---
modules/test/trunk/remote/src/main/org/jboss/unit/remote/driver/RemoteTestDriverClient.java 2007-10-14
05:44:03 UTC (rev 8641)
+++
modules/test/trunk/remote/src/main/org/jboss/unit/remote/driver/RemoteTestDriverClient.java 2007-10-14
12:05:55 UTC (rev 8642)
@@ -143,7 +143,7 @@
catch (Throwable throwable)
{
throwable.printStackTrace();
- failed = new FailureResponse(Failure.createErrorFailure("Could not startup
kernel", throwable));
+ failed = new FailureResponse(Failure.createFailure("Could not startup
kernel", throwable));
return;
}
@@ -158,7 +158,7 @@
catch (Throwable throwable)
{
throwable.printStackTrace();
- failed = new FailureResponse(Failure.createErrorFailure("Could not deploy
beans", throwable));
+ failed = new FailureResponse(Failure.createFailure("Could not deploy
beans", throwable));
}
}
@@ -205,7 +205,7 @@
}
catch (Exception e)
{
- return new FailureResponse(Failure.createErrorFailure(e));
+ return new FailureResponse(Failure.createFailure(e));
}
}
else
Modified:
modules/test/trunk/remote/src/main/org/jboss/unit/remote/driver/RemoteTestDriverServer.java
===================================================================
---
modules/test/trunk/remote/src/main/org/jboss/unit/remote/driver/RemoteTestDriverServer.java 2007-10-14
05:44:03 UTC (rev 8641)
+++
modules/test/trunk/remote/src/main/org/jboss/unit/remote/driver/RemoteTestDriverServer.java 2007-10-14
12:05:55 UTC (rev 8642)
@@ -23,42 +23,33 @@
package org.jboss.unit.remote.driver;
import org.jboss.unit.TestId;
-import org.jboss.unit.Failure;
-import org.jboss.unit.driver.DriverResponse;
-import org.jboss.unit.driver.DriverCommand;
import org.jboss.unit.driver.TestDriver;
-import org.jboss.unit.driver.AbstractTestDriver;
-import org.jboss.unit.driver.response.FailureResponse;
-import org.jboss.unit.info.TestInfo;
-import org.jboss.unit.info.impl.SimpleTestSuiteInfo;
+import org.jboss.unit.driver.impl.composite.CompositeTestDriver;
import org.jboss.unit.remote.RequestContext;
import org.jboss.unit.remote.ResponseContext;
-import java.util.Map;
-import java.util.HashMap;
-
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 5636 $
*/
-public class RemoteTestDriverServer extends AbstractTestDriver implements
RemoteTestDriver
+public class RemoteTestDriverServer extends CompositeTestDriver implements
RemoteTestDriver
{
- /** . */
- private SimpleTestSuiteInfo info = new SimpleTestSuiteInfo("Main");
-
- /** . */
- private Map<String, RemoteTestDriver> drivers = new HashMap<String,
RemoteTestDriver>();
-
public void pushContext(TestId testId, RequestContext requestContext)
{
String name = testId.getName(0);
//
- RemoteTestDriver driver = drivers.get(name);
+ TestDriver driver = drivers.get(name);
//
- driver.pushContext(testId.range(1), requestContext);
+ if (driver instanceof RemoteTestDriver)
+ {
+ RemoteTestDriver remoteDriver = (RemoteTestDriver)driver;
+
+ //
+ remoteDriver.pushContext(testId.range(1), requestContext);
+ }
}
public ResponseContext popContext(TestId testId)
@@ -66,67 +57,24 @@
String name = testId.getName(0);
//
- RemoteTestDriver driver = drivers.get(name);
-
- //
- return driver.popContext(testId.range(1));
- }
-
- public TestInfo getInfo()
- {
- return info;
- }
-
- public DriverResponse invoke(TestId id, DriverCommand command)
- {
- if (id.getLength() == 0)
- {
- return new FailureResponse(Failure.createErrorFailure("No null test id
accepted"));
- }
-
- //
- String name = id.getName(0);
-
- //
TestDriver driver = drivers.get(name);
//
- if (driver == null)
- {
- return new FailureResponse(Failure.createErrorFailure("No test driver found
for name " + name));
- }
-
//
- TestId driverId = id.range(1);
-
- //
- return driver.invoke(driverId, command);
- }
-
- public void mount(RemoteTestDriver driver)
- {
- synchronized(RemoteTestDriverServer.class)
+ if (driver instanceof RemoteTestDriver)
{
- info.addTest(driver.getInfo());
+ RemoteTestDriver remoteDriver = (RemoteTestDriver)driver;
- String name = driver.getInfo().getName();
-
- drivers.put(name, driver);
+ //
+ return remoteDriver.popContext(testId.range(1));
}
- }
-
- public synchronized void unmount(RemoteTestDriver driver)
- {
- synchronized(RemoteTestDriverServer.class)
+ else
{
- String name = driver.getInfo().getName();
-
- drivers.remove(name);
-
- info.removeTest(name);
+ return null;
}
}
+
// /** . */
// private String initialPath = "/test";
//
Modified:
modules/test/trunk/unit/src/main/org/jboss/test/unit/runner/GenericTestRunnerTests.java
===================================================================
---
modules/test/trunk/unit/src/main/org/jboss/test/unit/runner/GenericTestRunnerTests.java 2007-10-14
05:44:03 UTC (rev 8641)
+++
modules/test/trunk/unit/src/main/org/jboss/test/unit/runner/GenericTestRunnerTests.java 2007-10-14
12:05:55 UTC (rev 8642)
@@ -32,7 +32,8 @@
import org.jboss.unit.runner.results.TestSuccess;
import org.jboss.unit.driver.DriverResponse;
import org.jboss.unit.driver.DriverCommand;
-import org.jboss.unit.driver.AbstractTestDriver;
+import org.jboss.unit.driver.DriverContext;
+import org.jboss.unit.driver.TestDriver;
import org.jboss.unit.driver.command.StartTestCommand;
import org.jboss.unit.driver.response.EndTestResponse;
import org.jboss.unit.info.TestInfo;
@@ -64,15 +65,67 @@
testTwoTestCases2();
testParametrization();
testParametrizationOverride();
+ testProperties1();
+ testProperties2();
+ testProperties3();
}
+ private static void testProperties1()
+ {
+ Driver1.init();
+ SimpleTestCaseInfo fooInfo = new SimpleTestCaseInfo("foo");
+ Driver1.testSuiteInfo.addTest(fooInfo);
+ GenericTestSuiteDef suite = new GenericTestSuiteDef("generic",
Driver1.class.getName());
+ suite.setProperty("foo_def", "foo_def_value");
+ GenericTestRunner runner = new GenericTestRunner(suite);
+ runner.run(new TestRunnerContextSupport());
+ Map<String, String> expectedProperties = new HashMap<String,
String>();
+ expectedProperties.put("foo_def", "foo_def_value");
+ assertEquals(expectedProperties, Driver1.properties);
+ }
+
+ private static void testProperties2()
+ {
+ Driver1.init();
+ SimpleTestCaseInfo fooInfo = new SimpleTestCaseInfo("foo");
+ Driver1.testSuiteInfo.addTest(fooInfo);
+ GenericTestSuiteDef suite = new GenericTestSuiteDef("generic",
Driver1.class.getName());
+ GenericTestRunner runner = new GenericTestRunner(suite);
+ Map<String, String> properties = new HashMap<String, String>();
+ properties.put("foo_runner", "foo_runner_value");
+ runner.run(new TestRunnerContextSupport(properties));
+ Map<String, String> expectedProperties = new HashMap<String,
String>();
+ expectedProperties.put("foo_runner", "foo_runner_value");
+ assertEquals(expectedProperties, Driver1.properties);
+ }
+
+ private static void testProperties3()
+ {
+ Driver1.init();
+ SimpleTestCaseInfo fooInfo = new SimpleTestCaseInfo("foo");
+ Driver1.testSuiteInfo.addTest(fooInfo);
+ GenericTestSuiteDef suite = new GenericTestSuiteDef("generic",
Driver1.class.getName());
+ suite.setProperty("foo_def", "foo_def_value");
+ suite.setProperty("bar", "bar_def_value");
+ GenericTestRunner runner = new GenericTestRunner(suite);
+ Map<String, String> properties = new HashMap<String, String>();
+ properties.put("foo_runner", "foo_runner_value");
+ properties.put("bar", "bar_runner_value");
+ runner.run(new TestRunnerContextSupport(properties));
+ Map<String, String> expectedProperties = new HashMap<String,
String>();
+ expectedProperties.put("foo_def", "foo_def_value");
+ expectedProperties.put("foo_runner", "foo_runner_value");
+ expectedProperties.put("bar", "bar_runner_value");
+ assertEquals(expectedProperties, Driver1.properties);
+ }
+
private static void testParametrization()
{
Driver1.init();
SimpleTestCaseInfo fooInfo = new SimpleTestCaseInfo("foo");
fooInfo.addParameter(new SimpleParameterInfo("abc"));
Driver1.testSuiteInfo.addTest(fooInfo);
- GenericTestSuiteDef suite = new GenericTestSuiteDef(Driver1.class.getName());
+ GenericTestSuiteDef suite = new GenericTestSuiteDef("generic",
Driver1.class.getName());
TestDef foo = new TestDef(new TestId("foo"));
suite.addTest(foo);
ParametersDef fooParameters = new ParametersDef();
@@ -102,7 +155,7 @@
SimpleTestCaseInfo fooInfo = new SimpleTestCaseInfo("foo");
fooInfo.addParameter(new SimpleParameterInfo("abc"));
Driver1.testSuiteInfo.addTest(fooInfo);
- GenericTestSuiteDef suite = new GenericTestSuiteDef(Driver1.class.getName());
+ GenericTestSuiteDef suite = new GenericTestSuiteDef("generic",
Driver1.class.getName());
TestDef foo = new TestDef(new TestId("foo"));
suite.addTest(foo);
ParametersDef fooParameters = new ParametersDef();
@@ -127,7 +180,7 @@
private static void testNoTestCase()
{
Driver1.init();
- GenericTestSuiteDef suite = new GenericTestSuiteDef(Driver1.class.getName());
+ GenericTestSuiteDef suite = new GenericTestSuiteDef("generic",
Driver1.class.getName());
EventList events = new EventList();
GenericTestRunner runner = new GenericTestRunner(suite);
runner.run(new TestRunnerContextSupport(events));
@@ -142,7 +195,7 @@
{
Driver1.init();
Driver1.testSuiteInfo.addTest(new SimpleTestCaseInfo("foo"));
- GenericTestSuiteDef suite = new GenericTestSuiteDef(Driver1.class.getName());
+ GenericTestSuiteDef suite = new GenericTestSuiteDef("generic",
Driver1.class.getName());
suite.addTest(new TestDef(new TestId("foo")));
EventList events = new EventList();
GenericTestRunner runner = new GenericTestRunner(suite);
@@ -161,7 +214,7 @@
Driver1.init();
Driver1.testSuiteInfo.addTest(new SimpleTestCaseInfo("foo"));
Driver1.testSuiteInfo.addTest(new SimpleTestCaseInfo("bar"));
- GenericTestSuiteDef suite = new GenericTestSuiteDef(Driver1.class.getName());
+ GenericTestSuiteDef suite = new GenericTestSuiteDef("generic",
Driver1.class.getName());
suite.addTest(new TestDef(new TestId("foo")));
EventList events = new EventList();
GenericTestRunner runner = new GenericTestRunner(suite);
@@ -180,7 +233,7 @@
Driver1.init();
Driver1.testSuiteInfo.addTest(new SimpleTestCaseInfo("foo"));
Driver1.testSuiteInfo.addTest(new SimpleTestCaseInfo("bar"));
- GenericTestSuiteDef suite = new GenericTestSuiteDef(Driver1.class.getName());
+ GenericTestSuiteDef suite = new GenericTestSuiteDef("generic",
Driver1.class.getName());
EventList events = new EventList();
GenericTestRunner runner = new GenericTestRunner(suite);
runner.run(new TestRunnerContextSupport(events));
@@ -195,20 +248,35 @@
assertEquals(list(new HashMap(), new HashMap()), Driver1.parametrizations);
}
- public static class Driver1 extends AbstractTestDriver
+ public static class Driver1 implements TestDriver
{
static SimpleTestSuiteInfo testSuiteInfo;
static List<TestId> ids;
static List<Map<String,String>> parametrizations;
+ static Map<String, String> properties;
static void init()
{
testSuiteInfo = new SimpleTestSuiteInfo("foo");
ids = new ArrayList<TestId>();
parametrizations = new ArrayList<Map<String,String>>();
+ properties = new HashMap<String, String>();
}
+ public void initDriver(DriverContext context)
+ {
+ for (String name : context.getPropertyNames())
+ {
+ properties.put(name, context.getProperty(name));
+ }
+ }
+
+ public void destroyDriver()
+ {
+
+ }
+
public TestInfo getInfo()
{
return testSuiteInfo;
Modified: modules/test/trunk/unit/src/main/org/jboss/unit/Failure.java
===================================================================
--- modules/test/trunk/unit/src/main/org/jboss/unit/Failure.java 2007-10-14 05:44:03 UTC
(rev 8641)
+++ modules/test/trunk/unit/src/main/org/jboss/unit/Failure.java 2007-10-14 12:05:55 UTC
(rev 8642)
@@ -76,24 +76,48 @@
return type;
}
+ public static Failure createFailure(Throwable cause)
+ {
+ if (cause instanceof AssertionError)
+ {
+ return new Failure(cause, FailureType.ASSERTION);
+ }
+ else
+ {
+ return new Failure(cause, FailureType.ERROR);
+ }
+ }
+
+ public static Failure createFailure(String message, Throwable cause)
+ {
+ if (cause instanceof AssertionError)
+ {
+ return new Failure(message, cause, FailureType.ASSERTION);
+ }
+ else
+ {
+ return new Failure(message, cause, FailureType.ERROR);
+ }
+ }
+
public static Failure createErrorFailure(String message)
{
return new Failure(message, FailureType.ERROR);
}
- public static Failure createErrorFailure(String message, Throwable throwable)
+ public static Failure createErrorFailure(String message, Throwable cause)
{
- return new Failure(message, throwable, FailureType.ERROR);
+ return new Failure(message, cause, FailureType.ERROR);
}
- public static Failure createErrorFailure(Throwable throwable)
+ public static Failure createErrorFailure(Throwable cause)
{
- return new Failure(throwable, FailureType.ERROR);
+ return new Failure(cause, FailureType.ERROR);
}
- public static Failure createAssertionFailure(AssertionError throwable)
+ public static Failure createAssertionFailure(Throwable cause)
{
- return new Failure(throwable, FailureType.ASSERTION);
+ return new Failure(cause, FailureType.ASSERTION);
}
public static Failure createAssertionFailure(String message)
Modified: modules/test/trunk/unit/src/main/org/jboss/unit/driver/DriverContext.java
===================================================================
--- modules/test/trunk/unit/src/main/org/jboss/unit/driver/DriverContext.java 2007-10-14
05:44:03 UTC (rev 8641)
+++ modules/test/trunk/unit/src/main/org/jboss/unit/driver/DriverContext.java 2007-10-14
12:05:55 UTC (rev 8642)
@@ -22,6 +22,8 @@
******************************************************************************/
package org.jboss.unit.driver;
+import java.util.Set;
+
/**
* The context in which a driver is placed.
*
@@ -32,10 +34,17 @@
{
/**
- * Return a property of the context.
+ * Returns the set of names available properties.
+ *
+ * @return the set of property names
+ */
+ Set<String> getPropertyNames();
+
+ /**
+ * Return a property of the context or null if it does not exist.
*
- * @param name
- * @return
+ * @param name the property name
+ * @return the property value
*/
String getProperty(String name);
Added:
modules/test/trunk/unit/src/main/org/jboss/unit/driver/impl/composite/CompositeTestDriver.java
===================================================================
---
modules/test/trunk/unit/src/main/org/jboss/unit/driver/impl/composite/CompositeTestDriver.java
(rev 0)
+++
modules/test/trunk/unit/src/main/org/jboss/unit/driver/impl/composite/CompositeTestDriver.java 2007-10-14
12:05:55 UTC (rev 8642)
@@ -0,0 +1,115 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.unit.driver.impl.composite;
+
+import org.jboss.unit.driver.TestDriver;
+import org.jboss.unit.driver.DriverResponse;
+import org.jboss.unit.driver.DriverCommand;
+import org.jboss.unit.driver.AbstractTestDriver;
+import org.jboss.unit.driver.response.FailureResponse;
+import org.jboss.unit.info.impl.SimpleTestSuiteInfo;
+import org.jboss.unit.info.TestInfo;
+import org.jboss.unit.TestId;
+import org.jboss.unit.Failure;
+
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class CompositeTestDriver extends AbstractTestDriver
+{
+
+ /** . */
+ private final SimpleTestSuiteInfo info = new SimpleTestSuiteInfo("Main");
+
+ /** . */
+ protected final Map<String, TestDriver> drivers = new HashMap<String,
TestDriver>();
+
+ public TestInfo getInfo()
+ {
+ return info;
+ }
+
+ public DriverResponse invoke(TestId id, DriverCommand command)
+ {
+ if (id.getLength() == 0)
+ {
+ return new FailureResponse(Failure.createErrorFailure("No null test id
accepted"));
+ }
+
+ //
+ String name = id.getName(0);
+
+ //
+ TestDriver driver = drivers.get(name);
+
+ //
+ if (driver == null)
+ {
+ return new FailureResponse(Failure.createErrorFailure("No test driver found
for name " + name));
+ }
+
+ //
+ TestId driverId = id.range(1);
+
+ //
+ return driver.invoke(driverId, command);
+ }
+
+ public void mount(TestDriver driver)
+ {
+ synchronized(TestDriver.class)
+ {
+ driver.initDriver(getContext());
+
+ //
+ info.addTest(driver.getInfo());
+
+ //
+ String name = driver.getInfo().getName();
+
+ //
+ drivers.put(name, driver);
+ }
+ }
+
+ public synchronized void unmount(TestDriver driver)
+ {
+ synchronized(TestDriver.class)
+ {
+ String name = driver.getInfo().getName();
+
+ //
+ drivers.remove(name);
+
+ //
+ info.removeTest(name);
+
+ //
+ driver.destroyDriver();
+ }
+ }
+}
Modified:
modules/test/trunk/unit/src/main/org/jboss/unit/driver/impl/pojo/POJOTestSuiteDriver.java
===================================================================
---
modules/test/trunk/unit/src/main/org/jboss/unit/driver/impl/pojo/POJOTestSuiteDriver.java 2007-10-14
05:44:03 UTC (rev 8641)
+++
modules/test/trunk/unit/src/main/org/jboss/unit/driver/impl/pojo/POJOTestSuiteDriver.java 2007-10-14
12:05:55 UTC (rev 8642)
@@ -28,7 +28,6 @@
import org.jboss.unit.spi.pojo.TestLifeCycle;
import org.jboss.unit.spi.pojo.TestCase;
import org.jboss.unit.spi.pojo.annotations.Provider;
-import org.jboss.unit.driver.TestDriver;
import org.jboss.unit.driver.DriverResponse;
import org.jboss.unit.driver.DriverCommand;
import org.jboss.unit.driver.AbstractTestDriver;
@@ -192,13 +191,6 @@
}
//
- if (t instanceof AssertionError)
- {
- return new FailureResponse(Failure.createAssertionFailure((AssertionError)t));
- }
- else
- {
- return new FailureResponse(Failure.createErrorFailure(t));
- }
+ return new FailureResponse(Failure.createFailure(t));
}
}
Modified:
modules/test/trunk/unit/src/main/org/jboss/unit/driver/impl/pojo/SimpleDriverContext.java
===================================================================
---
modules/test/trunk/unit/src/main/org/jboss/unit/driver/impl/pojo/SimpleDriverContext.java 2007-10-14
05:44:03 UTC (rev 8641)
+++
modules/test/trunk/unit/src/main/org/jboss/unit/driver/impl/pojo/SimpleDriverContext.java 2007-10-14
12:05:55 UTC (rev 8642)
@@ -26,6 +26,8 @@
import java.util.Map;
import java.util.HashMap;
+import java.util.Set;
+import java.util.Collections;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -43,7 +45,7 @@
{
throw new IllegalArgumentException("No null property name accepted");
}
- this.properties = properties;
+ this.properties = Collections.unmodifiableMap(properties);
}
public SimpleDriverContext()
@@ -51,6 +53,11 @@
this(new HashMap<String, String>());
}
+ public Set<String> getPropertyNames()
+ {
+ return properties.keySet();
+ }
+
public String getProperty(String name)
{
if (name == null)
Modified:
modules/test/trunk/unit/src/main/org/jboss/unit/runner/impl/TestRunnerContextSupport.java
===================================================================
---
modules/test/trunk/unit/src/main/org/jboss/unit/runner/impl/TestRunnerContextSupport.java 2007-10-14
05:44:03 UTC (rev 8641)
+++
modules/test/trunk/unit/src/main/org/jboss/unit/runner/impl/TestRunnerContextSupport.java 2007-10-14
12:05:55 UTC (rev 8642)
@@ -60,6 +60,11 @@
this(new HashMap<String, String>(), parametrizations,
NullFilter.getInstance(), new TestRunnerEventBroadcaster());
}
+ public TestRunnerContextSupport(Map<String, String> properties)
+ {
+ this(properties, new ParametrizationSet(), NullFilter.getInstance(), new
TestRunnerEventBroadcaster());
+ }
+
public TestRunnerContextSupport(ParametrizationSet parametrizations,
TestRunnerEventListener eventListener)
{
this(new HashMap<String, String>(), parametrizations,
NullFilter.getInstance(), eventListener);
Modified:
modules/test/trunk/unit/src/main/org/jboss/unit/runner/impl/driver/TestDriverRunner.java
===================================================================
---
modules/test/trunk/unit/src/main/org/jboss/unit/runner/impl/driver/TestDriverRunner.java 2007-10-14
05:44:03 UTC (rev 8641)
+++
modules/test/trunk/unit/src/main/org/jboss/unit/runner/impl/driver/TestDriverRunner.java 2007-10-14
12:05:55 UTC (rev 8642)
@@ -104,7 +104,7 @@
}
catch (Exception e)
{
- context.getEventListener().onEvent(new
RunnerFailureEvent(Failure.createErrorFailure("Was not able to start the test driver
properly", e)));
+ context.getEventListener().onEvent(new
RunnerFailureEvent(Failure.createFailure("Was not able to start the test driver
properly", e)));
return;
}
Modified:
modules/test/trunk/unit/src/main/org/jboss/unit/runner/impl/generic/GenericTestRunner.java
===================================================================
---
modules/test/trunk/unit/src/main/org/jboss/unit/runner/impl/generic/GenericTestRunner.java 2007-10-14
05:44:03 UTC (rev 8641)
+++
modules/test/trunk/unit/src/main/org/jboss/unit/runner/impl/generic/GenericTestRunner.java 2007-10-14
12:05:55 UTC (rev 8642)
@@ -37,6 +37,8 @@
import java.util.Collection;
import java.util.Collections;
+import java.util.Map;
+import java.util.HashMap;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -75,6 +77,10 @@
testDefs = Collections.singleton(new TestDef(new TestId()));
}
+ // Compute properties
+ Map<String, String> properties = new HashMap<String,
String>(def.getProperties());
+ properties.putAll(context.getProperties());
+
for (TestDef testDef : testDefs)
{
// Create parametrization
@@ -83,7 +89,7 @@
parametrizations.combine(context.getParametrizations());
//
- TestRunnerContextSupport genericContext = new
TestRunnerContextSupport(context.getProperties(), parametrizations, context.getFilter(),
filter);
+ TestRunnerContextSupport genericContext = new
TestRunnerContextSupport(properties, parametrizations, context.getFilter(), filter);
//
TestDriverRunner runner = new TestDriverRunner(driver, testDef.getRefId());
@@ -94,7 +100,7 @@
}
catch (Exception e)
{
- context.getEventListener().onEvent(new
RunnerFailureEvent(Failure.createErrorFailure("Cannot execute test class " +
className,e)));
+ context.getEventListener().onEvent(new
RunnerFailureEvent(Failure.createFailure("Cannot execute test class " +
className,e)));
}
}
}
Modified:
modules/test/trunk/unit/src/main/org/jboss/unit/runner/impl/pojo/POJOTestRunner.java
===================================================================
---
modules/test/trunk/unit/src/main/org/jboss/unit/runner/impl/pojo/POJOTestRunner.java 2007-10-14
05:44:03 UTC (rev 8641)
+++
modules/test/trunk/unit/src/main/org/jboss/unit/runner/impl/pojo/POJOTestRunner.java 2007-10-14
12:05:55 UTC (rev 8642)
@@ -40,6 +40,8 @@
import java.util.List;
import java.util.ArrayList;
+import java.util.Map;
+import java.util.HashMap;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -49,16 +51,16 @@
{
/** . */
- private final POJOTestSuiteDef suite;
+ private final POJOTestSuiteDef def;
public POJOTestRunner(POJOTestSuiteDef suiteDef)
{
- this.suite = suiteDef;
+ this.def = suiteDef;
}
protected void internalRun(TestRunnerContext context)
{
- for (TestClassDef testClass : suite.getTestClasses())
+ for (TestClassDef testClass : def.getTestClasses())
{
String className = testClass.getName();
@@ -86,12 +88,16 @@
}
// Create parametrization
- ParametrizationSet parametrizations =
suite.getParameters().getParametrization().clone();
+ ParametrizationSet parametrizations =
def.getParameters().getParametrization().clone();
parametrizations.combine(testClass.getParameters().getParametrization());
parametrizations.combine(context.getParametrizations());
+ // Compute properties
+ Map<String, String> properties = new HashMap<String,
String>(def.getProperties());
+ properties.putAll(context.getProperties());
+
//
- TestRunnerContextSupport pojoContext = new
TestRunnerContextSupport(context.getProperties(), parametrizations, context.getFilter(),
filter);
+ TestRunnerContextSupport pojoContext = new
TestRunnerContextSupport(properties, parametrizations, context.getFilter(), filter);
//
TestDriverRunner runner = new TestDriverRunner(driver);
@@ -106,7 +112,7 @@
}
catch (Exception e)
{
- context.getEventListener().onEvent(new
RunnerFailureEvent(Failure.createErrorFailure("Cannot execute test class " +
className,e)));
+ context.getEventListener().onEvent(new
RunnerFailureEvent(Failure.createFailure("Cannot execute test class " +
className,e)));
}
}
}
Modified: modules/test/trunk/unit/src/main/org/jboss/unit/runner/model/ModelBuilder.java
===================================================================
---
modules/test/trunk/unit/src/main/org/jboss/unit/runner/model/ModelBuilder.java 2007-10-14
05:44:03 UTC (rev 8641)
+++
modules/test/trunk/unit/src/main/org/jboss/unit/runner/model/ModelBuilder.java 2007-10-14
12:05:55 UTC (rev 8642)
@@ -50,6 +50,8 @@
import javax.xml.transform.stream.StreamSource;
import java.util.List;
import java.util.ArrayList;
+import java.util.Map;
+import java.util.HashMap;
import java.io.IOException;
import java.io.InputStream;
@@ -162,17 +164,23 @@
}
//
- Attr attr = classElt.getAttributeNode("name");
- if (attr == null)
+ Attr nameAttrOfClassElt = classElt.getAttributeNode("name");
+ if (nameAttrOfClassElt == null)
{
throw new IllegalArgumentException();
}
//
- String className = attr.getValue();
- GenericTestSuiteDef suite = new GenericTestSuiteDef(className);
+ Attr nameAttr = suiteElt.getAttributeNode("name");
+ if (nameAttr == null)
+ {
+ throw new IllegalArgumentException();
+ }
//
+ GenericTestSuiteDef suite = new GenericTestSuiteDef(nameAttr.getValue(),
nameAttrOfClassElt.getValue());
+
+ //
for (Element testElt : children(suiteElt, "test"))
{
Attr refidAttr = testElt.getAttributeNode("refid");
@@ -198,6 +206,9 @@
}
//
+ suite.setProperties(buildProperties(suiteElt));
+
+ //
suite.setParameters(buildParameters(suiteElt));
//
@@ -246,6 +257,9 @@
}
//
+ suite.setProperties(buildProperties(suiteElt));
+
+ //
suite.setParameters(buildParameters(suiteElt));
//
@@ -256,6 +270,18 @@
private static final int ELEMENT_SOURCE = 1;
private static final int ATTRIBUTE_SOURCE = 2;
+ private Map<String, String> buildProperties(Element propertyEltContainer)
+ {
+ Map<String, String> properties = new HashMap<String, String>();
+ for (Element propertyElt : children(propertyEltContainer, "property"))
+ {
+ String propertyName = propertyElt.getAttribute("name");
+ String propertyValue = propertyElt.getAttribute("value");
+ properties.put(propertyName, propertyValue);
+ }
+ return properties;
+ }
+
private ParametersDef buildParameters(Element parameterEltContainer)
{
ParametersDef parameters = new ParametersDef();
Modified: modules/test/trunk/unit/src/main/org/jboss/unit/runner/model/TestSuiteDef.java
===================================================================
---
modules/test/trunk/unit/src/main/org/jboss/unit/runner/model/TestSuiteDef.java 2007-10-14
05:44:03 UTC (rev 8641)
+++
modules/test/trunk/unit/src/main/org/jboss/unit/runner/model/TestSuiteDef.java 2007-10-14
12:05:55 UTC (rev 8642)
@@ -27,6 +27,8 @@
import java.util.List;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Map;
+import java.util.HashMap;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -38,6 +40,9 @@
/** . */
protected ParametersDef parameters = new ParametersDef();
+ /** . */
+ protected Map<String, String> properties = new HashMap<String, String>();
+
public ParametersDef getParameters()
{
return parameters;
@@ -48,6 +53,32 @@
this.parameters = parameters;
}
+ public Map<String, String> getProperties()
+ {
+ return properties;
+ }
+
+ public void setProperties(Map<String, String> properties)
+ {
+ this.properties = properties;
+ }
+
+ public void setProperty(String name, String value)
+ {
+ if (name == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (value == null)
+ {
+ properties.remove(name);
+ }
+ else
+ {
+ properties.put(name, value);
+ }
+ }
+
public abstract TestRunner createRunner() throws BuilderException;
}
Modified:
modules/test/trunk/unit/src/main/org/jboss/unit/runner/model/generic/GenericTestSuiteDef.java
===================================================================
---
modules/test/trunk/unit/src/main/org/jboss/unit/runner/model/generic/GenericTestSuiteDef.java 2007-10-14
05:44:03 UTC (rev 8641)
+++
modules/test/trunk/unit/src/main/org/jboss/unit/runner/model/generic/GenericTestSuiteDef.java 2007-10-14
12:05:55 UTC (rev 8642)
@@ -24,7 +24,6 @@
import org.jboss.unit.runner.model.TestSuiteDef;
import org.jboss.unit.runner.model.BuilderException;
-import org.jboss.unit.runner.model.generic.TestDef;
import org.jboss.unit.runner.TestRunner;
import org.jboss.unit.runner.impl.generic.GenericTestRunner;
@@ -39,16 +38,25 @@
{
/** The tests. */
- private List<TestDef> tests = new ArrayList<TestDef>();
+ private final List<TestDef> tests = new ArrayList<TestDef>();
/** . */
- private String className;
+ private final String name;
- public GenericTestSuiteDef(String className)
+ /** . */
+ private final String className;
+
+ public GenericTestSuiteDef(String name, String className)
{
+ this.name = name;
this.className = className;
}
+ public String getName()
+ {
+ return name;
+ }
+
public String getClassName()
{
return className;
Modified:
modules/test/trunk/unit/src/resources/jboss-unit-jar/org/jboss/unit/runner/model/jboss-unit_1_0.xsd
===================================================================
---
modules/test/trunk/unit/src/resources/jboss-unit-jar/org/jboss/unit/runner/model/jboss-unit_1_0.xsd 2007-10-14
05:44:03 UTC (rev 8641)
+++
modules/test/trunk/unit/src/resources/jboss-unit-jar/org/jboss/unit/runner/model/jboss-unit_1_0.xsd 2007-10-14
12:05:55 UTC (rev 8642)
@@ -35,20 +35,10 @@
a set of test definitions and a set of tests to
execute.</xsd:documentation></xsd:annotation>
<xsd:sequence>
<xsd:element name="parameter" type="parameterType"
minOccurs="0" maxOccurs="unbounded"/>
- <xsd:element name="test-def" type="pojo_testDefType"
minOccurs="0" maxOccurs="unbounded"/>
<xsd:element name="test" type="pojo_testType"
minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
- <xsd:complexType name="pojo_testDefType">
- <xsd:annotation><xsd:documentation>Defines a pojo test with a mandatory
id attribute. The id attribute is used by
- test elements which can refer to
it.</xsd:documentation></xsd:annotation>
- <xsd:sequence>
- <xsd:element name="class" type="pojo_classType"
minOccurs="1" maxOccurs="1"/>
- </xsd:sequence>
- <xsd:attribute name="id" use="required"/>
- </xsd:complexType>
-
<xsd:complexType name="pojo_classType">
<xsd:annotation><xsd:documentation>Defines a tested class. A tested
class can contain any number of case.
If the class element contains no case then all test cases returned by the class
meta data will be executed. The
@@ -71,6 +61,7 @@
the test configuration, they override any existing parameter defined at the pojo
level.</xsd:documentation></xsd:annotation>
<xsd:sequence>
<xsd:element name="class" type="pojo_classType"
minOccurs="1" maxOccurs="1"/>
+ <xsd:element name="property" type="propertyType"
minOccurs="0" maxOccurs="unbounded"/>
<xsd:element name="parameter" type="parameterType"
minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
@@ -84,9 +75,11 @@
<xsd:attribute name="name" type="xsd:string"
use="required"/>
</xsd:complexType>
</xsd:element>
+ <xsd:element name="property" type="propertyType"
minOccurs="0" maxOccurs="unbounded"/>
<xsd:element name="parameter" type="parameterType"
minOccurs="0" maxOccurs="unbounded"/>
<xsd:element name="test" type="generic_testType"
minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string"
use="required"/>
</xsd:complexType>
<xsd:complexType name="generic_testType">
@@ -112,4 +105,10 @@
<xsd:attribute name="value" type="xsd:string"/>
</xsd:complexType>
+ <xsd:complexType name="propertyType">
+ <xsd:annotation><xsd:documentation>A property
element.</xsd:documentation></xsd:annotation>
+ <xsd:attribute name="name" type="xsd:string"
use="required"/>
+ <xsd:attribute name="value" type="xsd:string"
use="required"/>
+ </xsd:complexType>
+
</xsd:schema>
Modified:
modules/test/trunk/unit/src/resources/test/org/jboss/test/unit/runner/model/f2.xml
===================================================================
---
modules/test/trunk/unit/src/resources/test/org/jboss/test/unit/runner/model/f2.xml 2007-10-14
05:44:03 UTC (rev 8641)
+++
modules/test/trunk/unit/src/resources/test/org/jboss/test/unit/runner/model/f2.xml 2007-10-14
12:05:55 UTC (rev 8642)
@@ -3,7 +3,7 @@
xmlns="urn:jboss:jboss-unit:1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:jboss:jboss-unit:1.0 jboss-unit_1_0.xsd">
- <generic>
+ <generic name="foo_generic">
<class name="foo_generic"/>
<parameter name="red" value="blue"/>
<test refid="foo"/>