Author: julien(a)jboss.com
Date: 2007-10-02 15:09:12 -0400 (Tue, 02 Oct 2007)
New Revision: 8516
Added:
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/junit/
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/junit/JUnitPOJOTests.java
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/junit/JUnitTest1.java
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/junit/JUnitTest2.java
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/junit/JUnitTest3.java
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/junit/JUnitTest4.java
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/junit/JUnitTest5.java
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/junit/JUnitTest6.java
modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/TestLifeCycle.java
modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/TestSuiteDescriptor.java
modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/junit/JUnitDescriptor.java
modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/junit/JUnitLifeCycle.java
modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/junit/JUnitTestMethod.java
modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/junit/JUnitTestMethodLifeCycle.java
modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/junit/TestCase.java
Removed:
modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/junit/JUnitTestHandler.java
Modified:
modules/test/trunk/unit/src/main/org/jboss/test/unit/AllTests.java
modules/test/trunk/unit/src/main/org/jboss/test/unit/PrintListener.java
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/TestDriverPOJOTest.java
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/TestDriverPOJOTests.java
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/TestHandlerSupportPOJOTest.java
modules/test/trunk/unit/src/main/org/jboss/unit/Failure.java
modules/test/trunk/unit/src/main/org/jboss/unit/FailureType.java
modules/test/trunk/unit/src/main/org/jboss/unit/api/Assert.java
modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/TestHandler.java
modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/TestHandlerSupport.java
modules/test/trunk/unit/src/main/org/jboss/unit/unit/pojo/POJOTestSuiteDriver.java
modules/test/trunk/unit/src/main/org/jboss/unit/unit/pojo/POJOTestSuiteInfo.java
Log:
- split API of TestHandler to TestLifeCycle and TestSuiteDescriptor
- added basic support for junit test cases pattern
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-02 18:18:13
UTC (rev 8515)
+++ modules/test/trunk/unit/src/main/org/jboss/test/unit/AllTests.java 2007-10-02 19:09:12
UTC (rev 8516)
@@ -25,6 +25,7 @@
import org.jboss.test.unit.api.AssertTests;
import org.jboss.test.unit.blah.BlahTests;
import org.jboss.test.unit.pojo.AbstractPOJOTests;
+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.event.TestRunnerEventBroadcasterSupportTests;
@@ -41,9 +42,8 @@
public static void main(String[] args) throws Exception
{
AssertTests.main(args);
-// TestHandlerSupportTests.main(args);
-// POJOTestDriverTests.main(args);
AbstractPOJOTests.main(args);
+ JUnitPOJOTests.main(args);
CompositeTestRunnerTests.main(args);
//
Modified: modules/test/trunk/unit/src/main/org/jboss/test/unit/PrintListener.java
===================================================================
--- modules/test/trunk/unit/src/main/org/jboss/test/unit/PrintListener.java 2007-10-02
18:18:13 UTC (rev 8515)
+++ modules/test/trunk/unit/src/main/org/jboss/test/unit/PrintListener.java 2007-10-02
19:09:12 UTC (rev 8516)
@@ -56,7 +56,7 @@
{
RunnerFailureEvent failureEvent = (RunnerFailureEvent)event;
Failure failure = failureEvent.getFailure();
- System.out.println("Runner failure: " + failure.getLevel() + "
" + failure.getMessage());
+ System.out.println("Runner failure: " + failure.getType() + "
" + failure.getMessage());
}
else if (event instanceof StartTestEvent)
{
@@ -76,7 +76,7 @@
{
TestFailure testFailure = (TestFailure)testResult;
Failure failure = testFailure.getFailure();
- System.out.println("Test id=" + testId + " " +
failure.getLevel() + " failed " + failure.getMessage());
+ System.out.println("Test id=" + testId + " " +
failure.getType() + " failed " + failure.getMessage());
if (failure.getCause() != null)
{
failure.getCause().printStackTrace();
Modified:
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/TestDriverPOJOTest.java
===================================================================
---
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/TestDriverPOJOTest.java 2007-10-02
18:18:13 UTC (rev 8515)
+++
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/TestDriverPOJOTest.java 2007-10-02
19:09:12 UTC (rev 8516)
@@ -105,7 +105,7 @@
else if (response instanceof FailureResponse)
{
FailureResponse failureResponse = (FailureResponse)response;
- switch (failureResponse.getFailure().getLevel())
+ switch (failureResponse.getFailure().getType())
{
case ERROR:
return InvokeResult.ERROR;
Modified:
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/TestDriverPOJOTests.java
===================================================================
---
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/TestDriverPOJOTests.java 2007-10-02
18:18:13 UTC (rev 8515)
+++
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/TestDriverPOJOTests.java 2007-10-02
19:09:12 UTC (rev 8516)
@@ -24,7 +24,7 @@
import org.jboss.unit.driver.TestDriver;
import org.jboss.unit.unit.pojo.POJOTestSuiteDriver;
-import static org.jboss.unit.api.Assert.fail;
+import static org.jboss.unit.api.Assert.*;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -40,6 +40,14 @@
new POJOTestSuiteDriver(clazz);
fail();
}
+ catch (InstantiationException e)
+ {
+ fail(e);
+ }
+ catch (IllegalAccessException e)
+ {
+ fail(e);
+ }
catch (IllegalArgumentException expected)
{
}
@@ -47,9 +55,20 @@
protected AbstractPOJOTest assertCanBuildSuite(Class clazz)
{
- TestDriver driver = new POJOTestSuiteDriver(clazz);
+ try
+ {
+ TestDriver driver = new POJOTestSuiteDriver(clazz);
- //
- return new TestDriverPOJOTest(driver);
+ //
+ return new TestDriverPOJOTest(driver);
+ }
+ catch (InstantiationException e)
+ {
+ throw createFailure(e);
+ }
+ catch (IllegalAccessException e)
+ {
+ throw createFailure(e);
+ }
}
}
Modified:
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/TestHandlerSupportPOJOTest.java
===================================================================
---
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/TestHandlerSupportPOJOTest.java 2007-10-02
18:18:13 UTC (rev 8515)
+++
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/TestHandlerSupportPOJOTest.java 2007-10-02
19:09:12 UTC (rev 8516)
@@ -48,29 +48,29 @@
public Set<String> getParameterNames()
{
- return handler.getParameters().keySet();
+ return handler.getDescriptor().getParameters().keySet();
}
public Set<String> getTestCaseNames()
{
- return handler.getTestCases().keySet();
+ return handler.getDescriptor().getTestCases().keySet();
}
public Set<String> getKeywords()
{
- return handler.getKeywords();
+ return handler.getDescriptor().getKeywords();
}
public Set<String> getTestCaseKeywords(String testCaseName)
{
- TestCaseDescriptor descriptor = handler.getTestCases().get(testCaseName);
+ TestCaseDescriptor descriptor =
handler.getDescriptor().getTestCases().get(testCaseName);
assertNotNull(descriptor);
return descriptor.getKeywords();
}
public Set<String> getTestCaseParameterNames(String testCaseName)
{
- TestCaseDescriptor descriptor = handler.getTestCases().get(testCaseName);
+ TestCaseDescriptor descriptor =
handler.getDescriptor().getTestCases().get(testCaseName);
assertNotNull(descriptor);
return descriptor.getParameters().keySet();
}
@@ -81,11 +81,11 @@
boolean invokeDestroy = false;
try
{
- testCase = handler.newTestCase(testName);
- handler.testCaseParametrize(testCase, parametrization);
+ testCase = handler.getLifeCycle().newTestCase(testName);
+ handler.getLifeCycle().testCaseParametrize(testCase, parametrization);
invokeDestroy = true;
- handler.testCaseCreate(testCase);
- handler.testCaseInvoke(testCase);
+ handler.getLifeCycle().testCaseCreate(testCase);
+ handler.getLifeCycle().testCaseInvoke(testCase);
return InvokeResult.PASS;
}
catch (TestCaseLifeCycleException e)
@@ -104,7 +104,7 @@
{
if (invokeDestroy)
{
- handler.testCaseDestroy(testCase);
+ handler.getLifeCycle().testCaseDestroy(testCase);
}
}
}
Added:
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/junit/JUnitPOJOTests.java
===================================================================
--- modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/junit/JUnitPOJOTests.java
(rev 0)
+++
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/junit/JUnitPOJOTests.java 2007-10-02
19:09:12 UTC (rev 8516)
@@ -0,0 +1,151 @@
+/******************************************************************************
+ * 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.pojo.junit;
+
+import org.jboss.unit.unit.pojo.POJOTestSuiteDriver;
+
+import static org.jboss.unit.util.CollectionTools.*;
+import static org.jboss.unit.api.Assert.*;
+import org.jboss.unit.TestId;
+import org.jboss.unit.Failure;
+import org.jboss.unit.FailureType;
+import org.jboss.unit.info.TestInfo;
+import org.jboss.unit.info.TestSuiteInfo;
+import org.jboss.unit.driver.command.StartTestCommand;
+import org.jboss.unit.driver.DriverResponse;
+import org.jboss.unit.driver.response.FailureResponse;
+import org.jboss.unit.driver.response.EndTestResponse;
+
+import java.util.HashMap;
+import java.util.HashSet;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class JUnitPOJOTests
+{
+
+ public static void main(String[] args)
+ {
+ test1();
+ test2();
+ test3();
+ test4();
+ }
+
+ private static void test1()
+ {
+ POJOTestSuiteDriver driver = createDriver(JUnitTest1.class);
+ TestInfo driverInfo = driver.getInfo();
+ TestSuiteInfo suiteInfo = assertInstanceOf(driverInfo, TestSuiteInfo.class);
+ assertEquals(JUnitTest1.class.getName(), suiteInfo.getName());
+ assertEquals(new HashMap(), suiteInfo.getParameters());
+ assertEquals(new HashSet(), suiteInfo.getNames());
+
+ // Try to invoke a no op
+ DriverResponse response = driver.invoke(new TestId("foo"), new
StartTestCommand());
+ FailureResponse failureResponse = assertInstanceOf(response,
FailureResponse.class);
+ Failure failure = failureResponse.getFailure();
+ assertEquals(FailureType.ERROR, failure.getType());
+ }
+
+ private static void test2()
+ {
+ POJOTestSuiteDriver driver = createDriver(JUnitTest2.class);
+ TestInfo driverInfo = driver.getInfo();
+ TestSuiteInfo suiteInfo = assertInstanceOf(driverInfo, TestSuiteInfo.class);
+ assertEquals(JUnitTest2.class.getName(), suiteInfo.getName());
+ assertEquals(new HashMap(), suiteInfo.getParameters());
+ assertEquals(set("testBlah"), suiteInfo.getNames());
+
+ // Try to invoke a no op
+ DriverResponse response = driver.invoke(new TestId("testBlah"), new
StartTestCommand());
+ assertInstanceOf(response, EndTestResponse.class);
+ }
+
+ private static void test3()
+ {
+ POJOTestSuiteDriver driver = createDriver(JUnitTest3.class);
+ TestInfo driverInfo = driver.getInfo();
+ TestSuiteInfo suiteInfo = assertInstanceOf(driverInfo, TestSuiteInfo.class);
+ assertEquals(JUnitTest3.class.getName(), suiteInfo.getName());
+ assertEquals(new HashMap(), suiteInfo.getParameters());
+ assertEquals(set("testBlah"), suiteInfo.getNames());
+
+ // Try to invoke a no op
+ DriverResponse response = driver.invoke(new TestId("testBlah"), new
StartTestCommand());
+ FailureResponse failureResponse = assertInstanceOf(response,
FailureResponse.class);
+ Failure failure = failureResponse.getFailure();
+ assertEquals(FailureType.ERROR, failure.getType());
+ }
+
+ private static void test4()
+ {
+ POJOTestSuiteDriver driver = createDriver(JUnitTest4.class);
+ TestInfo driverInfo = driver.getInfo();
+ TestSuiteInfo suiteInfo = assertInstanceOf(driverInfo, TestSuiteInfo.class);
+ assertEquals(JUnitTest4.class.getName(), suiteInfo.getName());
+ assertEquals(new HashMap(), suiteInfo.getParameters());
+ assertEquals(set("testBlah"), suiteInfo.getNames());
+
+ // Try to invoke a no op
+ DriverResponse response = driver.invoke(new TestId("testBlah"), new
StartTestCommand());
+ FailureResponse failureResponse = assertInstanceOf(response,
FailureResponse.class);
+ Failure failure = failureResponse.getFailure();
+ assertEquals(FailureType.ERROR, failure.getType());
+ }
+
+ private static void test5()
+ {
+ POJOTestSuiteDriver driver = createDriver(JUnitTest5.class);
+ TestInfo driverInfo = driver.getInfo();
+ TestSuiteInfo suiteInfo = assertInstanceOf(driverInfo, TestSuiteInfo.class);
+ assertEquals(JUnitTest5.class.getName(), suiteInfo.getName());
+ assertEquals(new HashMap(), suiteInfo.getParameters());
+ assertEquals(set("testBlah"), suiteInfo.getNames());
+
+ // Try to invoke a no op
+ DriverResponse response = driver.invoke(new TestId("testBlah"), new
StartTestCommand());
+ FailureResponse failureResponse = assertInstanceOf(response,
FailureResponse.class);
+ Failure failure = failureResponse.getFailure();
+ assertEquals(FailureType.ERROR, failure.getType());
+ }
+
+ private static POJOTestSuiteDriver createDriver(Class clazz)
+ {
+ try
+ {
+ return new POJOTestSuiteDriver(clazz);
+ }
+ catch (InstantiationException e)
+ {
+ throw createFailure(e);
+ }
+ catch (IllegalAccessException e)
+ {
+ throw createFailure(e);
+ }
+ }
+
+}
Added: modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/junit/JUnitTest1.java
===================================================================
--- modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/junit/JUnitTest1.java
(rev 0)
+++
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/junit/JUnitTest1.java 2007-10-02
19:09:12 UTC (rev 8516)
@@ -0,0 +1,33 @@
+/******************************************************************************
+ * 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.pojo.junit;
+
+import org.jboss.unit.api.pojo.junit.TestCase;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class JUnitTest1 extends TestCase
+{
+}
Added: modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/junit/JUnitTest2.java
===================================================================
--- modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/junit/JUnitTest2.java
(rev 0)
+++
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/junit/JUnitTest2.java 2007-10-02
19:09:12 UTC (rev 8516)
@@ -0,0 +1,39 @@
+/******************************************************************************
+ * 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.pojo.junit;
+
+import org.jboss.unit.api.pojo.junit.TestCase;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class JUnitTest2 extends TestCase
+{
+
+ public void testBlah()
+ {
+
+ }
+
+}
Added: modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/junit/JUnitTest3.java
===================================================================
--- modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/junit/JUnitTest3.java
(rev 0)
+++
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/junit/JUnitTest3.java 2007-10-02
19:09:12 UTC (rev 8516)
@@ -0,0 +1,39 @@
+/******************************************************************************
+ * 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.pojo.junit;
+
+import org.jboss.unit.api.pojo.junit.TestCase;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class JUnitTest3 extends TestCase
+{
+
+ public void testBlah()
+ {
+ throw new RuntimeException();
+ }
+
+}
Added: modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/junit/JUnitTest4.java
===================================================================
--- modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/junit/JUnitTest4.java
(rev 0)
+++
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/junit/JUnitTest4.java 2007-10-02
19:09:12 UTC (rev 8516)
@@ -0,0 +1,39 @@
+/******************************************************************************
+ * 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.pojo.junit;
+
+import org.jboss.unit.api.pojo.junit.TestCase;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class JUnitTest4 extends TestCase
+{
+
+ public void testBlah() throws Exception
+ {
+ throw new Exception();
+ }
+
+}
Added: modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/junit/JUnitTest5.java
===================================================================
--- modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/junit/JUnitTest5.java
(rev 0)
+++
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/junit/JUnitTest5.java 2007-10-02
19:09:12 UTC (rev 8516)
@@ -0,0 +1,39 @@
+/******************************************************************************
+ * 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.pojo.junit;
+
+import org.jboss.unit.api.pojo.junit.TestCase;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class JUnitTest5 extends TestCase
+{
+
+ public void testBlah()
+ {
+ throw new Error();
+ }
+
+}
Added: modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/junit/JUnitTest6.java
===================================================================
--- modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/junit/JUnitTest6.java
(rev 0)
+++
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/junit/JUnitTest6.java 2007-10-02
19:09:12 UTC (rev 8516)
@@ -0,0 +1,32 @@
+/******************************************************************************
+ * 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.pojo.junit;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class JUnitTest6
+{
+
+}
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-02 18:18:13 UTC
(rev 8515)
+++ modules/test/trunk/unit/src/main/org/jboss/unit/Failure.java 2007-10-02 19:09:12 UTC
(rev 8516)
@@ -71,7 +71,7 @@
return cause;
}
- public FailureType getLevel()
+ public FailureType getType()
{
return type;
}
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-02 18:18:13
UTC (rev 8515)
+++ modules/test/trunk/unit/src/main/org/jboss/unit/FailureType.java 2007-10-02 19:09:12
UTC (rev 8516)
@@ -30,9 +30,7 @@
*/
public enum FailureType
{
-
ERROR,
ASSERTION,
-
-
+ INTERNAL_ERROR
}
Modified: modules/test/trunk/unit/src/main/org/jboss/unit/api/Assert.java
===================================================================
--- modules/test/trunk/unit/src/main/org/jboss/unit/api/Assert.java 2007-10-02 18:18:13
UTC (rev 8515)
+++ modules/test/trunk/unit/src/main/org/jboss/unit/api/Assert.java 2007-10-02 19:09:12
UTC (rev 8516)
@@ -253,7 +253,7 @@
public static Error createFailure()
{
- return createFailure(null);
+ return createFailure((String)null);
}
public static Error createFailure(String msg)
@@ -261,6 +261,11 @@
return createAssertionError(null, msg);
}
+ public static Error createFailure(Throwable throwable)
+ {
+ return createAssertionError(throwable, null);
+ }
+
public static Error createAssertionError(Throwable cause, String msg)
{
if (msg == null)
Modified: modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/TestHandler.java
===================================================================
--- modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/TestHandler.java 2007-10-02
18:18:13 UTC (rev 8515)
+++ modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/TestHandler.java 2007-10-02
19:09:12 UTC (rev 8516)
@@ -22,12 +22,6 @@
******************************************************************************/
package org.jboss.unit.api.pojo;
-import org.jboss.unit.api.pojo.ParameterDescriptor;
-import org.jboss.unit.api.pojo.TestCaseDescriptor;
-
-import java.util.Map;
-import java.util.Set;
-
/**
* Allow a pojo class to take care of providing its description and perform test case
life cycle management.
*
@@ -37,80 +31,8 @@
public interface TestHandler
{
- /**
- * Return the test name.
- *
- * @return the test name
- */
- String getName();
+ TestSuiteDescriptor getDescriptor();
- /**
- * Return the test description.
- *
- * @return the test description
- */
- String getDescription();
+ TestLifeCycle getLifeCycle();
- /**
- * Returns the keywords for the test.
- *
- * @return the test keywords
- */
- Set<String> getKeywords();
-
- /**
- * Return the test parameters.
- *
- * @return the test parameters
- */
- Map<String,? extends ParameterDescriptor> getParameters();
-
- /**
- * Return the test case descriptions.
- *
- * @return the test case descriptions
- */
- Map<String,? extends TestCaseDescriptor> getTestCases();
-
- /**
- * Instantiate life cycle operation of a test case.
- *
- * @param name the test case name
- * @return the test case object
- * @throws TestCaseLifeCycleException
- */
- Object newTestCase(String name) throws TestCaseLifeCycleException;
-
- /**
- * Parametrize life cycle operation of a test case.
- *
- * @param testCase the test case
- * @param parametrization the parametrization
- * @throws TestCaseLifeCycleException
- */
- void testCaseParametrize(Object testCase, Map<String,String> parametrization)
throws TestCaseLifeCycleException;
-
- /**
- * Create life cycle operation of a test case.
- *
- * @param testCase the test case
- * @throws TestCaseLifeCycleException
- */
- void testCaseCreate(Object testCase) throws TestCaseLifeCycleException;
-
- /**
- * Invocation life cycle operation of a test case.
- *
- * @param testCase the test case
- * @throws TestCaseLifeCycleException
- */
- void testCaseInvoke(Object testCase) throws TestCaseLifeCycleException;
-
- /**
- * Destroy life cycle operation of a test case.
- *
- * @param testCase the test case
- */
- void testCaseDestroy(Object testCase);
-
}
Modified:
modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/TestHandlerSupport.java
===================================================================
---
modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/TestHandlerSupport.java 2007-10-02
18:18:13 UTC (rev 8515)
+++
modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/TestHandlerSupport.java 2007-10-02
19:09:12 UTC (rev 8516)
@@ -54,7 +54,7 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
*/
-public class TestHandlerSupport implements TestHandler
+public class TestHandlerSupport implements TestHandler, TestLifeCycle,
TestSuiteDescriptor
{
/** . */
@@ -421,6 +421,16 @@
this.destroy = destroy;
}
+ public TestSuiteDescriptor getDescriptor()
+ {
+ return this;
+ }
+
+ public TestLifeCycle getLifeCycle()
+ {
+ return this;
+ }
+
public String getName()
{
return suiteName;
Added: modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/TestLifeCycle.java
===================================================================
--- modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/TestLifeCycle.java
(rev 0)
+++ modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/TestLifeCycle.java 2007-10-02
19:09:12 UTC (rev 8516)
@@ -0,0 +1,75 @@
+/******************************************************************************
+ * 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.api.pojo;
+
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public interface TestLifeCycle
+{
+
+ /**
+ * Instantiate life cycle operation of a test case.
+ *
+ * @param name the test case name
+ * @return the test case object
+ * @throws TestCaseLifeCycleException
+ */
+ Object newTestCase(String name) throws TestCaseLifeCycleException;
+
+ /**
+ * Parametrize life cycle operation of a test case.
+ *
+ * @param testCase the test case
+ * @param parametrization the parametrization
+ * @throws TestCaseLifeCycleException
+ */
+ void testCaseParametrize(Object testCase, Map<String,String> parametrization)
throws TestCaseLifeCycleException;
+
+ /**
+ * Create life cycle operation of a test case.
+ *
+ * @param testCase the test case
+ * @throws TestCaseLifeCycleException
+ */
+ void testCaseCreate(Object testCase) throws TestCaseLifeCycleException;
+
+ /**
+ * Invocation life cycle operation of a test case.
+ *
+ * @param testCase the test case
+ * @throws TestCaseLifeCycleException
+ */
+ void testCaseInvoke(Object testCase) throws TestCaseLifeCycleException;
+
+ /**
+ * Destroy life cycle operation of a test case.
+ *
+ * @param testCase the test case
+ */
+ void testCaseDestroy(Object testCase);
+
+}
Added: modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/TestSuiteDescriptor.java
===================================================================
--- modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/TestSuiteDescriptor.java
(rev 0)
+++
modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/TestSuiteDescriptor.java 2007-10-02
19:09:12 UTC (rev 8516)
@@ -0,0 +1,70 @@
+/******************************************************************************
+ * 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.api.pojo;
+
+import java.util.Set;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public interface TestSuiteDescriptor
+{
+
+ /**
+ * Return the test name.
+ *
+ * @return the test name
+ */
+ String getName();
+
+ /**
+ * Return the test description.
+ *
+ * @return the test description
+ */
+ String getDescription();
+
+ /**
+ * Returns the keywords for the test.
+ *
+ * @return the test keywords
+ */
+ Set<String> getKeywords();
+
+ /**
+ * Return the test parameters.
+ *
+ * @return the test parameters
+ */
+ Map<String,? extends ParameterDescriptor> getParameters();
+
+ /**
+ * Return the test case descriptions.
+ *
+ * @return the test case descriptions
+ */
+ Map<String,? extends TestCaseDescriptor> getTestCases();
+
+}
Added:
modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/junit/JUnitDescriptor.java
===================================================================
--- modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/junit/JUnitDescriptor.java
(rev 0)
+++
modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/junit/JUnitDescriptor.java 2007-10-02
19:09:12 UTC (rev 8516)
@@ -0,0 +1,128 @@
+/******************************************************************************
+ * 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.api.pojo.junit;
+
+import org.jboss.unit.api.pojo.TestSuiteDescriptor;
+import org.jboss.unit.api.pojo.ParameterDescriptor;
+import org.jboss.unit.api.pojo.TestCaseDescriptor;
+
+import java.util.Map;
+import java.util.Set;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.HashMap;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+class JUnitDescriptor implements TestSuiteDescriptor
+{
+
+ /** . */
+ final Class testClass;
+
+ /** . */
+ final Map<String,JUnitTestMethod> testMap;
+
+ public JUnitDescriptor(Class testClass)
+ {
+ this.testClass = testClass;
+ this.testMap = new HashMap<String, JUnitTestMethod>();
+
+ //
+ try
+ {
+ Method[] methods = testClass.getMethods();
+ for (int j = 0; j < methods.length; j++)
+ {
+ Method method = methods[j];
+
+ //
+ int modifiers = method.getModifiers();
+ if (Modifier.isPublic(modifiers) && !Modifier.isAbstract(modifiers)
&& !Modifier.isStatic(modifiers))
+ {
+ String methodName = method.getName();
+ if (methodName.startsWith("test") &&
+ method.getParameterTypes().length == 0)
+ {
+ JUnitTestMethod tm = new JUnitTestMethod(method);
+ testMap.put(method.getName(), tm);
+ }
+// else if (methodName.startsWith("set") &&
+// methodName.endsWith("Parameter") &&
+// method.getParameterTypes().length == 1)
+// {
+// String parameterName = methodName.substring(3, methodName.length() -
9);
+// setterMap.put(parameterName, method);
+// }
+ }
+ }
+
+ // Set all parameters on children
+// for (Iterator i = setterMap.keySet().iterator(); i.hasNext();)
+// {
+// String parameterName = (String)i.next();
+// for (Iterator j = testMap.keySet().iterator(); j.hasNext();)
+// {
+// String childName = (String)j.next();
+// TestInfo childInfo = (TestInfo)containerInfo.getChild(childName);
+// childInfo.addParameter(new TestParameterInfo(parameterName));
+// }
+// }
+ }
+ catch (Exception e)
+ {
+ IllegalArgumentException iae = new IllegalArgumentException();
+ iae.initCause(e);
+ throw iae;
+ }
+ }
+
+ public String getName()
+ {
+ return testClass.getName();
+ }
+
+ public String getDescription()
+ {
+ return "";
+ }
+
+ public Set<String> getKeywords()
+ {
+ return Collections.emptySet();
+ }
+
+ public Map<String, ? extends ParameterDescriptor> getParameters()
+ {
+ return Collections.emptyMap();
+ }
+
+ public Map<String, ? extends TestCaseDescriptor> getTestCases()
+ {
+ return Collections.unmodifiableMap(testMap);
+ }
+}
Added: modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/junit/JUnitLifeCycle.java
===================================================================
--- modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/junit/JUnitLifeCycle.java
(rev 0)
+++
modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/junit/JUnitLifeCycle.java 2007-10-02
19:09:12 UTC (rev 8516)
@@ -0,0 +1,111 @@
+/******************************************************************************
+ * 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.api.pojo.junit;
+
+import org.jboss.unit.api.pojo.TestLifeCycle;
+import org.jboss.unit.api.pojo.TestCaseLifeCycleException;
+
+import java.util.Map;
+import java.lang.reflect.InvocationTargetException;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+class JUnitLifeCycle implements TestLifeCycle
+{
+
+ /** . */
+ private final TestCase testCase;
+
+ public JUnitLifeCycle(TestCase testCase)
+ {
+ this.testCase = testCase;
+ }
+
+ public Object newTestCase(String name) throws TestCaseLifeCycleException
+ {
+ JUnitTestMethod method = testCase.descriptor.testMap.get(name);
+ if (method == null)
+ {
+ throw new TestCaseLifeCycleException("No test case " + name + "
found");
+ }
+ return new JUnitTestMethodLifeCycle(method);
+ }
+
+ public void testCaseParametrize(Object _lifeCycle, Map<String, String>
parametrization) throws TestCaseLifeCycleException
+ {
+ // No op
+ }
+
+ public void testCaseCreate(Object _lifeCycle) throws TestCaseLifeCycleException
+ {
+ try
+ {
+ testCase.setUp();
+ }
+ catch (Throwable e)
+ {
+ throw unwrap(e);
+ }
+ }
+
+ public void testCaseInvoke(Object _lifeCycle) throws TestCaseLifeCycleException
+ {
+ JUnitTestMethodLifeCycle lifeCycle = (JUnitTestMethodLifeCycle)_lifeCycle;
+
+ // Invoke test joinpoint
+ try
+ {
+ lifeCycle.testMethod.method.invoke(testCase, new Object[0]);
+ }
+ catch (IllegalAccessException e)
+ {
+ throw unwrap(e);
+ }
+ catch (InvocationTargetException e)
+ {
+ throw unwrap(e.getCause());
+ }
+ }
+
+ private TestCaseLifeCycleException unwrap(Throwable throwable)
+ {
+ // Look if it's an assertion failure from junit API
+ for (Class clazz = throwable.getClass();clazz != null;clazz =
clazz.getSuperclass())
+ {
+ if ("junit.framework.AssertionFailedError".equals(clazz.getName()))
+ {
+ return new TestCaseLifeCycleException(new AssertionError(throwable));
+ }
+ }
+
+ //
+ return new TestCaseLifeCycleException(throwable);
+ }
+
+ public void testCaseDestroy(Object _testCase)
+ {
+ testCase.tearDown();
+ }
+}
Deleted:
modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/junit/JUnitTestHandler.java
===================================================================
---
modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/junit/JUnitTestHandler.java 2007-10-02
18:18:13 UTC (rev 8515)
+++
modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/junit/JUnitTestHandler.java 2007-10-02
19:09:12 UTC (rev 8516)
@@ -1,33 +0,0 @@
-/******************************************************************************
- * 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.api.pojo.junit;
-
-/**
- * @todo
- *
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 1.1 $
- */
-public class JUnitTestHandler
-{
-}
Added:
modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/junit/JUnitTestMethod.java
===================================================================
--- modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/junit/JUnitTestMethod.java
(rev 0)
+++
modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/junit/JUnitTestMethod.java 2007-10-02
19:09:12 UTC (rev 8516)
@@ -0,0 +1,67 @@
+/******************************************************************************
+ * 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.api.pojo.junit;
+
+import org.jboss.unit.api.pojo.TestCaseDescriptor;
+import org.jboss.unit.api.pojo.ParameterDescriptor;
+
+import java.util.Map;
+import java.util.Set;
+import java.util.Collections;
+import java.lang.reflect.Method;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+class JUnitTestMethod implements TestCaseDescriptor
+{
+
+ /** . */
+ final Method method;
+
+ public JUnitTestMethod(Method method)
+ {
+ this.method = method;
+ }
+
+ public String getName()
+ {
+ return method.getName();
+ }
+
+ public String getDescription()
+ {
+ return "";
+ }
+
+ public Map<String, ? extends ParameterDescriptor> getParameters()
+ {
+ return Collections.emptyMap();
+ }
+
+ public Set<String> getKeywords()
+ {
+ return Collections.emptySet();
+ }
+}
Added:
modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/junit/JUnitTestMethodLifeCycle.java
===================================================================
---
modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/junit/JUnitTestMethodLifeCycle.java
(rev 0)
+++
modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/junit/JUnitTestMethodLifeCycle.java 2007-10-02
19:09:12 UTC (rev 8516)
@@ -0,0 +1,39 @@
+/******************************************************************************
+ * 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.api.pojo.junit;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+class JUnitTestMethodLifeCycle
+{
+
+ /** . */
+ final JUnitTestMethod testMethod;
+
+ public JUnitTestMethodLifeCycle(JUnitTestMethod testMethod)
+ {
+ this.testMethod = testMethod;
+ }
+}
Added: modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/junit/TestCase.java
===================================================================
--- modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/junit/TestCase.java
(rev 0)
+++
modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/junit/TestCase.java 2007-10-02
19:09:12 UTC (rev 8516)
@@ -0,0 +1,67 @@
+/******************************************************************************
+ * 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.api.pojo.junit;
+
+import org.jboss.unit.api.pojo.TestHandler;
+import org.jboss.unit.api.pojo.TestSuiteDescriptor;
+import org.jboss.unit.api.pojo.TestLifeCycle;
+
+
+/**
+ * @todo
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class TestCase implements TestHandler
+{
+
+ /** . */
+ final JUnitDescriptor descriptor;
+
+ final JUnitLifeCycle lifeCycle;
+
+ public TestCase()
+ {
+ descriptor = new JUnitDescriptor(getClass());
+ lifeCycle = new JUnitLifeCycle(this);
+ }
+
+ protected void setUp()
+ {
+ }
+
+ protected void tearDown()
+ {
+ }
+
+ public TestSuiteDescriptor getDescriptor()
+ {
+ return descriptor;
+ }
+
+ public TestLifeCycle getLifeCycle()
+ {
+ return lifeCycle;
+ }
+}
Modified:
modules/test/trunk/unit/src/main/org/jboss/unit/unit/pojo/POJOTestSuiteDriver.java
===================================================================
---
modules/test/trunk/unit/src/main/org/jboss/unit/unit/pojo/POJOTestSuiteDriver.java 2007-10-02
18:18:13 UTC (rev 8515)
+++
modules/test/trunk/unit/src/main/org/jboss/unit/unit/pojo/POJOTestSuiteDriver.java 2007-10-02
19:09:12 UTC (rev 8516)
@@ -25,6 +25,7 @@
import org.jboss.unit.api.pojo.TestHandler;
import org.jboss.unit.api.pojo.TestHandlerSupport;
import org.jboss.unit.api.pojo.TestCaseLifeCycleException;
+import org.jboss.unit.api.pojo.TestLifeCycle;
import org.jboss.unit.driver.TestDriver;
import org.jboss.unit.driver.DriverResponse;
import org.jboss.unit.driver.DriverCommand;
@@ -51,10 +52,18 @@
/** . */
private TestSuiteInfo info;
- public POJOTestSuiteDriver(Class testClass)
+ public POJOTestSuiteDriver(Class testClass) throws InstantiationException,
IllegalAccessException
{
- handler = new TestHandlerSupport(testClass);
- info = new POJOTestSuiteInfo(handler);
+ if (TestHandler.class.isAssignableFrom(testClass))
+ {
+ handler = (TestHandler)testClass.newInstance();
+ }
+ else
+ {
+ handler = new TestHandlerSupport(testClass);
+ }
+
+ info = new POJOTestSuiteInfo(handler.getDescriptor());
}
public TestInfo getInfo()
@@ -75,13 +84,16 @@
}
//
+ TestLifeCycle lifeCycle = handler.getLifeCycle();
+
+ //
String name = id.getName(0);
//
Object pojo;
try
{
- pojo = handler.newTestCase(name);
+ pojo = lifeCycle.newTestCase(name);
}
catch (Exception e)
{
@@ -94,7 +106,7 @@
//
try
{
- handler.testCaseParametrize(pojo, parametrization);
+ lifeCycle.testCaseParametrize(pojo, parametrization);
}
catch (Exception e)
{
@@ -104,10 +116,10 @@
//
try
{
- handler.testCaseCreate(pojo);
+ lifeCycle.testCaseCreate(pojo);
//
- handler.testCaseInvoke(pojo);
+ lifeCycle.testCaseInvoke(pojo);
}
catch (Exception e)
{
@@ -115,7 +127,7 @@
}
finally
{
- handler.testCaseDestroy(pojo);
+ lifeCycle.testCaseDestroy(pojo);
}
//
Modified:
modules/test/trunk/unit/src/main/org/jboss/unit/unit/pojo/POJOTestSuiteInfo.java
===================================================================
---
modules/test/trunk/unit/src/main/org/jboss/unit/unit/pojo/POJOTestSuiteInfo.java 2007-10-02
18:18:13 UTC (rev 8515)
+++
modules/test/trunk/unit/src/main/org/jboss/unit/unit/pojo/POJOTestSuiteInfo.java 2007-10-02
19:09:12 UTC (rev 8516)
@@ -22,8 +22,8 @@
******************************************************************************/
package org.jboss.unit.unit.pojo;
-import org.jboss.unit.api.pojo.TestHandler;
import org.jboss.unit.api.pojo.TestCaseDescriptor;
+import org.jboss.unit.api.pojo.TestSuiteDescriptor;
import org.jboss.unit.info.TestSuiteInfo;
import org.jboss.unit.info.TestInfo;
import org.jboss.unit.TestId;
@@ -40,36 +40,36 @@
{
/** . */
- private TestHandler handler;
+ private TestSuiteDescriptor descriptor;
/** . */
private Map<String,POJOTestCaseInfo> testCases;
- public POJOTestSuiteInfo(TestHandler handler)
+ public POJOTestSuiteInfo(TestSuiteDescriptor descriptor)
{
- super(handler.getParameters(), handler.getKeywords());
+ super(descriptor.getParameters(), descriptor.getKeywords());
//
HashMap<String, POJOTestCaseInfo> testCases = new HashMap<String,
POJOTestCaseInfo>();
- for (TestCaseDescriptor testCaseDescriptor : handler.getTestCases().values())
+ for (TestCaseDescriptor testCaseDescriptor : descriptor.getTestCases().values())
{
POJOTestCaseInfo testCase = new POJOTestCaseInfo(testCaseDescriptor);
testCases.put(testCase.getName(), testCase);
}
//
- this.handler = handler;
+ this.descriptor = descriptor;
this.testCases = testCases;
}
public String getName()
{
- return handler.getName();
+ return descriptor.getName();
}
public String getDescription()
{
- return handler.getDescription();
+ return descriptor.getDescription();
}
public TestInfo getTest(String name)