Author: julien(a)jboss.com
Date: 2007-10-04 18:24:45 -0400 (Thu, 04 Oct 2007)
New Revision: 8535
Added:
modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/TestCaseImpl.java
modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/annotations/Provider.java
modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/junit/JUnitProvider.java
Modified:
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/TestHandlerSupportPOJOTest.java
modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/TestCase.java
modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/TestHandlerSupport.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/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/JUnitTestMethodLifeCycle.java
modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/junit/TestCase.java
modules/test/trunk/unit/src/main/org/jboss/unit/info/impl/SimpleTestSuiteInfo.java
modules/test/trunk/unit/src/main/org/jboss/unit/unit/pojo/POJOTestSuiteDriver.java
Log:
decouple the test handler class from the tested pojo life cycle by using annotation
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-04
21:32:02 UTC (rev 8534)
+++
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/TestHandlerSupportPOJOTest.java 2007-10-04
22:24:45 UTC (rev 8535)
@@ -25,6 +25,7 @@
import org.jboss.unit.api.pojo.TestHandler;
import org.jboss.unit.api.pojo.TestCaseLifeCycleException;
import org.jboss.unit.api.pojo.TestCaseDescriptor;
+import org.jboss.unit.api.pojo.TestCase;
import static org.jboss.unit.api.Assert.*;
@@ -77,7 +78,7 @@
public InvokeResult invoke(String testName, Map<String, String>
parametrization)
{
- Object testCase = null;
+ TestCase testCase = null;
boolean invokeDestroy = false;
try
{
Modified: modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/TestCase.java
===================================================================
--- modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/TestCase.java 2007-10-04
21:32:02 UTC (rev 8534)
+++ modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/TestCase.java 2007-10-04
22:24:45 UTC (rev 8535)
@@ -22,26 +22,11 @@
******************************************************************************/
package org.jboss.unit.api.pojo;
-import java.util.Map;
-
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
*/
-class TestCase
+public interface TestCase
{
-
- final TestCaseDef def;
-
- /** . */
- final Object pojo;
-
- /** . */
- Map<String,String> parametrization;
-
- public TestCase(TestCaseDef def, Object pojo)
- {
- this.def = def;
- this.pojo = pojo;
- }
+ Object getPOJO();
}
Added: modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/TestCaseImpl.java
===================================================================
--- modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/TestCaseImpl.java
(rev 0)
+++ modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/TestCaseImpl.java 2007-10-04
22:24:45 UTC (rev 8535)
@@ -0,0 +1,52 @@
+/******************************************************************************
+ * 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 $
+ */
+class TestCaseImpl implements TestCase
+{
+
+ final TestCaseDef def;
+
+ /** . */
+ final Object pojo;
+
+ /** . */
+ Map<String,String> parametrization;
+
+ public TestCaseImpl(TestCaseDef def, Object pojo)
+ {
+ this.def = def;
+ this.pojo = pojo;
+ }
+
+ public Object getPOJO()
+ {
+ return pojo;
+ }
+}
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-04
21:32:02 UTC (rev 8534)
+++
modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/TestHandlerSupport.java 2007-10-04
22:24:45 UTC (rev 8535)
@@ -456,7 +456,7 @@
return Collections.unmodifiableMap(testCases);
}
- public Object newTestCase(String name) throws TestCaseLifeCycleException
+ public TestCase newTestCase(String name) throws TestCaseLifeCycleException
{
TestCaseDef testCaseDef = testCases.get(name);
@@ -482,12 +482,12 @@
}
//
- return new TestCase(testCaseDef, instance);
+ return new TestCaseImpl(testCaseDef, instance);
}
- public void testCaseParametrize(Object _testCase, Map<String,String>
parametrization) throws TestCaseLifeCycleException
+ public void testCaseParametrize(TestCase _testCase, Map<String,String>
parametrization) throws TestCaseLifeCycleException
{
- TestCase testCase = (TestCase)_testCase;
+ TestCaseImpl testCase = (TestCaseImpl)_testCase;
// Save parametrization
testCase.parametrization = parametrization;
@@ -518,16 +518,16 @@
}
}
- public void testCaseCreate(Object _testCase) throws TestCaseLifeCycleException
+ public void testCaseCreate(TestCase _testCase) throws TestCaseLifeCycleException
{
- TestCase testCase = (TestCase)_testCase;
+ TestCaseImpl testCase = (TestCaseImpl)_testCase;
//
if (create != null)
{
try
{
- create.invoke(testCase.pojo);
+ create.invoke(testCase.getPOJO());
}
catch (InvocationTargetException e)
{
@@ -540,9 +540,9 @@
}
}
- public void testCaseInvoke(Object _testCase) throws TestCaseLifeCycleException
+ public void testCaseInvoke(TestCase _testCase) throws TestCaseLifeCycleException
{
- TestCase testCase = (TestCase)_testCase;
+ TestCaseImpl testCase = (TestCaseImpl)_testCase;
List<Object> argList = new ArrayList<Object>();
for (String parameterName : testCase.def.arguments.keySet())
@@ -576,16 +576,16 @@
}
}
- public void testCaseDestroy(Object _testCase)
+ public void testCaseDestroy(TestCase _testCase)
{
- TestCase testCase = (TestCase)_testCase;
+ TestCaseImpl testCase = (TestCaseImpl)_testCase;
//
if (destroy != null)
{
try
{
- destroy.invoke(testCase.pojo);
+ destroy.invoke(testCase.getPOJO());
}
catch (Throwable t)
{
Modified: 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 2007-10-04
21:32:02 UTC (rev 8534)
+++ modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/TestLifeCycle.java 2007-10-04
22:24:45 UTC (rev 8535)
@@ -38,7 +38,7 @@
* @return the test case object
* @throws TestCaseLifeCycleException
*/
- Object newTestCase(String name) throws TestCaseLifeCycleException;
+ TestCase newTestCase(String name) throws TestCaseLifeCycleException;
/**
* Parametrize life cycle operation of a test case.
@@ -47,7 +47,7 @@
* @param parametrization the parametrization
* @throws TestCaseLifeCycleException
*/
- void testCaseParametrize(Object testCase, Map<String,String> parametrization)
throws TestCaseLifeCycleException;
+ void testCaseParametrize(TestCase testCase, Map<String,String> parametrization)
throws TestCaseLifeCycleException;
/**
* Create life cycle operation of a test case.
@@ -55,7 +55,7 @@
* @param testCase the test case
* @throws TestCaseLifeCycleException
*/
- void testCaseCreate(Object testCase) throws TestCaseLifeCycleException;
+ void testCaseCreate(TestCase testCase) throws TestCaseLifeCycleException;
/**
* Invocation life cycle operation of a test case.
@@ -63,13 +63,13 @@
* @param testCase the test case
* @throws TestCaseLifeCycleException
*/
- void testCaseInvoke(Object testCase) throws TestCaseLifeCycleException;
+ void testCaseInvoke(TestCase testCase) throws TestCaseLifeCycleException;
/**
* Destroy life cycle operation of a test case.
*
* @param testCase the test case
*/
- void testCaseDestroy(Object testCase);
+ void testCaseDestroy(TestCase testCase);
}
Added: modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/annotations/Provider.java
===================================================================
--- modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/annotations/Provider.java
(rev 0)
+++
modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/annotations/Provider.java 2007-10-04
22:24:45 UTC (rev 8535)
@@ -0,0 +1,43 @@
+/******************************************************************************
+ * 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.annotations;
+
+import org.jboss.unit.api.pojo.TestHandler;
+
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+@Inherited
+(a)Retention(RetentionPolicy.RUNTIME)
+(a)Target({ElementType.ANNOTATION_TYPE,ElementType.TYPE})
+public @interface Provider
+{
+ Class<? extends TestHandler> value();
+}
Modified:
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 2007-10-04
21:32:02 UTC (rev 8534)
+++
modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/junit/JUnitDescriptor.java 2007-10-04
22:24:45 UTC (rev 8535)
@@ -47,9 +47,9 @@
/** . */
final Map<String,JUnitTestMethod> testMap;
- public JUnitDescriptor(Class testClass)
+ public JUnitDescriptor(JUnitProvider provider)
{
- this.testClass = testClass;
+ this.testClass = provider.testClass;
this.testMap = new HashMap<String, JUnitTestMethod>();
//
Modified:
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 2007-10-04
21:32:02 UTC (rev 8534)
+++
modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/junit/JUnitLifeCycle.java 2007-10-04
22:24:45 UTC (rev 8535)
@@ -36,33 +36,47 @@
{
/** . */
- private final TestCase testCase;
+ private final JUnitProvider provider;
- public JUnitLifeCycle(TestCase testCase)
+ public JUnitLifeCycle(JUnitProvider testCase)
{
- this.testCase = testCase;
+ this.provider = testCase;
}
- public Object newTestCase(String name) throws TestCaseLifeCycleException
+ public org.jboss.unit.api.pojo.TestCase newTestCase(String name) throws
TestCaseLifeCycleException
{
- JUnitTestMethod method = testCase.descriptor.testMap.get(name);
+ JUnitTestMethod method = provider.descriptor.testMap.get(name);
if (method == null)
{
throw new TestCaseLifeCycleException("No test case " + name + "
found");
}
- return new JUnitTestMethodLifeCycle(method);
+
+ try
+ {
+ TestCase testCase = (TestCase)provider.testClass.newInstance();
+ return new JUnitTestMethodLifeCycle(testCase, method);
+ }
+ catch (InstantiationException e)
+ {
+ throw new TestCaseLifeCycleException(e);
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new TestCaseLifeCycleException(e);
+ }
}
- public void testCaseParametrize(Object _lifeCycle, Map<String, String>
parametrization) throws TestCaseLifeCycleException
+ public void testCaseParametrize(org.jboss.unit.api.pojo.TestCase testCase,
Map<String, String> parametrization) throws TestCaseLifeCycleException
{
// No op
}
- public void testCaseCreate(Object _lifeCycle) throws TestCaseLifeCycleException
+ public void testCaseCreate(org.jboss.unit.api.pojo.TestCase testCase) throws
TestCaseLifeCycleException
{
try
{
- testCase.setUp();
+ JUnitTestMethodLifeCycle lifeCycle = (JUnitTestMethodLifeCycle)testCase;
+ lifeCycle.pojo.setUp();
}
catch (Throwable e)
{
@@ -70,14 +84,14 @@
}
}
- public void testCaseInvoke(Object _lifeCycle) throws TestCaseLifeCycleException
+ public void testCaseInvoke(org.jboss.unit.api.pojo.TestCase testCase) throws
TestCaseLifeCycleException
{
- JUnitTestMethodLifeCycle lifeCycle = (JUnitTestMethodLifeCycle)_lifeCycle;
+ JUnitTestMethodLifeCycle lifeCycle = (JUnitTestMethodLifeCycle)testCase;
// Invoke test joinpoint
try
{
- lifeCycle.testMethod.method.invoke(testCase, new Object[0]);
+ lifeCycle.testMethod.method.invoke(lifeCycle.pojo);
}
catch (IllegalAccessException e)
{
@@ -104,8 +118,16 @@
return new TestCaseLifeCycleException(throwable);
}
- public void testCaseDestroy(Object _testCase)
+ public void testCaseDestroy(org.jboss.unit.api.pojo.TestCase testCase)
{
- testCase.tearDown();
+ try
+ {
+ JUnitTestMethodLifeCycle lifeCycle = (JUnitTestMethodLifeCycle)testCase;
+ lifeCycle.pojo.tearDown();
+ }
+ catch (Throwable e)
+ {
+ e.printStackTrace();
+ }
}
}
Added: modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/junit/JUnitProvider.java
===================================================================
--- modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/junit/JUnitProvider.java
(rev 0)
+++
modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/junit/JUnitProvider.java 2007-10-04
22:24:45 UTC (rev 8535)
@@ -0,0 +1,62 @@
+/******************************************************************************
+ * 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.annotations.Provider;
+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 JUnitProvider implements TestHandler
+{
+
+ /** . */
+ final JUnitDescriptor descriptor;
+
+ final JUnitLifeCycle lifeCycle;
+
+ final Class testClass;
+
+ public JUnitProvider(Class testClass)
+ {
+ this.testClass = testClass;
+ descriptor = new JUnitDescriptor(this);
+ lifeCycle = new JUnitLifeCycle(this);
+ }
+
+ public TestSuiteDescriptor getDescriptor()
+ {
+ return descriptor;
+ }
+
+ public TestLifeCycle getLifeCycle()
+ {
+ return lifeCycle;
+ }
+}
Modified:
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 2007-10-04
21:32:02 UTC (rev 8534)
+++
modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/junit/JUnitTestMethodLifeCycle.java 2007-10-04
22:24:45 UTC (rev 8535)
@@ -26,14 +26,23 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
*/
-class JUnitTestMethodLifeCycle
+class JUnitTestMethodLifeCycle implements org.jboss.unit.api.pojo.TestCase
{
/** . */
+ final TestCase pojo;
+
+ /** . */
final JUnitTestMethod testMethod;
- public JUnitTestMethodLifeCycle(JUnitTestMethod testMethod)
+ public JUnitTestMethodLifeCycle(TestCase pojo, JUnitTestMethod testMethod)
{
+ this.pojo = pojo;
this.testMethod = testMethod;
}
+
+ public Object getPOJO()
+ {
+ return pojo;
+ }
}
Modified: 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 2007-10-04
21:32:02 UTC (rev 8534)
+++
modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/junit/TestCase.java 2007-10-04
22:24:45 UTC (rev 8535)
@@ -22,9 +22,7 @@
******************************************************************************/
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;
+import org.jboss.unit.api.pojo.annotations.Provider;
/**
@@ -33,18 +31,12 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
*/
-public class TestCase implements TestHandler
+(a)Provider(JUnitProvider.class)
+public class TestCase
{
- /** . */
- final JUnitDescriptor descriptor;
-
- final JUnitLifeCycle lifeCycle;
-
public TestCase()
{
- descriptor = new JUnitDescriptor(getClass());
- lifeCycle = new JUnitLifeCycle(this);
}
protected void setUp()
@@ -54,14 +46,4 @@
protected void tearDown()
{
}
-
- public TestSuiteDescriptor getDescriptor()
- {
- return descriptor;
- }
-
- public TestLifeCycle getLifeCycle()
- {
- return lifeCycle;
- }
}
Modified:
modules/test/trunk/unit/src/main/org/jboss/unit/info/impl/SimpleTestSuiteInfo.java
===================================================================
---
modules/test/trunk/unit/src/main/org/jboss/unit/info/impl/SimpleTestSuiteInfo.java 2007-10-04
21:32:02 UTC (rev 8534)
+++
modules/test/trunk/unit/src/main/org/jboss/unit/info/impl/SimpleTestSuiteInfo.java 2007-10-04
22:24:45 UTC (rev 8535)
@@ -76,7 +76,39 @@
public TestInfo findTest(TestId id)
{
- return null;
+ if (id == null)
+ {
+ throw new IllegalArgumentException("No null id accepted");
+ }
+
+ //
+ if (id.getLength() == 0)
+ {
+ return this;
+ }
+
+ //
+ TestInfo child = tests.get(id.getName(0));
+
+ //
+ if (child == null)
+ {
+ return null;
+ }
+
+ //
+ if (child instanceof TestSuiteInfo)
+ {
+ return ((TestSuiteInfo)child).findTest(id.range(1));
+ }
+ else if (id.getLength() == 1)
+ {
+ return child;
+ }
+ else
+ {
+ return null;
+ }
}
public void addTest(TestInfo test)
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-04
21:32:02 UTC (rev 8534)
+++
modules/test/trunk/unit/src/main/org/jboss/unit/unit/pojo/POJOTestSuiteDriver.java 2007-10-04
22:24:45 UTC (rev 8535)
@@ -26,6 +26,8 @@
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.api.pojo.TestCase;
+import org.jboss.unit.api.pojo.annotations.Provider;
import org.jboss.unit.driver.TestDriver;
import org.jboss.unit.driver.DriverResponse;
import org.jboss.unit.driver.DriverCommand;
@@ -38,6 +40,10 @@
import org.jboss.unit.Failure;
import java.util.Map;
+import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.annotation.Annotation;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -54,15 +60,50 @@
public POJOTestSuiteDriver(Class testClass) throws InstantiationException,
IllegalAccessException
{
- if (TestHandler.class.isAssignableFrom(testClass))
+ // Get provider annotation
+ Provider provider = ((AnnotatedElement)testClass).getAnnotation(Provider.class);
+
+ // Scan meta annotations
+ if (provider == null)
{
- handler = (TestHandler)testClass.newInstance();
+ for (Annotation annotation : testClass.getAnnotations())
+ {
+ Class blah = annotation.annotationType();
+ provider = ((AnnotatedElement)blah).getAnnotation(Provider.class);
+ if (provider != null)
+ {
+ break;
+ }
+ }
}
+
+ if (provider != null)
+ {
+ try
+ {
+ Class<? extends TestHandler> providerClass = provider.value();
+ Constructor<? extends TestHandler> providerCtor =
providerClass.getConstructor(Class.class);
+ handler = providerCtor.newInstance(testClass);
+ }
+ catch (NoSuchMethodException e)
+ {
+ throw new IllegalArgumentException(e);
+ }
+ catch (InvocationTargetException e)
+ {
+ throw new IllegalArgumentException(e);
+ }
+ }
+// else if (TestHandler.class.isAssignableFrom(testClass))
+// {
+// handler = (TestHandler)testClass.newInstance();
+// }
else
{
handler = new TestHandlerSupport(testClass);
}
+ //
info = new POJOTestSuiteInfo(handler.getDescriptor());
}
@@ -90,10 +131,10 @@
String name = id.getName(0);
//
- Object pojo;
+ TestCase testCase;
try
{
- pojo = lifeCycle.newTestCase(name);
+ testCase = lifeCycle.newTestCase(name);
}
catch (Exception e)
{
@@ -106,7 +147,7 @@
//
try
{
- lifeCycle.testCaseParametrize(pojo, parametrization);
+ lifeCycle.testCaseParametrize(testCase, parametrization);
}
catch (Exception e)
{
@@ -116,10 +157,10 @@
//
try
{
- lifeCycle.testCaseCreate(pojo);
+ lifeCycle.testCaseCreate(testCase);
//
- lifeCycle.testCaseInvoke(pojo);
+ lifeCycle.testCaseInvoke(testCase);
}
catch (Exception e)
{
@@ -127,7 +168,7 @@
}
finally
{
- lifeCycle.testCaseDestroy(pojo);
+ lifeCycle.testCaseDestroy(testCase);
}
//