Author: julien(a)jboss.com
Date: 2007-10-09 18:05:30 -0400 (Tue, 09 Oct 2007)
New Revision: 8578
Added:
modules/test/trunk/unit/src/main/org/jboss/test/unit/runner/TestDriverRunnerTests.java
Modified:
modules/test/trunk/unit/src/main/org/jboss/test/unit/AllTests.java
modules/test/trunk/unit/src/main/org/jboss/unit/FailureType.java
modules/test/trunk/unit/src/main/org/jboss/unit/TestId.java
modules/test/trunk/unit/src/main/org/jboss/unit/report/junit/JUnitReporter.java
modules/test/trunk/unit/src/main/org/jboss/unit/runner/impl/composite/CompositeTestRunner.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/event/EventDrivenTestRunner.java
modules/test/trunk/unit/src/main/org/jboss/unit/runner/impl/pojo/POJOTestRunner.java
Log:
start to write test for TestDriverRunner
Modified: modules/test/trunk/unit/src/main/org/jboss/test/unit/AllTests.java
===================================================================
--- modules/test/trunk/unit/src/main/org/jboss/test/unit/AllTests.java 2007-10-09 18:59:45
UTC (rev 8577)
+++ modules/test/trunk/unit/src/main/org/jboss/test/unit/AllTests.java 2007-10-09 22:05:30
UTC (rev 8578)
@@ -28,6 +28,7 @@
import org.jboss.test.unit.pojo.junit.JUnitPOJOTests;
import org.jboss.test.unit.runner.CompositeTestRunnerTests;
import org.jboss.test.unit.runner.ParametrizationTests;
+import org.jboss.test.unit.runner.TestDriverRunnerTests;
import org.jboss.test.unit.runner.event.TestRunnerEventBroadcasterSupportTests;
import org.jboss.test.unit.runner.event.TestRunnerLifeCycleFilterTests;
import org.jboss.test.unit.runner.model.ModelTests;
@@ -46,6 +47,7 @@
AbstractPOJOTests.main(args);
JUnitPOJOTests.main(args);
CompositeTestRunnerTests.main(args);
+ TestDriverRunnerTests.main(args);
//
TestRunnerLifeCycleFilterTests.main(args);
Added:
modules/test/trunk/unit/src/main/org/jboss/test/unit/runner/TestDriverRunnerTests.java
===================================================================
---
modules/test/trunk/unit/src/main/org/jboss/test/unit/runner/TestDriverRunnerTests.java
(rev 0)
+++
modules/test/trunk/unit/src/main/org/jboss/test/unit/runner/TestDriverRunnerTests.java 2007-10-09
22:05:30 UTC (rev 8578)
@@ -0,0 +1,162 @@
+/******************************************************************************
+ * 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.test.unit.runner;
+
+import org.jboss.unit.runner.impl.driver.TestDriverRunner;
+import org.jboss.unit.runner.TestRunnerEventListener;
+import org.jboss.unit.runner.TestRunnerEvent;
+import org.jboss.unit.runner.results.TestFailure;
+import org.jboss.unit.runner.event.EndTestEvent;
+import org.jboss.unit.runner.event.StartTestEvent;
+import org.jboss.unit.driver.TestDriver;
+import org.jboss.unit.driver.DriverResponse;
+import org.jboss.unit.driver.DriverCommand;
+import org.jboss.unit.driver.response.EndTestResponse;
+import org.jboss.unit.driver.response.FailureResponse;
+import org.jboss.unit.info.TestInfo;
+import org.jboss.unit.info.impl.SimpleTestSuiteInfo;
+import org.jboss.unit.info.impl.SimpleTestCaseInfo;
+import org.jboss.unit.TestId;
+import org.jboss.unit.FailureType;
+import org.jboss.unit.Failure;
+
+import java.util.List;
+import java.util.ArrayList;
+
+import static org.jboss.unit.api.Assert.*;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class TestDriverRunnerTests
+{
+
+ private static class Blah implements TestRunnerEventListener
+ {
+
+ /** . */
+ private final List<TestRunnerEvent> events = new
ArrayList<TestRunnerEvent>();
+
+ public void onEvent(TestRunnerEvent event)
+ {
+ events.add(event);
+ }
+ }
+
+ public static void main(String[] args)
+ {
+ testEmptyDriver();
+ testTestDriverInvokeReturnsNull();
+ testTestDriverInvokeReturnsAnEndTestResponse();
+ testTestDriverInvokeReturnsAFailureResponse();
+
+
+ }
+
+ private static void testEmptyDriver()
+ {
+ TestDriverImpl testDriver = new TestDriverImpl();
+ TestDriverRunner runner = new TestDriverRunner(testDriver, new TestId());
+ runner.run();
+ }
+
+ private static void testTestDriverInvokeReturnsNull()
+ {
+ TestDriverImpl testDriver = new TestDriverImpl();
+ testDriver.info.addTest(new SimpleTestCaseInfo("Foo"));
+ TestDriverRunner runner = new TestDriverRunner(testDriver, new TestId());
+
+ Blah listener = new Blah();
+ runner.addListener(listener);
+
+ // Check that we received an error
+ runner.run();
+
+ //
+ assertEquals(4, listener.events.size());
+
+ //
+ StartTestEvent startEvent = assertInstanceOf(listener.events.get(1),
StartTestEvent.class);
+ assertEquals(new TestId("Foo"), startEvent.getTestId());
+
+ //
+ EndTestEvent endEvent = assertInstanceOf(listener.events.get(2),
EndTestEvent.class);
+ assertEquals(new TestId("Foo"), endEvent.getTestId());
+ TestFailure testFailure = assertInstanceOf(endEvent.getTestResult(),
TestFailure.class);
+ Failure failure = testFailure.getFailure();
+ assertEquals(FailureType.ERROR, failure.getType());
+ }
+
+ private static void testTestDriverInvokeReturnsAnEndTestResponse()
+ {
+ TestDriverImpl testDriver = new TestDriverImpl()
+ {
+ public DriverResponse invoke(TestId id, DriverCommand command)
+ {
+ return new EndTestResponse();
+ }
+ };
+ testDriver.info.addTest(new SimpleTestCaseInfo("Foo"));
+ TestDriverRunner runner = new TestDriverRunner(testDriver, new TestId());
+
+ // Check that we received an internal error
+ runner.run();
+ }
+
+ private static void testTestDriverInvokeReturnsAFailureResponse()
+ {
+ TestDriverImpl testDriver = new TestDriverImpl()
+ {
+ public DriverResponse invoke(TestId id, DriverCommand command)
+ {
+ return new FailureResponse(FailureType.ERROR);
+ }
+ };
+ testDriver.info.addTest(new SimpleTestCaseInfo("Foo"));
+ TestDriverRunner runner = new TestDriverRunner(testDriver, new TestId());
+
+ // Check that we received an internal error
+ runner.run();
+ }
+
+ private static class TestDriverImpl implements TestDriver
+ {
+
+ /** . */
+ private SimpleTestSuiteInfo info = new SimpleTestSuiteInfo("blah");
+
+ public TestInfo getInfo()
+ {
+ return info;
+ }
+
+ public DriverResponse invoke(TestId id, DriverCommand command)
+ {
+ return null;
+ }
+ }
+
+
+
+}
Modified: modules/test/trunk/unit/src/main/org/jboss/unit/FailureType.java
===================================================================
--- modules/test/trunk/unit/src/main/org/jboss/unit/FailureType.java 2007-10-09 18:59:45
UTC (rev 8577)
+++ modules/test/trunk/unit/src/main/org/jboss/unit/FailureType.java 2007-10-09 22:05:30
UTC (rev 8578)
@@ -30,7 +30,13 @@
*/
public enum FailureType
{
+ /**
+ * A failure that is not expected
+ */
ERROR,
+
+ /**
+ * A failure that is expected.
+ */
ASSERTION,
- INTERNAL_ERROR
}
Modified: modules/test/trunk/unit/src/main/org/jboss/unit/TestId.java
===================================================================
--- modules/test/trunk/unit/src/main/org/jboss/unit/TestId.java 2007-10-09 18:59:45 UTC
(rev 8577)
+++ modules/test/trunk/unit/src/main/org/jboss/unit/TestId.java 2007-10-09 22:05:30 UTC
(rev 8578)
@@ -220,6 +220,9 @@
return false;
}
}
+
+ //
+ return true;
}
//
Modified: modules/test/trunk/unit/src/main/org/jboss/unit/report/junit/JUnitReporter.java
===================================================================
---
modules/test/trunk/unit/src/main/org/jboss/unit/report/junit/JUnitReporter.java 2007-10-09
18:59:45 UTC (rev 8577)
+++
modules/test/trunk/unit/src/main/org/jboss/unit/report/junit/JUnitReporter.java 2007-10-09
22:05:30 UTC (rev 8578)
@@ -88,10 +88,6 @@
{
report.runnerFailed((RunnerFailureEvent) event);
}
- else if (event instanceof StartTestEvent)
- {
- report.startTest((StartTestEvent) event);
- }
else if (event instanceof EndTestEvent)
{
report.endTest((EndTestEvent) event);
Modified:
modules/test/trunk/unit/src/main/org/jboss/unit/runner/impl/composite/CompositeTestRunner.java
===================================================================
---
modules/test/trunk/unit/src/main/org/jboss/unit/runner/impl/composite/CompositeTestRunner.java 2007-10-09
18:59:45 UTC (rev 8577)
+++
modules/test/trunk/unit/src/main/org/jboss/unit/runner/impl/composite/CompositeTestRunner.java 2007-10-09
22:05:30 UTC (rev 8578)
@@ -52,7 +52,7 @@
this.lifeCycleFilter = new TestRunnerLifeCycleFilter(broadcaster);
}
- public void internalRun(TestFilter filter)
+ protected void internalRun(TestFilter filter)
{
for (TestRunner runner : runners)
{
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-09
18:59:45 UTC (rev 8577)
+++
modules/test/trunk/unit/src/main/org/jboss/unit/runner/impl/driver/TestDriverRunner.java 2007-10-09
22:05:30 UTC (rev 8578)
@@ -32,6 +32,7 @@
import org.jboss.unit.info.TestInfo;
import org.jboss.unit.TestId;
import org.jboss.unit.Failure;
+import org.jboss.unit.FailureType;
import org.jboss.unit.runner.results.TestSuccess;
import org.jboss.unit.runner.results.TestFailure;
import org.jboss.unit.runner.event.StartTestEvent;
@@ -40,6 +41,7 @@
import org.jboss.unit.runner.AbstractTestRunner;
import org.jboss.unit.runner.TestFilter;
import org.jboss.unit.runner.TestResult;
+import org.jboss.unit.runner.ParametrizationSet;
import java.util.Map;
import java.util.HashMap;
@@ -48,6 +50,13 @@
* An implementation that uses a test driver and transform test driver
* interactions into runner interactions.
*
+ * During the invocation of a test case through the <code>invoke</code>
method of the test driver, it
+ * expects a non null response of type <code>EndTestResponse</code> or
<code>FailureResponse</code>. For a normal
+ * test case invocation the runner will fire TODO
+ * If the test case invocation fails because an unexpected runtime exception is thrown or
because the returned
+ * value is not of the expected type then the runner will broadcast an
<code>EndTestEvent</code> with a <code>TestResult<code>
+ * object of type <code>TestFailure</code>.
+ *
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
*/
@@ -58,24 +67,24 @@
private final TestDriver driver;
/** . */
- private final Map<String,String> parametrization;
+ private final ParametrizationSet parametrizationSet;
/** . */
private final TestId testId;
- public TestDriverRunner(TestDriver driver, Map<String,String> parametrization,
TestId testId)
+ public TestDriverRunner(TestDriver driver, ParametrizationSet parametrizationSet,
TestId testId)
{
this.driver = driver;
- this.parametrization = parametrization;
+ this.parametrizationSet = parametrizationSet;
this.testId = testId;
}
public TestDriverRunner(TestDriver driver, TestId testId)
{
- this(driver, new HashMap<String, String>(), testId);
+ this(driver, new ParametrizationSet(), testId);
}
- public void internalRun(TestFilter filter)
+ protected void internalRun(TestFilter filter)
{
TestSuiteInfo info = (TestSuiteInfo)driver.getInfo();
@@ -83,38 +92,56 @@
TestInfo testInfo = info.findTest(testId);
//
+ internalRun(filter, testInfo, testId);
+ }
+
+ private void internalRun(TestFilter filter, TestInfo testInfo, TestId testId)
+ {
if (filter.include(testId, testInfo))
{
+ if (testInfo instanceof TestSuiteInfo)
+ {
+ TestSuiteInfo testSuiteInfo = (TestSuiteInfo)testInfo;
- if (testInfo instanceof TestCaseInfo)
+ //
+ for (String name : testSuiteInfo.getNames())
+ {
+ TestInfo childTestInfo = testSuiteInfo.getTest(name);
+ internalRun(filter, childTestInfo, new TestId(testId, name));
+ }
+ }
+ else
{
-
TestCaseInfo testCaseInfo = (TestCaseInfo)testInfo;
+ for (Map<String,String> parametrization :
parametrizationSet.enumerate(testCaseInfo.getParameters().keySet()))
+ {
+ fireEvent(new StartTestEvent(testId, testCaseInfo));
- fireEvent(new StartTestEvent(testId, testCaseInfo));
+ //
+ DriverResponse response = driver.invoke(testId, new
StartTestCommand(parametrization));
- DriverResponse response = driver.invoke(testId, new
StartTestCommand(parametrization));
+ //
+ TestResult result;
+ if (response instanceof EndTestResponse)
+ {
+ result = new TestSuccess(0);
+ }
+ else if (response instanceof FailureResponse)
+ {
+ FailureResponse failureResponse = (FailureResponse)response;
+ Failure failure = failureResponse.getFailure();
+ result = new TestFailure(failure, 0);
+ }
+ else
+ {
+ Failure failure = new Failure("The test driver returned an
unexpected response " + response, FailureType.ERROR);
+ result = new TestFailure(failure, 0);
+ }
- TestResult result = null;
-
- if (response instanceof EndTestResponse)
- {
- result = new TestSuccess(0);
+ //
+ fireEvent(new EndTestEvent(testId, result));
}
- else if (response instanceof FailureResponse)
- {
- FailureResponse failureResponse = (FailureResponse)response;
- Failure failure = failureResponse.getFailure();
- result = new TestFailure(failure, 0);
- }
-
- //
- fireEvent(new EndTestEvent(testId, result));
}
- else
- {
- fireEvent(new RunnerFailureEvent(Failure.createErrorFailure("Cannot
execute test id " + testId)));
- }
}
}
}
Modified:
modules/test/trunk/unit/src/main/org/jboss/unit/runner/impl/event/EventDrivenTestRunner.java
===================================================================
---
modules/test/trunk/unit/src/main/org/jboss/unit/runner/impl/event/EventDrivenTestRunner.java 2007-10-09
18:59:45 UTC (rev 8577)
+++
modules/test/trunk/unit/src/main/org/jboss/unit/runner/impl/event/EventDrivenTestRunner.java 2007-10-09
22:05:30 UTC (rev 8578)
@@ -49,7 +49,7 @@
this.events = events;
}
- public void internalRun(TestFilter filter)
+ protected void internalRun(TestFilter filter)
{
for (TestRunnerEvent event : events)
{
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-09
18:59:45 UTC (rev 8577)
+++
modules/test/trunk/unit/src/main/org/jboss/unit/runner/impl/pojo/POJOTestRunner.java 2007-10-09
22:05:30 UTC (rev 8578)
@@ -42,7 +42,6 @@
import java.util.List;
import java.util.ArrayList;
-import java.util.Map;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -103,26 +102,17 @@
}
// Create parametrization
-
-
ParametrizationSet parametrizations =
suite.getParameters().getParametrization();
parametrizations.merge(test.getParameters().getParametrization());
-// Map<String,Iterable<String>> generator = new
HashMap<String, Iterable<String>>();
-
//
for (String testCaseName : testCaseNames)
{
TestId testCaseId = new TestId(testCaseName);
-
TestCaseInfo testCaseInfo =
(TestCaseInfo)testSuiteInfo.findTest(testCaseId);
-
- for (Map<String,String> blah :
parametrizations.enumerate(testCaseInfo.getParameters().keySet()))
- {
- TestDriverRunner runner = new TestDriverRunner(driver, blah,
testCaseId);
- runner.addListener(lifeCycleFilter);
- runner.run(filter);
- }
+ TestDriverRunner runner = new TestDriverRunner(driver,
parametrizations, testCaseId);
+ runner.addListener(lifeCycleFilter);
+ runner.run(filter);
}
}
catch (Exception e)