Author: bdaw
Date: 2007-10-21 11:33:41 -0400 (Sun, 21 Oct 2007)
New Revision: 8730
Added:
modules/test/trunk/tooling/src/main/org/jboss/test/unit/tooling/simple/
modules/test/trunk/tooling/src/main/org/jboss/test/unit/tooling/simple/SimpleTest1.java
modules/test/trunk/tooling/src/main/org/jboss/unit/tooling/ant/ParameterType.java
modules/test/trunk/tooling/src/main/org/jboss/unit/tooling/ant/ValueType.java
modules/test/trunk/tooling/src/resources/test/simple-tests.xml
Removed:
modules/test/trunk/tooling/src/main/org/jboss/test/unit/tooling/simple/BoboTest1.java
Modified:
modules/test/trunk/tooling/build.xml
modules/test/trunk/tooling/src/main/org/jboss/unit/tooling/ant/JBossUnitTask.java
modules/test/trunk/tooling/src/main/org/jboss/unit/tooling/ant/TestsType.java
modules/test/trunk/tooling/src/main/org/jboss/unit/tooling/ant/ToolingConstants.java
modules/test/trunk/unit/src/main/org/jboss/unit/tooling/Main.java
modules/test/trunk/unit/src/main/org/jboss/unit/tooling/MainBuilder.java
Log:
- enable tooling to handle parameters from system properties
Modified: modules/test/trunk/tooling/build.xml
===================================================================
--- modules/test/trunk/tooling/build.xml 2007-10-21 15:23:23 UTC (rev 8729)
+++ modules/test/trunk/tooling/build.xml 2007-10-21 15:33:41 UTC (rev 8730)
@@ -217,34 +217,47 @@
<jboss-unit>
- <tests config="./output/resources/test/bobo-tests.xml"
suiteName="one">
+ <tests config="./output/resources/test/simple-tests.xml"
suiteName="one">
<!-- no include tag means invoke all -->
<!-- but you can still exclude some tests -->
<property name="propName" value="propValue"/>
+
+ <parameter name="param1">
+ <value>one</value>
+ <value>two</value>
+ <value>three</value>
+ </parameter>
+
+ <parameter name="param2">
+ <value>2one</value>
+ <value>2two</value>
+ <value>2three</value>
+ </parameter>
+
<exclude id="otherTestTwo"/>
</tests>
<tests config="./output/resources/test/assertkeyword-unit.xml">
</tests>
- <!--<tests config="./output/resources/test/bobo-tests.xml">
+ <!--<tests
config="./output/resources/test/simple-tests.xml">
<include id="testOne"/>
<include id="otherTestOne"/>
<exclude ids="testOne,testTwo"/>
</tests>
- <tests config="output/resources/test/bobo-tests.xml"
suiteName="three">
+ <tests config="output/resources/test/simple-tests.xml"
suiteName="three">
<include id="otherTestOne"/>
<include id="testOne"/>
<include id="otherTestTwo"/>
</tests>
- <tests config="output/resources/test/bobo-tests.xml"
suiteName="four">
+ <tests config="output/resources/test/simple-tests.xml"
suiteName="four">
<include keywords="simpleTag"/>
</tests>-->
- <!--<tests
config="output/resources/test/bobo-tests.xml">-->
+ <!--<tests
config="output/resources/test/simple-tests.xml">-->
<!-- this one should fail as attribute 'id' is exclusive -->
<!--<include id="otherTestOne"
ids="testOne,testTwo" keywords="lola,lolo,loli"/>-->
<!--</tests>-->
Copied: modules/test/trunk/tooling/src/main/org/jboss/test/unit/tooling/simple (from rev
8674, modules/test/trunk/tooling/src/main/org/jboss/test/unit/tooling/bobo)
Deleted:
modules/test/trunk/tooling/src/main/org/jboss/test/unit/tooling/simple/BoboTest1.java
===================================================================
---
modules/test/trunk/tooling/src/main/org/jboss/test/unit/tooling/bobo/BoboTest1.java 2007-10-17
11:11:09 UTC (rev 8674)
+++
modules/test/trunk/tooling/src/main/org/jboss/test/unit/tooling/simple/BoboTest1.java 2007-10-21
15:33:41 UTC (rev 8730)
@@ -1,62 +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.tooling.bobo;
-
-import org.jboss.unit.api.pojo.annotations.Test;
-import org.jboss.unit.api.pojo.annotations.Tag;
-
-/**
- * @author <a href="mailto:boleslaw dot dawidowicz at redhat anotherdot
com">Boleslaw Dawidowicz</a>
- * @version $Revision: 0.1 $
- */
-public class BoboTest1
-{
- @Test(name = "testOne")
- @Tag("simpleTag")
- public void test1()
- {
- System.out.println("Executed testOne");
- }
-
- @Test(name = "testTwo")
- @Tag("simpleTag")
- public void test2()
- {
- System.out.println("Executed testTwo");
-
- }
-
- @Test(name = "otherTestOne")
- @Tag({"simpleTag", "anotherTag"})
- public void test3()
- {
- System.out.println("Executed otherTestOne");
- }
-
- @Test(name = "otherTestTwo")
- @Tag("simpleTag")
- public void test4()
- {
- System.out.println("Executed otherTestTwo");
- }
-}
Added:
modules/test/trunk/tooling/src/main/org/jboss/test/unit/tooling/simple/SimpleTest1.java
===================================================================
---
modules/test/trunk/tooling/src/main/org/jboss/test/unit/tooling/simple/SimpleTest1.java
(rev 0)
+++
modules/test/trunk/tooling/src/main/org/jboss/test/unit/tooling/simple/SimpleTest1.java 2007-10-21
15:33:41 UTC (rev 8730)
@@ -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.test.unit.tooling.simple;
+
+import org.jboss.unit.api.pojo.annotations.Test;
+import org.jboss.unit.api.pojo.annotations.Tag;
+
+/**
+ * @author <a href="mailto:boleslaw dot dawidowicz at redhat anotherdot
com">Boleslaw Dawidowicz</a>
+ * @version $Revision: 0.1 $
+ */
+public class SimpleTest1
+{
+ @Test(name = "testOne")
+ @Tag("simpleTag")
+ public void test1()
+ {
+ System.out.println("Executed testOne");
+ }
+
+ @Test(name = "testTwo")
+ @Tag("simpleTag")
+ public void test2()
+ {
+ System.out.println("Executed testTwo");
+
+ }
+
+ @Test(name = "otherTestOne")
+ @Tag({"simpleTag", "anotherTag"})
+ public void test3()
+ {
+ System.out.println("Executed otherTestOne");
+ }
+
+ @Test(name = "otherTestTwo")
+ @Tag("simpleTag")
+ public void test4()
+ {
+ System.out.println("Executed otherTestTwo");
+ }
+}
Modified:
modules/test/trunk/tooling/src/main/org/jboss/unit/tooling/ant/JBossUnitTask.java
===================================================================
---
modules/test/trunk/tooling/src/main/org/jboss/unit/tooling/ant/JBossUnitTask.java 2007-10-21
15:23:23 UTC (rev 8729)
+++
modules/test/trunk/tooling/src/main/org/jboss/unit/tooling/ant/JBossUnitTask.java 2007-10-21
15:33:41 UTC (rev 8730)
@@ -51,6 +51,8 @@
private Set<Environment.Variable> sysproperties = new
HashSet<Environment.Variable>();
+ private Set<ParameterType> parameters = new HashSet<ParameterType>();
+
public JBossUnitTask()
{
}
@@ -72,10 +74,14 @@
this.reports = reports;
}
+ public void addConfiguredParameter(ParameterType param)
+ {
+ this.parameters.add(param);
+ }
+
public void execute() throws BuildException
{
- //System.out.println("Executing JBossUnit. tests: " +
testsTypes.size());
for (TestsType testsType : testsTypes)
{
@@ -92,12 +98,21 @@
}
+ // Merge system properties
Set<Environment.Variable> propCopy = new
HashSet<Environment.Variable>();
propCopy.addAll(sysproperties);
-
propCopy.addAll(testsType.getSysproperties());
testsType.setSysproperties(propCopy);
+
+ // Merge runtime parameters
+ Set<ParameterType> paramCopy = new HashSet<ParameterType>();
+ paramCopy.addAll(parameters);
+ paramCopy.addAll(testsType.getParameters());
+ testsType.setParameters(paramCopy);
+
testsType.execute();
+
+
}
Added: modules/test/trunk/tooling/src/main/org/jboss/unit/tooling/ant/ParameterType.java
===================================================================
--- modules/test/trunk/tooling/src/main/org/jboss/unit/tooling/ant/ParameterType.java
(rev 0)
+++
modules/test/trunk/tooling/src/main/org/jboss/unit/tooling/ant/ParameterType.java 2007-10-21
15:33:41 UTC (rev 8730)
@@ -0,0 +1,89 @@
+/*
+* 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.tooling.ant;
+
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:boleslaw dot dawidowicz at redhat anotherdot
com">Boleslaw Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class ParameterType
+{
+
+ private String name;
+
+ private List<String> values = new LinkedList<String>();
+
+ public boolean equals(Object o)
+ {
+ if (this == o)
+ {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass())
+ {
+ return false;
+ }
+
+ ParameterType that = (ParameterType)o;
+
+ if (!name.equals(that.name))
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ public int hashCode()
+ {
+ int result;
+ result = name.hashCode();
+ result = 31 * result + (values != null ? values.hashCode() : 0);
+ return result;
+ }
+
+ public void addConfiguredValue(ValueType value)
+ {
+ values.add(value.toString());
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+ public List<String> getValues()
+ {
+ return values;
+ }
+
+
+}
Modified: modules/test/trunk/tooling/src/main/org/jboss/unit/tooling/ant/TestsType.java
===================================================================
---
modules/test/trunk/tooling/src/main/org/jboss/unit/tooling/ant/TestsType.java 2007-10-21
15:23:23 UTC (rev 8729)
+++
modules/test/trunk/tooling/src/main/org/jboss/unit/tooling/ant/TestsType.java 2007-10-21
15:33:41 UTC (rev 8730)
@@ -69,6 +69,10 @@
private Set<Environment.Variable> sysproperties = new
HashSet<Environment.Variable>();
+ private Set<ParameterType> parameters = new HashSet<ParameterType>();
+
+
+
public TestsType()
{
}
@@ -308,8 +312,198 @@
javaTask.createArg().setValue(OPT_PROPERTIES + "=" + props);
}
+
+ Map<String,List<String>> sysParameters = new HashMap<String,
List<String>>();
+
+ Map<String,List<String>> mergedParameters = new HashMap<String,
List<String>>();
+
+ for (ParameterType parameter : parameters)
+ {
+ List<String> values;
+
+ if (mergedParameters.containsKey(parameter.getName()))
+ {
+ values = mergedParameters.get(parameter.getName());
+ }
+ else
+ {
+ values = new LinkedList<String>();
+ }
+
+ values.addAll(parameter.getValues());
+
+ mergedParameters.put(parameter.getName(), values);
+ }
+
+ updateParameters(sysParameters);
+
+ mergedParameters.putAll(sysParameters);
+
+
+ if (!mergedParameters.isEmpty())
+ {
+ StringBuilder params = new StringBuilder("[");
+
+ Set<String> paramNames = mergedParameters.keySet();
+
+ for (Iterator<String> stringIterator = paramNames.iterator();
stringIterator.hasNext();)
+ {
+ String name = stringIterator.next();
+
+
+ List<String> paramValues = mergedParameters.get(name);
+
+ for (Iterator<String> iterator = paramValues.iterator();
iterator.hasNext();)
+ {
+ String value = iterator.next();
+
+
+ params.append(name)
+ .append("=")
+ .append(value);
+
+ if (iterator.hasNext())
+ {
+ params.append(",");
+ }
+ }
+
+ if (stringIterator.hasNext())
+ {
+ params.append(",");
+ }
+ else
+ {
+ params.append("]");
+ }
+
+ }
+
+ javaTask.createArg().setValue(OPT_PARAMETERS + "=" + params);
+
+ }
+
+
+
+
}
+ private void updateParameters(Map<String, List<String>> taskParameters)
+ {
+ Hashtable<String, String> sysProps =
(Hashtable<String,String>)getProject().getProperties();
+
+ String sysParameters = sysProps.get(JBOSS_UNIT_PARAMETERS);
+
+ if (sysParameters != null && sysParameters.length() > 0)
+ {
+
+ Map<String,List<String>> parsedParams =
parseParameters(sysParameters);
+
+ taskParameters.putAll(parsedParams);
+ }
+
+ for (String sysPropKey : sysProps.keySet())
+ {
+ if (sysPropKey.startsWith(JBOSS_UNIT_PARAMETER + "."))
+ {
+ String propertyString = sysPropKey + "=" +
sysProps.get(sysPropKey);
+
+ propertyString = propertyString.replaceFirst(JBOSS_UNIT_PARAMETER +
"\\.", "");
+
+
+ //
+ String[] parameter = propertyString.split("=",2);
+
+ //
+ if (parameter.length != 2)
+ {
+ throw new IllegalArgumentException("Property not accepted, it should
match a=b and it is " + propertyString);
+ }
+
+
+ List parameterValues = new LinkedList<String>();
+
+ if (parameter[1].matches("\\[.+(,.+)*\\]"))
+ {
+
+
+
+ String valuesString = parameter[1];
+
+ valuesString =
valuesString.replaceAll("\\[","").replaceAll("\\]","");
+
+ String[] values = valuesString.split(",");
+
+ for (String value : values)
+ {
+ parameterValues.add(value);
+ }
+
+ }
+ else
+ {
+ parameterValues.add(parameter[1]);
+ }
+
+ if (taskParameters.containsKey(parameter[0]))
+ {
+ taskParameters.get(parameter[0]).addAll(parameterValues);
+ }
+ else
+ {
+ taskParameters.put(parameter[0], parameterValues);
+ }
+ }
+ }
+ }
+
+ private Map<String, List<String>> parseParameters(String
parametersString)
+ {
+
+ if (!parametersString.matches("\\[.+=.+(,.+=.+)*\\]"))
+ {
+ throw new IllegalArgumentException("Parameters don't follow proper
format: [a=b,c=d,e=f]");
+ }
+
+ Map<String,List<String>> parsedParams = new
HashMap<String,List<String>>();
+
+ parametersString =
parametersString.replaceAll("\\[","").replaceAll("\\]","");
+
+ String parameterGroups[] = parametersString.split(",");
+
+ for (String parameterGroup : parameterGroups)
+ {
+
+ String parameter[] = parameterGroup.split("=");
+
+ //
+ if (parameter.length != 2)
+ {
+ throw new IllegalArgumentException("Parameter not accepted, it should
match a=b and it is " + parameter);
+ }
+
+ List<String> values;
+
+ if (parsedParams.containsKey(parameter[0]))
+ {
+ values = parsedParams.get(parameter[0]);
+ }
+ else
+ {
+ values = new LinkedList<String>();
+ }
+
+ values.add(parameter[1]);
+
+ parsedParams.put(parameter[0], values);
+ }
+
+ return parsedParams;
+
+
+ }
+
+
private void addUnparsedString(Set<String> set, String valueString)
{
if (valueString == null)
@@ -384,7 +578,7 @@
{
if (!propertiesString.matches("\\[.+=.+(,.+=.+)*\\]"))
{
- throw new IllegalArgumentException("Parameters don't follow proper
format: [a=b,c=d,e=f]");
+ throw new IllegalArgumentException("Properties don't follow proper
format: [a=b,c=d,e=f]");
}
Map<String,String> parsedProps = new HashMap<String,String>();
@@ -440,6 +634,21 @@
this.properties.add(property);
}
+ public void addConfiguredParameter(ParameterType param)
+ {
+ this.parameters.add(param);
+ }
+
+ public Set<ParameterType> getParameters()
+ {
+ return parameters;
+ }
+
+ public void setParameters(Set<ParameterType> parameters)
+ {
+ this.parameters = parameters;
+ }
+
public String getConfig()
{
return config;
Modified:
modules/test/trunk/tooling/src/main/org/jboss/unit/tooling/ant/ToolingConstants.java
===================================================================
---
modules/test/trunk/tooling/src/main/org/jboss/unit/tooling/ant/ToolingConstants.java 2007-10-21
15:23:23 UTC (rev 8729)
+++
modules/test/trunk/tooling/src/main/org/jboss/unit/tooling/ant/ToolingConstants.java 2007-10-21
15:33:41 UTC (rev 8730)
@@ -63,5 +63,9 @@
public static final String OPT_PROPERTIES = "--properties";
+ public static final String OPT_PARAMETER = "--parameter";
+ public static final String OPT_PARAMETERS = "--parameters";
+
+
}
Added: modules/test/trunk/tooling/src/main/org/jboss/unit/tooling/ant/ValueType.java
===================================================================
--- modules/test/trunk/tooling/src/main/org/jboss/unit/tooling/ant/ValueType.java
(rev 0)
+++
modules/test/trunk/tooling/src/main/org/jboss/unit/tooling/ant/ValueType.java 2007-10-21
15:33:41 UTC (rev 8730)
@@ -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.unit.tooling.ant;
+
+/**
+ * @author <a href="mailto:boleslaw dot dawidowicz at redhat anotherdot
com">Boleslaw Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class ValueType
+{
+ private String value;
+
+ public void addText(String text)
+ {
+ this.value = text;
+ }
+
+ public String getValue()
+ {
+ return value;
+ }
+
+ public String toString()
+ {
+ return this.value;
+ }
+}
Copied: modules/test/trunk/tooling/src/resources/test/simple-tests.xml (from rev 8728,
modules/test/trunk/tooling/src/resources/test/bobo-tests.xml)
===================================================================
--- modules/test/trunk/tooling/src/resources/test/simple-tests.xml
(rev 0)
+++ modules/test/trunk/tooling/src/resources/test/simple-tests.xml 2007-10-21 15:33:41 UTC
(rev 8730)
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<jboss-unit
+ xmlns="urn:jboss:jboss-unit:1.0"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:jboss:jboss-unit:1.0 jboss-unit_1_0.xsd">
+ <pojo>
+ <test>
+ <class name="org.jboss.test.unit.tooling.simple.SimpleTest1"/>
+ </test>
+ </pojo>
+</jboss-unit>
\ No newline at end of file
Modified: modules/test/trunk/unit/src/main/org/jboss/unit/tooling/Main.java
===================================================================
--- modules/test/trunk/unit/src/main/org/jboss/unit/tooling/Main.java 2007-10-21 15:23:23
UTC (rev 8729)
+++ modules/test/trunk/unit/src/main/org/jboss/unit/tooling/Main.java 2007-10-21 15:33:41
UTC (rev 8730)
@@ -52,6 +52,8 @@
private final Map<String,String> properties;
+ private final Map<String, String[]> parameters;
+
private final TestRunnerEventBroadcaster broadcaster;
public static final String JBOSS_UNIT_PROPERTIES = "jboss.unit.properties";
@@ -93,6 +95,10 @@
public static final String OPT_PROPERTIES = "--properties";
+ public static final String OPT_PARAMETER = "--parameter";
+
+ public static final String OPT_PARAMETERS = "--parameters";
+
public static final Set options;
public static final Set options_no_arg;
@@ -119,7 +125,7 @@
options_no_arg = Collections.unmodifiableSet(opts);
}
- public Main(TestRunner runner, MainTestFilter mainFilter, TestRunnerEventBroadcaster
broadcaster, TestSuiteDef suiteDef, Map<String,String> properties)
+ public Main(TestRunner runner, MainTestFilter mainFilter, TestRunnerEventBroadcaster
broadcaster, TestSuiteDef suiteDef, Map<String,String> properties, Map<String,
String[]> parameters)
{
if (runner == null)
{
@@ -146,11 +152,17 @@
throw new IllegalArgumentException("properties cannot be null");
}
+ if (parameters == null)
+ {
+ throw new IllegalArgumentException("parameters cannot be null");
+ }
+
this.mainFilter = mainFilter;
this.runner = runner;
this.suiteDef = suiteDef;
this.properties = properties;
this.broadcaster = broadcaster;
+ this.parameters = parameters;
}
private SystemOutputManager systemManager;
@@ -177,7 +189,7 @@
StringWriter sw = new StringWriter();
broadcaster.addListener(new PrintListener(sw));
- TestRunnerContextSupport runnerContext = new
TestRunnerContextSupport(properties, new ParametrizationSet(), mainFilter, broadcaster);
+ TestRunnerContextSupport runnerContext = new
TestRunnerContextSupport(properties, new ParametrizationSet(parameters), mainFilter,
broadcaster);
runner.run(runnerContext);
sw.close();
@@ -274,10 +286,10 @@
builder.setHTMLReportDir(arguments.get(OPT_HTML_REPORT_DIR));
}
- if (argument.startsWith(OPT_PROPERTY))
+ if (argument.startsWith(OPT_PROPERTY) &&
!argument.equals(OPT_PROPERTIES))
{
- //pass whole --properties.name=value to be parsed
+ // Pass whole --properties.name=value to be parsed
builder.addUnparsedProperty(argument + arguments.get(OPT_PROPERTY));
}
@@ -285,6 +297,18 @@
{
builder.addUnparsedProperties(arguments.get(OPT_PROPERTIES));
}
+
+ if (argument.startsWith(OPT_PARAMETER) &&
!argument.equals(OPT_PARAMETERS))
+ {
+
+ // Pass whole --parameter.name=value/values to be parsed
+ builder.addUnparsedParameter(argument + arguments.get(OPT_PARAMETER));
+ }
+
+ if (argument.equals(OPT_PARAMETERS))
+ {
+ builder.addUnparsedParameters(arguments.get(OPT_PARAMETERS));
+ }
}
Modified: modules/test/trunk/unit/src/main/org/jboss/unit/tooling/MainBuilder.java
===================================================================
--- modules/test/trunk/unit/src/main/org/jboss/unit/tooling/MainBuilder.java 2007-10-21
15:23:23 UTC (rev 8729)
+++ modules/test/trunk/unit/src/main/org/jboss/unit/tooling/MainBuilder.java 2007-10-21
15:33:41 UTC (rev 8730)
@@ -22,26 +22,28 @@
package org.jboss.unit.tooling;
+import org.jboss.unit.report.impl.junit.JUnitReporter;
+import org.jboss.unit.runner.TestRunner;
import org.jboss.unit.runner.TestRunnerEventListener;
-import org.jboss.unit.runner.TestRunner;
+import org.jboss.unit.runner.impl.NullFilter;
import org.jboss.unit.runner.impl.TestRunnerEventBroadcaster;
-import org.jboss.unit.runner.impl.NullFilter;
import org.jboss.unit.runner.model.ModelBuilder;
import org.jboss.unit.runner.model.TestSuiteDef;
-import org.jboss.unit.report.impl.junit.JUnitReporter;
import org.jboss.unit.tooling.filter.ExcludeTestFilter;
import org.jboss.unit.tooling.filter.IncludeTestFilter;
import org.jboss.unit.tooling.filter.MainTestFilter;
import org.jboss.unit.tooling.report.DelegatingReporter;
import org.xml.sax.InputSource;
-import java.util.Set;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.HashMap;
import java.util.HashSet;
+import java.util.List;
import java.util.Map;
-import java.util.HashMap;
-import java.io.InputStream;
-import java.io.FileInputStream;
-import java.io.File;
+import java.util.Set;
+import java.util.LinkedList;
/**
* @author <a href="mailto:boleslaw dot dawidowicz at redhat anotherdot
com">Boleslaw Dawidowicz</a>
@@ -76,7 +78,9 @@
private Map<String,String> properties = new HashMap<String, String>();
+ private Map<String, List<String>> parameters = new HashMap<String,
List<String>>();
+
private MainBuilder()
{
@@ -352,8 +356,103 @@
return parsedProps;
}
+ public void addUnparsedParameter(String paramString)
+ {
+ paramString = paramString.replaceFirst(Main.OPT_PARAMETER + "\\.",
"");
+ //
+ String[] parameter = paramString.split("=",2);
+ //
+ if (parameter.length != 2)
+ {
+ throw new IllegalArgumentException("Parameter not accepted, it should match
a=b and it is " + paramString);
+ }
+
+
+ List<String> parameterValues = new LinkedList<String>();
+
+ if (parameter[1].matches("\\[.+(,.+)*\\]"))
+ {
+
+ String valuesString = parameter[1];
+
+ valuesString =
valuesString.replaceAll("\\[","").replaceAll("\\]","");
+
+ String[] values = valuesString.split(",");
+
+ for (String value : values)
+ {
+ parameterValues.add(value);
+ }
+
+ }
+ else
+ {
+ parameterValues.add(parameter[1]);
+ }
+
+ if (parameters.containsKey(parameter[0]))
+ {
+ parameters.get(parameter[0]).addAll(parameterValues);
+ }
+ else
+ {
+ parameters.put(parameter[0], parameterValues);
+ }
+
+ }
+
+ public void addUnparsedParameters(String parametersString)
+ {
+
+ parametersString =
parametersString.replaceAll("\\[","").replaceAll("\\]","");
+
+ String parameterGroups[] = parametersString.split(",");
+
+ for (String parameterGroup : parameterGroups)
+ {
+
+ String parameter[] = parameterGroup.split("=");
+
+ //
+ if (parameter.length != 2)
+ {
+ throw new IllegalArgumentException("Parameter not accepted, it should
match a=b and it is " + parameter);
+ }
+
+ List<String> values;
+
+ if (parameters.containsKey(parameter[0]))
+ {
+ values = parameters.get(parameter[0]);
+ }
+ else
+ {
+ values = new LinkedList<String>();
+ }
+
+ values.add(parameter[1]);
+
+ parameters.put(parameter[0], values);
+ }
+ }
+
+ public Map<String, String[]> getParameters()
+ {
+ Map<String, String[]> params = new HashMap<String,String[]>();
+
+ for (String paramKey : parameters.keySet())
+ {
+ List<String> values = parameters.get(paramKey);
+ params.put(paramKey, values.toArray(new String[values.size()]));
+ }
+
+ return params;
+
+ }
+
+
public String getSuiteName()
{
return suiteName;
@@ -447,7 +546,7 @@
}
- return new Main(runner, filter, broadcaster, suite, properties);
+ return new Main(runner, filter, broadcaster, suite, properties, getParameters());
}
public static void checkCreateOutputDirectory(String dir) throws Exception
@@ -481,5 +580,6 @@
}
+
}