Author: julien(a)jboss.com
Date: 2007-08-16 08:04:20 -0400 (Thu, 16 Aug 2007)
New Revision: 7949
Added:
modules/common/trunk/common/src/main/org/jboss/portal/common/junit/ant/ConfigurableXMLJUnitResultFormatter.java
Modified:
modules/common/trunk/build/build-thirdparty.xml
modules/common/trunk/common/src/main/org/jboss/portal/common/junit/ant/ConfigurableJUnitTask.java
modules/common/trunk/common/src/main/org/jboss/portal/common/junit/ant/ConfigurableJUnitTest.java
modules/common/trunk/common/src/main/org/jboss/portal/common/junit/ant/TestParameter.java
Log:
Improve integration of test parametrization and add the possibility to specify the test id
in the zest ant task
Modified: modules/common/trunk/build/build-thirdparty.xml
===================================================================
--- modules/common/trunk/build/build-thirdparty.xml 2007-08-16 11:53:30 UTC (rev 7948)
+++ modules/common/trunk/build/build-thirdparty.xml 2007-08-16 12:04:20 UTC (rev 7949)
@@ -50,7 +50,7 @@
<componentref name="apache-ant" version="1.6.5"/>
<componentref name="apache-httpclient" version="3.0.1"/>
<componentref name="apache-log4j" version="1.2.8"/>
- <componentref name="jbossas/core-libs"
version="4.2.0.GA"/>
+ <componentref name="jbossas/core-libs"
version="4.0.4.GA"/>
<componentref name="jboss/backport-concurrent"
version="2.1.0.GA"/>
<componentref name="jboss/jbossretro-rt"
version="1.0.3.GA"/>
<componentref name="jboss/test" version="1.0.0.CR1"/>
Modified:
modules/common/trunk/common/src/main/org/jboss/portal/common/junit/ant/ConfigurableJUnitTask.java
===================================================================
---
modules/common/trunk/common/src/main/org/jboss/portal/common/junit/ant/ConfigurableJUnitTask.java 2007-08-16
11:53:30 UTC (rev 7948)
+++
modules/common/trunk/common/src/main/org/jboss/portal/common/junit/ant/ConfigurableJUnitTask.java 2007-08-16
12:04:20 UTC (rev 7949)
@@ -23,7 +23,11 @@
package org.jboss.portal.common.junit.ant;
import org.apache.tools.ant.taskdefs.optional.junit.JUnitTask;
+import org.apache.tools.ant.taskdefs.optional.junit.JUnitTest;
+import org.apache.tools.ant.BuildException;
+import java.io.File;
+
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 7228 $
@@ -40,4 +44,41 @@
test.setTask(this);
addTest(test);
}
+
+ protected void execute(JUnitTest test) throws BuildException
+ {
+ // Delete any existing file
+ File tmp = new File(System.getProperty("java.io.tmpdir"),
TestParameter.PARAMETRIZATION_FILE_NAME);
+ if (tmp.exists() && tmp.isFile())
+ {
+ if (!tmp.delete())
+ {
+ throw new Error("Cannot delete previous saved parametrization");
+ }
+ }
+
+ //
+ try
+ {
+ // Basically we are only sure at this time of the execution that the nested
parameter map is fully initialized
+ if (test instanceof ConfigurableJUnitTest)
+ {
+ ((ConfigurableJUnitTest)test).saveState();
+ }
+
+ // Let the parent class execute the super class
+ super.execute(test);
+ }
+ finally
+ {
+ // Cleanup any save state
+ if (tmp.exists() && tmp.isFile())
+ {
+ if (!tmp.delete())
+ {
+ tmp.deleteOnExit();
+ }
+ }
+ }
+ }
}
Modified:
modules/common/trunk/common/src/main/org/jboss/portal/common/junit/ant/ConfigurableJUnitTest.java
===================================================================
---
modules/common/trunk/common/src/main/org/jboss/portal/common/junit/ant/ConfigurableJUnitTest.java 2007-08-16
11:53:30 UTC (rev 7948)
+++
modules/common/trunk/common/src/main/org/jboss/portal/common/junit/ant/ConfigurableJUnitTest.java 2007-08-16
12:04:20 UTC (rev 7949)
@@ -33,6 +33,8 @@
import java.util.Map;
/**
+ * Used by ant to create a representation of the test to run.
+ *
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 7228 $
*/
@@ -40,13 +42,13 @@
{
/** . */
- public static final String PARAMETER_PROPERTY_NAME = "test.params";
+ private final ArrayList nestedParameters;
/** . */
- private ArrayList nestedParameters;
+ private ConfigurableJUnitTask task;
/** . */
- private ConfigurableJUnitTask task;
+ private String id;
public ConfigurableJUnitTest()
{
@@ -58,8 +60,34 @@
nestedParameters.add(parameter);
}
- public String getName()
+ public void setTask(ConfigurableJUnitTask task)
{
+ this.task = task;
+ }
+
+ public String getId()
+ {
+ return id;
+ }
+
+ public void setId(String id)
+ {
+ this.id = id;
+
+ //
+ TestParameter parameter = new TestParameter();
+ parameter.setName(TestParameter.TEST_ID_PARAM);
+ parameter.setValue(id);
+ addParameter(parameter);
+ }
+
+ /**
+ * Save the state of the junit test on the disk for reuse later in the forked virtual
machine.
+ * As there is not clear life cycle of the usage of this class, we need to save the
state initially
+ * and on every update.
+ */
+ public void saveState()
+ {
try
{
Map parameters = new HashMap();
@@ -84,22 +112,17 @@
parameters.put(parameter.name, values);
}
}
- File tmp = new File(System.getProperty("java.io.tmpdir"),
"junit.parameters");
+ File tmp = new File(System.getProperty("java.io.tmpdir"),
TestParameter.PARAMETRIZATION_FILE_NAME);
tmp.deleteOnExit();
FileOutputStream fos = new FileOutputStream(tmp);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(parameters);
oos.close();
- return super.getName();
+
}
catch (IOException e)
{
throw new Error(e);
}
}
-
- public void setTask(ConfigurableJUnitTask task)
- {
- this.task = task;
- }
}
Added:
modules/common/trunk/common/src/main/org/jboss/portal/common/junit/ant/ConfigurableXMLJUnitResultFormatter.java
===================================================================
---
modules/common/trunk/common/src/main/org/jboss/portal/common/junit/ant/ConfigurableXMLJUnitResultFormatter.java
(rev 0)
+++
modules/common/trunk/common/src/main/org/jboss/portal/common/junit/ant/ConfigurableXMLJUnitResultFormatter.java 2007-08-16
12:04:20 UTC (rev 7949)
@@ -0,0 +1,82 @@
+/******************************************************************************
+ * 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.portal.common.junit.ant;
+
+import org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter;
+import org.apache.tools.ant.taskdefs.optional.junit.JUnitTest;
+import org.w3c.dom.Element;
+
+import java.lang.reflect.Field;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class ConfigurableXMLJUnitResultFormatter extends XMLJUnitResultFormatter
+{
+
+ /** . */
+ private static final Field f;
+
+ static
+ {
+ try
+ {
+ f = XMLJUnitResultFormatter.class.getDeclaredField("rootElement");
+ if (!f.isAccessible())
+ {
+ f.setAccessible(true);
+ }
+ }
+ catch (NoSuchFieldException e)
+ {
+ throw new Error(e);
+ }
+ }
+
+ public void startTestSuite(JUnitTest suite)
+ {
+ super.startTestSuite(suite);
+
+ //
+ Map parameters = TestParameter.readExternalParameters();
+ if (parameters != null)
+ {
+ String[] values = (String[])parameters.get(TestParameter.TEST_ID_PARAM);
+ if (values != null && values.length > 0)
+ {
+ try
+ {
+ String id = values[0];
+ Element rootElement = (Element)f.get(this);
+ rootElement.setAttribute("name", id);
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new Error(e);
+ }
+ }
+ }
+ }
+}
Modified:
modules/common/trunk/common/src/main/org/jboss/portal/common/junit/ant/TestParameter.java
===================================================================
---
modules/common/trunk/common/src/main/org/jboss/portal/common/junit/ant/TestParameter.java 2007-08-16
11:53:30 UTC (rev 7948)
+++
modules/common/trunk/common/src/main/org/jboss/portal/common/junit/ant/TestParameter.java 2007-08-16
12:04:20 UTC (rev 7949)
@@ -36,6 +36,12 @@
{
/** . */
+ static final String TEST_ID_PARAM = "test.param.id";
+
+ /** . */
+ static final String PARAMETRIZATION_FILE_NAME = "junit.parameters";
+
+ /** . */
protected String name;
/** . */
@@ -63,7 +69,7 @@
{
try
{
- File tmp = new File(System.getProperty("java.io.tmpdir"),
"junit.parameters");
+ File tmp = new File(System.getProperty("java.io.tmpdir"),
PARAMETRIZATION_FILE_NAME);
if (tmp.exists() && tmp.isFile())
{
FileInputStream fis = new FileInputStream(tmp);