Author: julien(a)jboss.com
Date: 2007-10-10 18:50:59 -0400 (Wed, 10 Oct 2007)
New Revision: 8596
Added:
modules/test/trunk/unit/src/main/org/jboss/unit/runner/impl/generic/
modules/test/trunk/unit/src/main/org/jboss/unit/runner/impl/generic/GenericTestRunner.java
Log:
- minor javadoc
Added:
modules/test/trunk/unit/src/main/org/jboss/unit/runner/impl/generic/GenericTestRunner.java
===================================================================
---
modules/test/trunk/unit/src/main/org/jboss/unit/runner/impl/generic/GenericTestRunner.java
(rev 0)
+++
modules/test/trunk/unit/src/main/org/jboss/unit/runner/impl/generic/GenericTestRunner.java 2007-10-10
22:50:59 UTC (rev 8596)
@@ -0,0 +1,95 @@
+/******************************************************************************
+ * 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.runner.impl.generic;
+
+import org.jboss.unit.runner.AbstractTestRunner;
+import org.jboss.unit.runner.TestFilter;
+import org.jboss.unit.runner.ParametrizationSet;
+import org.jboss.unit.runner.event.TestRunnerLifeCycleFilter;
+import org.jboss.unit.runner.event.RunnerFailureEvent;
+import org.jboss.unit.runner.impl.driver.TestDriverRunner;
+import org.jboss.unit.runner.model.generic.GenericTestSuiteDef;
+import org.jboss.unit.runner.model.generic.TestDef;
+import org.jboss.unit.driver.TestDriver;
+import org.jboss.unit.TestId;
+import org.jboss.unit.Failure;
+
+import java.util.Collection;
+import java.util.Collections;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class GenericTestRunner extends AbstractTestRunner
+{
+
+ /** . */
+ private final GenericTestSuiteDef def;
+
+ /** . */
+ private final TestRunnerLifeCycleFilter lifeCycleFilter;
+
+ public GenericTestRunner(GenericTestSuiteDef def)
+ {
+ this.def = def;
+ this.lifeCycleFilter = new TestRunnerLifeCycleFilter(broadcaster);
+ }
+
+ protected void internalRun(TestFilter filter)
+ {
+ String className = def.getClassName();
+
+ //
+ try
+ {
+ Class<TestDriver> clazz =
(Class<TestDriver>)Thread.currentThread().getContextClassLoader().loadClass(className);
+ TestDriver driver = clazz.newInstance();
+
+ //
+ Collection<TestDef> testDefs = def.getTests();
+
+ // If nothing is provided we execute the whole suite
+ if (testDefs.isEmpty())
+ {
+ testDefs = Collections.singleton(new TestDef(new TestId("")));
+ }
+
+ for (TestDef testDef : testDefs)
+ {
+ // Create parametrization
+ ParametrizationSet parametrizations =
def.getParameters().getParametrization();
+ parametrizations.merge(testDef.getParameters().getParametrization());
+
+ //
+ TestDriverRunner runner = new TestDriverRunner(driver, parametrizations,
testDef.getRefId());
+ runner.addListener(lifeCycleFilter);
+ runner.run(filter);
+ }
+ }
+ catch (Exception e)
+ {
+ fireEvent(new RunnerFailureEvent(Failure.createErrorFailure("Cannot execute
test class " + className,e)));
+ }
+ }
+}