You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by jb...@apache.org on 2007/02/12 03:46:41 UTC
svn commit: r506233 - in
/incubator/tuscany/java/sca/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest:
MavenEmbeddedRuntime.java SCATestSet.java SCATestSuite.java
TuscanyITestMojo.java
Author: jboynes
Date: Sun Feb 11 18:46:40 2007
New Revision: 506233
URL: http://svn.apache.org/viewvc?view=rev&rev=506233
Log:
define a SurefireTestSuite for tests defined as SCA components
start introspecting junit components to find tests
Added:
incubator/tuscany/java/sca/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/SCATestSet.java (with props)
incubator/tuscany/java/sca/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/SCATestSuite.java (with props)
Modified:
incubator/tuscany/java/sca/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/MavenEmbeddedRuntime.java
incubator/tuscany/java/sca/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/TuscanyITestMojo.java
Modified: incubator/tuscany/java/sca/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/MavenEmbeddedRuntime.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/MavenEmbeddedRuntime.java?view=diff&rev=506233&r1=506232&r2=506233
==============================================================================
--- incubator/tuscany/java/sca/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/MavenEmbeddedRuntime.java (original)
+++ incubator/tuscany/java/sca/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/MavenEmbeddedRuntime.java Sun Feb 11 18:46:40 2007
@@ -18,7 +18,6 @@
*/
package org.apache.tuscany.sca.plugin.itest;
-import java.io.File;
import java.net.URI;
import org.apache.tuscany.core.runtime.AbstractRuntime;
@@ -57,17 +56,9 @@
this.artifactRepository = artifactRepository;
}
- public void deployTestScdl(File testScdl, ClassLoader testClassLoader) throws Exception {
+ public Component deployTestScdl(ComponentDefinition<CompositeImplementation> definition) throws Exception {
Deployer deployer = getDeployer();
-
- URI name = URI.create("itest://testDomain/");
- CompositeImplementation impl = new CompositeImplementation();
- impl.setScdlLocation(testScdl.toURI().toURL());
- impl.setClassLoader(testClassLoader);
-
- ComponentDefinition<CompositeImplementation> definition =
- new ComponentDefinition<CompositeImplementation>(name, impl);
- Component testComponent = deployer.deploy(null, definition);
+ return deployer.deploy(null, definition);
}
protected Deployer getDeployer() {
Added: incubator/tuscany/java/sca/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/SCATestSet.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/SCATestSet.java?view=auto&rev=506233
==============================================================================
--- incubator/tuscany/java/sca/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/SCATestSet.java (added)
+++ incubator/tuscany/java/sca/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/SCATestSet.java Sun Feb 11 18:46:40 2007
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.plugin.itest;
+
+import org.apache.maven.surefire.testset.SurefireTestSet;
+import org.apache.maven.surefire.testset.TestSetFailedException;
+import org.apache.maven.surefire.report.ReporterManager;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class SCATestSet implements SurefireTestSet {
+ private final String name;
+ private final int testCount;
+
+ public SCATestSet(String name, int testCount) {
+ this.name = name;
+ this.testCount = testCount;
+ }
+
+ public void execute(ReporterManager reporterManager, ClassLoader classLoader) throws TestSetFailedException {
+ }
+
+ public int getTestCount() {
+ return testCount;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public Class getTestClass() {
+ throw new UnsupportedOperationException();
+ }
+}
Propchange: incubator/tuscany/java/sca/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/SCATestSet.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/SCATestSet.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/SCATestSuite.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/SCATestSuite.java?view=auto&rev=506233
==============================================================================
--- incubator/tuscany/java/sca/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/SCATestSuite.java (added)
+++ incubator/tuscany/java/sca/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/SCATestSuite.java Sun Feb 11 18:46:40 2007
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.plugin.itest;
+
+import java.util.Map;
+import java.util.HashMap;
+
+import org.apache.maven.surefire.suite.SurefireTestSuite;
+import org.apache.maven.surefire.report.ReporterManager;
+import org.apache.maven.surefire.report.ReporterException;
+import org.apache.maven.surefire.testset.TestSetFailedException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class SCATestSuite implements SurefireTestSuite {
+ private final Map<String, SCATestSet> testSets = new HashMap<String, SCATestSet>();
+ private int testSetCount = 0;
+ private int testCount = 0;
+
+ public void add(SCATestSet testSet) {
+ testSets.put(testSet.getName(), testSet);
+ testSetCount += 1;
+ testCount += testSet.getTestCount();
+ }
+
+ public int getNumTests() {
+ return testCount;
+ }
+
+ public int getNumTestSets() {
+ return testSetCount;
+ }
+
+ public void execute(ReporterManager reporterManager, ClassLoader classLoader)
+ throws ReporterException, TestSetFailedException {
+ for (SCATestSet testSet : testSets.values()) {
+ execute(testSet, reporterManager, classLoader);
+ }
+ }
+
+ public void execute(String name, ReporterManager reporterManager, ClassLoader classLoader)
+ throws ReporterException, TestSetFailedException {
+ SCATestSet testSet = testSets.get(name);
+ if (testSet == null) {
+ throw new TestSetFailedException("Suite does not contain TestSet: " + name);
+ }
+ execute(testSet, reporterManager, classLoader);
+ }
+
+ protected void execute(SCATestSet testSet, ReporterManager reporterManager, ClassLoader classLoader)
+ throws ReporterException, TestSetFailedException {
+ testSet.execute(reporterManager, classLoader);
+ }
+
+ public Map locateTestSets(ClassLoader classLoader) throws TestSetFailedException {
+ throw new UnsupportedOperationException();
+ }
+}
Propchange: incubator/tuscany/java/sca/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/SCATestSuite.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/SCATestSuite.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: incubator/tuscany/java/sca/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/TuscanyITestMojo.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/TuscanyITestMojo.java?view=diff&rev=506233&r1=506232&r2=506233
==============================================================================
--- incubator/tuscany/java/sca/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/TuscanyITestMojo.java (original)
+++ incubator/tuscany/java/sca/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/TuscanyITestMojo.java Sun Feb 11 18:46:40 2007
@@ -19,31 +19,41 @@
package org.apache.tuscany.sca.plugin.itest;
import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.net.URI;
import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
import java.util.List;
import java.util.Properties;
-import java.util.Iterator;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.net.MalformedURLException;
+import java.util.Map;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.logging.Log;
-import org.apache.maven.surefire.junit.JUnitDirectoryTestSuite;
import org.apache.maven.surefire.report.BriefFileReporter;
+import org.apache.maven.surefire.report.Reporter;
import org.apache.maven.surefire.report.ReporterException;
import org.apache.maven.surefire.report.ReporterManager;
import org.apache.maven.surefire.suite.SurefireTestSuite;
import org.apache.maven.surefire.testset.TestSetFailedException;
-import org.apache.maven.artifact.resolver.ArtifactResolver;
-import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.artifact.factory.ArtifactFactory;
-import org.apache.tuscany.host.runtime.InitializationException;
import org.apache.tuscany.api.TuscanyRuntimeException;
+import org.apache.tuscany.host.runtime.InitializationException;
+import org.apache.tuscany.spi.model.CompositeImplementation;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.CompositeComponentType;
+import org.apache.tuscany.spi.model.Implementation;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.sca.plugin.itest.implementation.junit.ImplementationJUnit;
/**
* @version $Rev$ $Date$
@@ -156,23 +166,30 @@
throw new MojoExecutionException("Error initializing Tuscany runtime", e);
}
try {
+ SurefireTestSuite testSuite;
log.info("Deploying test SCDL from " + testScdl);
try {
// fixme this should probably be an isolated classloader
ClassLoader testClassLoader = createTestClassLoader(getClass().getClassLoader());
- runtime.deployTestScdl(testScdl, testClassLoader);
+ URI name = URI.create("itest://testDomain/");
+ CompositeImplementation impl = new CompositeImplementation();
+ impl.setScdlLocation(testScdl.toURI().toURL());
+ impl.setClassLoader(testClassLoader);
+
+ ComponentDefinition<CompositeImplementation> definition =
+ new ComponentDefinition<CompositeImplementation>(name, impl);
+ Component testComponent = runtime.deployTestScdl(definition);
+ testSuite = createTestSuite(definition, testComponent);
} catch (Exception e) {
throw new MojoExecutionException("Error deploying test component " + testScdl, e);
}
-/*
log.info("Executing tests...");
- boolean success = runSurefire();
+ boolean success = runSurefire(testSuite);
if (!success) {
String msg = "There were test failures";
throw new MojoFailureException(msg);
}
-*/
} finally {
log.info("Stopping Tuscany...");
try {
@@ -183,12 +200,10 @@
}
}
- public boolean runSurefire() throws MojoExecutionException {
- // FIXME get classloader for tests
- ClassLoader testsClassLoader = null;
+ public boolean runSurefire(SurefireTestSuite testSuite) throws MojoExecutionException {
try {
Properties status = new Properties();
- boolean success = run(testsClassLoader, status);
+ boolean success = run(testSuite, status);
getLog().info("Test results: "+status);
return success;
} catch (ReporterException e) {
@@ -198,31 +213,20 @@
}
}
- public boolean run(ClassLoader testsClassLoader, Properties status) throws ReporterException,
- TestSetFailedException {
- List reports = new ArrayList();
- reports.add(new BriefFileReporter(reportsDirectory, trimStackTrace));
+ public boolean run(SurefireTestSuite suite, Properties status) throws ReporterException, TestSetFailedException {
+ int totalTests = suite.getNumTests();
+
+ Reporter reporter = new BriefFileReporter(reportsDirectory, trimStackTrace);
+ List<Reporter> reports = Collections.singletonList(reporter);
ReporterManager reporterManager = new ReporterManager(reports);
reporterManager.initResultsFromProperties(status);
- List suites = new ArrayList();
-
- int totalTests = 0;
- SurefireTestSuite suite =
- new JUnitDirectoryTestSuite(testClassesDirectory, (ArrayList)includes, (ArrayList)excludes);
- suite.locateTestSets(testsClassLoader);
-
- int testCount = suite.getNumTests();
- if (testCount > 0) {
- suites.add(suite);
- totalTests += testCount;
- }
reporterManager.runStarting(totalTests);
if (totalTests == 0) {
reporterManager.writeMessage("There are no tests to run.");
} else {
- suite.execute(reporterManager, testsClassLoader);
+ suite.execute(reporterManager, null);
}
reporterManager.runCompleted();
@@ -266,5 +270,33 @@
}
return new URLClassLoader(urls, parent);
+ }
+
+ protected SurefireTestSuite createTestSuite(ComponentDefinition<CompositeImplementation> definition,
+ Component testComponent) {
+ SCATestSuite suite = new SCATestSuite();
+ String uriBase = testComponent.getUri().toString();
+
+ CompositeImplementation impl = definition.getImplementation();
+ CompositeComponentType<?,?,?> componentType = impl.getComponentType();
+ Map<String, ComponentDefinition<? extends Implementation<?>>> components = componentType.getComponents();
+ for (Map.Entry<String, ComponentDefinition<? extends Implementation<?>>> entry : components.entrySet()) {
+ String name = entry.getKey();
+ ComponentDefinition<? extends Implementation<?>> junitDefinition = entry.getValue();
+ Implementation<?> implementation = junitDefinition.getImplementation();
+ if (ImplementationJUnit.class.isAssignableFrom(implementation.getClass())) {
+ String testSetName = uriBase + name;
+ SCATestSet testSet = createTestSet(testSetName, junitDefinition);
+ suite.add(testSet);
+ }
+ }
+ return suite;
+ }
+
+ protected SCATestSet createTestSet(String name, ComponentDefinition definition) {
+ ImplementationJUnit impl = (ImplementationJUnit) definition.getImplementation();
+ PojoComponentType componentType = impl.getComponentType();
+ Map services = componentType.getServices();
+ return new SCATestSet(name, 1);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org