Author: bdaw
Date: 2007-10-07 18:44:24 -0400 (Sun, 07 Oct 2007)
New Revision: 8552
Added:
modules/test/trunk/unit/src/main/org/jboss/unit/report/impl/
modules/test/trunk/unit/src/main/org/jboss/unit/report/impl/console/
modules/test/trunk/unit/src/main/org/jboss/unit/report/impl/console/PrintListener.java
modules/test/trunk/unit/src/main/org/jboss/unit/tooling/
modules/test/trunk/unit/src/main/org/jboss/unit/tooling/ExcludeTestFilter.java
modules/test/trunk/unit/src/main/org/jboss/unit/tooling/IncludeTestFilter.java
modules/test/trunk/unit/src/main/org/jboss/unit/tooling/InfoTestFilter.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
modules/test/trunk/unit/src/main/org/jboss/unit/tooling/MainTestFilter.java
Removed:
modules/test/trunk/unit/src/main/org/jboss/test/unit/PrintListener.java
Modified:
modules/test/trunk/tools/etc/buildfragments/defaults.ent
modules/test/trunk/tools/etc/buildfragments/modules.ent
modules/test/trunk/unit/build.xml
modules/test/trunk/unit/src/main/org/jboss/test/unit/blah/BlahTestTwo.java
modules/test/trunk/unit/src/main/org/jboss/test/unit/blah/BlahTests.java
Log:
command line part of tolling support for jboss unit test framework (initial stuff)
Modified: modules/test/trunk/tools/etc/buildfragments/defaults.ent
===================================================================
--- modules/test/trunk/tools/etc/buildfragments/defaults.ent 2007-10-05 19:45:41 UTC (rev
8551)
+++ modules/test/trunk/tools/etc/buildfragments/defaults.ent 2007-10-07 22:44:24 UTC (rev
8552)
@@ -118,8 +118,8 @@
<property name="javac.depend.cachedir"
value="${build.cache}/depends"/>
- <property name="javac.source" value="1.4"/>
- <property name="javac.target" value="1.4"/>
+ <property name="javac.source" value="1.5"/>
+ <property name="javac.target" value="1.5"/>
<property name="rmic.stubVersion" value="1.2"/>
<!-- classpath and local.classpath must have a value using with a path -->
Modified: modules/test/trunk/tools/etc/buildfragments/modules.ent
===================================================================
--- modules/test/trunk/tools/etc/buildfragments/modules.ent 2007-10-05 19:45:41 UTC (rev
8551)
+++ modules/test/trunk/tools/etc/buildfragments/modules.ent 2007-10-07 22:44:24 UTC (rev
8552)
@@ -199,4 +199,11 @@
<path id="jboss.portal-samples.classpath">
<pathelement
path="${jboss.portal-samples.lib}/portal-samples-lib.jar"/>
</path>
+
+ <!-- unit module -->
+ <property name="jboss.unit.root"
value="${project.root}/unit/output"/>
+ <property name="jboss.unit.lib"
value="${jboss.unit.root}/lib"/>
+ <path id="jboss.unit.classpath">
+ <pathelement path="${jboss.unit.lib}/jboss-unit-lib.jar"/>
+ </path>
</target>
Modified: modules/test/trunk/unit/build.xml
===================================================================
--- modules/test/trunk/unit/build.xml 2007-10-05 19:45:41 UTC (rev 8551)
+++ modules/test/trunk/unit/build.xml 2007-10-07 22:44:24 UTC (rev 8552)
@@ -85,6 +85,7 @@
<!-- Configure thirdparty libraries -->
&libraries;
<path id="library.classpath">
+
</path>
<!-- Configure modules -->
Deleted: modules/test/trunk/unit/src/main/org/jboss/test/unit/PrintListener.java
===================================================================
--- modules/test/trunk/unit/src/main/org/jboss/test/unit/PrintListener.java 2007-10-05
19:45:41 UTC (rev 8551)
+++ modules/test/trunk/unit/src/main/org/jboss/test/unit/PrintListener.java 2007-10-07
22:44:24 UTC (rev 8552)
@@ -1,88 +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;
-
-import org.jboss.unit.Failure;
-import org.jboss.unit.TestId;
-import org.jboss.unit.runner.TestResult;
-import org.jboss.unit.runner.TestRunnerEvent;
-import org.jboss.unit.runner.TestRunnerEventListener;
-import org.jboss.unit.runner.event.EndRunnerEvent;
-import org.jboss.unit.runner.event.EndTestEvent;
-import org.jboss.unit.runner.event.RunnerFailureEvent;
-import org.jboss.unit.runner.event.StartRunnerEvent;
-import org.jboss.unit.runner.event.StartTestEvent;
-import org.jboss.unit.runner.results.TestFailure;
-import org.jboss.unit.runner.results.TestSuccess;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 1.1 $
- */
-public class PrintListener implements TestRunnerEventListener
-{
-
- public void onEvent(TestRunnerEvent event)
- {
- if (event instanceof StartRunnerEvent)
- {
- System.out.println("--- Start ---");
- }
- else if (event instanceof EndRunnerEvent)
- {
- System.out.println("--- End ---");
- }
- else if (event instanceof RunnerFailureEvent)
- {
- RunnerFailureEvent failureEvent = (RunnerFailureEvent)event;
- Failure failure = failureEvent.getFailure();
- System.out.println("Runner failure: " + failure.getType() + "
" + failure.getMessage());
- }
- else if (event instanceof StartTestEvent)
- {
- StartTestEvent startTestEvent = (StartTestEvent)event;
- System.out.println("Starting id=" + startTestEvent.getTestId() +
" name=" + startTestEvent.getTestInfo().getName() + " description=" +
startTestEvent.getTestInfo().getDescription());
- }
- else if (event instanceof EndTestEvent)
- {
- EndTestEvent endTestEvent = (EndTestEvent)event;
- TestId testId = endTestEvent.getTestId();
- TestResult testResult = endTestEvent.getTestResult();
- if (testResult instanceof TestSuccess)
- {
- System.out.println("Test id=" + testId + " is
successful");
- }
- else if (testResult instanceof TestFailure)
- {
- TestFailure testFailure = (TestFailure)testResult;
- Failure failure = testFailure.getFailure();
- System.out.println("Test id=" + testId + " " +
failure.getType() + " failed " + failure.getMessage());
- if (failure.getCause() != null)
- {
- failure.getCause().printStackTrace();
- }
- }
- }
-
- }
-}
Modified: modules/test/trunk/unit/src/main/org/jboss/test/unit/blah/BlahTestTwo.java
===================================================================
--- modules/test/trunk/unit/src/main/org/jboss/test/unit/blah/BlahTestTwo.java 2007-10-05
19:45:41 UTC (rev 8551)
+++ modules/test/trunk/unit/src/main/org/jboss/test/unit/blah/BlahTestTwo.java 2007-10-07
22:44:24 UTC (rev 8552)
@@ -24,7 +24,7 @@
import java.io.InputStream;
-import org.jboss.test.unit.PrintListener;
+import org.jboss.unit.report.impl.console.PrintListener;
import org.jboss.unit.report.junit.JUnitReporter;
import org.jboss.unit.runner.TestRunner;
import org.jboss.unit.runner.TestRunnerEventListener;
Modified: modules/test/trunk/unit/src/main/org/jboss/test/unit/blah/BlahTests.java
===================================================================
--- modules/test/trunk/unit/src/main/org/jboss/test/unit/blah/BlahTests.java 2007-10-05
19:45:41 UTC (rev 8551)
+++ modules/test/trunk/unit/src/main/org/jboss/test/unit/blah/BlahTests.java 2007-10-07
22:44:24 UTC (rev 8552)
@@ -22,7 +22,7 @@
******************************************************************************/
package org.jboss.test.unit.blah;
-import org.jboss.test.unit.PrintListener;
+import org.jboss.unit.report.impl.console.PrintListener;
import org.jboss.unit.runner.TestRunner;
import org.jboss.unit.runner.model.ModelBuilder;
import org.jboss.unit.runner.model.TestSuiteDef;
Added:
modules/test/trunk/unit/src/main/org/jboss/unit/report/impl/console/PrintListener.java
===================================================================
---
modules/test/trunk/unit/src/main/org/jboss/unit/report/impl/console/PrintListener.java
(rev 0)
+++
modules/test/trunk/unit/src/main/org/jboss/unit/report/impl/console/PrintListener.java 2007-10-07
22:44:24 UTC (rev 8552)
@@ -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.report.impl.console;
+
+import org.jboss.unit.Failure;
+import org.jboss.unit.TestId;
+import org.jboss.unit.runner.TestResult;
+import org.jboss.unit.runner.TestRunnerEvent;
+import org.jboss.unit.runner.TestRunnerEventListener;
+import org.jboss.unit.runner.event.EndRunnerEvent;
+import org.jboss.unit.runner.event.EndTestEvent;
+import org.jboss.unit.runner.event.RunnerFailureEvent;
+import org.jboss.unit.runner.event.StartRunnerEvent;
+import org.jboss.unit.runner.event.StartTestEvent;
+import org.jboss.unit.runner.results.TestFailure;
+import org.jboss.unit.runner.results.TestSuccess;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class PrintListener implements TestRunnerEventListener
+{
+
+ public void onEvent(TestRunnerEvent event)
+ {
+ if (event instanceof StartRunnerEvent)
+ {
+ System.out.println("--- Start ---");
+ }
+ else if (event instanceof EndRunnerEvent)
+ {
+ System.out.println("--- End ---");
+ }
+ else if (event instanceof RunnerFailureEvent)
+ {
+ RunnerFailureEvent failureEvent = (RunnerFailureEvent)event;
+ Failure failure = failureEvent.getFailure();
+ System.out.println("Runner failure: " + failure.getType() + "
" + failure.getMessage());
+ failure.getCause().printStackTrace();
+ }
+ else if (event instanceof StartTestEvent)
+ {
+ StartTestEvent startTestEvent = (StartTestEvent)event;
+ System.out.println("Starting id=" + startTestEvent.getTestId() +
" name=" + startTestEvent.getTestInfo().getName() + " description=" +
startTestEvent.getTestInfo().getDescription());
+ }
+ else if (event instanceof EndTestEvent)
+ {
+ EndTestEvent endTestEvent = (EndTestEvent)event;
+ TestId testId = endTestEvent.getTestId();
+ TestResult testResult = endTestEvent.getTestResult();
+ if (testResult instanceof TestSuccess)
+ {
+ System.out.println("Test id=" + testId + " is
successful");
+ }
+ else if (testResult instanceof TestFailure)
+ {
+ TestFailure testFailure = (TestFailure)testResult;
+ Failure failure = testFailure.getFailure();
+ System.out.println("Test id=" + testId + " " +
failure.getType() + " failed " + failure.getMessage());
+ if (failure.getCause() != null)
+ {
+ failure.getCause().printStackTrace();
+ }
+ }
+ }
+
+ }
+}
Added: modules/test/trunk/unit/src/main/org/jboss/unit/tooling/ExcludeTestFilter.java
===================================================================
--- modules/test/trunk/unit/src/main/org/jboss/unit/tooling/ExcludeTestFilter.java
(rev 0)
+++
modules/test/trunk/unit/src/main/org/jboss/unit/tooling/ExcludeTestFilter.java 2007-10-07
22:44:24 UTC (rev 8552)
@@ -0,0 +1,78 @@
+/*
+* 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.TestId;
+import org.jboss.unit.runner.TestFilter;
+import org.jboss.unit.info.TestInfo;
+
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:boleslaw dot dawidowicz at redhat anotherdot
com">Boleslaw Dawidowicz</a>
+ * @version $Revision: 0.1 $
+ */
+public class ExcludeTestFilter extends InfoTestFilter
+{
+
+
+ public ExcludeTestFilter()
+ {
+ }
+
+ public ExcludeTestFilter(Set<String> keywords, Set<String> names,
Set<String> namePatterns)
+ {
+ super(keywords, names, namePatterns);
+ }
+
+ public boolean include(TestId testId, TestInfo testInfo)
+ {
+ // First check names
+
+ if (checkName(testInfo.getName()))
+ {
+ return false;
+ }
+
+ // ... then keywords
+
+ if (checkKeywords(testInfo.getKeywords()))
+ {
+ return false;
+ }
+
+ // ... then check if name matches any of provided regex
+
+ if (checkNamePatterns(testInfo.getName()))
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+
+
+}
Added: modules/test/trunk/unit/src/main/org/jboss/unit/tooling/IncludeTestFilter.java
===================================================================
--- modules/test/trunk/unit/src/main/org/jboss/unit/tooling/IncludeTestFilter.java
(rev 0)
+++
modules/test/trunk/unit/src/main/org/jboss/unit/tooling/IncludeTestFilter.java 2007-10-07
22:44:24 UTC (rev 8552)
@@ -0,0 +1,77 @@
+/*
+* 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.TestId;
+import org.jboss.unit.runner.TestFilter;
+import org.jboss.unit.info.TestInfo;
+
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:boleslaw dot dawidowicz at redhat anotherdot
com">Boleslaw Dawidowicz</a>
+ * @version $Revision: 0.1 $
+ */
+public class IncludeTestFilter extends InfoTestFilter
+{
+
+
+ public IncludeTestFilter()
+ {
+ }
+
+ public IncludeTestFilter(Set<String> keywords, Set<String> names,
Set<String> namePatterns)
+ {
+ super(keywords, names, namePatterns);
+ }
+
+ public boolean include(TestId testId, TestInfo testInfo)
+ {
+
+ // First check names
+
+ if (checkName(testInfo.getName()))
+ {
+ return true;
+ }
+
+ // ... then keywords
+
+ if (checkKeywords(testInfo.getKeywords()))
+ {
+ return true;
+ }
+
+ // ... then check if name matches any of provided regex
+
+ if (checkNamePatterns(testInfo.getName()))
+ {
+ return true;
+ }
+
+ return false;
+ }
+
+}
Added: modules/test/trunk/unit/src/main/org/jboss/unit/tooling/InfoTestFilter.java
===================================================================
--- modules/test/trunk/unit/src/main/org/jboss/unit/tooling/InfoTestFilter.java
(rev 0)
+++ modules/test/trunk/unit/src/main/org/jboss/unit/tooling/InfoTestFilter.java 2007-10-07
22:44:24 UTC (rev 8552)
@@ -0,0 +1,226 @@
+/*
+* 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.TestFilter;
+import org.jboss.unit.TestId;
+import org.jboss.unit.info.TestInfo;
+
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:boleslaw dot dawidowicz at redhat anotherdot
com">Boleslaw Dawidowicz</a>
+ * @version $Revision: 0.1 $
+ */
+public abstract class InfoTestFilter implements TestFilter
+{
+
+ private Set<String> keywords = new HashSet<String>();
+
+ private Set<String> names = new HashSet<String>();
+
+ private Set<String> namePatterns = new HashSet<String>();
+
+ public InfoTestFilter()
+ {
+ }
+
+ public InfoTestFilter(Set<String> keywords, Set<String> names,
Set<String> namePatterns)
+ {
+ if (keywords == null)
+ {
+ throw new IllegalArgumentException("keywords cannot be null");
+ }
+ if (names == null)
+ {
+ throw new IllegalArgumentException("names cannot be null");
+ }
+ if (namePatterns == null)
+ {
+ throw new IllegalArgumentException("namePatterns cannot be null");
+ }
+
+ this.keywords = keywords;
+ this.names = names;
+ this.namePatterns = namePatterns;
+ }
+
+ public InfoTestFilter addKeyword(String keyword)
+ {
+ if (keyword == null)
+ {
+ throw new IllegalArgumentException("keyword cannot be null");
+ }
+
+ keywords.add(keyword);
+
+ return this;
+ }
+
+
+ public InfoTestFilter addUnparsedKeywords(String keywordsString)
+ {
+ if (keywordsString == null)
+ {
+ throw new IllegalArgumentException("keywordsString cannot be null");
+ }
+ String[] keywordValues = keywordsString.split(",");
+ for (String keyword : keywordValues)
+ {
+ this.keywords.add(keyword.trim());
+ }
+ return this;
+ }
+
+ public InfoTestFilter addName(String name)
+ {
+ if (name == null)
+ {
+ throw new IllegalArgumentException("name cannot be null");
+ }
+ names.add(name);
+
+ return this;
+ }
+
+ public InfoTestFilter addUnparsedNames(String namesString)
+ {
+ if (namesString == null)
+ {
+ throw new IllegalArgumentException("namesString cannot be null");
+ }
+ String[] namesValues = namesString.split(",");
+ for (String name : namesValues)
+ {
+ this.names.add(name.trim());
+ }
+ return this;
+ }
+
+ public InfoTestFilter addNamePattern(String pattern)
+ {
+ if (pattern == null)
+ {
+ throw new IllegalArgumentException("pattern cannot be null");
+ }
+ namePatterns.add(pattern);
+
+ return this;
+ }
+
+ public InfoTestFilter addUnparsedNamePatterns(String patternString)
+ {
+ if (patternString == null)
+ {
+ throw new IllegalArgumentException("patternString cannot be null");
+ }
+ String[] patternValues = patternString.split(",");
+ for (String pattern : patternValues)
+ {
+ this.namePatterns.add(pattern.trim());
+ }
+ return this;
+ }
+
+ public abstract boolean include(TestId testId, TestInfo testInfo);
+
+ public boolean include(TestId testId, Map<String, String> parametrization,
TestInfo testInfo)
+ {
+ // At the moment no parametrization match
+
+ return include (testId, testInfo);
+ }
+
+ boolean checkName(String name)
+ {
+ for (String s : names)
+ {
+ if (s.equals(name))
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ boolean checkKeywords(Set<String> keywords)
+ {
+ for (String keyword : this.keywords)
+ {
+ for (String toMatch : keywords)
+ {
+ if (keyword.equals(toMatch))
+ {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ boolean checkNamePatterns(String name)
+ {
+ for (String regex : this.namePatterns)
+ {
+ if (name.matches(regex))
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+
+ public String toString()
+ {
+ StringBuffer sb = new StringBuffer();
+ sb.append("Filter: ")
+ .append(getClass().getName())
+ .append("; names: ")
+ .append(names.toString())
+ .append("; keywords: ")
+ .append(keywords.toString())
+ .append("; namePatterns: ")
+ .append(namePatterns.toString())
+ .append(";");
+ return sb.toString();
+ }
+
+
+ public Set<String> getKeywords()
+ {
+ return keywords;
+ }
+
+ public Set<String> getNames()
+ {
+ return names;
+ }
+
+ public Set<String> getNamePatterns()
+ {
+ return namePatterns;
+ }
+}
Added: modules/test/trunk/unit/src/main/org/jboss/unit/tooling/Main.java
===================================================================
--- modules/test/trunk/unit/src/main/org/jboss/unit/tooling/Main.java
(rev 0)
+++ modules/test/trunk/unit/src/main/org/jboss/unit/tooling/Main.java 2007-10-07 22:44:24
UTC (rev 8552)
@@ -0,0 +1,218 @@
+/*
+* 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.TestRunnerEventListener;
+import org.jboss.unit.runner.TestRunner;
+import org.jboss.unit.runner.model.TestSuiteDef;
+
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Collections;
+
+/**
+ * @author <a href="mailto:boleslaw dot dawidowicz at redhat anotherdot
com">Boleslaw Dawidowicz</a>
+ * @version $Revision: 0.1 $
+ */
+public class Main
+{
+
+ private final MainTestFilter mainFilter;
+
+ private final Set<TestRunnerEventListener> listeners;
+
+ private final TestRunner runner;
+
+ private final TestSuiteDef suiteDef;
+
+// public static final String JBOSS_UNIT_NAMES = "jboss.unit.names";
+//
+// public static final String JBOSS_UNIT_KEYWORDS = "jboss.unit.keywords";
+//
+// public static final String JBOSS_UNIT_PATTERNS = "jboss.unit.patterns";
+//
+// public static final String JBOSS_UNIT_CONFIG = "jboss.unit.config";
+//
+// public static final String JBOSS_UNIT_SUITE_NAME =
"jboss.unit.suite_name";
+
+ public static final String OPT_ID = "--id";
+
+ public static final String OPT_NAMES = "--names";
+
+ public static final String OPT_KEYWORDS = "--keywords";
+
+ public static final String OPT_PATTERNS = "--patterns";
+
+ public static final String OPT_EX_ID = "--ex_id";
+
+ public static final String OPT_EX_NAMES = "--ex_names";
+
+ public static final String OPT_EX_KEYWORDS = "--ex_keywords";
+
+ public static final String OPT_EX_PATTERNS = "--ex_patterns";
+
+ public static final String OPT_CONFIG = "--config";
+
+ public static final String OPT_SUITE_NAME = "--suite_name";
+
+ public static final String OPT_NO_CONSOLE = "--noconsole";
+
+ public static final String OPT_XML_REPORT_DIR = "--xml_report_dir";
+
+ public static final String OPT_HTML_REPORT_DIR = "--html_report_dir";
+
+ public static final Set options;
+
+ static {
+ Set<String> opts = new HashSet<String>();
+ opts.add(OPT_ID);
+ opts.add(OPT_NAMES);
+ opts.add(OPT_KEYWORDS);
+ opts.add(OPT_PATTERNS);
+ opts.add(OPT_EX_ID);
+ opts.add(OPT_EX_NAMES);
+ opts.add(OPT_EX_KEYWORDS);
+ opts.add(OPT_EX_PATTERNS);
+ opts.add(OPT_CONFIG);
+ opts.add(OPT_SUITE_NAME);
+
+ options = Collections.unmodifiableSet(opts);
+ }
+
+ private Main()
+ {
+ mainFilter = null;
+ listeners = null;
+ runner = null;
+ suiteDef = null;
+ }
+
+ public Main(TestRunner runner, MainTestFilter mainFilter,
Set<TestRunnerEventListener> listeners, TestSuiteDef suiteDef)
+ {
+ if (runner == null)
+ {
+ throw new IllegalArgumentException("runner cannot be null");
+ }
+
+ if (mainFilter == null)
+ {
+ throw new IllegalArgumentException("mainFilter cannot be null");
+ }
+
+ if (listeners == null)
+ {
+ throw new IllegalArgumentException("listeners cannot be null");
+ }
+
+ if (suiteDef == null)
+ {
+ throw new IllegalArgumentException("suiteDef cannot be null");
+ }
+
+ this.mainFilter = mainFilter;
+ this.listeners = listeners;
+ this.runner = runner;
+ this.suiteDef = suiteDef;
+ }
+
+ public void execute()
+ {
+ runner.run(mainFilter);
+ }
+
+ public static void main(String[] args) throws Exception
+ {
+ Map<String, String> arguments = new HashMap();
+
+ for (String arg : args)
+ {
+ String[] params = arg.split("=",2);
+ if (params.length < 2)
+ {
+ throw new IllegalArgumentException("Argument '" + arg +
"' doesn't follow the name=value pattern");
+ }
+ arguments.put(params[0], params[1]);
+ }
+
+ if (!arguments.keySet().contains(OPT_CONFIG))
+ {
+ throw new IllegalArgumentException("Argument '" + OPT_CONFIG +
"' is missing");
+ }
+
+ if (!arguments.keySet().contains(OPT_SUITE_NAME))
+ {
+ throw new IllegalArgumentException("Argument '" + OPT_SUITE_NAME +
"' is missing");
+ }
+
+ MainBuilder builder = new MainBuilder(arguments.get(OPT_CONFIG),
arguments.get(OPT_SUITE_NAME));
+
+ if (arguments.keySet().contains(OPT_NAMES))
+ {
+ builder.addUnparsedNames(arguments.get(OPT_NAMES));
+ }
+
+ if (arguments.keySet().contains(OPT_ID))
+ {
+ builder.addName(arguments.get(OPT_ID));
+ }
+
+ if (arguments.keySet().contains(OPT_KEYWORDS))
+ {
+ builder.addUnparsedKeywords(arguments.get(OPT_KEYWORDS));
+ }
+
+ if (arguments.keySet().contains(OPT_PATTERNS))
+ {
+ builder.addUnparsedNamePatterns(arguments.get(OPT_PATTERNS));
+ }
+
+ if (arguments.keySet().contains(OPT_EX_NAMES))
+ {
+ builder.addUnparsedExcludeNames(arguments.get(OPT_EX_NAMES));
+ }
+
+ if (arguments.keySet().contains(OPT_EX_ID))
+ {
+ builder.addExcludeName(arguments.get(OPT_EX_ID));
+ }
+
+ if (arguments.keySet().contains(OPT_EX_KEYWORDS))
+ {
+ builder.addUnparsedExcludeKeywords(arguments.get(OPT_EX_KEYWORDS));
+ }
+
+ if (arguments.keySet().contains(OPT_EX_PATTERNS))
+ {
+ builder.addUnparsedExcludeNamePatterns(arguments.get(OPT_EX_PATTERNS));
+ }
+
+
+ Main main = builder.build();
+
+ main.execute();
+
+
+ }
+}
Added: modules/test/trunk/unit/src/main/org/jboss/unit/tooling/MainBuilder.java
===================================================================
--- modules/test/trunk/unit/src/main/org/jboss/unit/tooling/MainBuilder.java
(rev 0)
+++ modules/test/trunk/unit/src/main/org/jboss/unit/tooling/MainBuilder.java 2007-10-07
22:44:24 UTC (rev 8552)
@@ -0,0 +1,308 @@
+/*
+* 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.TestRunnerEventListener;
+import org.jboss.unit.runner.TestRunner;
+import org.jboss.unit.runner.filter.NullFilter;
+import org.jboss.unit.runner.model.ModelBuilder;
+import org.jboss.unit.runner.model.TestSuiteDef;
+import org.jboss.unit.report.junit.JUnitReporter;
+import org.jboss.unit.report.impl.console.PrintListener;
+import org.xml.sax.InputSource;
+
+import java.util.Set;
+import java.util.HashSet;
+import java.io.InputStream;
+import java.io.FileInputStream;
+
+/**
+ * @author <a href="mailto:boleslaw dot dawidowicz at redhat anotherdot
com">Boleslaw Dawidowicz</a>
+ * @version $Revision: 0.1 $
+ */
+public class MainBuilder
+{
+
+ private Set<String> keywords = new HashSet();
+
+ private Set<String> names = new HashSet();
+
+ private Set<String> namePatterns = new HashSet();
+
+ private Set<String> excludeKeywords = new HashSet();
+
+ private Set<String> excludeNames = new HashSet();
+
+ private Set<String> excludeNamePatterns = new HashSet();
+
+ private Set<TestRunnerEventListener> listeners = new HashSet();
+
+ private String name = "noname";
+
+ private String configFile;
+
+
+ private MainBuilder()
+ {
+
+ }
+
+ public MainBuilder(String configFile, String name)
+ {
+ if (configFile == null)
+ {
+ throw new IllegalArgumentException("configFile cannot be null");
+ }
+
+ if (name == null)
+ {
+ throw new IllegalArgumentException("name cannot be null");
+ }
+
+ this.configFile = configFile;
+ this.name = name;
+
+ }
+
+ public MainBuilder addKeyword(String keyword)
+ {
+ if (keyword == null)
+ {
+ throw new IllegalArgumentException("keyword cannot be null");
+ }
+
+ keywords.add(keyword);
+ return this;
+ }
+
+ public MainBuilder addExcludeKeyword(String keyword)
+ {
+ if (keyword == null)
+ {
+ throw new IllegalArgumentException("keyword cannot be null");
+ }
+
+ excludeKeywords.add(keyword);
+ return this;
+ }
+
+ public MainBuilder addUnparsedKeywords(String keywordsString)
+ {
+ if (keywordsString == null)
+ {
+ throw new IllegalArgumentException("keywordsString cannot be null");
+ }
+ String[] keywordValues = keywordsString.split(",");
+ for (String keyword : keywordValues)
+ {
+ this.keywords.add(keyword.trim());
+ }
+ return this;
+ }
+
+ public MainBuilder addUnparsedExcludeKeywords(String keywordsString)
+ {
+ if (keywordsString == null)
+ {
+ throw new IllegalArgumentException("keywordsString cannot be null");
+ }
+ String[] keywordValues = keywordsString.split(",");
+ for (String keyword : keywordValues)
+ {
+ this.excludeKeywords.add(keyword.trim());
+ }
+ return this;
+ }
+
+ public MainBuilder addName(String name)
+ {
+ if (name == null)
+ {
+ throw new IllegalArgumentException("name cannot be null");
+ }
+
+ names.add(name);
+ return this;
+ }
+
+ public MainBuilder addExcludeName(String name)
+ {
+ if (name == null)
+ {
+ throw new IllegalArgumentException("name cannot be null");
+ }
+
+ excludeNames.add(name);
+ return this;
+ }
+
+ public MainBuilder addUnparsedNames(String namesString)
+ {
+ if (namesString == null)
+ {
+ throw new IllegalArgumentException("namesString cannot be null");
+ }
+ String[] namesValues = namesString.split(",");
+ for (String name : namesValues)
+ {
+ this.names.add(name.trim());
+ }
+ return this;
+ }
+
+ public MainBuilder addUnparsedExcludeNames(String namesString)
+ {
+ if (namesString == null)
+ {
+ throw new IllegalArgumentException("namesString cannot be null");
+ }
+ String[] namesValues = namesString.split(",");
+ for (String name : namesValues)
+ {
+ this.excludeNames.add(name.trim());
+ }
+ return this;
+ }
+
+ public MainBuilder addNamePattern(String pattern)
+ {
+ if (pattern == null)
+ {
+ throw new IllegalArgumentException("pattern cannot be null");
+ }
+
+ namePatterns.add(pattern);
+ return this;
+ }
+
+ public MainBuilder addExcludeNamePattern(String pattern)
+ {
+ if (pattern == null)
+ {
+ throw new IllegalArgumentException("pattern cannot be null");
+ }
+
+ excludeNamePatterns.add(pattern);
+ return this;
+ }
+
+ public MainBuilder addUnparsedNamePatterns(String patternString)
+ {
+ if (patternString == null )
+ {
+ throw new IllegalArgumentException("patternString cannot be null");
+ }
+ String[] patternValues = patternString.split(",");
+ for (String pattern : patternValues)
+ {
+ this.namePatterns.add(pattern.trim());
+ }
+ return this;
+ }
+
+ public MainBuilder addUnparsedExcludeNamePatterns(String patternString)
+ {
+ if (patternString == null)
+ {
+ throw new IllegalArgumentException("patternString cannot be null");
+ }
+ String[] patternValues = patternString.split(",");
+ for (String pattern : patternValues)
+ {
+ this.excludeNamePatterns.add(pattern.trim());
+ }
+ return this;
+ }
+
+ public MainBuilder addJunitReporting(String directory)
+ {
+ if (directory == null)
+ {
+ throw new IllegalArgumentException("directory cannot be null");
+ }
+
+ listeners.add(new JUnitReporter(directory, name));
+
+ return this;
+ }
+
+
+ public MainBuilder addXMLReporting(String directory)
+ {
+ throw new RuntimeException("NYI");
+
+ }
+
+ public MainBuilder addHTMLReporting(String directory)
+ {
+ throw new RuntimeException("NYI");
+ }
+
+ public Main build() throws Exception
+ {
+
+
+ InputStream in;// =
Thread.currentThread().getContextClassLoader().getResourceAsStream(configFile);
+ in = new FileInputStream(configFile);
+ InputSource source = new InputSource(in);
+ ModelBuilder builder = new ModelBuilder(source);
+ TestSuiteDef suite = builder.build();
+ TestRunner runner = suite.createRunner();
+
+ // Add listeners
+
+ for (TestRunnerEventListener listener : listeners)
+ {
+ runner.addListener(listener);
+ }
+
+ //add PrintListener by default
+ runner.addListener(new PrintListener());
+
+
+
+ MainTestFilter filter = new MainTestFilter();
+
+ if (keywords.size() == 0 && names.size() == 0 &&
namePatterns.size() == 0)
+ {
+ // If no conditions - add filter that match all
+
+ filter.addIncludeFilter(new NullFilter());
+ }
+ else
+ {
+ filter.addIncludeFilter(new IncludeTestFilter(keywords, names, namePatterns));
+ }
+
+ // Add exclude filter only if there is a need for one...
+
+ if (excludeKeywords.size() != 0 || excludeNames.size() != 0 ||
excludeNamePatterns.size() != 0)
+ {
+ filter.addExcludeFilter(new ExcludeTestFilter(excludeKeywords, excludeNames,
excludeNamePatterns));
+ }
+
+
+ return new Main(runner, filter, listeners, suite);
+ }
+
+}
Added: modules/test/trunk/unit/src/main/org/jboss/unit/tooling/MainTestFilter.java
===================================================================
--- modules/test/trunk/unit/src/main/org/jboss/unit/tooling/MainTestFilter.java
(rev 0)
+++ modules/test/trunk/unit/src/main/org/jboss/unit/tooling/MainTestFilter.java 2007-10-07
22:44:24 UTC (rev 8552)
@@ -0,0 +1,122 @@
+/*
+* 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.TestFilter;
+import org.jboss.unit.TestId;
+import org.jboss.unit.info.TestInfo;
+
+import java.util.Map;
+import java.util.List;
+import java.util.LinkedList;
+
+/**
+ * @author <a href="mailto:boleslaw dot dawidowicz at redhat anotherdot
com">Boleslaw Dawidowicz</a>
+ * @version $Revision: 0.1 $
+ */
+public class MainTestFilter implements TestFilter
+{
+
+ private List<TestFilter> includeFilters = new LinkedList();
+
+ private List<TestFilter> excludeFilters = new LinkedList();
+
+
+ public MainTestFilter()
+ {
+ }
+
+ public MainTestFilter(List<TestFilter> matchFilters, List<TestFilter>
excludeFilters)
+ {
+ if (matchFilters == null)
+ {
+ throw new IllegalArgumentException("includeFilters cannot be null");
+ }
+ if (excludeFilters == null)
+ {
+ throw new IllegalArgumentException("excludeFilters cannot be null");
+ }
+
+
+ this.includeFilters = matchFilters;
+ this.excludeFilters = excludeFilters;
+ }
+
+ public boolean include(TestId testId, TestInfo testInfo)
+ {
+
+ // First check if test isn't excluded
+
+ // Make logic OR on all filters
+
+ for (TestFilter ef : excludeFilters)
+ {
+ if (!ef.include(testId, testInfo))
+ {
+ return false;
+ }
+ }
+
+ // make logic OR on all match filters
+
+ for (TestFilter mf : includeFilters)
+ {
+ if (mf.include(testId, testInfo))
+ {
+ return true;
+ }
+
+ }
+
+
+ return false;
+ }
+
+ public boolean include(TestId testId, Map<String, String> parametrization,
TestInfo testInfo)
+ {
+
+ // At the moment no parametrization match
+
+ return include (testId, testInfo);
+ }
+
+ public void addIncludeFilter(TestFilter filter)
+ {
+ if (filter == null)
+ {
+ throw new IllegalArgumentException("filter cannot be null");
+ }
+ includeFilters.add(filter);
+ }
+
+ public void addExcludeFilter(TestFilter filter)
+ {
+ if (filter == null)
+ {
+ throw new IllegalArgumentException("filter cannot be null");
+ }
+ excludeFilters.add(filter);
+ }
+
+
+}