Author: julien(a)jboss.com
Date: 2007-10-15 18:45:01 -0400 (Mon, 15 Oct 2007)
New Revision: 8668
Added:
modules/test/trunk/unit/src/main/org/jboss/unit/driver/DriverException.java
Modified:
modules/test/trunk/remote/src/main/org/jboss/unit/remote/driver/RemoteTestDriverClient.java
modules/test/trunk/unit/src/main/org/jboss/test/unit/runner/EventList.java
modules/test/trunk/unit/src/main/org/jboss/test/unit/runner/TestDriverRunnerTests.java
modules/test/trunk/unit/src/main/org/jboss/unit/driver/TestDriver.java
modules/test/trunk/unit/src/main/org/jboss/unit/driver/impl/composite/CompositeTestDriver.java
modules/test/trunk/unit/src/main/org/jboss/unit/runner/impl/driver/TestDriverRunner.java
Log:
added support for failure during test driver init by throwing an exception + the test
cases for testing failures behavior during init/destroy phases
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-15
22:09:35 UTC (rev 8667)
+++
modules/test/trunk/remote/src/main/org/jboss/unit/remote/driver/RemoteTestDriverClient.java 2007-10-15
22:45:01 UTC (rev 8668)
@@ -26,6 +26,7 @@
import org.jboss.unit.driver.DriverCommand;
import org.jboss.unit.driver.DriverResponse;
import org.jboss.unit.driver.DriverContext;
+import org.jboss.unit.driver.DriverException;
import org.jboss.unit.driver.response.FailureResponse;
import org.jboss.unit.driver.command.StartTestCommand;
import org.jboss.unit.info.TestInfo;
@@ -132,11 +133,10 @@
return (RemoteTestDriver)node.lookupService(RemoteTestDriver.SERVICE_ID);
}
- private FailureResponse failed;
private KernelDeployment deployment;
private BeanXMLDeployer beanDeployer;
- public void initDriver(DriverContext context)
+ public void initDriver(DriverContext context) throws DriverException
{
this.context = context;
@@ -160,9 +160,7 @@
}
catch (Throwable throwable)
{
- throwable.printStackTrace();
- failed = new FailureResponse(Failure.createFailure("Could not startup
kernel", throwable));
- return;
+ throw new DriverException("Could not start the kernel", throwable);
}
// Now deploy beans
@@ -183,8 +181,7 @@
}
catch (Throwable throwable)
{
- throwable.printStackTrace();
- failed = new FailureResponse(Failure.createFailure("Could not deploy
beans", throwable));
+ throw new DriverException("Could not deploy the beans", throwable);
}
// Always retrieve meta data from the default node
Modified: modules/test/trunk/unit/src/main/org/jboss/test/unit/runner/EventList.java
===================================================================
--- modules/test/trunk/unit/src/main/org/jboss/test/unit/runner/EventList.java 2007-10-15
22:09:35 UTC (rev 8667)
+++ modules/test/trunk/unit/src/main/org/jboss/test/unit/runner/EventList.java 2007-10-15
22:45:01 UTC (rev 8668)
@@ -33,6 +33,7 @@
import org.jboss.unit.runner.event.EndRunnerEvent;
import org.jboss.unit.runner.event.StartTestSuiteEvent;
import org.jboss.unit.runner.event.EndTestSuiteEvent;
+import org.jboss.unit.runner.event.RunnerFailureEvent;
import static org.jboss.unit.api.Assert.*;
import org.jboss.unit.TestId;
@@ -54,6 +55,18 @@
events.add(event);
}
+ protected RunnerFailureEvent assertRunnerFailureEvent(int index)
+ {
+ assertTrue(events.size() > index);
+ TestRunnerEvent event = assertNotNull(events.get(index));
+ return assertRunnerFailureEvent(event);
+ }
+
+ protected RunnerFailureEvent assertRunnerFailureEvent(TestRunnerEvent event)
+ {
+ return assertInstanceOf(event, RunnerFailureEvent.class);
+ }
+
protected StartRunnerEvent assertStartRunnerEvent(int index)
{
assertTrue(events.size() > index);
Modified:
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 2007-10-15
22:09:35 UTC (rev 8667)
+++
modules/test/trunk/unit/src/main/org/jboss/test/unit/runner/TestDriverRunnerTests.java 2007-10-15
22:45:01 UTC (rev 8668)
@@ -30,11 +30,15 @@
import org.jboss.unit.runner.event.EndTestCaseEvent;
import org.jboss.unit.driver.DriverResponse;
import org.jboss.unit.driver.DriverCommand;
+import org.jboss.unit.driver.TestDriver;
+import org.jboss.unit.driver.DriverContext;
+import org.jboss.unit.driver.DriverException;
import org.jboss.unit.driver.response.EndTestResponse;
import org.jboss.unit.driver.response.FailureResponse;
import org.jboss.unit.info.impl.SimpleTestCaseInfo;
import org.jboss.unit.info.impl.SimpleParameterInfo;
import org.jboss.unit.info.impl.SimpleTestSuiteInfo;
+import org.jboss.unit.info.TestInfo;
import org.jboss.unit.TestId;
import org.jboss.unit.FailureType;
import org.jboss.unit.Failure;
@@ -75,8 +79,188 @@
//
testEvents1();
+
+ //
+ testInit();
+ testInitThrowsDriverException();
+ testInitThrowsRuntimeException();
+ testInitThrowsError();
+
+ //
+ testDestroyThrowsRuntimeException();
+ testDestroyThrowsError();
}
+ private static void testDestroyThrowsError()
+ {
+ final Error error = new Error();
+ FailureTestDriver testDriver = new FailureTestDriver()
+ {
+ public void destroyDriver()
+ {
+ throw error;
+ }
+ };
+
+ //
+ TestDriverRunner runner = new TestDriverRunner(testDriver, new TestId());
+ EventList listener = new EventList();
+ try
+ {
+ runner.run(new TestRunnerContextSupport(listener));
+ fail();
+ }
+ catch (Error e)
+ {
+ assertSame(error, e);
+ }
+
+ //
+ assertEquals(3, listener.events.size());
+ listener.assertStartRunnerEvent(0);
+ listener.assertStartTestEvent(1, new TestId());
+ listener.assertEndTestEvent(2, new TestId(), new TestSuccess(0));
+ }
+
+ private static void testDestroyThrowsRuntimeException()
+ {
+ FailureTestDriver testDriver = new FailureTestDriver()
+ {
+ public void destroyDriver()
+ {
+ throw new RuntimeException();
+ }
+ };
+
+ //
+ TestDriverRunner runner = new TestDriverRunner(testDriver, new TestId());
+ EventList listener = new EventList();
+ runner.run(new TestRunnerContextSupport(listener));
+
+ //
+ assertEquals(4, listener.events.size());
+ listener.assertStartRunnerEvent(0);
+ listener.assertStartTestEvent(1, new TestId());
+ listener.assertEndTestEvent(2, new TestId(), new TestSuccess(0));
+ listener.assertEndRunnerEvent(3);
+ }
+
+ private static void testInit()
+ {
+ FailureTestDriver testDriver = new FailureTestDriver()
+ {
+ public void initDriver(DriverContext context) throws DriverException
+ {
+ }
+ };
+
+ //
+ TestDriverRunner runner = new TestDriverRunner(testDriver, new TestId());
+ EventList listener = new EventList();
+ runner.run(new TestRunnerContextSupport(listener));
+
+ //
+ assertTrue(testDriver.invoked1);
+ assertTrue(testDriver.invoked2);
+ assertTrue(testDriver.invoked3);
+
+ //
+ assertEquals(4, listener.events.size());
+ listener.assertStartRunnerEvent(0);
+ listener.assertStartTestEvent(1, new TestId());
+ listener.assertEndTestEvent(2, new TestId(), new TestSuccess(0));
+ listener.assertEndRunnerEvent(3);
+ }
+
+ private static void testInitThrowsDriverException()
+ {
+ FailureTestDriver testDriver = new FailureTestDriver()
+ {
+ public void initDriver(DriverContext context) throws DriverException
+ {
+ throw new DriverException();
+ }
+ };
+
+ //
+ TestDriverRunner runner = new TestDriverRunner(testDriver, new TestId());
+ EventList listener = new EventList();
+ runner.run(new TestRunnerContextSupport(listener));
+
+ //
+ assertFalse(testDriver.invoked1);
+ assertFalse(testDriver.invoked2);
+ assertFalse(testDriver.invoked3);
+
+ //
+ assertEquals(3, listener.events.size());
+ listener.assertStartRunnerEvent(0);
+ listener.assertRunnerFailureEvent(1);
+ listener.assertEndRunnerEvent(2);
+ }
+
+ private static void testInitThrowsRuntimeException()
+ {
+ FailureTestDriver testDriver = new FailureTestDriver()
+ {
+ public void initDriver(DriverContext context) throws DriverException
+ {
+ throw new RuntimeException();
+ }
+ };
+
+ //
+ TestDriverRunner runner = new TestDriverRunner(testDriver, new TestId());
+ EventList listener = new EventList();
+ runner.run(new TestRunnerContextSupport(listener));
+
+ //
+ assertFalse(testDriver.invoked1);
+ assertFalse(testDriver.invoked2);
+ assertFalse(testDriver.invoked3);
+
+ //
+ assertEquals(3, listener.events.size());
+ listener.assertStartRunnerEvent(0);
+ listener.assertRunnerFailureEvent(1);
+ listener.assertEndRunnerEvent(2);
+ }
+
+ private static void testInitThrowsError()
+ {
+ final Error error = new Error();
+ FailureTestDriver testDriver = new FailureTestDriver()
+ {
+ public void initDriver(DriverContext context) throws DriverException
+ {
+ throw error;
+ }
+ };
+
+ //
+ TestDriverRunner runner = new TestDriverRunner(testDriver, new TestId());
+ EventList listener = new EventList();
+
+ try
+ {
+ runner.run(new TestRunnerContextSupport(listener));
+ fail();
+ }
+ catch (Error e)
+ {
+ assertSame(error, e);
+ }
+
+ //
+ assertFalse(testDriver.invoked1);
+ assertFalse(testDriver.invoked2);
+ assertFalse(testDriver.invoked3);
+
+ //
+ assertEquals(1, listener.events.size());
+ listener.assertStartRunnerEvent(0);
+ }
+
private static void testEvents1()
{
TestDriverImpl testDriver = new TestDriverImpl()
@@ -407,4 +591,29 @@
listener.assertStartTestEvent(2, new TestId("Foo"));
}
+ private abstract static class FailureTestDriver implements TestDriver
+ {
+ boolean invoked0 = false;
+ boolean invoked1 = false;
+ boolean invoked2 = false;
+ boolean invoked3 = false;
+ public void initDriver(DriverContext context) throws DriverException
+ {
+ invoked0 = true;
+ }
+ public TestInfo getInfo()
+ {
+ invoked1 = true;
+ return new SimpleTestCaseInfo("Foo");
+ }
+ public DriverResponse invoke(TestId id, DriverCommand command)
+ {
+ invoked2 = true;
+ return new EndTestResponse();
+ }
+ public void destroyDriver()
+ {
+ invoked3 = true;
+ }
+ }
}
Added: modules/test/trunk/unit/src/main/org/jboss/unit/driver/DriverException.java
===================================================================
--- modules/test/trunk/unit/src/main/org/jboss/unit/driver/DriverException.java
(rev 0)
+++ modules/test/trunk/unit/src/main/org/jboss/unit/driver/DriverException.java 2007-10-15
22:45:01 UTC (rev 8668)
@@ -0,0 +1,49 @@
+/******************************************************************************
+ * 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;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class DriverException extends Exception
+{
+ public DriverException()
+ {
+ }
+
+ public DriverException(String string)
+ {
+ super(string);
+ }
+
+ public DriverException(String string, Throwable throwable)
+ {
+ super(string, throwable);
+ }
+
+ public DriverException(Throwable throwable)
+ {
+ super(throwable);
+ }
+}
Modified: modules/test/trunk/unit/src/main/org/jboss/unit/driver/TestDriver.java
===================================================================
--- modules/test/trunk/unit/src/main/org/jboss/unit/driver/TestDriver.java 2007-10-15
22:09:35 UTC (rev 8667)
+++ modules/test/trunk/unit/src/main/org/jboss/unit/driver/TestDriver.java 2007-10-15
22:45:01 UTC (rev 8668)
@@ -38,8 +38,9 @@
* Initialize the test driver.
*
* @param context the driver context
+ * @throws DriverException if anything occurs that would prevent the initialization of
the driver
*/
- void initDriver(DriverContext context);
+ void initDriver(DriverContext context) throws DriverException;
/**
* Destroy the test driver.
Modified:
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 2007-10-15
22:09:35 UTC (rev 8667)
+++
modules/test/trunk/unit/src/main/org/jboss/unit/driver/impl/composite/CompositeTestDriver.java 2007-10-15
22:45:01 UTC (rev 8668)
@@ -26,6 +26,7 @@
import org.jboss.unit.driver.DriverResponse;
import org.jboss.unit.driver.DriverCommand;
import org.jboss.unit.driver.AbstractTestDriver;
+import org.jboss.unit.driver.DriverException;
import org.jboss.unit.driver.response.FailureResponse;
import org.jboss.unit.info.impl.SimpleTestSuiteInfo;
import org.jboss.unit.info.TestInfo;
@@ -95,7 +96,7 @@
return drivers.get(name);
}
- public void mount(TestDriver driver)
+ public void mount(TestDriver driver) throws DriverException
{
synchronized(TestDriver.class)
{
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-15
22:09:35 UTC (rev 8667)
+++
modules/test/trunk/unit/src/main/org/jboss/unit/runner/impl/driver/TestDriverRunner.java 2007-10-15
22:45:01 UTC (rev 8668)
@@ -113,7 +113,7 @@
//
try
{
- TestSuiteInfo info = (TestSuiteInfo)driver.getInfo();
+ TestInfo info = driver.getInfo();
//
internalRun(context, info, testId, new TestId());
@@ -125,7 +125,7 @@
{
driver.destroyDriver();
}
- catch (Throwable ignore)
+ catch (RuntimeException ignore)
{
}
}