summaryrefslogtreecommitdiffstats
path: root/sandbox/old/contrib/runtime-itest/plugin/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'sandbox/old/contrib/runtime-itest/plugin/src/main/java/org')
-rw-r--r--sandbox/old/contrib/runtime-itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/Dependency.java81
-rw-r--r--sandbox/old/contrib/runtime-itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/MavenEmbeddedArtifactRepository.java159
-rw-r--r--sandbox/old/contrib/runtime-itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/MavenEmbeddedRuntime.java88
-rw-r--r--sandbox/old/contrib/runtime-itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/MavenMonitorFactory.java136
-rw-r--r--sandbox/old/contrib/runtime-itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/MavenRuntimeInfo.java56
-rw-r--r--sandbox/old/contrib/runtime-itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/SCATestSet.java81
-rw-r--r--sandbox/old/contrib/runtime-itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/SCATestSuite.java79
-rw-r--r--sandbox/old/contrib/runtime-itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/TuscanyITestMojo.java429
-rw-r--r--sandbox/old/contrib/runtime-itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/implementation/junit/ImplementationJUnit.java56
-rw-r--r--sandbox/old/contrib/runtime-itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/implementation/junit/ImplementationJUnitLoader.java54
-rw-r--r--sandbox/old/contrib/runtime-itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/implementation/junit/JUnitComponentBuilder.java192
-rw-r--r--sandbox/old/contrib/runtime-itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/implementation/junit/JUnitComponentTypeLoader.java146
-rw-r--r--sandbox/old/contrib/runtime-itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/implementation/junit/JUnitServiceContract.java35
13 files changed, 1592 insertions, 0 deletions
diff --git a/sandbox/old/contrib/runtime-itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/Dependency.java b/sandbox/old/contrib/runtime-itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/Dependency.java
new file mode 100644
index 0000000000..4f3f6b0f10
--- /dev/null
+++ b/sandbox/old/contrib/runtime-itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/Dependency.java
@@ -0,0 +1,81 @@
+/*
+ * 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.artifact.Artifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+
+/**
+ * Represents a configured tuscany dependency for boot and extension libraries.
+ *
+ * @version $Rev$ $Date$
+ */
+public class Dependency {
+
+ /**
+ * JAR type artifact.
+ */
+ private static final String TYPE_JAR = "jar";
+
+ /**
+ * Group Id that is injected in from configuration.
+ */
+ private String groupId;
+
+ /**
+ * Artifact Id that is injected in from configuration.
+ */
+ private String artifactId;
+
+ /**
+ * Version that is injected in from configuration.
+ */
+ private String version;
+
+ /**
+ * Default constructor.
+ */
+ public Dependency() {
+ }
+
+ /**
+ * Initializes the field.
+ *
+ * @param groupId Group id.
+ * @param artifactId Artifact id.
+ * @param version Artifact version.
+ */
+ public Dependency(String groupId, String artifactId, String version) {
+ super();
+ this.groupId = groupId;
+ this.artifactId = artifactId;
+ this.version = version;
+ }
+
+ /**
+ * Gets the artifact using the specified artifact factory.
+ *
+ * @param artifactFactory Artifact factory to use.
+ * @return Artifact identified by the dependency.
+ */
+ public Artifact getArtifact(ArtifactFactory artifactFactory) {
+ return artifactFactory.createArtifact(groupId, artifactId, version, Artifact.SCOPE_RUNTIME, TYPE_JAR);
+ }
+
+}
diff --git a/sandbox/old/contrib/runtime-itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/MavenEmbeddedArtifactRepository.java b/sandbox/old/contrib/runtime-itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/MavenEmbeddedArtifactRepository.java
new file mode 100644
index 0000000000..282099062d
--- /dev/null
+++ b/sandbox/old/contrib/runtime-itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/MavenEmbeddedArtifactRepository.java
@@ -0,0 +1,159 @@
+/*
+ * 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.net.MalformedURLException;
+import java.net.URI;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
+import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
+import org.apache.maven.artifact.metadata.ResolutionGroup;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
+import org.apache.maven.artifact.resolver.ArtifactResolutionException;
+import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
+import org.apache.maven.artifact.resolver.ArtifactResolver;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class MavenEmbeddedArtifactRepository implements org.apache.tuscany.spi.services.artifact.ArtifactRepository {
+ public static final URI COMPONENT_NAME = URI.create("MavenEmbeddedArtifactRepository");
+
+ private ArtifactFactory artifactFactory;
+ private ArtifactResolver resolver;
+ private ArtifactMetadataSource metadataSource;
+ private ArtifactRepository localRepository;
+ private List remoteRepositories;
+
+ public MavenEmbeddedArtifactRepository(ArtifactFactory artifactFactory,
+ ArtifactResolver resolver,
+ ArtifactMetadataSource metadataSource,
+ ArtifactRepository localRepository,
+ List remoteRepositories) {
+ this.artifactFactory = artifactFactory;
+ this.resolver = resolver;
+ this.metadataSource = metadataSource;
+ this.localRepository = localRepository;
+ this.remoteRepositories = remoteRepositories;
+ }
+
+ public void resolve(org.apache.tuscany.spi.services.artifact.Artifact artifact) {
+ resolveTransitively(artifact);
+ }
+
+ public void resolve(Collection artifacts) {
+ for (Object a : artifacts) {
+ resolve((Artifact) a);
+ }
+ }
+
+ /**
+ * Resolves the dependencies transitively.
+ *
+ * @param rootArtifact Artifact whose dependencies need to be resolved.
+ * @return true if all dependencies were resolved
+ */
+ public boolean resolveTransitively(org.apache.tuscany.spi.services.artifact.Artifact rootArtifact) {
+
+ Artifact mavenRootArtifact =
+ artifactFactory.createArtifact(rootArtifact.getGroup(), rootArtifact.getName(), rootArtifact
+ .getVersion(), Artifact.SCOPE_RUNTIME, rootArtifact.getType());
+
+ try {
+
+ if (resolve(mavenRootArtifact)) {
+ rootArtifact.setUrl(mavenRootArtifact.getFile().toURL());
+ return resolveDependencies(rootArtifact, mavenRootArtifact);
+ } else {
+ return false;
+ }
+ } catch (MalformedURLException ex) {
+ throw new IllegalArgumentException(ex);
+ }
+
+ }
+
+ /*
+ * Resolves the artifact.
+ */
+ private boolean resolve(Artifact mavenRootArtifact) {
+
+ try {
+ resolver.resolve(mavenRootArtifact, remoteRepositories, localRepository);
+ return true;
+ } catch (ArtifactResolutionException ex) {
+ return false;
+ } catch (ArtifactNotFoundException ex) {
+ return false;
+ }
+
+ }
+
+ /*
+ * Resolves transitive dependencies.
+ */
+ private boolean resolveDependencies(org.apache.tuscany.spi.services.artifact.Artifact rootArtifact,
+ Artifact mavenRootArtifact) {
+
+ try {
+
+ ResolutionGroup resolutionGroup = metadataSource.retrieve(mavenRootArtifact,
+ localRepository,
+ remoteRepositories);
+
+ ArtifactResolutionResult result = resolver.resolveTransitively(resolutionGroup.getArtifacts(),
+ mavenRootArtifact,
+ remoteRepositories,
+ localRepository,
+ metadataSource);
+
+ // Add the artifacts to the deployment unit
+ for (Object obj : result.getArtifacts()) {
+ Artifact depArtifact = (Artifact) obj;
+ org.apache.tuscany.spi.services.artifact.Artifact artifact =
+ new org.apache.tuscany.spi.services.artifact.Artifact();
+ artifact.setName(depArtifact.getArtifactId());
+ artifact.setGroup(depArtifact.getGroupId());
+ artifact.setType(depArtifact.getType());
+ artifact.setClassifier(depArtifact.getClassifier());
+ artifact.setUrl(depArtifact.getFile().toURL());
+ artifact.setVersion(depArtifact.getVersion());
+ rootArtifact.addDependency(artifact);
+ }
+
+ } catch (ArtifactMetadataRetrievalException ex) {
+ return false;
+ } catch (MalformedURLException ex) {
+ throw new IllegalArgumentException(ex);
+ } catch (ArtifactResolutionException ex) {
+ return false;
+ } catch (ArtifactNotFoundException ex) {
+ return false;
+ }
+
+ return true;
+
+ }
+
+}
diff --git a/sandbox/old/contrib/runtime-itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/MavenEmbeddedRuntime.java b/sandbox/old/contrib/runtime-itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/MavenEmbeddedRuntime.java
new file mode 100644
index 0000000000..407b07e72e
--- /dev/null
+++ b/sandbox/old/contrib/runtime-itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/MavenEmbeddedRuntime.java
@@ -0,0 +1,88 @@
+/*
+ * 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.net.URI;
+import java.util.Collection;
+
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.component.GroupInitializationException;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.deployer.Deployer;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.CompositeImplementation;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.services.artifact.ArtifactRepository;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+
+import org.apache.maven.plugin.logging.Log;
+import org.apache.tuscany.core.runtime.AbstractRuntime;
+import org.apache.tuscany.core.component.SimpleWorkContext;
+import org.apache.tuscany.core.implementation.PojoWorkContextTunnel;
+import org.apache.tuscany.host.MonitorFactory;
+import org.apache.tuscany.host.runtime.InitializationException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class MavenEmbeddedRuntime extends AbstractRuntime<MavenRuntimeInfo> {
+ private ArtifactRepository artifactRepository;
+
+ public MavenEmbeddedRuntime(Log log) {
+ super(MavenRuntimeInfo.class);
+ MonitorFactory monitorFactory = new MavenMonitorFactory(log);
+ setMonitorFactory(monitorFactory);
+ }
+
+ protected void registerBaselineSystemComponents() throws InitializationException {
+ super.registerBaselineSystemComponents();
+ registerSystemComponent(MavenEmbeddedArtifactRepository.COMPONENT_NAME,
+ ArtifactRepository.class,
+ artifactRepository);
+ }
+
+ public void setArtifactRepository(ArtifactRepository artifactRepository) {
+ this.artifactRepository = artifactRepository;
+ }
+
+ public Collection<Component> deployTestScdl(ComponentDefinition<CompositeImplementation> definition)
+ throws Exception {
+ Deployer deployer = getDeployer();
+ return deployer.deploy(null, definition);
+ }
+
+ public void startContext(URI compositeId) throws GroupInitializationException {
+ getScopeRegistry().getScopeContainer(Scope.COMPOSITE).startContext(compositeId, compositeId);
+ }
+
+ public void executeTest(URI contextId, URI componentId, Operation<?> operation) throws Exception {
+ Component testComponent = getComponentManager().getComponent(componentId);
+ TargetInvoker targetInvoker = testComponent.createTargetInvoker("testService", operation);
+ getWorkContext().setIdentifier(Scope.COMPOSITE, contextId);
+ WorkContext workContext = new SimpleWorkContext();
+ workContext.setIdentifier(Scope.COMPOSITE, contextId);
+ PojoWorkContextTunnel.setThreadWorkContext(workContext);
+ try {
+ targetInvoker.invokeTarget(null, TargetInvoker.NONE, workContext);
+ } finally {
+ getWorkContext().clearIdentifier(Scope.COMPOSITE);
+ }
+ }
+}
diff --git a/sandbox/old/contrib/runtime-itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/MavenMonitorFactory.java b/sandbox/old/contrib/runtime-itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/MavenMonitorFactory.java
new file mode 100644
index 0000000000..0fd4aa7d59
--- /dev/null
+++ b/sandbox/old/contrib/runtime-itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/MavenMonitorFactory.java
@@ -0,0 +1,136 @@
+/*
+ * 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.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.util.Map;
+import java.util.ResourceBundle;
+import java.util.HashMap;
+import java.util.logging.Level;
+import java.text.MessageFormat;
+
+import org.apache.maven.plugin.logging.Log;
+
+import org.apache.tuscany.core.monitor.ProxyMonitorFactory;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class MavenMonitorFactory extends ProxyMonitorFactory {
+ private final Log log;
+
+ public MavenMonitorFactory(Log log) {
+ this.log = log;
+ Map<String, Object> configProperties = new HashMap<String, Object>();
+ configProperties.put("defaultLevel", Level.FINEST);
+ initInternal(configProperties);
+ }
+
+ protected <T> InvocationHandler createInvocationHandler(Class<T> monitorInterface, Map<String, Level> levels) {
+ ResourceBundle bundle = locateBundle(monitorInterface, bundleName);
+ return new MonitorHandler(monitorInterface.getName(), levels, bundle);
+ }
+
+ private class MonitorHandler implements InvocationHandler {
+ private final String monitorName;
+ private final Map<String, Level> methodLevels;
+ private final ResourceBundle bundle;
+
+ public MonitorHandler(String monitorName, Map<String, Level> methodLevels, ResourceBundle bundle) {
+ this.monitorName = monitorName;
+ this.methodLevels = methodLevels;
+ this.bundle = bundle;
+ }
+
+ public Object invoke(Object object, Method method, Object[] objects) throws Throwable {
+ String sourceMethod = method.getName();
+ Level level = methodLevels.get(sourceMethod);
+ if (level == Level.OFF) {
+ return null;
+ }
+
+ int value = level.intValue();
+ if (isLogEnabled(value)) {
+ String key = monitorName + '#' + sourceMethod;
+ String message;
+ if (bundle != null) {
+ message = bundle.getString(key);
+ } else {
+ message = null;
+ }
+ if (message != null) {
+ message = MessageFormat.format(message, objects);
+ } else {
+ StringBuilder builder = new StringBuilder();
+ builder.append(key).append(":");
+ for (Object o : objects) {
+ builder.append(' ');
+ if (o instanceof Throwable) {
+ builder.append(formatException((Throwable) o));
+ } else {
+ builder.append(String.valueOf(o));
+ }
+ }
+ message = builder.toString();
+ }
+ Throwable cause = getFirstException(objects);
+ if (cause != null) {
+ if (value >= Level.SEVERE.intValue()) {
+ log.error(message, cause);
+ } else if (value >= Level.WARNING.intValue()) {
+ log.warn(message, cause);
+ } else if (value >= Level.INFO.intValue()) {
+ log.info(message, cause);
+ } else if (value >= Level.FINEST.intValue()) {
+ log.debug(message, cause);
+ }
+ } else {
+ if (value >= Level.SEVERE.intValue()) {
+ log.error(message);
+ } else if (value >= Level.WARNING.intValue()) {
+ log.warn(message);
+ } else if (value >= Level.INFO.intValue()) {
+ log.info(message);
+ } else if (value >= Level.FINEST.intValue()) {
+ log.debug(message);
+ }
+ }
+ }
+
+ return null;
+ }
+
+ private boolean isLogEnabled(int value) {
+ return log.isDebugEnabled() && value >= Level.FINEST.intValue()
+ || log.isInfoEnabled() && value >= Level.INFO.intValue()
+ || log.isWarnEnabled() && value >= Level.WARNING.intValue()
+ || log.isErrorEnabled() && value >= Level.SEVERE.intValue();
+ }
+
+ private Throwable getFirstException(Object[] objects) {
+ for (Object object : objects) {
+ if (object instanceof Throwable) {
+ return (Throwable) object;
+ }
+ }
+ return null;
+ }
+ }
+}
diff --git a/sandbox/old/contrib/runtime-itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/MavenRuntimeInfo.java b/sandbox/old/contrib/runtime-itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/MavenRuntimeInfo.java
new file mode 100644
index 0000000000..f6a4e1f52c
--- /dev/null
+++ b/sandbox/old/contrib/runtime-itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/MavenRuntimeInfo.java
@@ -0,0 +1,56 @@
+/*
+ * 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.io.File;
+import java.net.URL;
+import java.net.URI;
+
+import org.apache.tuscany.host.RuntimeInfo;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class MavenRuntimeInfo implements RuntimeInfo {
+ public static final URI COMPONENT_NAME = URI.create("MavenRuntimeInfo");
+
+ public File getInstallDirectory() {
+ throw new UnsupportedOperationException();
+ }
+
+ public File getApplicationRootDirectory() {
+ throw new UnsupportedOperationException();
+ }
+
+ public URL getBaseURL() {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean isOnline() {
+ throw new UnsupportedOperationException();
+ }
+
+ public URI getDomain() {
+ throw new UnsupportedOperationException();
+ }
+
+ public String getRuntimeId() {
+ throw new UnsupportedOperationException();
+ }
+}
diff --git a/sandbox/old/contrib/runtime-itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/SCATestSet.java b/sandbox/old/contrib/runtime-itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/SCATestSet.java
new file mode 100644
index 0000000000..9e3d0d3f55
--- /dev/null
+++ b/sandbox/old/contrib/runtime-itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/SCATestSet.java
@@ -0,0 +1,81 @@
+/*
+ * 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.Collection;
+import java.net.URI;
+
+import org.apache.maven.surefire.testset.SurefireTestSet;
+import org.apache.maven.surefire.testset.TestSetFailedException;
+import org.apache.maven.surefire.report.ReporterManager;
+import org.apache.maven.surefire.report.ReportEntry;
+import org.apache.maven.surefire.report.StackTraceWriter;
+import org.apache.maven.surefire.report.PojoStackTraceWriter;
+
+import org.apache.tuscany.spi.model.Operation;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class SCATestSet implements SurefireTestSet {
+ private final MavenEmbeddedRuntime runtime;
+ private final String name;
+ private final URI contextId;
+ private final URI componentId;
+ private final Collection<? extends Operation<?>> operations;
+
+ public SCATestSet(MavenEmbeddedRuntime runtime,
+ String name,
+ URI contextId,
+ URI uri,
+ Collection<? extends Operation<?>> operations) {
+ this.runtime = runtime;
+ this.name = name;
+ this.contextId = contextId;
+ this.componentId = uri;
+ this.operations = operations;
+ }
+
+ public void execute(ReporterManager reporterManager, ClassLoader classLoader) throws TestSetFailedException {
+ for (Operation<?> operation : operations) {
+ String operationName = operation.getName();
+ reporterManager.testStarting(new ReportEntry(this, operationName, name));
+ try {
+ runtime.executeTest(contextId, componentId, operation);
+ reporterManager.testSucceeded(new ReportEntry(this, operationName, name));
+ } catch (Exception e) {
+ StackTraceWriter stw = new PojoStackTraceWriter(name, operationName, e);
+ reporterManager.testFailed(new ReportEntry(this, operationName, name, stw));
+ throw new TestSetFailedException(e);
+ }
+ }
+ }
+
+ public int getTestCount() {
+ return operations.size();
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public Class getTestClass() {
+ throw new UnsupportedOperationException();
+ }
+}
diff --git a/sandbox/old/contrib/runtime-itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/SCATestSuite.java b/sandbox/old/contrib/runtime-itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/SCATestSuite.java
new file mode 100644
index 0000000000..1029b70733
--- /dev/null
+++ b/sandbox/old/contrib/runtime-itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/SCATestSuite.java
@@ -0,0 +1,79 @@
+/*
+ * 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.report.ReportEntry;
+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 {
+ reporterManager.testSetStarting(new ReportEntry(this, testSet.getName(), "Starting"));
+ testSet.execute(reporterManager, classLoader);
+ reporterManager.testSetCompleted(new ReportEntry(this, testSet.getName(), "Completed"));
+ reporterManager.reset();
+ }
+
+ public Map locateTestSets(ClassLoader classLoader) throws TestSetFailedException {
+ throw new UnsupportedOperationException();
+ }
+}
diff --git a/sandbox/old/contrib/runtime-itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/TuscanyITestMojo.java b/sandbox/old/contrib/runtime-itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/TuscanyITestMojo.java
new file mode 100644
index 0000000000..78cd505a67
--- /dev/null
+++ b/sandbox/old/contrib/runtime-itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/TuscanyITestMojo.java
@@ -0,0 +1,429 @@
+/*
+ * 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.io.File;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Collection;
+import java.util.Set;
+import java.util.HashSet;
+
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
+import org.apache.maven.artifact.metadata.ResolutionGroup;
+import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.resolver.ArtifactResolver;
+import org.apache.maven.artifact.resolver.ArtifactResolutionException;
+import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
+import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
+import org.apache.maven.artifact.Artifact;
+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.report.BriefConsoleReporter;
+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.tuscany.api.TuscanyRuntimeException;
+import org.apache.tuscany.api.annotation.LogLevel;
+import org.apache.tuscany.host.runtime.InitializationException;
+import org.apache.tuscany.sca.plugin.itest.implementation.junit.ImplementationJUnit;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.CompositeComponentType;
+import org.apache.tuscany.spi.model.CompositeImplementation;
+import org.apache.tuscany.spi.model.Implementation;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.deployer.CompositeClassLoader;
+
+/**
+ * Integration-tests an SCA composite by running it in local copy of Apache Tuscany
+ * and calling JUnit-based test components to exercise it.
+ *
+ * @version $Rev$ $Date$
+ * @goal test
+ * @phase integration-test
+ */
+public class TuscanyITestMojo extends AbstractMojo {
+ /**
+ * The directory where reports will be written.
+ *
+ * @parameter expression="${project.build.directory}/surefire-reports"
+ */
+ public File reportsDirectory;
+
+ /**
+ * Whether to trim the stack trace in the reports to just the lines within
+ * the test, or show the full trace.
+ *
+ * @parameter expression="${trimStackTrace}" default-value="true"
+ */
+ public boolean trimStackTrace;
+
+ /**
+ * The directory containing generated test classes of the project being tested.
+ *
+ * @parameter expression="${project.build.testOutputDirectory}"
+ * @required
+ */
+ public File testClassesDirectory;
+
+ /**
+ * The SCA domain in which to deploy the test components.
+ *
+ * @parameter expression="itest://localhost/testDomain/"
+ * @required
+ */
+ public String testDomain;
+
+ /**
+ * The name of the component that will be implemented by the test harness composite.
+ *
+ * @parameter expression="testHarness"
+ * @required
+ */
+ public String testComponentName;
+
+ /**
+ * The location if the SCDL that defines the test harness composite.
+ * The source for this would normally be placed in the test/resources
+ * directory and be copied by the resource plugin; this allows property
+ * substitution if required.
+ *
+ * @parameter expression="${project.build.testOutputDirectory}/itest.scdl"
+ */
+ public File testScdl;
+
+ /**
+ * The location of the SCDL that configures the Apache Tuscany runtime.
+ * This allows the default runtime configuration supplied in this plugin
+ * to be overridden.
+ *
+ * @parameter
+ */
+ public URL systemScdl;
+
+ /**
+ * Set of extension artifacts that should be deployed to the runtime.
+ *
+ * @parameter
+ */
+ public Dependency[] extensions;
+
+ /**
+ * @parameter expression="${project.testClasspathElements}"
+ * @required
+ * @readonly
+ */
+ public List<String> testClassPath;
+
+ /**
+ * Used to look up Artifacts in the remote repository.
+ *
+ * @parameter expression="${component.org.apache.maven.artifact.resolver.ArtifactResolver}"
+ * @required
+ * @readonly
+ */
+ public ArtifactResolver resolver;
+
+ /**
+ * Used to look up Artifacts in the remote repository.
+ *
+ * @parameter expression="${component.org.apache.maven.artifact.metadata.ArtifactMetadataSource}"
+ * @required
+ * @readonly
+ */
+ public ArtifactMetadataSource metadataSource;
+
+ /**
+ * Location of the local repository.
+ *
+ * @parameter expression="${localRepository}"
+ * @readonly
+ * @required
+ */
+ public ArtifactRepository localRepository;
+
+ /**
+ * List of Remote Repositories used by the resolver
+ *
+ * @parameter expression="${project.remoteArtifactRepositories}"
+ * @readonly
+ * @required
+ */
+ public List remoteRepositories;
+
+ /**
+ * Used to look up Artifacts in the remote repository.
+ *
+ * @parameter expression="${component.org.apache.maven.artifact.factory.ArtifactFactory}"
+ * @required
+ * @readonly
+ */
+ public ArtifactFactory artifactFactory;
+ private MojoMonitor monitor;
+
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ Log log = getLog();
+ if (!testScdl.exists()) {
+ log.info("No itest SCDL found, skipping integration tests");
+ return;
+ }
+
+ log.info("Starting Tuscany...");
+ ClassLoader cl = createHostClassLoader(getClass().getClassLoader(), extensions);
+ MavenEmbeddedRuntime runtime = createRuntime(cl);
+ MavenMonitorFactory monitorFactory = new MavenMonitorFactory(log);
+ runtime.setMonitorFactory(monitorFactory);
+ monitor = monitorFactory.getMonitor(MojoMonitor.class);
+ try {
+ runtime.initialize();
+ } catch (InitializationException e) {
+ 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());
+
+ URI domain = URI.create(testDomain);
+ String harnessComponentName = testComponentName;
+ URI componentName = domain.resolve(harnessComponentName);
+ URI base = domain.resolve(harnessComponentName + "/");
+
+ CompositeImplementation impl = new CompositeImplementation();
+ impl.setScdlLocation(testScdl.toURI().toURL());
+ impl.setClassLoader(testClassLoader);
+
+ ComponentDefinition<CompositeImplementation> definition =
+ new ComponentDefinition<CompositeImplementation>(componentName, impl);
+ Collection<Component> testComponent = runtime.deployTestScdl(definition);
+ testSuite = createTestSuite(runtime, definition, base);
+ for (Component component : testComponent) {
+ component.start();
+ }
+
+ runtime.startContext(componentName);
+ } catch (Exception e) {
+ monitor.runError(e);
+ throw new MojoExecutionException("Error deploying test component " + testScdl, e);
+ }
+ log.info("Executing tests...");
+
+ boolean success = runSurefire(testSuite);
+ if (!success) {
+ String msg = "There were test failures";
+ throw new MojoFailureException(msg);
+ }
+ } finally {
+ log.info("Stopping Tuscany...");
+ try {
+ runtime.destroy();
+ } catch (TuscanyRuntimeException e) {
+ monitor.runError(e);
+ }
+ }
+ }
+
+ protected ClassLoader createHostClassLoader(ClassLoader parent, Dependency[] extensions)
+ throws MojoExecutionException {
+ if (extensions == null || extensions.length == 0) {
+ return parent;
+ }
+
+ Set<Artifact> artifacts = new HashSet<Artifact>();
+ for (Dependency extension : extensions) {
+ Artifact artifact = extension.getArtifact(artifactFactory);
+ try {
+ resolver.resolve(artifact, remoteRepositories, localRepository);
+ ResolutionGroup resolutionGroup = metadataSource.retrieve(artifact,
+ localRepository,
+ remoteRepositories);
+ ArtifactResolutionResult result = resolver.resolveTransitively(resolutionGroup.getArtifacts(),
+ artifact,
+ remoteRepositories,
+ localRepository,
+ metadataSource);
+ artifacts.add(artifact);
+ artifacts.addAll(result.getArtifacts());
+ } catch (ArtifactResolutionException e) {
+ throw new MojoExecutionException(e.getMessage(), e);
+ } catch (ArtifactNotFoundException e) {
+ throw new MojoExecutionException(e.getMessage(), e);
+ } catch (ArtifactMetadataRetrievalException e) {
+ throw new MojoExecutionException(e.getMessage(), e);
+ }
+ }
+ URL[] urls = new URL[artifacts.size()];
+ int i = 0;
+ for (Artifact artifact : artifacts) {
+ File file = artifact.getFile();
+ assert file != null;
+ try {
+ urls[i++] = file.toURI().toURL();
+ } catch (MalformedURLException e) {
+ // toURI should have made this valid
+ throw new AssertionError();
+ }
+ }
+
+ Log log = getLog();
+ if (log.isDebugEnabled()) {
+ log.debug("Tuscany extension classpath:");
+ for (URL url : urls) {
+ log.debug(" " + url);
+ }
+ }
+
+ return new CompositeClassLoader(null, urls, parent);
+ }
+
+ public boolean runSurefire(SurefireTestSuite testSuite) throws MojoExecutionException {
+ try {
+ Properties status = new Properties();
+ boolean success = run(testSuite, status);
+ getLog().debug("Test results: "+status);
+ return success;
+ } catch (ReporterException e) {
+ throw new MojoExecutionException(e.getMessage(), e);
+ } catch (TestSetFailedException e) {
+ throw new MojoExecutionException(e.getMessage(), e);
+ }
+ }
+
+ public boolean run(SurefireTestSuite suite, Properties status) throws ReporterException, TestSetFailedException {
+ int totalTests = suite.getNumTests();
+
+ List<Reporter> reports = new ArrayList<Reporter>();
+ reports.add(new BriefFileReporter(reportsDirectory, trimStackTrace));
+ reports.add(new BriefConsoleReporter(trimStackTrace));
+ ReporterManager reporterManager = new ReporterManager(reports);
+ reporterManager.initResultsFromProperties(status);
+
+ reporterManager.runStarting(totalTests);
+
+ if (totalTests == 0) {
+ reporterManager.writeMessage("There are no tests to run.");
+ } else {
+ suite.execute(reporterManager, null);
+ }
+
+ reporterManager.runCompleted();
+ reporterManager.updateResultsProperties(status);
+ return reporterManager.getNumErrors() == 0 && reporterManager.getNumFailures() == 0;
+ }
+
+ protected MavenEmbeddedRuntime createRuntime(ClassLoader hostClassLoader) throws MojoExecutionException {
+ if (systemScdl == null) {
+ systemScdl = hostClassLoader.getResource("META-INF/tuscany/embeddedMaven.scdl");
+ }
+
+ MavenRuntimeInfo runtimeInfo = new MavenRuntimeInfo();
+ MavenEmbeddedArtifactRepository artifactRepository = new MavenEmbeddedArtifactRepository(artifactFactory,
+ resolver,
+ metadataSource,
+ localRepository,
+ remoteRepositories);
+ MavenEmbeddedRuntime runtime = new MavenEmbeddedRuntime(getLog());
+ runtime.setRuntimeInfo(runtimeInfo);
+ runtime.setSystemScdl(systemScdl);
+ runtime.setHostClassLoader(hostClassLoader);
+ runtime.setArtifactRepository(artifactRepository);
+ return runtime;
+ }
+
+ public ClassLoader createTestClassLoader(ClassLoader parent) {
+ URL[] urls = new URL[testClassPath.size()];
+ int idx = 0;
+ for (String s : testClassPath) {
+ File pathElement = new File(s);
+ try {
+ URL url = pathElement.toURI().toURL();
+ getLog().debug("Adding application URL: " + url);
+ urls[idx++] = url;
+ } catch (MalformedURLException e) {
+ // toURI should have encoded the URL
+ throw new AssertionError();
+ }
+
+ }
+ return new URLClassLoader(urls, parent);
+ }
+
+ protected SurefireTestSuite createTestSuite(MavenEmbeddedRuntime runtime,
+ ComponentDefinition<CompositeImplementation> definition,
+ URI uriBase) throws MojoExecutionException {
+ SCATestSuite suite = new SCATestSuite();
+
+ URI contextId = definition.getUri();
+ 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())) {
+ URI uri = uriBase.resolve(name);
+ SCATestSet testSet = createTestSet(runtime, name, contextId, uri, junitDefinition);
+ suite.add(testSet);
+ }
+ }
+ return suite;
+ }
+
+ protected SCATestSet createTestSet(MavenEmbeddedRuntime runtime,
+ String name,
+ URI contextId,
+ URI uri,
+ ComponentDefinition definition) throws MojoExecutionException {
+ ImplementationJUnit impl = (ImplementationJUnit) definition.getImplementation();
+ PojoComponentType componentType = impl.getComponentType();
+ Map services = componentType.getServices();
+ JavaMappedService testService = (JavaMappedService) services.get("testService");
+ if (testService == null) {
+ throw new MojoExecutionException("No testService defined on component: " + definition.getUri());
+ }
+ Map<String, ? extends Operation<?>> operations = testService.getServiceContract().getOperations();
+ return new SCATestSet(runtime, name, contextId, uri, operations.values());
+ }
+
+ public interface MojoMonitor {
+ @LogLevel("SEVERE")
+ void runError(Exception e);
+ }
+
+}
diff --git a/sandbox/old/contrib/runtime-itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/implementation/junit/ImplementationJUnit.java b/sandbox/old/contrib/runtime-itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/implementation/junit/ImplementationJUnit.java
new file mode 100644
index 0000000000..592cd91a76
--- /dev/null
+++ b/sandbox/old/contrib/runtime-itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/implementation/junit/ImplementationJUnit.java
@@ -0,0 +1,56 @@
+/*
+ * 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.implementation.junit;
+
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.model.AtomicImplementation;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ImplementationJUnit extends AtomicImplementation<PojoComponentType> {
+ private String className;
+
+ /**
+ * Constructor supplying the name of the JUnit test class
+ *
+ * @param className the name of the JUnit test class
+ */
+ public ImplementationJUnit(String className) {
+ this.className = className;
+ }
+
+ /**
+ * Returns the name of the JUnit test class.
+ *
+ * @return the name of the JUnit test class
+ */
+ public String getClassName() {
+ return className;
+ }
+
+ /**
+ * Sets the name of the JUnit test class.
+ *
+ * @param className the name of the JUnit test class
+ */
+ public void setClassName(String className) {
+ this.className = className;
+ }
+}
diff --git a/sandbox/old/contrib/runtime-itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/implementation/junit/ImplementationJUnitLoader.java b/sandbox/old/contrib/runtime-itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/implementation/junit/ImplementationJUnitLoader.java
new file mode 100644
index 0000000000..e2daa7a3ec
--- /dev/null
+++ b/sandbox/old/contrib/runtime-itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/implementation/junit/ImplementationJUnitLoader.java
@@ -0,0 +1,54 @@
+/*
+ * 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.implementation.junit;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.LoaderExtension;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.model.ModelObject;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ImplementationJUnitLoader extends LoaderExtension<ImplementationJUnit> {
+ private static final QName JUNIT = new QName("http://tuscany.apache.org/xmlns/sca/2.0-alpha", "junit");
+
+ public ImplementationJUnitLoader(@Reference LoaderRegistry registry) {
+ super(registry);
+ }
+
+ public QName getXMLType() {
+ return JUNIT;
+ }
+
+ public ImplementationJUnit load(
+ ModelObject object,
+ XMLStreamReader reader,
+ DeploymentContext deploymentContext) throws XMLStreamException, LoaderException {
+ String className = reader.getAttributeValue(null, "class");
+ return new ImplementationJUnit(className);
+ }
+}
diff --git a/sandbox/old/contrib/runtime-itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/implementation/junit/JUnitComponentBuilder.java b/sandbox/old/contrib/runtime-itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/implementation/junit/JUnitComponentBuilder.java
new file mode 100644
index 0000000000..7407ed1150
--- /dev/null
+++ b/sandbox/old/contrib/runtime-itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/implementation/junit/JUnitComponentBuilder.java
@@ -0,0 +1,192 @@
+/*
+ * 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.implementation.junit;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Member;
+import java.lang.reflect.Method;
+
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.ObjectFactory;
+import org.apache.tuscany.spi.builder.BuilderConfigException;
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.ComponentBuilderExtension;
+import org.apache.tuscany.spi.host.ResourceHost;
+import org.apache.tuscany.spi.implementation.java.ConstructorDefinition;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.Parameter;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.implementation.java.Resource;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.PropertyValue;
+
+import org.apache.tuscany.core.implementation.PojoConfiguration;
+import org.apache.tuscany.core.implementation.java.JavaAtomicComponent;
+import org.apache.tuscany.core.injection.MethodEventInvoker;
+import org.apache.tuscany.core.injection.PojoObjectFactory;
+import org.apache.tuscany.core.injection.ResourceObjectFactory;
+
+/**
+ * Builds a Java-based atomic context from a component definition
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public class JUnitComponentBuilder extends ComponentBuilderExtension<ImplementationJUnit> {
+
+ private ResourceHost host;
+
+ @Reference
+ public void setHost(ResourceHost host) {
+ this.host = host;
+ }
+
+ @SuppressWarnings("unchecked")
+ public AtomicComponent build(ComponentDefinition<ImplementationJUnit> definition, DeploymentContext deployment)
+ throws BuilderConfigException {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> componentType =
+ definition.getImplementation().getComponentType();
+ Class<?> implClass = componentType.getImplClass();
+
+ PojoConfiguration configuration = new PojoConfiguration();
+ if (definition.getInitLevel() != null) {
+ configuration.setInitLevel(definition.getInitLevel());
+ } else {
+ configuration.setInitLevel(componentType.getInitLevel());
+ }
+ if (componentType.getMaxAge() > 0) {
+ configuration.setMaxAge(componentType.getMaxAge());
+ } else if (componentType.getMaxIdleTime() > 0) {
+ configuration.setMaxIdleTime(componentType.getMaxIdleTime());
+ }
+ Method initMethod = componentType.getInitMethod();
+ if (initMethod != null) {
+ configuration.setInitInvoker(new MethodEventInvoker(initMethod));
+ }
+ Method destroyMethod = componentType.getDestroyMethod();
+ if (destroyMethod != null) {
+ configuration.setDestroyInvoker(new MethodEventInvoker(destroyMethod));
+ }
+
+ configuration.setProxyService(proxyService);
+ configuration.setWorkContext(workContext);
+ configuration.setImplementationClass(implClass);
+ configuration.setGroupId(deployment.getGroupId());
+
+ // setup property injection sites
+ for (JavaMappedProperty<?> property : componentType.getProperties().values()) {
+ configuration.addPropertySite(property.getName(), property.getMember());
+ }
+
+ // setup reference injection sites
+ for (JavaMappedReference reference : componentType.getReferences().values()) {
+ Member member = reference.getMember();
+ if (member != null) {
+ // could be null if the reference is mapped to a constructor
+ configuration.addReferenceSite(reference.getUri().getFragment(), member);
+ }
+ }
+
+ for (Resource resource : componentType.getResources().values()) {
+ Member member = resource.getMember();
+ if (member != null) {
+ // could be null if the resource is mapped to a constructor
+ configuration.addResourceSite(resource.getName(), member);
+ }
+ }
+
+ // setup constructor injection
+ ConstructorDefinition<?> ctorDef = componentType.getConstructorDefinition();
+ Constructor<?> constr = ctorDef.getConstructor();
+ PojoObjectFactory<?> instanceFactory = new PojoObjectFactory(constr);
+ configuration.setInstanceFactory(instanceFactory);
+ configuration.setConstructor(ctorDef);
+ configuration.setName(definition.getUri());
+ JavaAtomicComponent component = new JavaAtomicComponent(configuration);
+
+ // handle properties
+ handleProperties(definition, component);
+
+ // handle resources
+ handleResources(componentType, component);
+
+ handleCallbackSites(componentType, configuration);
+
+ if (componentType.getConversationIDMember() != null) {
+ component.addConversationIDFactory(componentType.getConversationIDMember());
+ }
+
+ return component;
+ }
+
+ private void handleCallbackSites(
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> componentType,
+ PojoConfiguration configuration) {
+ for (JavaMappedService service : componentType.getServices().values()) {
+ // setup callback injection sites
+ if (service.getCallbackReferenceName() != null) {
+ // Only if there is a callback reference in the service
+ configuration.addCallbackSite(service.getCallbackReferenceName(), service.getCallbackMember());
+ }
+ }
+ }
+
+ @SuppressWarnings({"unchecked"})
+ private void handleResources(
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> componentType,
+ JavaAtomicComponent component) {
+
+ for (Resource resource : componentType.getResources().values()) {
+ ObjectFactory<?> objectFactory = resource.getObjectFactory();
+ if (objectFactory != null) {
+ component.addResourceFactory(resource.getName(), objectFactory);
+ } else {
+ String name = resource.getName();
+ boolean optional = resource.isOptional();
+ Class<Object> type = (Class<Object>) resource.getType();
+ ResourceObjectFactory<Object> factory;
+ String mappedName = resource.getMappedName();
+ if (mappedName == null) {
+ // by type
+ factory = new ResourceObjectFactory<Object>(type, optional, host);
+ } else {
+ factory = new ResourceObjectFactory<Object>(type, mappedName, optional, host);
+ }
+ component.addResourceFactory(name, factory);
+ }
+ }
+ }
+
+ private void handleProperties(ComponentDefinition<ImplementationJUnit> definition, JavaAtomicComponent component) {
+ for (PropertyValue<?> property : definition.getPropertyValues().values()) {
+ ObjectFactory<?> factory = property.getValueFactory();
+ if (factory != null) {
+ component.addPropertyFactory(property.getName(), factory);
+ }
+ }
+ }
+
+ protected Class<ImplementationJUnit> getImplementationType() {
+ return ImplementationJUnit.class;
+ }
+
+}
diff --git a/sandbox/old/contrib/runtime-itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/implementation/junit/JUnitComponentTypeLoader.java b/sandbox/old/contrib/runtime-itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/implementation/junit/JUnitComponentTypeLoader.java
new file mode 100644
index 0000000000..bb7ff476a2
--- /dev/null
+++ b/sandbox/old/contrib/runtime-itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/implementation/junit/JUnitComponentTypeLoader.java
@@ -0,0 +1,146 @@
+/*
+ * 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.implementation.junit;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.lang.reflect.Type;
+import java.net.URI;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.osoa.sca.annotations.Constructor;
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.ComponentTypeLoaderExtension;
+import org.apache.tuscany.spi.implementation.java.IntrospectionRegistry;
+import org.apache.tuscany.spi.implementation.java.Introspector;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.implementation.java.ProcessingException;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.loader.MissingResourceException;
+import org.apache.tuscany.spi.model.DataType;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.ServiceContract;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JUnitComponentTypeLoader extends ComponentTypeLoaderExtension<ImplementationJUnit> {
+ private static final URI TEST_SERVICE_NAME = URI.create("#testService");
+ private Introspector introspector;
+
+ @Constructor
+ public JUnitComponentTypeLoader(@Reference LoaderRegistry loaderRegistry,
+ @Reference IntrospectionRegistry introspector) {
+ super(loaderRegistry);
+ this.introspector = introspector;
+ }
+
+ @Override
+ protected Class<ImplementationJUnit> getImplementationClass() {
+ return ImplementationJUnit.class;
+ }
+
+ public void load(ImplementationJUnit implementation, DeploymentContext context) throws LoaderException {
+ String className = implementation.getClassName();
+ Class<?> implClass;
+ try {
+ implClass = context.getClassLoader().loadClass(className);
+ } catch (ClassNotFoundException e) {
+ throw new MissingResourceException(className, e);
+ }
+ PojoComponentType componentType = loadByIntrospection(implementation, context, implClass);
+ implementation.setComponentType(componentType);
+ }
+
+ protected PojoComponentType loadByIntrospection(ImplementationJUnit implementation,
+ DeploymentContext deploymentContext,
+ Class<?> implClass) throws ProcessingException {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> componentType =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(implClass);
+ introspector.introspect(implClass, componentType, deploymentContext);
+
+ if (componentType.getInitMethod() == null) {
+ componentType.setInitMethod(getCallback(implClass, "setUp"));
+ }
+ if (componentType.getDestroyMethod() == null) {
+ componentType.setDestroyMethod(getCallback(implClass, "tearDown"));
+ }
+ ServiceContract testContract = generateTestContract(implClass);
+ JavaMappedService testService = new JavaMappedService(TEST_SERVICE_NAME, testContract, false);
+ componentType.add(testService);
+ return componentType;
+ }
+
+ protected Method getCallback(Class<?> implClass, String name) {
+ while (Object.class != implClass) {
+ try {
+ Method callback = implClass.getDeclaredMethod(name);
+ callback.setAccessible(true);
+ return callback;
+ } catch (NoSuchMethodException e) {
+ implClass = implClass.getSuperclass();
+ continue;
+ }
+ }
+ return null;
+ }
+
+ private static final DataType<List<DataType<Type>>> INPUT_TYPE;
+ private static final DataType<Type> OUTPUT_TYPE;
+ private static final List<DataType<Type>> FAULT_TYPE;
+
+ static {
+ List<DataType<Type>> paramDataTypes = Collections.emptyList();
+ INPUT_TYPE = new DataType<List<DataType<Type>>>("idl:input", Object[].class, paramDataTypes);
+ OUTPUT_TYPE = new DataType<Type>(null, void.class, void.class);
+ FAULT_TYPE = Collections.emptyList();
+ }
+
+ protected ServiceContract generateTestContract(Class<?> implClass) {
+ Map<String, Operation<Type>> operations = new HashMap<String, Operation<Type>>();
+ for (Method method : implClass.getMethods()) {
+ // see if this is a test method
+ if (Modifier.isStatic(method.getModifiers())) {
+ continue;
+ }
+ if (method.getReturnType() != void.class) {
+ continue;
+ }
+ if (method.getParameterTypes().length != 0) {
+ continue;
+ }
+ String name = method.getName();
+ if (name.length() < 5 || !name.startsWith("test")) {
+ continue;
+ }
+ Operation<Type> operation = new Operation<Type>(name, INPUT_TYPE, OUTPUT_TYPE, FAULT_TYPE);
+ operations.put(name, operation);
+ }
+ return new JUnitServiceContract(operations);
+ }
+}
diff --git a/sandbox/old/contrib/runtime-itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/implementation/junit/JUnitServiceContract.java b/sandbox/old/contrib/runtime-itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/implementation/junit/JUnitServiceContract.java
new file mode 100644
index 0000000000..4e3fad0db2
--- /dev/null
+++ b/sandbox/old/contrib/runtime-itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/implementation/junit/JUnitServiceContract.java
@@ -0,0 +1,35 @@
+/*
+ * 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.implementation.junit;
+
+import java.util.Map;
+import java.lang.reflect.Type;
+
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.model.Operation;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JUnitServiceContract extends ServiceContract<Type> {
+
+ public JUnitServiceContract(Map<String, Operation<Type>> operations) {
+ setOperations(operations);
+ }
+}