Author: bdaw
Date: 2008-01-22 06:39:19 -0500 (Tue, 22 Jan 2008)
New Revision: 9549
Added:
modules/test/trunk/tooling/core/src/main/java/org/jboss/unit/tooling/TestFailedException.java
modules/test/trunk/unit/src/main/java/org/jboss/unit/tooling/FailureManagerListener.java
Modified:
modules/test/trunk/tooling/ant/src/main/java/org/jboss/unit/tooling/ant/JBossUnitTask.java
modules/test/trunk/tooling/ant/src/main/java/org/jboss/unit/tooling/ant/TestsType.java
modules/test/trunk/tooling/core/src/main/java/org/jboss/unit/tooling/JavaBuilder.java
modules/test/trunk/tooling/core/src/main/java/org/jboss/unit/tooling/ToolingConstants.java
modules/test/trunk/tooling/examples/maven2/pom.xml
modules/test/trunk/tooling/examples/maven2/src/test/java/org/jboss/test/unit/tooling/TestSimple.java
modules/test/trunk/tooling/maven2/pom.xml
modules/test/trunk/tooling/maven2/src/main/java/org/jboss/unit/tooling/maven2/TestSuiteExecutor.java
modules/test/trunk/tooling/maven2/src/main/java/org/jboss/unit/tooling/maven2/UnitMojo.java
modules/test/trunk/tooling/maven2/src/main/java/org/jboss/unit/tooling/maven2/configuration/Testsuite.java
modules/test/trunk/unit/src/main/java/org/jboss/unit/report/impl/writer/PrintListener.java
modules/test/trunk/unit/src/main/java/org/jboss/unit/tooling/Main.java
modules/test/trunk/unit/src/main/java/org/jboss/unit/tooling/MainBuilder.java
Log:
- extend configuration using commandline arguments
Modified:
modules/test/trunk/tooling/ant/src/main/java/org/jboss/unit/tooling/ant/JBossUnitTask.java
===================================================================
---
modules/test/trunk/tooling/ant/src/main/java/org/jboss/unit/tooling/ant/JBossUnitTask.java 2008-01-21
21:32:53 UTC (rev 9548)
+++
modules/test/trunk/tooling/ant/src/main/java/org/jboss/unit/tooling/ant/JBossUnitTask.java 2008-01-22
11:39:19 UTC (rev 9549)
@@ -41,6 +41,7 @@
*/
public class JBossUnitTask extends Task
{
+ public static final String MAVEN_SKIP_TEST = "maven.skip.test";
List<TestsType> testsTypes = new LinkedList();
@@ -48,6 +49,18 @@
private Path path;
+ private boolean jpda;
+
+ private String jpdaPort = "9000";
+
+ private boolean jpdaSuspend = true;
+
+ private boolean useJUL = true;
+
+ private boolean assertions = true;
+
+ private boolean failOnError = false;
+
private Set<Environment.Variable> sysproperties = new
HashSet<Environment.Variable>();
private Set<ParameterType> parameters = new HashSet<ParameterType>();
@@ -59,6 +72,7 @@
public void addConfiguredTests(TestsType tests)
{
tests.setProject(getProject());
+ tests.setParent(this);
testsTypes.add(tests);
}
@@ -81,6 +95,19 @@
public void execute() throws BuildException
{
+
+ String testSkip = (String)getProject().getProperties().get(MAVEN_SKIP_TEST);
+
+ // Skip tests
+ if (testSkip != null && testSkip.equalsIgnoreCase("true"))
+ {
+ //TODO: make it logging
+
+ System.out.println("Skipping test execution: " + MAVEN_SKIP_TEST +
" set to true");
+
+ return;
+ }
+
for (TestsType testsType : testsTypes)
{
@@ -132,5 +159,63 @@
this.reports = reports;
}
-
+ public boolean isJpda()
+ {
+ return jpda;
+ }
+
+ public void setJpda(boolean jpda)
+ {
+ this.jpda = jpda;
+ }
+
+ public String getJpdaPort()
+ {
+ return jpdaPort;
+ }
+
+ public void setJpdaPort(String jpdaPort)
+ {
+ this.jpdaPort = jpdaPort;
+ }
+
+ public boolean isJpdaSuspend()
+ {
+ return jpdaSuspend;
+ }
+
+ public void setJpdaSuspend(boolean jpdaSuspend)
+ {
+ this.jpdaSuspend = jpdaSuspend;
+ }
+
+ public boolean isUseJUL()
+ {
+ return useJUL;
+ }
+
+ public void setUseJUL(boolean useJUL)
+ {
+ this.useJUL = useJUL;
+ }
+
+ public boolean isAssertions()
+ {
+ return assertions;
+ }
+
+ public void setAssertions(boolean assertions)
+ {
+ this.assertions = assertions;
+ }
+
+ public boolean isFailOnError()
+ {
+ return failOnError;
+ }
+
+ public void setFailOnError(boolean failOnError)
+ {
+ this.failOnError = failOnError;
+ }
}
Modified:
modules/test/trunk/tooling/ant/src/main/java/org/jboss/unit/tooling/ant/TestsType.java
===================================================================
---
modules/test/trunk/tooling/ant/src/main/java/org/jboss/unit/tooling/ant/TestsType.java 2008-01-21
21:32:53 UTC (rev 9548)
+++
modules/test/trunk/tooling/ant/src/main/java/org/jboss/unit/tooling/ant/TestsType.java 2008-01-22
11:39:19 UTC (rev 9549)
@@ -29,6 +29,7 @@
import org.apache.tools.ant.types.Path;
import org.jboss.unit.tooling.JavaBuilder;
import org.jboss.unit.tooling.TaskExecutingThread;
+import org.jboss.unit.tooling.TestFailedException;
import org.jboss.unit.tooling.ant.configuration.ExcludeType;
import org.jboss.unit.tooling.ant.configuration.IncludeType;
import org.jboss.unit.tooling.ant.configuration.ParameterType;
@@ -64,16 +65,14 @@
private String suiteName;
- private boolean jpda;
-
private List<PropertyType> properties = new ArrayList<PropertyType>();
private Set<Environment.Variable> sysproperties = new
HashSet<Environment.Variable>();
private Set<ParameterType> parameters = new HashSet<ParameterType>();
+ private JBossUnitTask jbossUnitTask;
-
public TestsType()
{
}
@@ -95,7 +94,7 @@
}
catch (Exception e)
{
- e.printStackTrace();
+ throw new BuildException("Testsuite executed with test failures");
}
}
@@ -110,6 +109,9 @@
addArguments(javaBuilder);
+ // Update settings using environment variables
+ javaBuilder.applyVariables(getProject().getProperties());
+
javaTask = javaBuilder.buildJava();
// Apply task classpath
@@ -135,17 +137,33 @@
return javaTask;
}
-
+ /**
+ * Set all needed settings on JavaBuilder object based on passed configuration
+ * @param javaBuilder
+ */
private void addArguments(JavaBuilder javaBuilder)
{
javaBuilder.setConfig(config);
- if (isJpda())
- {
- javaBuilder.setJPDA(true);
- }
+ // JPDA
+ javaBuilder.setJPDA(jbossUnitTask.isJpda());
+ javaBuilder.setJPDAport(Integer.decode(jbossUnitTask.getJpdaPort()));
+ javaBuilder.setSuspend(jbossUnitTask.isJpdaSuspend());
+ // JUL
+ javaBuilder.setUseJUL(jbossUnitTask.isUseJUL());
+
+ // Assertions
+ javaBuilder.setAssertions(jbossUnitTask.isAssertions());
+
+ // Fork
+ javaBuilder.setFork(isFork());
+
+ // Fail on Error
+ javaBuilder.setFailOnError(jbossUnitTask.isFailOnError());
+
+
if (getSuiteName() != null)
{
javaBuilder.setSuiteName(getSuiteName());
@@ -309,7 +327,6 @@
this.fork = fork;
}
-
public Project getProject()
{
return project;
@@ -320,7 +337,6 @@
this.project = project;
}
-
public ReportsType getReports()
{
return reports;
@@ -341,13 +357,13 @@
this.suiteName = suiteName;
}
- public boolean isJpda()
+ public JBossUnitTask getParent()
{
- return jpda;
+ return jbossUnitTask;
}
- public void setJpda(boolean jpda)
+ public void setParent(JBossUnitTask jbossUnitTask)
{
- this.jpda = jpda;
+ this.jbossUnitTask = jbossUnitTask;
}
}
Modified:
modules/test/trunk/tooling/core/src/main/java/org/jboss/unit/tooling/JavaBuilder.java
===================================================================
---
modules/test/trunk/tooling/core/src/main/java/org/jboss/unit/tooling/JavaBuilder.java 2008-01-21
21:32:53 UTC (rev 9548)
+++
modules/test/trunk/tooling/core/src/main/java/org/jboss/unit/tooling/JavaBuilder.java 2008-01-22
11:39:19 UTC (rev 9549)
@@ -38,6 +38,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.LinkedList;
+import java.util.Arrays;
import static org.jboss.unit.tooling.ToolingConstants.*;
@@ -48,6 +49,8 @@
public class JavaBuilder
{
+ private final static String JBOSS_UNIT_CLASSNAME =
"org.jboss.unit.tooling.Main";
+
private Project antProject;
private String config;
@@ -64,8 +67,18 @@
private boolean jPDA = false;
+ private boolean suspend = true;
+
+ private int jPDAport = 9000;
+
+ private boolean useJUL = true;
+
private boolean fork = true;
+ private boolean assertions = true;
+
+ private boolean failOnError = false;
+
private String xmlReportDir;
private String htmlReportDir;
@@ -94,38 +107,54 @@
}
}
+
+
public Java buildJava()
{
Java java = (Java)antProject.createTask("java");
- java.setClassname("org.jboss.unit.tooling.Main");
+ java.setClassname(JBOSS_UNIT_CLASSNAME);
- // Set jboss logging to use JUL
- Environment.Variable pluginProperty = new Environment.Variable();
- pluginProperty.setKey("org.jboss.logging.Logger.pluginClass");
- pluginProperty.setValue("org.jboss.logging.jdk.JDK14LoggerPlugin");
- java.addSysproperty(pluginProperty);
+ if (isUseJUL())
+ {
+ // Set jboss logging to use JUL
+ Environment.Variable pluginProperty = new Environment.Variable();
+ pluginProperty.setKey("org.jboss.logging.Logger.pluginClass");
+ pluginProperty.setValue("org.jboss.logging.jdk.JDK14LoggerPlugin");
+ java.addSysproperty(pluginProperty);
- // Set JUL to configure using the logging.properties file found in the current dir
- Environment.Variable julProperty = new Environment.Variable();
- julProperty.setKey("java.util.logging.config.file");
- julProperty.setValue("logging.properties");
- java.addSysproperty(julProperty);
+ // Set JUL to configure using the logging.properties file found in the current
dir
+ Environment.Variable julProperty = new Environment.Variable();
+ julProperty.setKey("java.util.logging.config.file");
+ julProperty.setValue("logging.properties");
+ java.addSysproperty(julProperty);
+ }
- // We enable by default all assertions : todo make it configurable perhaps (see JDK
doc about assertions)
- Assertions assertions = new Assertions();
- assertions.setProject(antProject);
- assertions.addEnable(new Assertions.EnabledAssertion());
- java.addAssertions(assertions);
+ if (isAssertions())
+ {
+ // We enable by default all assertions : todo make it configurable perhaps (see
JDK doc about assertions)
+ Assertions assertions = new Assertions();
+ assertions.setProject(antProject);
+ assertions.addEnable(new Assertions.EnabledAssertion());
+ java.addAssertions(assertions);
+ }
+
// Beginning of jpda option implementation, need to improve it
- if (jPDA)
+ // Now the only configurable is port and suspend mode
+ if (isJPDA())
{
Environment.Variable javaDotCompilerProperty = new Environment.Variable();
javaDotCompilerProperty.setKey("java.compiler");
javaDotCompilerProperty.setValue("NONE");
java.addSysproperty(javaDotCompilerProperty);
- java.setJvmargs("-Xdebug -Xnoagent
-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=9000");
+ StringBuilder jvmArgs = new StringBuilder();
+
+ jvmArgs.append("-Xdebug -Xnoagent
-Xrunjdwp:transport=dt_socket,server=y")
+ .append(",address=").append(jPDAport)
+ .append(",suspend=").append(suspend ? "y" :
"n");
+
+ java.setJvmargs(jvmArgs.toString());
}
// Set fork
@@ -134,7 +163,16 @@
java.setFork(true);
}
+ // If the build should fail on error
+ if (isFailOnError()){
+ java.setFailonerror(isFailOnError());
+ java.createArg().setValue(OPT_FAIL_ON_ERROR);
+
+ }
+
+
+
java.createArg().setValue(OPT_CONFIG + "=" + config);
if (getSuiteName() != null)
@@ -249,8 +287,66 @@
return java;
}
+ /**
+ * Uodate options using variables stored in Map
+ * @param variables
+ */
+ public void applyVariables(Map variables)
+ {
+ String jpda = (String)variables.get(JBOSS_UNIT_JPDA);
+ String jpdaport = (String)variables.get(JBOSS_UNIT_JPDA_PORT);
+ String jpdasuspend = (String)variables.get(JBOSS_UNIT_JPDA_SUSPEND);
+ String jul = (String)System.getProperties().get(JBOSS_UNIT_LOGGING);
+ String assertions = (String)System.getProperties().get(JBOSS_UNIT_ASSERTIONS);
+ String failonerror = (String)System.getProperties().get(JBOSS_UNIT_FAIL_ON_ERROR);
+ String forcedIncludes = (String)System.getProperties().get(JBOSS_UNIT_TESTS);
+ // JPDA
+ if (jpda != null && jpda.length() != 0)
+ {
+ setJPDA(jpda.equalsIgnoreCase("true"));
+ }
+ if (jpdaport != null && jpdaport.length() != 0)
+ {
+ setJPDAport(Integer.decode(jpdaport));
+ }
+ if (jpdasuspend != null && jpdasuspend.length() != 0)
+ {
+ setSuspend(jpdasuspend.equalsIgnoreCase("true"));
+ }
+
+ // JUL
+ if (jul != null && jul.length() != 0)
+ {
+ if (jul.equalsIgnoreCase("JUL"))
+ {
+ setUseJUL(true);
+ }
+ }
+
+ // Assertions
+ if (assertions != null && assertions.length() != 0)
+ {
+ setAssertions(assertions.equalsIgnoreCase("true"));
+ }
+
+ // Fail on error
+ if (failonerror != null && failonerror.length() != 0)
+ {
+ setFailOnError(failonerror.equalsIgnoreCase("true"));
+ }
+
+ if (forcedIncludes != null && forcedIncludes.length() != 0)
+ {
+ Set<String> includes = new HashSet<String>();
+ String[] ids = forcedIncludes.split(",");
+ includes.addAll(Arrays.asList(ids));
+ setIncludeIDs(includes);
+ }
+ }
+
+
public String getConfig()
{
return config;
@@ -420,11 +516,61 @@
this.excludeKeywords = excludeKeywords;
}
+ public boolean isUseJUL()
+ {
+ return useJUL;
+ }
+
+ public void setUseJUL(boolean useJUL)
+ {
+ this.useJUL = useJUL;
+ }
+
public boolean isJPDA()
{
return jPDA;
}
+ public boolean isFailOnError()
+ {
+ return failOnError;
+ }
+
+ public void setFailOnError(boolean failOnError)
+ {
+ this.failOnError = failOnError;
+ }
+
+ public boolean isSuspend()
+ {
+ return suspend;
+ }
+
+ public void setSuspend(boolean suspend)
+ {
+ this.suspend = suspend;
+ }
+
+ public int getJPDAport()
+ {
+ return jPDAport;
+ }
+
+ public void setJPDAport(int jPDAport)
+ {
+ this.jPDAport = jPDAport;
+ }
+
+ public boolean isAssertions()
+ {
+ return assertions;
+ }
+
+ public void setAssertions(boolean assertions)
+ {
+ this.assertions = assertions;
+ }
+
public void setJPDA(boolean jPDA)
{
this.jPDA = jPDA;
@@ -454,6 +600,7 @@
}
+
public String getXmlReportDir()
{
return xmlReportDir;
@@ -701,6 +848,8 @@
}
}
+
+
private Map<String, List<String>> parseParameters(String
parametersString)
{
@@ -744,7 +893,6 @@
return parsedParams;
-
}
private String generateArgument(Set<String> values, String argumentName)
Added:
modules/test/trunk/tooling/core/src/main/java/org/jboss/unit/tooling/TestFailedException.java
===================================================================
---
modules/test/trunk/tooling/core/src/main/java/org/jboss/unit/tooling/TestFailedException.java
(rev 0)
+++
modules/test/trunk/tooling/core/src/main/java/org/jboss/unit/tooling/TestFailedException.java 2008-01-22
11:39:19 UTC (rev 9549)
@@ -0,0 +1,36 @@
+/*
+* 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;
+
+/**
+ * @author <a href="mailto:boleslaw dot dawidowicz at redhat anotherdot
com">Boleslaw Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class TestFailedException extends Exception
+{
+ public TestFailedException(String message)
+ {
+ super(message);
+ }
+
+}
Modified:
modules/test/trunk/tooling/core/src/main/java/org/jboss/unit/tooling/ToolingConstants.java
===================================================================
---
modules/test/trunk/tooling/core/src/main/java/org/jboss/unit/tooling/ToolingConstants.java 2008-01-21
21:32:53 UTC (rev 9548)
+++
modules/test/trunk/tooling/core/src/main/java/org/jboss/unit/tooling/ToolingConstants.java 2008-01-22
11:39:19 UTC (rev 9549)
@@ -35,8 +35,24 @@
public static final String JBOSS_UNIT_PARAMETER = "jboss.unit.parameter";
- public static final String JBOSS_UNIT_PARAMETERS = "jboss.unit.parameters";
+ public static final String JBOSS_UNIT_PARAMETERS = "jboss.unit.parameters";
+ public static final String JBOSS_UNIT_TESTS = "jboss.unit.tests";
+
+ public static final String JBOSS_UNIT_LOGGING = "jboss.unit.logging";
+
+ public static final String JBOSS_UNIT_JPDA = "jboss.unit.jpda";
+
+ public static final String JBOSS_UNIT_JPDA_PORT = "jboss.unit.jpda.port";
+
+ public static final String JBOSS_UNIT_JPDA_SUSPEND =
"jboss.unit.jpda.suspend";
+
+ public static final String JBOSS_UNIT_ASSERTIONS = "jboss.unit.assertions";
+
+ public static final String JBOSS_UNIT_FAIL_ON_ERROR =
"jboss.unit.failonerror";
+
+ public static final String OPT_FAIL_ON_ERROR = "--failonerror";
+
public static final String OPT_ID = "--id";
public static final String OPT_IDS = "--ids";
Modified: modules/test/trunk/tooling/examples/maven2/pom.xml
===================================================================
--- modules/test/trunk/tooling/examples/maven2/pom.xml 2008-01-21 21:32:53 UTC (rev 9548)
+++ modules/test/trunk/tooling/examples/maven2/pom.xml 2008-01-22 11:39:19 UTC (rev 9549)
@@ -11,6 +11,7 @@
<dependency>
<groupId>org.jboss.unit</groupId>
<artifactId>jboss-unit</artifactId>
+ <version>1.2.0-SNAPSHOT</version>
</dependency>
</dependencies>
@@ -38,6 +39,7 @@
<plugin>
<groupId>org.jboss.unit</groupId>
<artifactId>jboss-unit-tooling-maven2</artifactId>
+ <version>1.2.0-SNAPSHOT</version>
<executions>
<execution>
<phase>test</phase>
@@ -47,6 +49,11 @@
</execution>
</executions>
<configuration>
+
+ <jpda>true</jpda>
+ <!--<jpdaPort>9000</jpdaPort>
+ <jpdaSuspend>true</jpdaSuspend>-->
+
<testsuites>
<testsuite>
<config>jboss-unit.xml</config>
@@ -107,4 +114,4 @@
<properties>
</properties>
-</project>
\ No newline at end of file
+</project>
Modified:
modules/test/trunk/tooling/examples/maven2/src/test/java/org/jboss/test/unit/tooling/TestSimple.java
===================================================================
---
modules/test/trunk/tooling/examples/maven2/src/test/java/org/jboss/test/unit/tooling/TestSimple.java 2008-01-21
21:32:53 UTC (rev 9548)
+++
modules/test/trunk/tooling/examples/maven2/src/test/java/org/jboss/test/unit/tooling/TestSimple.java 2008-01-22
11:39:19 UTC (rev 9549)
@@ -41,6 +41,12 @@
@Test
public void testTwo()
{
+ Assert.assertFalse(true);
+ }
+
+ @Test
+ public void testThree()
+ {
Assert.assertFalse(false);
}
Modified: modules/test/trunk/tooling/maven2/pom.xml
===================================================================
--- modules/test/trunk/tooling/maven2/pom.xml 2008-01-21 21:32:53 UTC (rev 9548)
+++ modules/test/trunk/tooling/maven2/pom.xml 2008-01-22 11:39:19 UTC (rev 9549)
@@ -41,8 +41,8 @@
<artifactId>jboss-unit</artifactId>
</dependency>
<dependency>
- <groupId>org.jboss.unit</groupId>
- <artifactId>jboss-unit-tooling-core</artifactId>
+ <groupId>org.jboss.unit</groupId>
+ <artifactId>jboss-unit-tooling-core</artifactId>
</dependency>
</dependencies>
Modified:
modules/test/trunk/tooling/maven2/src/main/java/org/jboss/unit/tooling/maven2/TestSuiteExecutor.java
===================================================================
---
modules/test/trunk/tooling/maven2/src/main/java/org/jboss/unit/tooling/maven2/TestSuiteExecutor.java 2008-01-21
21:32:53 UTC (rev 9548)
+++
modules/test/trunk/tooling/maven2/src/main/java/org/jboss/unit/tooling/maven2/TestSuiteExecutor.java 2008-01-22
11:39:19 UTC (rev 9549)
@@ -22,15 +22,14 @@
package org.jboss.unit.tooling.maven2;
-import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DependencyResolutionRequiredException;
-import org.apache.maven.model.Resource;
import org.apache.maven.project.MavenProject;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.taskdefs.Java;
import org.apache.tools.ant.types.Path;
import org.jboss.unit.tooling.JavaBuilder;
import org.jboss.unit.tooling.TaskExecutingThread;
+import org.jboss.unit.tooling.TestFailedException;
import org.jboss.unit.tooling.maven2.configuration.CasesDescription;
import org.jboss.unit.tooling.maven2.configuration.Parameter;
import org.jboss.unit.tooling.maven2.configuration.Reports;
@@ -41,8 +40,6 @@
import java.io.FileReader;
import java.util.Arrays;
import java.util.Collection;
-import java.util.List;
-import java.util.Set;
/**
* @author <a href="mailto:boleslaw dot dawidowicz at redhat anotherdot
com">Boleslaw Dawidowicz</a>
@@ -52,55 +49,71 @@
{
private final MavenProject project;
- private final Reports reports;
-
private final Testsuite testsuite;
+ private final UnitMojo unitMojo;
+
private TestSuiteExecutor()
{
project = null;
- reports = null;
testsuite = null;
+ unitMojo = null;
}
- public TestSuiteExecutor(MavenProject project, Reports reports, Testsuite testsuite)
+ public TestSuiteExecutor(MavenProject project, Testsuite testsuite, UnitMojo
unitMojo)
{
this.project = project;
- this.reports = reports;
this.testsuite = testsuite;
+ this.unitMojo = unitMojo;
}
- public void execute()
+ public void execute() throws Exception
{
+
+ // Prepare all settings for java invocation
+
Java javaTask = createJavaTask();
- System.out.println("Executing very first....");
+ System.out.println("Invoking java: " +
javaTask.getCommandLine().toString());
- try
- {
- System.out.println("Invoking java: " +
javaTask.getCommandLine().toString());
+ // This is really stupid workaround to the fact that maven eats whole output of
invoked java task.
+ // Should be investigated and fixed in more proper way ...
- // This is really stupid workaround to the fact that maven eats whole output of
invoked java task.
- // Should be investigated and fixed in more proper way ...
+ //javaTask.setFork(true);
- javaTask.setFork(true);
+ File log = null;
- File log = File.createTempFile("jboss-unit-" +
System.currentTimeMillis(), "log");
+ javaTask.setAppend(true);
+ javaTask.setLogError(true);
+
+
+
+ try
+ {
+ log = File.createTempFile("jboss-unit-" + System.currentTimeMillis(),
"log");
+
javaTask.setOutput(log);
javaTask.setError(log);
- javaTask.setAppend(true);
- javaTask.setLogError(true);
-
// Execution of jboss-unit
TaskExecutingThread executor = new TaskExecutingThread(javaTask);
executor.run();
+
+
+ }
+ catch (Exception e)
+ {
+ throw new TestFailedException("Testsuite executed with test
failures");
+ }
+ finally
+ {
// Print the collected output
+
BufferedReader br = new BufferedReader(new FileReader(log));
String line = null;
while (( line = br.readLine()) != null){
@@ -110,12 +123,12 @@
// Cleanup
log.delete();
}
- catch (Exception e)
- {
- e.printStackTrace();
- }
}
+ /**
+ * Creates ant Java object with all proper settings
+ * @return
+ */
private Java createJavaTask()
{
Java javaTask = null;
@@ -124,58 +137,23 @@
JavaBuilder javaBuilder = new JavaBuilder();
+ // Apply all settings for Java object creation
addArguments(javaBuilder);
+ // Update settings using environment variables
+ javaBuilder.applyVariables(System.getProperties());
+
+ // Create Java object
javaTask = javaBuilder.buildJava();
+ // Apply proper classpath taken from maven project
Path path = javaTask.createClasspath();
- // Apply task classpath
-
-// System.out.println("Creating classpath: ");
-
-// for (Artifact artifact :
(Collection<Artifact>)project.getCompileArtifacts())
-// {
-// System.out.println("Compile Artifact: " + artifact.getGroupId() +
":" + artifact.getArtifactId());
-// path.createPathElement().setLocation(artifact.getFile());
-// }
-//
-// for (Artifact artifact :
(Collection<Artifact>)project.getTestArtifacts())
-// {
-//// System.out.println("Test Artifact: " + artifact.getGroupId() +
":" + artifact.getArtifactId());
-// path.createPathElement().setLocation(artifact.getFile());
-// }
-//
-// for (Artifact artifact :
(Collection<Artifact>)project.getRuntimeArtifacts())
-// {
-//// System.out.println("Runtime Artifact: " + artifact.getGroupId()
+ ":" + artifact.getArtifactId());
-// path.createPathElement().setLocation(artifact.getFile());
-// }
-//
-// for (Artifact artifact :
(Collection<Artifact>)project.getSystemArtifacts())
-// {
-//// System.out.println("System Artifact: " + artifact.getGroupId()
+ ":" + artifact.getArtifactId());
-// path.createPathElement().setLocation(artifact.getFile());
-// }
-//
-// for (Artifact artifact :
(Collection<Artifact>)project.getDependencyArtifacts())
-// {
-//// System.out.println("Dependency Artifact: " +
artifact.getGroupId() + ":" + artifact.getArtifactId());
-// path.createPathElement().setLocation(artifact.getFile());
-// }
-//
-// for (Resource resource :
(Collection<Resource>)project.getTestResources())
-// {
-//// System.out.println("Test Resource: " +
resource.getDirectory());
-// path.createPathElement().setLocation(new File(resource.getDirectory()));
-// }
-
try
{
for (String element :
(Collection<String>)project.getTestClasspathElements())
{
-// System.out.println("TestClasspathElement: " + element);
path.createPathElement().setLocation(new File(element));
}
}
@@ -197,10 +175,7 @@
{
javaBuilder.setConfig(testsuite.getConfig());
-// if (getSuiteName() != null)
-// {
-// javaBuilder.setSuiteName(getSuiteName());
-// }
+ Reports reports = testsuite.getReports();
if (reports != null && reports.getXml() != null)
{
@@ -212,18 +187,48 @@
javaBuilder.setHtmlReportDir(reports.getHtml());
}
- javaBuilder.setJPDA(testsuite.isJPDA());
+ // JPDA properties
- for (CasesDescription include : testsuite.getIncludes())
+
+ // JPDA
+ if (unitMojo.isJpda())
{
- //Check attributes consistency
+ javaBuilder.setJPDA(true);
+ }
-// if (include.getId() != null && (include.getIds() != null ||
include.getKeywords() != null))
-// {
-// throw new IllegalStateException("The use of <id> in
<include> tag should be exclusive");
-// }
+ // JPDA port
+ if (unitMojo.getJpdaPort() != null)
+ {
+ javaBuilder.setJPDAport(Integer.decode(unitMojo.getJpdaPort()));
+ }
+ // JPDA suspend
+ javaBuilder.setSuspend(Boolean.parseBoolean(unitMojo.getJpdaSuspend()));
+ // JUL
+
+ javaBuilder.setUseJUL(unitMojo.isUseJUL());
+
+ // Assertions
+
+ javaBuilder.setAssertions(unitMojo.isAssertions());
+
+
+ // Fail on error
+
+
+ javaBuilder.setFailOnError(unitMojo.isFailOnError());
+
+
+ // Fork
+ javaBuilder.setFork(unitMojo.isFork());
+
+
+ // Check if IDs to execute are not forced from the command line
+
+ for (CasesDescription include : testsuite.getIncludes())
+ {
+
if (include.getIds() != null)
{
for (String id : include.getIds())
@@ -239,20 +244,11 @@
javaBuilder.addIncludeKeyword(keyword);
}
}
-// if (include.getId() != null)
-// {
-// javaBuilder.addIncludeID(include.getId());
-// }
}
for (CasesDescription exclude : testsuite.getExcludes())
{
-// if (exclude.getId() != null && (exclude.getIds() != null ||
exclude.getKeywords() != null))
-// {
-// throw new IllegalStateException("The use of <id> in
<exclude> tag should be exclusive");
-// }
-
if (exclude.getIds() != null)
{
for (String id : exclude.getIds())
@@ -268,14 +264,10 @@
javaBuilder.addExcludeKeyword(keyword);
}
}
-// if (exclude.getId() != null)
-// {
-// javaBuilder.addIncludeID(exclude.getId());
-// }
}
- // Properties
+ // Properties
if (testsuite.getProperties().size() > 0)
{
@@ -284,7 +276,7 @@
javaBuilder.addProperty(propertyName.toString(),testsuite.getProperties().get(propertyName).toString());
}
- javaBuilder.updateFQNProperties(project.getProperties());
+ javaBuilder.updateFQNProperties(System.getProperties());
}
@@ -296,8 +288,7 @@
javaBuilder.addParameter(parameter.getName(),
Arrays.asList(parameter.getValues()));
}
- javaBuilder.updateFQNParameters(project.getProperties());
+ javaBuilder.updateFQNParameters(System.getProperties());
-
}
}
Modified:
modules/test/trunk/tooling/maven2/src/main/java/org/jboss/unit/tooling/maven2/UnitMojo.java
===================================================================
---
modules/test/trunk/tooling/maven2/src/main/java/org/jboss/unit/tooling/maven2/UnitMojo.java 2008-01-21
21:32:53 UTC (rev 9548)
+++
modules/test/trunk/tooling/maven2/src/main/java/org/jboss/unit/tooling/maven2/UnitMojo.java 2008-01-22
11:39:19 UTC (rev 9549)
@@ -22,7 +22,6 @@
package org.jboss.unit.tooling.maven2;
-import org.apache.maven.model.Dependency;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
@@ -36,6 +35,9 @@
*/
public class UnitMojo extends AbstractMojo
{
+
+ public static final String MAVEN_SKIP_TEST = "maven.skip.test";
+
/**
* @parameter
*/
@@ -47,6 +49,41 @@
private Reports reports;
/**
+ * @parameter
+ */
+ private boolean jpda;
+
+ /**
+ * @parameter
+ */
+ private String jpdaPort;
+
+ /**
+ * @parameter
+ */
+ private String jpdaSuspend;
+
+ /** s
+ * @parameter
+ */
+ private boolean useJUL = true;
+
+ /**
+ * @parameter
+ */
+ private boolean fork = true;
+
+ /**
+ * @parameter
+ */
+ private boolean assertions = true;
+
+ /**
+ * @parameter
+ */
+ private boolean failOnError = false;
+
+ /**
* The Maven project object
*
* @parameter expression="${project}"
@@ -58,15 +95,97 @@
throws MojoExecutionException
{
+ String testSkip = (String)System.getProperties().get(MAVEN_SKIP_TEST);
+
+ // Skip tests
+ if (testSkip != null && testSkip.equalsIgnoreCase("true"))
+ {
+ //TODO: make it logging
+
+ System.out.println("Skipping test execution: " + MAVEN_SKIP_TEST +
" set to true");
+
+ return;
+ }
+
//Invoke all configured testsuites
for (Testsuite testsuite : testsuites)
{
- TestSuiteExecutor executor = new TestSuiteExecutor(project, reports,
testsuite);
- executor.execute();
+ // Propagate global reports settings if needed
+ if (testsuite.getReports() == null && reports != null)
+ {
+ testsuite.setReports(reports);
+ }
+
+ TestSuiteExecutor executor = new TestSuiteExecutor(project, testsuite, this);
+ try
+ {
+ executor.execute();
+ }
+ catch (Exception e)
+ {
+ throw new MojoExecutionException("Build failed",e);
+ }
}
}
+ public boolean isJpda()
+ {
+ return jpda;
+ }
+
+ public String getJpdaPort()
+ {
+ return jpdaPort;
+ }
+
+ public String getJpdaSuspend()
+ {
+ return jpdaSuspend;
+ }
+
+ public boolean isUseJUL()
+ {
+ return useJUL;
+ }
+
+ public void setUseJUL(boolean useJUL)
+ {
+ this.useJUL = useJUL;
+ }
+
+ public boolean isFork()
+ {
+ return fork;
+ }
+
+ public void setFork(boolean fork)
+ {
+ this.fork = fork;
+ }
+
+ public boolean isAssertions()
+ {
+ return assertions;
+ }
+
+ public void setAssertions(boolean assertions)
+ {
+ this.assertions = assertions;
+ }
+
+ public boolean isFailOnError()
+ {
+ return failOnError;
+ }
+
+ public void setFailOnError(boolean failOnError)
+ {
+ this.failOnError = failOnError;
+ }
+
+
+
}
Modified:
modules/test/trunk/tooling/maven2/src/main/java/org/jboss/unit/tooling/maven2/configuration/Testsuite.java
===================================================================
---
modules/test/trunk/tooling/maven2/src/main/java/org/jboss/unit/tooling/maven2/configuration/Testsuite.java 2008-01-21
21:32:53 UTC (rev 9548)
+++
modules/test/trunk/tooling/maven2/src/main/java/org/jboss/unit/tooling/maven2/configuration/Testsuite.java 2008-01-22
11:39:19 UTC (rev 9549)
@@ -59,7 +59,7 @@
/**
* @parameter
*/
- boolean jPDA = false;
+ private Reports reports;
public String getConfig()
{
@@ -91,8 +91,13 @@
return parameters;
}
- public boolean isJPDA()
+ public Reports getReports()
{
- return jPDA;
+ return reports;
}
+
+ public void setReports(Reports reports)
+ {
+ this.reports = reports;
+ }
}
Modified:
modules/test/trunk/unit/src/main/java/org/jboss/unit/report/impl/writer/PrintListener.java
===================================================================
---
modules/test/trunk/unit/src/main/java/org/jboss/unit/report/impl/writer/PrintListener.java 2008-01-21
21:32:53 UTC (rev 9548)
+++
modules/test/trunk/unit/src/main/java/org/jboss/unit/report/impl/writer/PrintListener.java 2008-01-22
11:39:19 UTC (rev 9549)
@@ -156,17 +156,26 @@
SuiteStat stat = stack.removeLast();
StringBuffer sb = new StringBuffer("Testsuite: ");
+
sb.append(tmp);
sb.append(NEW_LINE);
- sb.append("Tests run: ");
- sb.append(stat.count);
- sb.append(", Failures: ");
- sb.append(stat.failures);
- sb.append(", Errors: ");
- sb.append(stat.errors);
- sb.append(", Time elapsed: ");
- sb.append(FORMAT.format((System.currentTimeMillis() - stat.timestamp) /
1000.0));
- sb.append(" sec");
+
+ if (stat.count > 0)
+ {
+ sb.append("Tests run: ");
+ sb.append(stat.count);
+ sb.append(", Failures: ");
+ sb.append(stat.failures);
+ sb.append(", Errors: ");
+ sb.append(stat.errors);
+ sb.append(", Time elapsed: ");
+ sb.append(FORMAT.format((System.currentTimeMillis() - stat.timestamp) /
1000.0));
+ sb.append(" sec");
+ }
+ else
+ {
+ sb.append("Testcase skipped...");
+ }
sb.append(NEW_LINE);
sb.append(NEW_LINE);
out.print(sb);
Added:
modules/test/trunk/unit/src/main/java/org/jboss/unit/tooling/FailureManagerListener.java
===================================================================
---
modules/test/trunk/unit/src/main/java/org/jboss/unit/tooling/FailureManagerListener.java
(rev 0)
+++
modules/test/trunk/unit/src/main/java/org/jboss/unit/tooling/FailureManagerListener.java 2008-01-22
11:39:19 UTC (rev 9549)
@@ -0,0 +1,81 @@
+/*
+* 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;
+
+import org.jboss.unit.runner.TestResult;
+import org.jboss.unit.runner.TestRunnerEvent;
+import org.jboss.unit.runner.TestRunnerEventListener;
+import org.jboss.unit.runner.results.TestFailure;
+import org.jboss.unit.runner.event.EndTestCaseEvent;
+import org.jboss.unit.runner.event.RunnerFailureEvent;
+
+/**
+ * Event Listener that manages runner failures.
+ *
+ * @author <a href="mailto:boleslaw dot dawidowicz at redhat anotherdot
com">Boleslaw Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class FailureManagerListener implements TestRunnerEventListener
+{
+ private boolean runnerFailure = false;
+
+ private boolean testCaseFailure = false;
+
+ public void onEvent(TestRunnerEvent event)
+ {
+ if (event instanceof RunnerFailureEvent)
+ {
+ // Return with code -1
+ //System.exit(-1);
+ runnerFailure = true;
+ }
+ if (event instanceof EndTestCaseEvent)
+ {
+ EndTestCaseEvent endEvent = (EndTestCaseEvent)event;
+ TestResult result = endEvent.getTestResult();
+
+ if (result instanceof TestFailure)
+ {
+ // Return with code -1
+ //System.exit(-1);
+ testCaseFailure = true;
+ }
+ }
+ }
+
+ public void reset()
+ {
+ runnerFailure = false;
+ testCaseFailure = false;
+ }
+
+ public boolean isRunnerFailure()
+ {
+ return runnerFailure;
+ }
+
+ public boolean isTestCaseFailure()
+ {
+ return testCaseFailure;
+ }
+}
Modified: modules/test/trunk/unit/src/main/java/org/jboss/unit/tooling/Main.java
===================================================================
--- modules/test/trunk/unit/src/main/java/org/jboss/unit/tooling/Main.java 2008-01-21
21:32:53 UTC (rev 9548)
+++ modules/test/trunk/unit/src/main/java/org/jboss/unit/tooling/Main.java 2008-01-22
11:39:19 UTC (rev 9549)
@@ -56,14 +56,18 @@
private final TestRunnerEventBroadcaster broadcaster;
+ private final boolean failonerror;
+
public static final String JBOSS_UNIT_PROPERTIES = "jboss.unit.properties";
public static final String JBOSS_UNIT_PROPERTY = "jboss.unit.property";
public static final String JBOSS_UNIT_PARAMETER = "jboss.unit.parameter";
- public static final String JBOSS_UNIT_PARAMETERS = "jboss.unit.parameters";
+ public static final String JBOSS_UNIT_PARAMETERS = "jboss.unit.parameters";
+ public static final String OPT_FAIL_ON_ERROR = "--failonerror";
+
public static final String OPT_ID = "--id";
public static final String OPT_IDS = "--ids";
@@ -117,15 +121,17 @@
opts.add(OPT_XML_REPORT_DIR);
opts.add(OPT_HTML_REPORT_DIR);
opts.add(OPT_PROPERTY);
+ opts.add(OPT_FAIL_ON_ERROR);
options = Collections.unmodifiableSet(opts);
opts = new HashSet<String>();
opts.add(OPT_NO_CONSOLE);
+ opts.add(OPT_FAIL_ON_ERROR);
options_no_arg = Collections.unmodifiableSet(opts);
}
- public Main(TestRunner runner, MainTestFilter mainFilter, TestRunnerEventBroadcaster
broadcaster, TestSuiteDef suiteDef, Map<String,String> properties, Map<String,
String[]> parameters)
+ public Main(TestRunner runner, MainTestFilter mainFilter, TestRunnerEventBroadcaster
broadcaster, TestSuiteDef suiteDef, Map<String,String> properties, Map<String,
String[]> parameters, boolean failonerror)
{
if (runner == null)
{
@@ -163,6 +169,7 @@
this.properties = properties;
this.broadcaster = broadcaster;
this.parameters = parameters;
+ this.failonerror = failonerror;
}
public void execute() throws Exception
@@ -170,6 +177,8 @@
SystemOutputManager systemManager = new SystemOutputManager();
systemManager.start();
+ FailureManagerListener failureListener = new FailureManagerListener();
+
//
try
{
@@ -187,16 +196,30 @@
StringWriter sw = new StringWriter();
broadcaster.addListener(new PrintListener(sw));
+
+
+ // Track runner and test case failures;
+ broadcaster.addListener(failureListener);
+
TestRunnerContextSupport runnerContext = new
TestRunnerContextSupport(properties, new ParametrizationSet(parameters), mainFilter,
broadcaster);
runner.run(runnerContext);
sw.close();
System.out.println(sw.toString());
+
+
+
+
}
finally
{
systemManager.stop();
+
+ if (failonerror && (failureListener.isRunnerFailure() ||
failureListener.isTestCaseFailure()))
+ {
+ System.exit(-1);
+ }
}
}
@@ -208,11 +231,20 @@
for (String arg : args)
{
String[] params = arg.split("=",2);
- if (params.length < 2 && !options_no_arg.contains(params[0]))
+
+ if (!options_no_arg.contains(params[0]))
{
- throw new IllegalArgumentException("Argument '" + arg +
"' doesn't follow the name=value pattern");
+ if (params.length < 2)
+ {
+ throw new IllegalArgumentException("Argument '" + arg +
"' doesn't follow the name=value pattern");
+ }
+
+ arguments.put(params[0], params[1]);
}
- arguments.put(params[0], params[1]);
+ else
+ {
+ arguments.put(params[0], null);
+ }
}
if (!arguments.keySet().contains(OPT_CONFIG))
@@ -274,6 +306,11 @@
builder.setNoConsole(true);
}
+ if (argument.equals(OPT_FAIL_ON_ERROR))
+ {
+ builder.setFailonerror(true);
+ }
+
if (argument.equals(OPT_XML_REPORT_DIR))
{
builder.setXMLReportDir(arguments.get(OPT_XML_REPORT_DIR));
Modified: modules/test/trunk/unit/src/main/java/org/jboss/unit/tooling/MainBuilder.java
===================================================================
---
modules/test/trunk/unit/src/main/java/org/jboss/unit/tooling/MainBuilder.java 2008-01-21
21:32:53 UTC (rev 9548)
+++
modules/test/trunk/unit/src/main/java/org/jboss/unit/tooling/MainBuilder.java 2008-01-22
11:39:19 UTC (rev 9549)
@@ -73,6 +73,8 @@
private boolean noConsole = false;
+ private boolean failonerror = false;
+
private String xmlReportDir;
private String htmlReportDir;
@@ -469,6 +471,16 @@
this.noConsole = noConsole;
}
+ public boolean isFailonerror()
+ {
+ return failonerror;
+ }
+
+ public void setFailonerror(boolean failonerror)
+ {
+ this.failonerror = failonerror;
+ }
+
public void setXMLReportDir(String xmlReportDir)
{
this.xmlReportDir = xmlReportDir;
@@ -551,7 +563,7 @@
filter.addExcludeFilter(new ExcludeTestFilter(excludeKeywords, excludeNames,
excludeNamePatterns));
}
- return new Main(runner, filter, broadcaster, suite, properties, getParameters());
+ return new Main(runner, filter, broadcaster, suite, properties, getParameters(),
isFailonerror());
}
public static File checkCreateOutputDirectory(String dir) throws Exception