Author: julien(a)jboss.com
Date: 2007-10-01 12:34:06 -0400 (Mon, 01 Oct 2007)
New Revision: 8504
Added:
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/AbstractPOJOTest.java
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/AbstractPOJOTests.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/test/unit/pojo/TestHandlerSupportPOJOTests.java
Removed:
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/POJOTestDriverTests.java
Modified:
modules/test/trunk/unit/build.xml
modules/test/trunk/unit/src/main/org/jboss/test/unit/AllTests.java
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/MethodAnnotatedWithCreate05.java
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/MethodAnnotatedWithCreate06.java
modules/test/trunk/unit/src/main/org/jboss/unit/api/Assert.java
modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/TestHandlerSupport.java
Log:
refactored the pojo tests to test the TestHandler in addition of the pojo test driver
Modified: modules/test/trunk/unit/build.xml
===================================================================
--- modules/test/trunk/unit/build.xml 2007-10-01 10:08:06 UTC (rev 8503)
+++ modules/test/trunk/unit/build.xml 2007-10-01 16:34:06 UTC (rev 8504)
@@ -181,9 +181,13 @@
<target name="most" depends="_default:most"/>
<target name="help" depends="_default:help"/>
- <target name="test" depends="init">
+ <target name="test" depends="output">
<java classname="org.jboss.test.unit.AllTests"
fork="true">
+<!--
+ <jvmarg value="-Xdebug"/>
+ <jvmarg
value="-Xrunjdwp:transport=dt_socket,address=7878,server=y,suspend=y"/>
+-->
<classpath>
<path location="${build.lib}/jboss-unit-lib.jar"/>
<path location="${build.lib}/jboss-unit-test.jar"/>
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-01 10:08:06
UTC (rev 8503)
+++ modules/test/trunk/unit/src/main/org/jboss/test/unit/AllTests.java 2007-10-01 16:34:06
UTC (rev 8504)
@@ -24,7 +24,7 @@
import org.jboss.test.unit.api.AssertTests;
import org.jboss.test.unit.blah.BlahTests;
-import org.jboss.test.unit.pojo.POJOTestDriverTests;
+import org.jboss.test.unit.pojo.AbstractPOJOTests;
import org.jboss.test.unit.runner.CompositeTestRunnerTests;
import org.jboss.test.unit.runner.ParametrizationTests;
import org.jboss.test.unit.runner.event.TestRunnerEventBroadcasterSupportTests;
@@ -41,7 +41,9 @@
public static void main(String[] args) throws Exception
{
AssertTests.main(args);
- POJOTestDriverTests.main(args);
+// TestHandlerSupportTests.main(args);
+// POJOTestDriverTests.main(args);
+ AbstractPOJOTests.main(args);
CompositeTestRunnerTests.main(args);
//
Added: modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/AbstractPOJOTest.java
===================================================================
--- modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/AbstractPOJOTest.java
(rev 0)
+++
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/AbstractPOJOTest.java 2007-10-01
16:34:06 UTC (rev 8504)
@@ -0,0 +1,47 @@
+/******************************************************************************
+ * 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;
+
+import java.util.Set;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class AbstractPOJOTest
+{
+
+ public abstract Set<String> getParameterNames();
+
+ public abstract Set<String> getTestCaseNames();
+
+ public abstract Set<String> getTestCaseParameterNames(String testCaseName);
+
+ public abstract InvokeResult invoke(String testName, Map<String,String>
parametrization);
+
+ public enum InvokeResult
+ {
+ PASS, FAILURE, ERROR
+ }
+}
Added: modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/AbstractPOJOTests.java
===================================================================
--- modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/AbstractPOJOTests.java
(rev 0)
+++
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/AbstractPOJOTests.java 2007-10-01
16:34:06 UTC (rev 8504)
@@ -0,0 +1,316 @@
+/******************************************************************************
+ * 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;
+
+import org.jboss.unit.api.Assert;
+
+import java.util.Map;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class AbstractPOJOTests
+{
+
+ public static void main(String[] args)
+ {
+ new TestDriverPOJOTests().test();
+ new TestHandlerSupportPOJOTests().test();
+ }
+
+
+ public void test()
+ {
+ testAbstractClassWithoutAnnotations();
+ testClassWithoutAnnotations();
+ testAbstractClassAnnotatedWithTest();
+ testClassAnnotatedWithTest();
+
+ //
+ testMethodAnnotatedWithTest();
+ testTestMethodHavingArgumentsAnnotatedWithParameter();
+ testTestMethodAnnotatedWithConflictingAnnotations();
+ testMethodAnnotatedWithParameter();
+ testMethodAnnotatedWithCreate();
+
+ //
+ testClassHavingSamePropertyParameterAndMethodArgumentParameter();
+
+ //
+ testClassWithoutDefaultConstructor();
+ testClassWithFailingConstructor();
+
+ //
+ testLifeCycleSequence();
+ }
+
+ private void testLifeCycleSequence()
+ {
+ testLifeCycleSequence(LifeCycleSequence01.class,
AbstractPOJOTest.InvokeResult.ERROR, null, false);
+ testLifeCycleSequence(LifeCycleSequence02.class,
AbstractPOJOTest.InvokeResult.FAILURE, null, false);
+ testLifeCycleSequence(LifeCycleSequence03.class,
AbstractPOJOTest.InvokeResult.ERROR, "C", false);
+ testLifeCycleSequence(LifeCycleSequence04.class,
AbstractPOJOTest.InvokeResult.FAILURE, "C", false);
+ testLifeCycleSequence(LifeCycleSequence05.class,
AbstractPOJOTest.InvokeResult.ERROR, "CSD", false);
+ testLifeCycleSequence(LifeCycleSequence06.class,
AbstractPOJOTest.InvokeResult.FAILURE, "CSD", false);
+ testLifeCycleSequence(LifeCycleSequence07.class,
AbstractPOJOTest.InvokeResult.ERROR, "CSRD", false);
+ testLifeCycleSequence(LifeCycleSequence08.class,
AbstractPOJOTest.InvokeResult.FAILURE, "CSRD", false);
+ testLifeCycleSequence(LifeCycleSequence09.class,
AbstractPOJOTest.InvokeResult.PASS, "CSRD", true);
+ testLifeCycleSequence(LifeCycleSequence10.class,
AbstractPOJOTest.InvokeResult.PASS, "CSRD", true);
+ testLifeCycleSequence(LifeCycleSequence11.class,
AbstractPOJOTest.InvokeResult.PASS, "CSRD", true);
+ }
+
+ private void testLifeCycleSequence(Class clazz, AbstractPOJOTest.InvokeResult result,
String expected, boolean invoked)
+ {
+ AbstractPOJOTest driver = assertCanBuildSuite(clazz);
+
+ //
+ invoke(driver, clazz, "testFoo", result, invoked);
+
+ //
+ Assert.assertEquals(expected, POJOAssert.buffer1);
+ }
+
+ private void testMethodAnnotatedWithCreate()
+ {
+ testMethodAnnotatedWithCreate(MethodAnnotatedWithCreate01.class);
+ testMethodAnnotatedWithCreate(MethodAnnotatedWithCreate02.class);
+ testMethodAnnotatedWithCreate(MethodAnnotatedWithCreate03.class);
+ testMethodAnnotatedWithCreate(MethodAnnotatedWithCreate04.class);
+ assertCannotBuildSuite(MethodAnnotatedWithCreate05.class);
+ assertCannotBuildSuite(MethodAnnotatedWithCreate06.class);
+ assertCannotBuildSuite(MethodAnnotatedWithCreate07.class);
+ }
+
+ private void testMethodAnnotatedWithCreate(Class clazz)
+ {
+ AbstractPOJOTest driver = assertCanBuildSuite(clazz);
+
+ //
+ invoke(driver, clazz, "testFoo", AbstractPOJOTest.InvokeResult.PASS,
true);
+ }
+
+ private void testClassHavingSamePropertyParameterAndMethodArgumentParameter()
+ {
+ AbstractPOJOTest driver =
assertCanBuildSuite(ClassHavingSamePropertyParameterAndMethodArgumentParameter.class);
+
+ //
+ invoke(driver, ClassHavingSamePropertyParameterAndMethodArgumentParameter.class,
"testFoo", AbstractPOJOTest.InvokeResult.PASS, true);
+ }
+
+ private void testClassWithFailingConstructor()
+ {
+ testClassWithFailingConstructor(ClassWithFailingConstructor1.class,
AbstractPOJOTest.InvokeResult.ERROR, false);
+ testClassWithFailingConstructor(ClassWithFailingConstructor2.class,
AbstractPOJOTest.InvokeResult.ERROR, false);
+ testClassWithFailingConstructor(ClassWithFailingConstructor3.class,
AbstractPOJOTest.InvokeResult.ERROR, false);
+ testClassWithFailingConstructor(ClassWithFailingConstructor4.class,
AbstractPOJOTest.InvokeResult.FAILURE, false);
+ }
+
+ private void testClassWithFailingConstructor(Class clazz,
AbstractPOJOTest.InvokeResult result, boolean invoked)
+ {
+ AbstractPOJOTest driver = assertCanBuildSuite(clazz);
+
+ //
+ invoke(driver, clazz, "testFoo", result, invoked);
+ }
+
+ private void testClassWithoutDefaultConstructor()
+ {
+ assertCannotBuildSuite(ClassWithoutDefaultConstructor1.class);
+ assertCannotBuildSuite(ClassWithoutDefaultConstructor2.class);
+ assertCannotBuildSuite(ClassWithoutDefaultConstructor3.class);
+ assertCannotBuildSuite(ClassWithoutDefaultConstructor4.class);
+ }
+
+ private void testMethodAnnotatedWithParameter()
+ {
+ testMethodAnnotatedWithParameter(MethodAnnotatedWithParameter01.class, false,
AbstractPOJOTest.InvokeResult.PASS, true, "foo");
+ testMethodAnnotatedWithParameter(MethodAnnotatedWithParameter02.class, false,
AbstractPOJOTest.InvokeResult.PASS, true, "bar");
+ testMethodAnnotatedWithParameter(MethodAnnotatedWithParameter05.class, true,
AbstractPOJOTest.InvokeResult.PASS, true, "foo");
+ testMethodAnnotatedWithParameter(MethodAnnotatedWithParameter06.class, true,
AbstractPOJOTest.InvokeResult.PASS, true, "bar");
+ testMethodAnnotatedWithParameter(MethodAnnotatedWithParameter07.class, true,
AbstractPOJOTest.InvokeResult.PASS, true, "foo");
+ testMethodAnnotatedWithParameter(MethodAnnotatedWithParameter09.class, true,
AbstractPOJOTest.InvokeResult.PASS, true, "foo");
+ testMethodAnnotatedWithParameter(MethodAnnotatedWithParameter10.class, true,
AbstractPOJOTest.InvokeResult.ERROR, false, "foo");
+ testMethodAnnotatedWithParameter(MethodAnnotatedWithParameter11.class, true,
AbstractPOJOTest.InvokeResult.ERROR, false, "foo");
+ testMethodAnnotatedWithParameter(MethodAnnotatedWithParameter12.class, true,
AbstractPOJOTest.InvokeResult.ERROR, false, "foo");
+ testMethodAnnotatedWithParameter(MethodAnnotatedWithParameter13.class, true,
AbstractPOJOTest.InvokeResult.FAILURE, false, "foo");
+ }
+
+ private void testMethodAnnotatedWithParameter(Class clazz, boolean invoke,
AbstractPOJOTest.InvokeResult result, boolean invoked, String... expectedParameterNames)
+ {
+ AbstractPOJOTest driver = assertCanBuildSuite(clazz);
+
+ //
+ assertParametersEquals(driver.getParameterNames(), expectedParameterNames);
+
+ //
+ if (invoke)
+ {
+ Assert.assertEquals(1, driver.getTestCaseNames().size());
+ Assert.assertEquals(driver.getParameterNames(),
driver.getTestCaseParameterNames("test"));
+ invoke(driver, clazz, "test", result, invoked);
+ }
+ else
+ {
+ Assert.assertEquals(0, driver.getTestCaseNames().size());
+ }
+ }
+
+ private void testTestMethodAnnotatedWithConflictingAnnotations()
+ {
+ assertCannotBuildSuite(TestMethodAnnotatedWithConflictingAnnotations1.class);
+ assertCannotBuildSuite(TestMethodAnnotatedWithConflictingAnnotations2.class);
+ assertCannotBuildSuite(TestMethodAnnotatedWithConflictingAnnotations3.class);
+ assertCannotBuildSuite(TestMethodAnnotatedWithConflictingAnnotations4.class);
+ }
+
+ private void testTestMethodHavingArgumentsAnnotatedWithParameter(Class clazz,
String... expectedParameterNames)
+ {
+ AbstractPOJOTest driver = assertCanBuildSuite(clazz);
+
+ //
+ Assert.assertEquals(Collections.singleton("testFoo"),
driver.getTestCaseNames());
+
+ //
+ assertParametersEquals(driver.getTestCaseParameterNames("testFoo"),
expectedParameterNames);
+
+ //
+ invoke(driver, clazz, "testFoo", AbstractPOJOTest.InvokeResult.PASS,
true);
+ }
+
+ private void testTestMethodHavingArgumentsAnnotatedWithParameter()
+ {
+
testTestMethodHavingArgumentsAnnotatedWithParameter(TestMethodHavingArgumentsAnnotatedWithParameter1.class,
"paramFoo");
+
testTestMethodHavingArgumentsAnnotatedWithParameter(TestMethodHavingArgumentsAnnotatedWithParameter2.class,
"paramFoo", "paramBar");
+ assertCannotBuildSuite(TestMethodHavingArgumentsAnnotatedWithParameter3.class);
+ assertCannotBuildSuite(TestMethodHavingArgumentsAnnotatedWithParameter4.class);
+ assertCannotBuildSuite(TestMethodHavingArgumentsAnnotatedWithParameter5.class);
+ assertCannotBuildSuite(TestMethodHavingArgumentsAnnotatedWithParameter6.class);
+ assertCannotBuildSuite(TestMethodHavingArgumentsAnnotatedWithParameter7.class);
+ assertCannotBuildSuite(TestMethodHavingArgumentsAnnotatedWithParameter8.class);
+ }
+
+ private void testMethodAnnotatedWithTest()
+ {
+ testMethodAnnotatedWithTest(MethodAnnotatedWithTest1.class, "testFoo");
+ testMethodAnnotatedWithTest(MethodAnnotatedWithTest2.class, "testBar");
+ assertCannotBuildSuite(MethodAnnotatedWithTest5.class);
+ assertClassHasNoTests(MethodAnnotatedWithTest6.class);
+ assertClassHasNoTests(MethodAnnotatedWithTest7.class);
+ assertClassHasNoTests(MethodAnnotatedWithTest8.class);
+ assertCannotBuildSuite(MethodAnnotatedWithTest9.class);
+ }
+
+ private void testMethodAnnotatedWithTest(Class clazz, String testName)
+ {
+ AbstractPOJOTest driver = assertCanBuildSuite(clazz);
+
+ //
+ Assert.assertEquals(Collections.singleton(testName), driver.getTestCaseNames());
+ Assert.assertEquals(Collections.emptySet(),
driver.getTestCaseParameterNames(testName));
+
+ //
+ invoke(driver, clazz, testName, AbstractPOJOTest.InvokeResult.PASS, true);
+ }
+
+ private void testAbstractClassWithoutAnnotations()
+ {
+ assertCannotBuildSuite(AbstractClassWithoutAnnotations.class);
+ }
+
+ private void testClassWithoutAnnotations()
+ {
+ AbstractPOJOTest driver = assertCanBuildSuite(ClassWithoutAnnotations.class);
+ Assert.assertEquals(new HashSet(), driver.getParameterNames());
+ Assert.assertEquals(new HashSet(), driver.getTestCaseNames());
+ }
+
+ private void testAbstractClassAnnotatedWithTest()
+ {
+ assertCannotBuildSuite(AbstractClassAnnotatedWithTest1.class);
+ assertCannotBuildSuite(AbstractClassAnnotatedWithTest2.class);
+ }
+
+ private void testClassAnnotatedWithTest()
+ {
+ testClassAnnotatedPOJO(ClassAnnotatedWithTest1.class,
ClassAnnotatedWithTest1.class.getName(), null);
+ testClassAnnotatedPOJO(ClassAnnotatedWithTest2.class, "foo", null);
+ }
+
+ private void testClassAnnotatedPOJO(Class clazz, String name, String description)
+ {
+ AbstractPOJOTest driver = assertCanBuildSuite(clazz);
+ Assert.assertEquals(new HashSet(), driver.getParameterNames());
+ Assert.assertEquals(new HashSet(), driver.getTestCaseNames());
+ }
+
+ private void assertParametersEquals(Set<String> parametersInfo, String...
expectedParameterNames)
+ {
+ Assert.assertEquals(expectedParameterNames.length, parametersInfo.size());
+ for (String expectedParameterName : expectedParameterNames)
+ {
+ Assert.assertTrue(parametersInfo.contains(expectedParameterName));
+ }
+ }
+
+ // *************************
+
+ private void invoke(AbstractPOJOTest driver, Class clazz, String testName,
AbstractPOJOTest.InvokeResult expectedResult, boolean invoked)
+ {
+ Map<String, String> parametrization = new HashMap<String, String>();
+ Map<String,Object> expectedParameterValues = new HashMap<String,
Object>();
+ for (String expectedParameterName : driver.getTestCaseParameterNames(testName))
+ {
+ String expectedParameterValue = expectedParameterName + "_value";
+ parametrization.put(expectedParameterName, expectedParameterValue);
+ expectedParameterValues.put(expectedParameterName, expectedParameterValue);
+ }
+
+ //
+ POJOAssert.clear();
+ AbstractPOJOTest.InvokeResult result = driver.invoke(testName, parametrization);
+ Assert.assertEquals(expectedResult, result);
+ if (invoked)
+ {
+ POJOAssert.assertWasCalled(clazz, expectedParameterValues);
+ }
+ else
+ {
+ POJOAssert.assertWasNotCalled();
+ }
+ }
+
+ private void assertClassHasNoTests(Class clazz)
+ {
+ AbstractPOJOTest driver = assertCanBuildSuite(clazz);
+ Assert.assertEquals(Collections.EMPTY_SET, driver.getTestCaseNames());
+ }
+
+ protected abstract void assertCannotBuildSuite(Class clazz);
+
+ protected abstract AbstractPOJOTest assertCanBuildSuite(Class clazz);
+}
Modified:
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/MethodAnnotatedWithCreate05.java
===================================================================
---
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/MethodAnnotatedWithCreate05.java 2007-10-01
10:08:06 UTC (rev 8503)
+++
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/MethodAnnotatedWithCreate05.java 2007-10-01
16:34:06 UTC (rev 8504)
@@ -34,5 +34,6 @@
@Create
public static void foo()
{
+ POJOAssert.buffer1 = "foo";
}
}
Modified:
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/MethodAnnotatedWithCreate06.java
===================================================================
---
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/MethodAnnotatedWithCreate06.java 2007-10-01
10:08:06 UTC (rev 8503)
+++
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/MethodAnnotatedWithCreate06.java 2007-10-01
16:34:06 UTC (rev 8504)
@@ -34,5 +34,6 @@
@Create
public void foo(String s)
{
+ POJOAssert.buffer1 = "foo";
}
}
Deleted:
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/POJOTestDriverTests.java
===================================================================
---
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/POJOTestDriverTests.java 2007-10-01
10:08:06 UTC (rev 8503)
+++
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/POJOTestDriverTests.java 2007-10-01
16:34:06 UTC (rev 8504)
@@ -1,406 +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.test.unit.pojo;
-
-import org.jboss.unit.Failure;
-import org.jboss.unit.FailureType;
-import org.jboss.unit.TestId;
-import static org.jboss.unit.api.Assert.*;
-import org.jboss.unit.driver.DriverResponse;
-import org.jboss.unit.driver.TestDriver;
-import org.jboss.unit.driver.command.StartTestCommand;
-import org.jboss.unit.driver.response.EndTestResponse;
-import org.jboss.unit.driver.response.FailureResponse;
-import org.jboss.unit.info.ParameterInfo;
-import org.jboss.unit.info.TestCaseInfo;
-import org.jboss.unit.info.TestInfo;
-import org.jboss.unit.info.TestSuiteInfo;
-import org.jboss.unit.unit.pojo.POJOTestSuiteDriver;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 1.1 $
- */
-public class POJOTestDriverTests
-{
-
- public static void main(String[] args)
- {
- testAbstractClassWithoutAnnotations();
- testClassWithoutAnnotations();
- testAbstractClassAnnotatedWithTest();
- testClassAnnotatedWithTest();
-
- //
- testMethodAnnotatedWithTest();
- testTestMethodHavingArgumentsAnnotatedWithParameter();
- testTestMethodAnnotatedWithConflictingAnnotations();
- testMethodAnnotatedWithParameter();
- testMethodAnnotatedWithCreate();
-
- //
- testClassHavingSamePropertyParameterAndMethodArgumentParameter();
-
- //
- testClassWithoutDefaultConstructor();
- testClassWithFailingConstructor();
-
- //
- testLifeCycleSequence();
- }
-
- private static void testLifeCycleSequence()
- {
- testLifeCycleSequence(LifeCycleSequence01.class, InvokeResult.NOT_CALLED_ERROR,
null);
- testLifeCycleSequence(LifeCycleSequence02.class, InvokeResult.NOT_CALLED_FAIL,
null);
- testLifeCycleSequence(LifeCycleSequence03.class, InvokeResult.NOT_CALLED_ERROR,
"C");
- testLifeCycleSequence(LifeCycleSequence04.class, InvokeResult.NOT_CALLED_FAIL,
"C");
- testLifeCycleSequence(LifeCycleSequence05.class, InvokeResult.NOT_CALLED_ERROR,
"CSD");
- testLifeCycleSequence(LifeCycleSequence06.class, InvokeResult.NOT_CALLED_FAIL,
"CSD");
- testLifeCycleSequence(LifeCycleSequence07.class, InvokeResult.NOT_CALLED_ERROR,
"CSRD");
- testLifeCycleSequence(LifeCycleSequence08.class, InvokeResult.NOT_CALLED_FAIL,
"CSRD");
- testLifeCycleSequence(LifeCycleSequence09.class, InvokeResult.PASS,
"CSRD");
- testLifeCycleSequence(LifeCycleSequence10.class, InvokeResult.PASS,
"CSRD");
- testLifeCycleSequence(LifeCycleSequence11.class, InvokeResult.PASS,
"CSRD");
-
-
-
-
-// testMethodAnnotatedWithFailingCreate(LifeCycleSequence02_.class,
InvokeResult.NOT_CALLED_ERROR);
-// testMethodAnnotatedWithFailingCreate(LifeCycleSequence03_.class,
InvokeResult.NOT_CALLED_ERROR);
-// testMethodAnnotatedWithFailingCreate(LifeCycleSequence04_.class,
InvokeResult.NOT_CALLED_FAIL);
-// testMethodAnnotatedWithCreate(LifeCycleSequence05_.class);
- }
-
- private static void testLifeCycleSequence(Class clazz, InvokeResult result, String
expected)
- {
- TestDriver driver = assertCanBuildSuite(clazz);
-
- //
- invoke(driver, clazz, "testFoo", result);
-
- //
- assertEquals(expected, POJOAssert.buffer1);
- }
-
- private static void testMethodAnnotatedWithCreate()
- {
- testMethodAnnotatedWithCreate(MethodAnnotatedWithCreate01.class);
- testMethodAnnotatedWithCreate(MethodAnnotatedWithCreate02.class);
- testMethodAnnotatedWithCreate(MethodAnnotatedWithCreate03.class);
- testMethodAnnotatedWithCreate(MethodAnnotatedWithCreate04.class);
- assertCannotBuildSuite(MethodAnnotatedWithCreate05.class);
- assertCannotBuildSuite(MethodAnnotatedWithCreate06.class);
- assertCannotBuildSuite(MethodAnnotatedWithCreate07.class);
- }
-
- private static void testMethodAnnotatedWithCreate(Class clazz)
- {
- TestDriver driver = assertCanBuildSuite(clazz);
-
- //
- invoke(driver, clazz, "testFoo", InvokeResult.PASS);
- }
-
- private static void testClassHavingSamePropertyParameterAndMethodArgumentParameter()
- {
- TestDriver driver =
assertCanBuildSuite(ClassHavingSamePropertyParameterAndMethodArgumentParameter.class);
-
- //
- invoke(driver, ClassHavingSamePropertyParameterAndMethodArgumentParameter.class,
"testFoo", InvokeResult.PASS);
- }
-
- private static void testClassWithFailingConstructor()
- {
- testClassWithFailingConstructor(ClassWithFailingConstructor1.class,
InvokeResult.NOT_CALLED_ERROR);
- testClassWithFailingConstructor(ClassWithFailingConstructor2.class,
InvokeResult.NOT_CALLED_ERROR);
- testClassWithFailingConstructor(ClassWithFailingConstructor3.class,
InvokeResult.NOT_CALLED_ERROR);
- testClassWithFailingConstructor(ClassWithFailingConstructor4.class,
InvokeResult.NOT_CALLED_FAIL);
- }
-
- private static void testClassWithFailingConstructor(Class clazz, InvokeResult result)
- {
- TestDriver driver = assertCanBuildSuite(clazz);
-
- //
- invoke(driver, clazz, "testFoo", result);
- }
-
- private static void testClassWithoutDefaultConstructor()
- {
- assertCannotBuildSuite(ClassWithoutDefaultConstructor1.class);
- assertCannotBuildSuite(ClassWithoutDefaultConstructor2.class);
- assertCannotBuildSuite(ClassWithoutDefaultConstructor3.class);
- assertCannotBuildSuite(ClassWithoutDefaultConstructor4.class);
- }
-
- private static void testMethodAnnotatedWithParameter()
- {
- testMethodAnnotatedWithParameter(MethodAnnotatedWithParameter01.class, false,
InvokeResult.PASS, "foo");
- testMethodAnnotatedWithParameter(MethodAnnotatedWithParameter02.class, false,
InvokeResult.PASS, "bar");
- testMethodAnnotatedWithParameter(MethodAnnotatedWithParameter05.class, true,
InvokeResult.PASS, "foo");
- testMethodAnnotatedWithParameter(MethodAnnotatedWithParameter06.class, true,
InvokeResult.PASS, "bar");
- testMethodAnnotatedWithParameter(MethodAnnotatedWithParameter07.class, true,
InvokeResult.PASS, "foo");
- testMethodAnnotatedWithParameter(MethodAnnotatedWithParameter09.class, true,
InvokeResult.PASS, "foo");
- testMethodAnnotatedWithParameter(MethodAnnotatedWithParameter10.class, true,
InvokeResult.NOT_CALLED_ERROR, "foo");
- testMethodAnnotatedWithParameter(MethodAnnotatedWithParameter11.class, true,
InvokeResult.NOT_CALLED_ERROR, "foo");
- testMethodAnnotatedWithParameter(MethodAnnotatedWithParameter12.class, true,
InvokeResult.NOT_CALLED_ERROR, "foo");
- testMethodAnnotatedWithParameter(MethodAnnotatedWithParameter13.class, true,
InvokeResult.NOT_CALLED_FAIL, "foo");
- }
-
- private static void testMethodAnnotatedWithParameter(Class clazz, boolean invoke,
InvokeResult result, String... expectedParameterNames)
- {
- TestDriver driver = assertCanBuildSuite(clazz);
-
- //
- TestSuiteInfo info = (TestSuiteInfo)driver.getInfo();
-
- //
- Map<String, ? extends ParameterInfo> parametersInfo = info.getParameters();
- assertParametersEquals(parametersInfo, expectedParameterNames);
-
- //
- if (invoke)
- {
- assertEquals(1, info.getNames().size());
- TestCaseInfo caseInfo = (TestCaseInfo)info.getTest("test");
- assertNotNull(caseInfo);
- assertParametersEquals(caseInfo.getParameters(), expectedParameterNames);
-
- //
- invoke(driver, clazz, "test", result);
- }
- else
- {
- assertEquals(0, info.getNames().size());
- }
- }
-
- private static void testTestMethodAnnotatedWithConflictingAnnotations()
- {
- assertCannotBuildSuite(TestMethodAnnotatedWithConflictingAnnotations1.class);
- assertCannotBuildSuite(TestMethodAnnotatedWithConflictingAnnotations2.class);
- assertCannotBuildSuite(TestMethodAnnotatedWithConflictingAnnotations3.class);
- assertCannotBuildSuite(TestMethodAnnotatedWithConflictingAnnotations4.class);
- }
-
- private static void testTestMethodHavingArgumentsAnnotatedWithParameter(Class clazz,
String... expectedParameterNames)
- {
- TestDriver driver = assertCanBuildSuite(clazz);
-
- //
- TestSuiteInfo suiteInfo = (TestSuiteInfo)driver.getInfo();
-
- //
- assertEquals(Collections.singleton("testFoo"), suiteInfo.getNames());
- TestInfo testFooInfo = suiteInfo.getTest("testFoo");
- assertNotNull(testFooInfo);
- assertInstanceOf(testFooInfo, TestCaseInfo.class);
-
- //
- Map<String, ? extends ParameterInfo> parametersInfo =
testFooInfo.getParameters();
- assertParametersEquals(parametersInfo, expectedParameterNames);
-
- //
- invoke(driver, clazz, "testFoo", InvokeResult.PASS);
- }
-
- private static void testTestMethodHavingArgumentsAnnotatedWithParameter()
- {
-
testTestMethodHavingArgumentsAnnotatedWithParameter(TestMethodHavingArgumentsAnnotatedWithParameter1.class,
"paramFoo");
-
testTestMethodHavingArgumentsAnnotatedWithParameter(TestMethodHavingArgumentsAnnotatedWithParameter2.class,
"paramFoo", "paramBar");
- assertCannotBuildSuite(TestMethodHavingArgumentsAnnotatedWithParameter3.class);
- assertCannotBuildSuite(TestMethodHavingArgumentsAnnotatedWithParameter4.class);
- assertCannotBuildSuite(TestMethodHavingArgumentsAnnotatedWithParameter5.class);
- assertCannotBuildSuite(TestMethodHavingArgumentsAnnotatedWithParameter6.class);
- assertCannotBuildSuite(TestMethodHavingArgumentsAnnotatedWithParameter7.class);
- assertCannotBuildSuite(TestMethodHavingArgumentsAnnotatedWithParameter8.class);
- }
-
- private static void testMethodAnnotatedWithTest()
- {
- testMethodAnnotatedWithTest(MethodAnnotatedWithTest1.class, "testFoo");
- testMethodAnnotatedWithTest(MethodAnnotatedWithTest2.class, "testBar");
- assertCannotBuildSuite(MethodAnnotatedWithTest5.class);
- assertClassHasNoTests(MethodAnnotatedWithTest6.class);
- assertClassHasNoTests(MethodAnnotatedWithTest7.class);
- assertClassHasNoTests(MethodAnnotatedWithTest8.class);
- assertCannotBuildSuite(MethodAnnotatedWithTest9.class);
- }
-
- private static void testMethodAnnotatedWithTest(Class clazz, String testName)
- {
- TestDriver driver = assertCanBuildSuite(clazz);
-
- //
- TestSuiteInfo info = (TestSuiteInfo)driver.getInfo();
- assertEquals(Collections.singleton(testName), info.getNames());
- TestInfo testFooInfo = info.getTest(testName);
- assertNotNull(testFooInfo);
- assertInstanceOf(testFooInfo, TestCaseInfo.class);
- assertEquals(testName, testFooInfo.getName());
- assertEquals(Collections.EMPTY_MAP, testFooInfo.getParameters());
-
- //
- POJOAssert.clear();
- DriverResponse response = driver.invoke(new TestId(testName), new
StartTestCommand());
- assertInstanceOf(response, EndTestResponse.class);
- POJOAssert.assertWasCalled(clazz);
- }
-
- private static void testAbstractClassWithoutAnnotations()
- {
- assertCannotBuildSuite(AbstractClassWithoutAnnotations.class);
- }
-
- private static void testClassWithoutAnnotations()
- {
- TestDriver driver = assertCanBuildSuite(ClassWithoutAnnotations.class);
- TestSuiteInfo info = (TestSuiteInfo)driver.getInfo();
- assertEquals(new HashMap(), info.getParameters());
- assertEquals(new HashSet(), info.getNames());
- }
-
- private static void testAbstractClassAnnotatedWithTest()
- {
- assertCannotBuildSuite(AbstractClassAnnotatedWithTest1.class);
- assertCannotBuildSuite(AbstractClassAnnotatedWithTest2.class);
- }
-
- private static void testClassAnnotatedWithTest()
- {
- testClassAnnotatedPOJO(ClassAnnotatedWithTest1.class,
ClassAnnotatedWithTest1.class.getName(), null);
- testClassAnnotatedPOJO(ClassAnnotatedWithTest2.class, "foo", null);
- }
-
- private static void testClassAnnotatedPOJO(Class clazz, String name, String
description)
- {
- TestDriver driver = assertCanBuildSuite(clazz);
- TestSuiteInfo info = (TestSuiteInfo)driver.getInfo();
- assertEquals(new HashMap(), info.getParameters());
- assertEquals(new HashSet(), info.getNames());
- }
-
- private static void assertParametersEquals(Map<String, ? extends ParameterInfo>
parametersInfo, String... expectedParameterNames)
- {
- assertEquals(expectedParameterNames.length, parametersInfo.size());
- for (String expectedParameterName : expectedParameterNames)
- {
- ParameterInfo parameterInfo = parametersInfo.get(expectedParameterName);
- assertNotNull(parameterInfo);
- assertEquals(expectedParameterName, parameterInfo.getName());
- }
- }
-
- // *************************
-
- private enum InvokeResult
- {
- PASS, NOT_CALLED_FAIL, NOT_CALLED_ERROR
- }
-
- private static void invoke(TestDriver driver, Class clazz, String testName,
InvokeResult result)
- {
- TestCaseInfo testInfo =
(TestCaseInfo)((TestSuiteInfo)driver.getInfo()).getTest(testName);
- assertNotNull(testInfo);
-
- //
- Map<String, String> expectedParametrization = new HashMap<String,
String>();
- Map<String,Object> expectedParameterValues = new HashMap<String,
Object>();
- for (String expectedParameterName : testInfo.getParameters().keySet())
- {
- String expectedParameterValue = expectedParameterName + "_value";
- expectedParametrization.put(expectedParameterName, expectedParameterValue);
- expectedParameterValues.put(expectedParameterName, expectedParameterValue);
- }
-
- //
- POJOAssert.clear();
- DriverResponse response = driver.invoke(new TestId(testName), new
StartTestCommand(expectedParametrization));
- switch(result)
- {
- case PASS:
- {
- assertInstanceOf(response, EndTestResponse.class);
- POJOAssert.assertWasCalled(clazz, expectedParameterValues);
- break;
- }
- case NOT_CALLED_FAIL:
- {
- FailureResponse failureResponse = assertInstanceOf(response,
FailureResponse.class);
- Failure failure = failureResponse.getFailure();
- assertEquals(FailureType.ASSERTION, failure.getLevel());
- POJOAssert.assertWasNotCalled();
- break;
- }
- case NOT_CALLED_ERROR:
- {
- FailureResponse failureResponse = assertInstanceOf(response,
FailureResponse.class);
- Failure failure = failureResponse.getFailure();
- assertEquals(FailureType.ERROR, failure.getLevel());
- POJOAssert.assertWasNotCalled();
- break;
- }
- }
- }
-
- private static void assertClassHasNoTests(Class clazz)
- {
- TestDriver driver = assertCanBuildSuite(clazz);
- TestSuiteInfo suiteInfo = (TestSuiteInfo)driver.getInfo();
- assertEquals(Collections.EMPTY_SET, suiteInfo.getNames());
- }
-
- private static void assertCannotBuildSuite(Class clazz)
- {
- try
- {
- new POJOTestSuiteDriver(clazz);
- fail();
- }
- catch (IllegalArgumentException expected)
- {
- }
- }
-
- private static TestDriver assertCanBuildSuite(Class clazz)
- {
- TestDriver driver = new POJOTestSuiteDriver(clazz);
-
- //
- assertNotNull(driver);
-
- //
- TestInfo info = driver.getInfo();
- assertNotNull(info);
- assertInstanceOf(info, TestSuiteInfo.class);
-
- //
- return driver;
- }
-}
Added: 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
(rev 0)
+++
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/TestDriverPOJOTest.java 2007-10-01
16:34:06 UTC (rev 8504)
@@ -0,0 +1,105 @@
+/******************************************************************************
+ * 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;
+
+import org.jboss.unit.driver.TestDriver;
+import org.jboss.unit.driver.DriverResponse;
+import org.jboss.unit.driver.response.EndTestResponse;
+import org.jboss.unit.driver.response.FailureResponse;
+import org.jboss.unit.driver.command.StartTestCommand;
+import org.jboss.unit.info.ParameterInfo;
+import org.jboss.unit.info.TestSuiteInfo;
+import org.jboss.unit.info.TestInfo;
+import org.jboss.unit.info.TestCaseInfo;
+import static org.jboss.unit.api.Assert.*;
+import org.jboss.unit.TestId;
+
+import java.util.Set;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class TestDriverPOJOTest extends AbstractPOJOTest
+{
+
+ /** . */
+ private final TestDriver testDriver;
+
+ /** . */
+ private final TestSuiteInfo suiteInfo;
+
+ public TestDriverPOJOTest(TestDriver testDriver)
+ {
+ TestInfo info = testDriver.getInfo();
+ assertNotNull(info);
+ TestSuiteInfo suiteInfo = assertInstanceOf(info, TestSuiteInfo.class);
+
+ //
+ this.testDriver = testDriver;
+ this.suiteInfo = suiteInfo;
+ }
+
+ public Set<String> getParameterNames()
+ {
+ return suiteInfo.getParameters().keySet();
+ }
+
+ public Set<String> getTestCaseNames()
+ {
+ return suiteInfo.getNames();
+ }
+
+ public Set<String> getTestCaseParameterNames(String testCaseName)
+ {
+ TestInfo info = suiteInfo.getTest(testCaseName);
+ assertNotNull(info);
+ TestCaseInfo testCaseInfo = assertInstanceOf(info, TestCaseInfo.class);
+ Map<String, ? extends ParameterInfo> testCaseParameterInfos =
testCaseInfo.getParameters();
+ assertNotNull(testCaseParameterInfos);
+ return testCaseParameterInfos.keySet();
+ }
+
+ public InvokeResult invoke(String testName, Map<String, String>
parametrization)
+ {
+ DriverResponse response = testDriver.invoke(new TestId(testName), new
StartTestCommand(parametrization));
+ assertNotNull(response);
+ if (response instanceof EndTestResponse)
+ {
+ return InvokeResult.PASS;
+ }
+ else if (response instanceof FailureResponse)
+ {
+ FailureResponse failureResponse = (FailureResponse)response;
+ switch (failureResponse.getFailure().getLevel())
+ {
+ case ERROR:
+ return InvokeResult.ERROR;
+ case ASSERTION:
+ return InvokeResult.FAILURE;
+ }
+ }
+ throw createFailure();
+ }
+}
Added: 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
(rev 0)
+++
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/TestDriverPOJOTests.java 2007-10-01
16:34:06 UTC (rev 8504)
@@ -0,0 +1,55 @@
+/******************************************************************************
+ * 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;
+
+import org.jboss.unit.driver.TestDriver;
+import org.jboss.unit.unit.pojo.POJOTestSuiteDriver;
+import static org.jboss.unit.api.Assert.fail;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class TestDriverPOJOTests extends AbstractPOJOTests
+{
+
+ protected void assertCannotBuildSuite(Class clazz)
+ {
+ try
+ {
+ new POJOTestSuiteDriver(clazz);
+ fail();
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ }
+
+ protected AbstractPOJOTest assertCanBuildSuite(Class clazz)
+ {
+ TestDriver driver = new POJOTestSuiteDriver(clazz);
+
+ //
+ return new TestDriverPOJOTest(driver);
+ }
+}
Added:
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
(rev 0)
+++
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/TestHandlerSupportPOJOTest.java 2007-10-01
16:34:06 UTC (rev 8504)
@@ -0,0 +1,99 @@
+/******************************************************************************
+ * 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;
+
+import org.jboss.unit.api.pojo.TestHandler;
+import org.jboss.unit.api.pojo.TestCaseLifeCycleException;
+import org.jboss.unit.api.pojo.TestCaseDescriptor;
+
+import static org.jboss.unit.api.Assert.*;
+
+import java.util.Set;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class TestHandlerSupportPOJOTest extends AbstractPOJOTest
+{
+
+ /** . */
+ private TestHandler handler;
+
+ public TestHandlerSupportPOJOTest(TestHandler handler)
+ {
+ this.handler = handler;
+ }
+
+ public Set<String> getParameterNames()
+ {
+ return handler.getParameters().keySet();
+ }
+
+ public Set<String> getTestCaseNames()
+ {
+ return handler.getTestCases().keySet();
+ }
+
+ public Set<String> getTestCaseParameterNames(String testCaseName)
+ {
+ TestCaseDescriptor descriptor = handler.getTestCases().get(testCaseName);
+ assertNotNull(descriptor);
+ return descriptor.getParameters().keySet();
+ }
+
+ public InvokeResult invoke(String testName, Map<String, String>
parametrization)
+ {
+ Object testCase = null;
+ boolean invokeDestroy = false;
+ try
+ {
+ testCase = handler.newTestCase(testName);
+ handler.testCaseParametrize(testCase, parametrization);
+ invokeDestroy = true;
+ handler.testCaseCreate(testCase);
+ handler.testCaseInvoke(testCase);
+ return InvokeResult.PASS;
+ }
+ catch (TestCaseLifeCycleException e)
+ {
+ Throwable cause = e.getCause();
+ if (cause instanceof AssertionError)
+ {
+ return InvokeResult.FAILURE;
+ }
+ else
+ {
+ return InvokeResult.ERROR;
+ }
+ }
+ finally
+ {
+ if (invokeDestroy)
+ {
+ handler.testCaseDestroy(testCase);
+ }
+ }
+ }
+}
Added:
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/TestHandlerSupportPOJOTests.java
===================================================================
---
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/TestHandlerSupportPOJOTests.java
(rev 0)
+++
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/TestHandlerSupportPOJOTests.java 2007-10-01
16:34:06 UTC (rev 8504)
@@ -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.test.unit.pojo;
+
+import org.jboss.unit.api.pojo.TestHandlerSupport;
+import org.jboss.unit.api.Assert;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class TestHandlerSupportPOJOTests extends AbstractPOJOTests
+{
+
+
+ protected void assertCannotBuildSuite(Class clazz)
+ {
+ try
+ {
+ new TestHandlerSupport(clazz);
+ Assert.fail();
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ }
+
+ protected AbstractPOJOTest assertCanBuildSuite(Class clazz)
+ {
+ return new TestHandlerSupportPOJOTest(new TestHandlerSupport(clazz));
+ }
+}
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-01 10:08:06
UTC (rev 8503)
+++ modules/test/trunk/unit/src/main/org/jboss/unit/api/Assert.java 2007-10-01 16:34:06
UTC (rev 8504)
@@ -251,6 +251,16 @@
throw createAssertionError(cause, msg);
}
+ public static Error createFailure()
+ {
+ return createFailure(null);
+ }
+
+ public static Error createFailure(String msg)
+ {
+ return createAssertionError(null, msg);
+ }
+
public static Error createAssertionError(Throwable cause, String msg)
{
if (msg == null)
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-01
10:08:06 UTC (rev 8503)
+++
modules/test/trunk/unit/src/main/org/jboss/unit/api/pojo/TestHandlerSupport.java 2007-10-01
16:34:06 UTC (rev 8504)
@@ -443,7 +443,7 @@
//
if (testCaseDef == null)
{
- throw new TestCaseLifeCycleException();
+ throw new TestCaseLifeCycleException("No such test case <" + name +
">");
}
//