summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/tags/2.0.1-RC1/modules/domain-node/src/test/java/org/apache/tuscany/sca/impl
diff options
context:
space:
mode:
Diffstat (limited to 'sca-java-2.x/tags/2.0.1-RC1/modules/domain-node/src/test/java/org/apache/tuscany/sca/impl')
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/domain-node/src/test/java/org/apache/tuscany/sca/impl/ContributionClassLoaderTestCase.java49
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/domain-node/src/test/java/org/apache/tuscany/sca/impl/ContributionUpdateTestCase.java75
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/domain-node/src/test/java/org/apache/tuscany/sca/impl/DependencyUtilsTestCase.java61
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/domain-node/src/test/java/org/apache/tuscany/sca/impl/DeployerTestCase.java51
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/domain-node/src/test/java/org/apache/tuscany/sca/impl/DirectoryDomainTestCase.java123
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/domain-node/src/test/java/org/apache/tuscany/sca/impl/Node2TestCase.java315
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/domain-node/src/test/java/org/apache/tuscany/sca/impl/UsedCompositesTestCase.java79
7 files changed, 753 insertions, 0 deletions
diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/domain-node/src/test/java/org/apache/tuscany/sca/impl/ContributionClassLoaderTestCase.java b/sca-java-2.x/tags/2.0.1-RC1/modules/domain-node/src/test/java/org/apache/tuscany/sca/impl/ContributionClassLoaderTestCase.java
new file mode 100644
index 0000000000..298c20b093
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/domain-node/src/test/java/org/apache/tuscany/sca/impl/ContributionClassLoaderTestCase.java
@@ -0,0 +1,49 @@
+/*
+ * 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.impl;
+
+import junit.framework.Assert;
+
+import org.apache.tuscany.sca.Node;
+import org.apache.tuscany.sca.TuscanyRuntime;
+import org.apache.tuscany.sca.contribution.Contribution;
+import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
+import org.apache.tuscany.sca.monitor.ValidationException;
+import org.apache.tuscany.sca.runtime.ActivationException;
+import org.junit.Test;
+
+/**
+ * Tests that the contribution classloader is created after doing a validateContribution
+ */
+public class ContributionClassLoaderTestCase {
+
+ @Test
+ public void testInstallDeployable() throws ContributionReadException, ValidationException, ActivationException {
+ Node node = TuscanyRuntime.newInstance().createNode();
+ String curi = node.installContribution("src/test/resources/sample-helloworld.jar");
+ Contribution contribution = node.getContribution(curi);
+ Assert.assertNull(contribution.getClassLoader());
+ node.validateContribution(curi);
+ ClassLoader cl1 = contribution.getClassLoader();
+ Assert.assertNotNull(cl1);
+ node.startComposite(curi, "helloworld.composite");
+ Assert.assertEquals(cl1, node.getContribution(curi).getClassLoader());
+ }
+
+}
diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/domain-node/src/test/java/org/apache/tuscany/sca/impl/ContributionUpdateTestCase.java b/sca-java-2.x/tags/2.0.1-RC1/modules/domain-node/src/test/java/org/apache/tuscany/sca/impl/ContributionUpdateTestCase.java
new file mode 100644
index 0000000000..f270eb3f23
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/domain-node/src/test/java/org/apache/tuscany/sca/impl/ContributionUpdateTestCase.java
@@ -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.impl;
+
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.util.Collection;
+
+import javax.xml.stream.XMLStreamException;
+
+import org.apache.tuscany.sca.Node;
+import org.apache.tuscany.sca.TuscanyRuntime;
+import org.apache.tuscany.sca.assembly.Endpoint;
+import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
+import org.apache.tuscany.sca.monitor.ValidationException;
+import org.apache.tuscany.sca.runtime.ActivationException;
+import org.junit.Assert;
+import org.junit.Test;
+import org.oasisopen.sca.NoSuchDomainException;
+import org.oasisopen.sca.NoSuchServiceException;
+
+public class ContributionUpdateTestCase {
+
+ @Test
+ public void updateTest1() throws NoSuchServiceException, NoSuchDomainException, ContributionReadException, ActivationException, ValidationException, XMLStreamException, FileNotFoundException {
+ Node node = TuscanyRuntime.newInstance().createNode("updateTest1");
+ String curi = node.installContribution("src/test/resources/sample-helloworld.jar");
+ node.startDeployables(curi);
+
+ Collection<Endpoint> eps = ((NodeImpl)node).getEndpointRegistry().getEndpoints();
+ Assert.assertEquals(1, eps.size());
+ Assert.assertEquals("HelloworldComponent#service-binding(Helloworld/Helloworld)", eps.iterator().next().getURI());
+
+ ((NodeImpl)node).updateContribution(curi, "src/test/resources/sample-helloworld2.jar", null, null);
+
+ eps = ((NodeImpl)node).getEndpointRegistry().getEndpoints();
+ Assert.assertEquals(1, eps.size());
+ Assert.assertEquals("Helloworld2Component#service-binding(Helloworld/Helloworld)", eps.iterator().next().getURI());
+ }
+
+ @Test
+ public void updateWithAdditionalDeployablesTest() throws NoSuchServiceException, NoSuchDomainException, ContributionReadException, ActivationException, ValidationException, XMLStreamException, FileNotFoundException {
+ Node node = TuscanyRuntime.newInstance().createNode("updateWithAdditionalDeployablesTest");
+ String curi = node.installContribution("src/test/resources/sample-helloworld.jar");
+ String compURI = node.addDeploymentComposite(curi, new FileReader("src/test/resources/helloworld2.composite"));
+ node.startComposite(curi, compURI);
+
+ Collection<Endpoint> eps = ((NodeImpl)node).getEndpointRegistry().getEndpoints();
+ Assert.assertEquals(1, eps.size());
+ Assert.assertEquals("Helloworld2Component#service-binding(Helloworld/Helloworld)", eps.iterator().next().getURI());
+
+ ((NodeImpl)node).updateContribution(curi, "src/test/resources/sample-helloworld.jar", null, null);
+
+ eps = ((NodeImpl)node).getEndpointRegistry().getEndpoints();
+ Assert.assertEquals(1, eps.size());
+ Assert.assertEquals("Helloworld2Component#service-binding(Helloworld/Helloworld)", eps.iterator().next().getURI());
+ }
+
+}
diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/domain-node/src/test/java/org/apache/tuscany/sca/impl/DependencyUtilsTestCase.java b/sca-java-2.x/tags/2.0.1-RC1/modules/domain-node/src/test/java/org/apache/tuscany/sca/impl/DependencyUtilsTestCase.java
new file mode 100644
index 0000000000..a2e6abd893
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/domain-node/src/test/java/org/apache/tuscany/sca/impl/DependencyUtilsTestCase.java
@@ -0,0 +1,61 @@
+/*
+ * 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.impl;
+
+import java.io.BufferedInputStream;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.zip.ZipInputStream;
+
+import javax.xml.stream.XMLStreamException;
+
+import junit.framework.Assert;
+
+import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
+import org.apache.tuscany.sca.monitor.ValidationException;
+import org.junit.Test;
+
+public class DependencyUtilsTestCase {
+
+ @Test
+ public void loadTest() throws ValidationException, ContributionReadException, FileNotFoundException, IOException, XMLStreamException {
+
+ List<String> importDs = DependencyUtils.getDependencies("import", initZips());
+ Assert.assertEquals(1, importDs.size());
+ Assert.assertEquals("export", importDs.get(0));
+
+ List<String> exportDs = DependencyUtils.getDependencies("export", initZips());
+ Assert.assertEquals(0, exportDs.size());
+
+ List<String> unrelatedDs = DependencyUtils.getDependencies("unrelated", initZips());
+ Assert.assertEquals(0, unrelatedDs.size());
+ }
+
+ private Map<String, ZipInputStream> initZips() throws FileNotFoundException {
+ Map<String, ZipInputStream> contributions = new HashMap<String, ZipInputStream>();
+ contributions.put("import", new ZipInputStream(new BufferedInputStream(new FileInputStream("src/test/resources/import.jar"))));
+ contributions.put("export", new ZipInputStream(new BufferedInputStream(new FileInputStream("src/test/resources/export.jar"))));
+ contributions.put("unrelated", new ZipInputStream(new BufferedInputStream(new FileInputStream("src/test/resources/sample-helloworld-nodeployable.jar"))));
+ return contributions;
+ }
+}
diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/domain-node/src/test/java/org/apache/tuscany/sca/impl/DeployerTestCase.java b/sca-java-2.x/tags/2.0.1-RC1/modules/domain-node/src/test/java/org/apache/tuscany/sca/impl/DeployerTestCase.java
new file mode 100644
index 0000000000..9892b0d8a7
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/domain-node/src/test/java/org/apache/tuscany/sca/impl/DeployerTestCase.java
@@ -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.impl;
+
+import org.apache.tuscany.sca.Node;
+import org.apache.tuscany.sca.TuscanyRuntime;
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.Service;
+import org.apache.tuscany.sca.contribution.Contribution;
+import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
+import org.apache.tuscany.sca.monitor.ValidationException;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class DeployerTestCase {
+
+ @Test
+ public void testArtifacts() throws ContributionReadException, ValidationException {
+
+ Node node = TuscanyRuntime.newInstance().createNode();
+ String curi = node.installContribution("src/test/resources/sample-helloworld.jar");
+ node.validateContribution(curi);
+
+ Contribution contribution = node.getContribution(curi);
+ Composite composite = contribution.getArtifactModel("helloworld.composite");
+ Component component = composite.getComponents().get(0);
+ Service service = component.getImplementation().getServices().get(0);
+
+ Assert.assertEquals("helloworld", composite.getName().getLocalPart());
+ Assert.assertEquals("HelloworldComponent", component.getName());
+ Assert.assertEquals("Helloworld", service.getName());
+ }
+
+}
diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/domain-node/src/test/java/org/apache/tuscany/sca/impl/DirectoryDomainTestCase.java b/sca-java-2.x/tags/2.0.1-RC1/modules/domain-node/src/test/java/org/apache/tuscany/sca/impl/DirectoryDomainTestCase.java
new file mode 100644
index 0000000000..d89271f14b
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/domain-node/src/test/java/org/apache/tuscany/sca/impl/DirectoryDomainTestCase.java
@@ -0,0 +1,123 @@
+/*
+ * 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.impl;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.stream.XMLStreamException;
+
+import junit.framework.Assert;
+
+import org.apache.tuscany.sca.Node;
+import org.apache.tuscany.sca.TuscanyRuntime;
+import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
+import org.apache.tuscany.sca.monitor.ValidationException;
+import org.apache.tuscany.sca.runtime.ActivationException;
+import org.apache.tuscany.sca.runtime.ContributionDescription;
+import org.junit.Test;
+import org.oasisopen.sca.NoSuchDomainException;
+import org.oasisopen.sca.NoSuchServiceException;
+import org.oasisopen.sca.annotation.Remotable;
+
+public class DirectoryDomainTestCase {
+
+ @Test
+ public void testDefaultDomain() throws NoSuchServiceException, NoSuchDomainException, ContributionReadException, ActivationException, ValidationException, XMLStreamException, IOException {
+ Node node = TuscanyRuntime.newInstance().createNode(new File("src/test/resources/test-domains/default"));
+
+ Assert.assertEquals("default", node.getDomainName());
+ Assert.assertEquals(1, node.getInstalledContributionURIs().size());
+ Assert.assertEquals("sample-helloworld", node.getInstalledContributionURIs().get(0));
+ Assert.assertEquals("helloworld.composite", node.getStartedCompositeURIs().get("sample-helloworld").get(0));
+ }
+
+ @Test
+ public void testMyDomain() throws NoSuchServiceException, NoSuchDomainException, ContributionReadException, ActivationException, ValidationException, XMLStreamException, IOException {
+ Node node = TuscanyRuntime.newInstance().createNode(new File("src/test/resources/test-domains/MyDomain"));
+
+ Assert.assertEquals("foo", node.getDomainName());
+ Assert.assertEquals(1, node.getInstalledContributionURIs().size());
+ Assert.assertEquals("helloworld-contribution", node.getInstalledContributionURIs().get(0));
+
+ // validate additional deployable composite
+ Map<String, List<String>> scs = node.getStartedCompositeURIs();
+ Assert.assertEquals(2, scs.get("helloworld-contribution").size());
+ Assert.assertTrue(scs.get("helloworld-contribution").contains("helloworld.composite"));
+ Assert.assertTrue(scs.get("helloworld-contribution").contains("helloworld2.composite"));
+
+ // validate metadata side file
+ ContributionDescription ic = node.getInstalledContribution("helloworld-contribution");
+ Assert.assertEquals(1, ic.getJavaExports().size());
+ Assert.assertEquals("sample", ic.getJavaExports().get(0));
+ }
+
+ @Test
+ public void testNodeXMLFile() throws ContributionReadException, ActivationException, ValidationException, XMLStreamException, IOException {
+ Node node = TuscanyRuntime.newInstance().createNode(new File("src/test/resources/helloworldNode.xml"));
+ Assert.assertEquals("helloworld", node.getDomainName());
+ List<String> cs = node.getInstalledContributionURIs();
+ Assert.assertEquals(1, cs.size());
+ Assert.assertEquals("sample-helloworld", cs.get(0));
+ Map<String, List<String>> startedComposites = node.getStartedCompositeURIs();
+ Assert.assertEquals(1, startedComposites.size());
+ Assert.assertEquals("helloworld.composite", startedComposites.get("sample-helloworld").get(0));
+ }
+
+ @Test
+ public void testNodeXMLDomain() throws ContributionReadException, ActivationException, ValidationException, XMLStreamException, IOException {
+ Node node = TuscanyRuntime.newInstance().createNode(new File("src/test/resources/test-domains/NodeXMLDomain"));
+ Assert.assertEquals("helloworld", node.getDomainName());
+ List<String> cs = node.getInstalledContributionURIs();
+ Assert.assertEquals(1, cs.size());
+ Assert.assertEquals("sample-helloworld", cs.get(0));
+ Map<String, List<String>> startedComposites = node.getStartedCompositeURIs();
+ Assert.assertEquals(1, startedComposites.size());
+ Assert.assertEquals("helloworld.composite", startedComposites.get("sample-helloworld").get(0));
+ }
+
+ @Test
+ public void testExploded() throws ContributionReadException, ActivationException, ValidationException, XMLStreamException, IOException {
+ Node node = TuscanyRuntime.newInstance().createNode(new File("src/test/resources/test-domains/exploded"));
+ Assert.assertEquals("exploded", node.getDomainName());
+ List<String> cs = node.getInstalledContributionURIs();
+ Assert.assertEquals(1, cs.size());
+ Assert.assertEquals("sample-helloworld", cs.get(0));
+ Map<String, List<String>> startedComposites = node.getStartedCompositeURIs();
+ Assert.assertEquals(1, startedComposites.size());
+ Assert.assertEquals("helloworld.composite", startedComposites.get("sample-helloworld").get(0));
+ }
+
+ @Test
+ public void testDependencies() throws ContributionReadException, ActivationException, ValidationException, XMLStreamException, IOException, NoSuchServiceException {
+ Node node = TuscanyRuntime.newInstance().createNode(new File("src/test/resources/test-domains/dependencies"));
+ Assert.assertEquals("dependencies", node.getDomainName());
+ List<String> cs = node.getInstalledContributionURIs();
+ Assert.assertEquals(4, cs.size());
+ Assert.assertEquals("Hello 1 Petra", node.getService(TestIface.class, "Helloworld1Component").sayHello("Petra"));
+ Assert.assertEquals("Hello 2 Amelia", node.getService(TestIface.class, "Helloworld2Component").sayHello("Amelia"));
+ }
+
+ @Remotable
+ interface TestIface {
+ String sayHello(String name);
+ }
+}
diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/domain-node/src/test/java/org/apache/tuscany/sca/impl/Node2TestCase.java b/sca-java-2.x/tags/2.0.1-RC1/modules/domain-node/src/test/java/org/apache/tuscany/sca/impl/Node2TestCase.java
new file mode 100644
index 0000000000..04dca98062
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/domain-node/src/test/java/org/apache/tuscany/sca/impl/Node2TestCase.java
@@ -0,0 +1,315 @@
+/*
+ * 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.impl;
+
+import java.io.Reader;
+import java.io.StringReader;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.stream.XMLStreamException;
+
+import junit.framework.Assert;
+
+import org.apache.tuscany.sca.Node;
+import org.apache.tuscany.sca.TuscanyRuntime;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.contribution.Contribution;
+import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
+import org.apache.tuscany.sca.monitor.ValidationException;
+import org.apache.tuscany.sca.runtime.ActivationException;
+import org.apache.tuscany.sca.runtime.ContributionDescription;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.oasisopen.sca.NoSuchDomainException;
+import org.oasisopen.sca.NoSuchServiceException;
+
+public class Node2TestCase {
+
+ @Test
+ public void localInstall() throws NoSuchServiceException, NoSuchDomainException, ContributionReadException, ActivationException, ValidationException {
+ Node node = TuscanyRuntime.newInstance().createNode("ImportTestCase");
+ node.installContribution("src/test/resources/import.jar");
+
+ Assert.assertEquals(1, node.getInstalledContributionURIs().size());
+ Assert.assertEquals("import", node.getInstalledContributionURIs().get(0));
+ Contribution c = node.getContribution("import");
+ Assert.assertNotNull(c);
+ }
+
+ @Test
+ public void remoteInstall() throws NoSuchServiceException, NoSuchDomainException, ContributionReadException, ActivationException, ValidationException {
+ Node node = TuscanyRuntime.newInstance().createNode("ImportTestCase");
+ node.installContribution("http://repository.apache.org/content/groups/snapshots/org/apache/tuscany/sca/samples/helloworld/2.0-SNAPSHOT/helloworld-2.0-SNAPSHOT.jar");
+
+ Assert.assertEquals(1, node.getInstalledContributionURIs().size());
+ Assert.assertEquals("helloworld", node.getInstalledContributionURIs().get(0));
+ Contribution c = node.getContribution("helloworld");
+ Assert.assertNotNull(c);
+ }
+
+ @Ignore("TUSCANY-3953")
+ @Test
+ public void DistributedInstall() throws NoSuchServiceException, NoSuchDomainException, ContributionReadException, ActivationException, ValidationException {
+ TuscanyRuntime runtime = TuscanyRuntime.newInstance();
+ try {
+ Node nodeA = runtime.createNode("uri:DistributedInstall");
+ nodeA.installContribution("http://repository.apache.org/content/groups/snapshots/org/apache/tuscany/sca/samples/helloworld/2.0-SNAPSHOT/helloworld-2.0-SNAPSHOT.jar");
+ nodeA.installContribution("src/test/resources/export.jar");
+
+ Assert.assertEquals(2, nodeA.getInstalledContributionURIs().size());
+ Assert.assertTrue(nodeA.getInstalledContributionURIs().contains("export"));
+ Assert.assertTrue(nodeA.getInstalledContributionURIs().contains("helloworld"));
+ Contribution cA = nodeA.getContribution("helloworld");
+ Assert.assertNotNull(cA);
+
+ Node nodeB = runtime.createNode("uri:DistributedInstall");
+ Assert.assertEquals(2, nodeB.getInstalledContributionURIs().size());
+ Assert.assertTrue(nodeB.getInstalledContributionURIs().contains("export"));
+ Assert.assertTrue(nodeB.getInstalledContributionURIs().contains("helloworld"));
+ Contribution cB = nodeB.getContribution("helloworld");
+ Assert.assertNotNull(cB);
+
+ ContributionDescription cd = ((NodeImpl)nodeB).getInstalledContribution("export");
+ Assert.assertEquals(1, cd.getJavaExports().size());
+ Assert.assertEquals("sample", cd.getJavaExports().get(0));
+ } finally {
+ runtime.stop();
+ }
+ }
+
+ @Test
+ public void deployables() throws NoSuchServiceException, NoSuchDomainException, ContributionReadException, ActivationException, ValidationException {
+ Node node = TuscanyRuntime.newInstance().createNode("ImportTestCase");
+ node.installContribution("src/test/resources/import.jar");
+
+ Assert.assertEquals(1, node.getInstalledContributionURIs().size());
+ Assert.assertEquals("import", node.getInstalledContributionURIs().get(0));
+ List<String> ds = node.getDeployableCompositeURIs("import");
+ Assert.assertEquals(1, ds.size());
+ Assert.assertEquals("helloworld.composite", ds.get(0));
+
+ }
+
+ @Test
+ public void exports() throws NoSuchServiceException, NoSuchDomainException, ContributionReadException, ActivationException, ValidationException {
+ Node node = TuscanyRuntime.newInstance().createNode("ImportTestCase");
+ node.installContribution("src/test/resources/export.jar");
+
+ Assert.assertEquals(1, node.getInstalledContributionURIs().size());
+ Assert.assertEquals("export", node.getInstalledContributionURIs().get(0));
+
+ ContributionDescription cd = ((NodeImpl)node).getInstalledContribution("export");
+ Assert.assertEquals(1, cd.getJavaExports().size());
+ Assert.assertEquals("sample", cd.getJavaExports().get(0));
+ }
+
+ @Test
+ public void validValidate() throws NoSuchServiceException, NoSuchDomainException, ContributionReadException, ActivationException, ValidationException {
+ Node node = TuscanyRuntime.newInstance().createNode("ImportTestCase");
+ node.installContribution("src/test/resources/sample-helloworld.jar");
+ node.validateContribution("sample-helloworld");
+ }
+
+ @Test
+ public void invalidValidate() throws NoSuchServiceException, NoSuchDomainException, ContributionReadException, ActivationException, ValidationException {
+ Node node = TuscanyRuntime.newInstance().createNode("ImportTestCase");
+ node.installContribution("src/test/resources/import.jar");
+ try {
+ node.validateContribution("import");
+ } catch (ValidationException e) {
+ Assert.assertTrue(e.getMessage().endsWith("Unresolved import: Import = sample"));
+ }
+ }
+
+ @Test
+ public void importExportValidate() throws NoSuchServiceException, NoSuchDomainException, ContributionReadException, ActivationException, ValidationException {
+ Node node = TuscanyRuntime.newInstance().createNode("ImportTestCase");
+ node.installContribution("src/test/resources/import.jar");
+ try {
+ node.validateContribution("import");
+ } catch (ValidationException e) {
+ // expected
+ }
+ node.installContribution("src/test/resources/export.jar");
+ node.validateContribution("import");
+ node.startComposite("import", "helloworld.composite");
+ Map<String, List<String>> scs = node.getStartedCompositeURIs();
+ Assert.assertEquals(1, scs.size());
+ }
+
+ @Ignore("TUSCANY-3953")
+ @Test
+ public void importExportDistributedValidate() throws NoSuchServiceException, NoSuchDomainException, ContributionReadException, ActivationException, ValidationException {
+ TuscanyRuntime runtime = TuscanyRuntime.newInstance();
+ try {
+ Node nodeA = runtime.createNode("uri:ImportTestCase");
+ nodeA.installContribution("src/test/resources/import.jar");
+ try {
+ nodeA.validateContribution("import");
+ } catch (ValidationException e) {
+ // expected
+ }
+ Node nodeB =runtime.createNode("uri:ImportTestCase");
+ nodeB.installContribution("src/test/resources/export.jar");
+ nodeA.validateContribution("import");
+ nodeA.startComposite("import", "helloworld.composite");
+ Map<String, List<String>> scs = nodeB.getStartedCompositeURIs();
+ Assert.assertEquals(1, scs.size());
+ }finally {
+ runtime.stop();
+ }
+
+ }
+
+ @Test
+ public void startTest() throws NoSuchServiceException, NoSuchDomainException, ContributionReadException, ActivationException, ValidationException {
+ Node node = TuscanyRuntime.newInstance().createNode("ImportTestCase");
+ node.installContribution("src/test/resources/sample-helloworld.jar");
+ Assert.assertEquals(0, node.getStartedCompositeURIs().size());
+
+ node.startComposite("sample-helloworld", "helloworld.composite");
+ Assert.assertEquals(1, node.getStartedCompositeURIs().size());
+ Assert.assertEquals("helloworld.composite", node.getStartedCompositeURIs().get("sample-helloworld").get(0));
+
+ node.stopComposite("sample-helloworld", "helloworld.composite");
+// Assert.assertEquals(0, node.getStartedComposites().size());
+ node.startComposite("sample-helloworld", "helloworld.composite");
+ Assert.assertEquals(1, node.getStartedCompositeURIs().size());
+ Assert.assertEquals("helloworld.composite", node.getStartedCompositeURIs().get("sample-helloworld").get(0));
+ node.stopComposite("sample-helloworld", "helloworld.composite");
+ }
+
+ @Ignore("TUSCANY-3953")
+ @Test
+ public void startDistributedTest() throws NoSuchServiceException, NoSuchDomainException, ContributionReadException, ActivationException, ValidationException, InterruptedException {
+ TuscanyRuntime runtime = TuscanyRuntime.newInstance();
+ try {
+ Node node = runtime.createNode("uri:ImportTestCase");
+ Node node2 = runtime.createNode("uri:ImportTestCase");
+
+ node.installContribution("src/test/resources/sample-helloworld.jar");
+ Assert.assertEquals(1, node.getInstalledContributionURIs().size());
+ Assert.assertEquals(1, node2.getInstalledContributionURIs().size());
+
+ node.startComposite("sample-helloworld", "helloworld.composite");
+ Assert.assertEquals(1, node.getStartedCompositeURIs().size());
+ Assert.assertEquals(1, node2.getStartedCompositeURIs().size());
+
+ Assert.assertEquals("helloworld.composite", node.getStartedCompositeURIs().get("sample-helloworld").get(0));
+ Assert.assertEquals("helloworld.composite", node2.getStartedCompositeURIs().get("sample-helloworld").get(0));
+
+ node.stopComposite("sample-helloworld", "helloworld.composite");
+ Assert.assertEquals(0, node.getStartedCompositeURIs().size());
+ Assert.assertEquals(0, node2.getStartedCompositeURIs().size());
+
+ node2.startComposite("sample-helloworld", "helloworld.composite");
+ Assert.assertEquals(1, node.getStartedCompositeURIs().size());
+ Assert.assertEquals("helloworld.composite", node.getStartedCompositeURIs().get("sample-helloworld").get(0));
+
+ Assert.assertEquals(1, node2.getStartedCompositeURIs().size());
+ Assert.assertEquals("helloworld.composite", node2.getStartedCompositeURIs().get("sample-helloworld").get(0));
+
+ } finally {
+ runtime.stop();
+ }
+ }
+
+ @Test
+ public void addDeploymentCompositeTest() throws NoSuchServiceException, NoSuchDomainException, ContributionReadException, ActivationException, ValidationException, XMLStreamException {
+ Node node = TuscanyRuntime.newInstance().createNode("addDeploymentCompositeTest");
+ String curi = node.installContribution("src/test/resources/sample-helloworld.jar");
+
+ String compositeXML =
+ "<composite xmlns=\"http://docs.oasis-open.org/ns/opencsa/sca/200912\""
+ + " xmlns:tuscany=\"http://tuscany.apache.org/xmlns/sca/1.1\""
+ + " targetNamespace=\"http://test/composite\""
+ + " name=\"TestComposite\">"
+ + " <component name=\"TestComponent\">"
+ + " <implementation.java class=\"sample.HelloworldImpl\"/>"
+ + " </component>"
+ + "</composite>";
+ String compositeURI = node.addDeploymentComposite(curi, new StringReader(compositeXML));
+
+ node.startComposite(curi, compositeURI);
+ Assert.assertEquals(1, node.getStartedCompositeURIs().size());
+
+ Composite dc = node.getDomainComposite();
+ Assert.assertEquals(1, dc.getIncludes().size());
+ Composite runningComposite = dc.getIncludes().get(0);
+ Assert.assertEquals("TestComposite", runningComposite.getName().getLocalPart());
+ }
+
+ @Test
+ public void invalidCompositeStartTest() throws NoSuchServiceException, NoSuchDomainException, ContributionReadException, ActivationException, ValidationException, XMLStreamException {
+ Node node = TuscanyRuntime.newInstance().createNode("invalidCompositeStartTest");
+ String curi = node.installContribution("src/test/resources/helloworld-invalidComposite.jar");
+ Assert.assertEquals(1, node.getInstalledContributionURIs().size());
+ Assert.assertEquals(0, node.getStartedCompositeURIs().size());
+ ContributionDescription cd = node.getInstalledContribution(curi);
+ Assert.assertEquals(1, cd.getDeployables().size());
+
+ String compositeXML =
+ "<composite xmlns=\"http://docs.oasis-open.org/ns/opencsa/sca/200912\""
+ + " xmlns:tuscany=\"http://tuscany.apache.org/xmlns/sca/1.1\""
+ + " targetNamespace=\"http://test/composite\""
+ + " name=\"TestComposite\">"
+ + " <component name=\"TestComponent\">"
+ + " <implementation.java class=\"sample.HelloworldImpl\"/>"
+ + " </component>"
+ + "</composite>";
+ String compositeURI = node.addDeploymentComposite(curi, new StringReader(compositeXML));
+ node.startComposite(curi, compositeURI);
+
+// node.startComposite("sample-helloworld", "helloworld.composite");
+// Assert.assertEquals(1, node.getStartedCompositeURIs().size());
+// Assert.assertEquals("helloworld.composite", node.getStartedCompositeURIs().get("sample-helloworld").get(0));
+//
+// node.stopComposite("sample-helloworld", "helloworld.composite");
+//// Assert.assertEquals(0, node.getStartedComposites().size());
+// node.startComposite("sample-helloworld", "helloworld.composite");
+// Assert.assertEquals(1, node.getStartedCompositeURIs().size());
+// Assert.assertEquals("helloworld.composite", node.getStartedCompositeURIs().get("sample-helloworld").get(0));
+// node.stopComposite("sample-helloworld", "helloworld.composite");
+ }
+
+ @Test
+ public void stopAndUnistallTest() throws NoSuchServiceException, NoSuchDomainException, ContributionReadException, ActivationException, ValidationException, XMLStreamException {
+ Node node = TuscanyRuntime.newInstance().createNode("stopAndUnistallTest");
+ node.installContribution("src/test/resources/import.jar");
+ node.installContribution("src/test/resources/export.jar");
+ String compositeXML =
+ "<composite xmlns=\"http://docs.oasis-open.org/ns/opencsa/sca/200912\""
+ + " xmlns:tuscany=\"http://tuscany.apache.org/xmlns/sca/1.1\""
+ + " targetNamespace=\"http://test/composite\""
+ + " name=\"TestComposite\">"
+ + " <component name=\"TestComponent\">"
+ + " <implementation.java class=\"sample.HelloworldImpl\"/>"
+ + " </component>"
+ + "</composite>";
+ String compositeURI = node.addDeploymentComposite("export", new StringReader(compositeXML));
+ node.startComposite("import", "helloworld.composite");
+ node.startComposite("export", compositeURI);
+ Assert.assertEquals(2, node.getInstalledContributionURIs().size());
+ node.stopCompositeAndUninstallUnused("import", "helloworld.composite");
+ Assert.assertEquals(1, node.getInstalledContributionURIs().size());
+ node.stopCompositeAndUninstallUnused("export", compositeURI);
+ Assert.assertEquals(0, node.getInstalledContributionURIs().size());
+ }
+}
diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/domain-node/src/test/java/org/apache/tuscany/sca/impl/UsedCompositesTestCase.java b/sca-java-2.x/tags/2.0.1-RC1/modules/domain-node/src/test/java/org/apache/tuscany/sca/impl/UsedCompositesTestCase.java
new file mode 100644
index 0000000000..b5c24c4450
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/domain-node/src/test/java/org/apache/tuscany/sca/impl/UsedCompositesTestCase.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.impl;
+
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.util.List;
+
+import javax.xml.stream.XMLStreamException;
+
+import org.apache.tuscany.sca.Node;
+import org.apache.tuscany.sca.TuscanyRuntime;
+import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
+import org.apache.tuscany.sca.monitor.ValidationException;
+import org.apache.tuscany.sca.runtime.ActivationException;
+import org.junit.Assert;
+import org.junit.Test;
+import org.oasisopen.sca.NoSuchDomainException;
+import org.oasisopen.sca.NoSuchServiceException;
+
+public class UsedCompositesTestCase {
+
+ @Test
+ public void includeTest1() throws NoSuchServiceException, NoSuchDomainException, ContributionReadException, ActivationException, ValidationException, XMLStreamException, FileNotFoundException {
+ Node node = TuscanyRuntime.newInstance().createNode("localTest");
+ String curi = node.installContribution("src/test/resources/sample-helloworld.jar");
+ String compositeURI = node.addDeploymentComposite(curi, new FileReader("src/test/resources/include.composite"));
+
+ node.startComposite(curi, compositeURI);
+
+ List<String> xs = ((NodeImpl)node).updateUsingComposites(curi, "helloworld.composite");
+ Assert.assertEquals(1, xs.size());
+ Assert.assertEquals("sample-helloworld/include.composite", xs.get(0));
+ }
+ @Test
+ public void implCompositeTest() throws NoSuchServiceException, NoSuchDomainException, ContributionReadException, ActivationException, ValidationException, XMLStreamException, FileNotFoundException {
+ Node node = TuscanyRuntime.newInstance().createNode("localTest");
+ String curi = node.installContribution("src/test/resources/sample-helloworld.jar");
+ String compositeURI = node.addDeploymentComposite(curi, new FileReader("src/test/resources/compositeImpl.composite"));
+
+ node.startComposite(curi, compositeURI);
+
+ List<String> xs = ((NodeImpl)node).updateUsingComposites(curi, "helloworld.composite");
+ Assert.assertEquals(1, xs.size());
+ Assert.assertEquals("sample-helloworld/compositeImpl.composite", xs.get(0));
+ }
+
+ @Test
+ public void nestedTest1() throws NoSuchServiceException, NoSuchDomainException, ContributionReadException, ActivationException, ValidationException, XMLStreamException, FileNotFoundException {
+ Node node = TuscanyRuntime.newInstance().createNode("NestedTest");
+ String curi = node.installContribution("src/test/resources/helloworld2.jar");
+
+ node.startComposite(curi, "compositeImpl.composite");
+
+ String compositeURI = node.addDeploymentComposite(curi, new FileReader("src/test/resources/nested.composite"));
+ node.startComposite(curi, compositeURI);
+
+ List<String> xs = ((NodeImpl)node).updateUsingComposites(curi, "helloworld.composite");
+ Assert.assertEquals(2, xs.size());
+ Assert.assertTrue(xs.contains("helloworld2/compositeImpl.composite"));
+ Assert.assertTrue(xs.contains("helloworld2/nested.composite"));
+ }
+}