From 875e50908c2630d263661af492654cd44bef2d65 Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Tue, 25 Jan 2011 23:30:28 +0000 Subject: Sandbox to experiment with dynamic mass virtual hosting and running a different composite per vhost. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1063520 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/test/java/itest/nodes/Helloworld.java | 29 +++++ .../sca/domain/node/GetServiceTestCase.java | 84 ++++++++++++ .../domain/node/MultipleNodesPerJVMTestCase.java | 87 +++++++++++++ .../tuscany/sca/domain/node/OneNodeTestCase.java | 105 +++++++++++++++ .../sca/domain/node/StopStartNodesTestCase.java | 82 ++++++++++++ .../apache/tuscany/sca/node2/DeployerTestCase.java | 77 +++++++++++ .../org/apache/tuscany/sca/node2/NodeTestCase.java | 141 +++++++++++++++++++++ .../apache/tuscany/sca/node2/NodeXMLTestCase.java | 44 +++++++ .../src/test/java/sample/Helloworld.java | 24 ++++ .../src/test/resources/helloworld2.composite | 29 +++++ .../src/test/resources/helloworldNode.xml | 27 ++++ .../itest-nodes-helloworld-client-2.0-SNAPSHOT.jar | Bin 0 -> 4708 bytes ...itest-nodes-helloworld-service-2.0-SNAPSHOT.jar | Bin 0 -> 4515 bytes .../resources/sample-helloworld-nodeployable.jar | Bin 0 -> 4761 bytes .../src/test/resources/sample-helloworld.jar | Bin 0 -> 4753 bytes .../test/resources/sca-contribution-generated.xml | 23 ++++ 16 files changed, 752 insertions(+) create mode 100644 sandbox/sebastien/java/vhost/modules/domain-node/src/test/java/itest/nodes/Helloworld.java create mode 100644 sandbox/sebastien/java/vhost/modules/domain-node/src/test/java/org/apache/tuscany/sca/domain/node/GetServiceTestCase.java create mode 100644 sandbox/sebastien/java/vhost/modules/domain-node/src/test/java/org/apache/tuscany/sca/domain/node/MultipleNodesPerJVMTestCase.java create mode 100644 sandbox/sebastien/java/vhost/modules/domain-node/src/test/java/org/apache/tuscany/sca/domain/node/OneNodeTestCase.java create mode 100644 sandbox/sebastien/java/vhost/modules/domain-node/src/test/java/org/apache/tuscany/sca/domain/node/StopStartNodesTestCase.java create mode 100644 sandbox/sebastien/java/vhost/modules/domain-node/src/test/java/org/apache/tuscany/sca/node2/DeployerTestCase.java create mode 100644 sandbox/sebastien/java/vhost/modules/domain-node/src/test/java/org/apache/tuscany/sca/node2/NodeTestCase.java create mode 100644 sandbox/sebastien/java/vhost/modules/domain-node/src/test/java/org/apache/tuscany/sca/node2/NodeXMLTestCase.java create mode 100644 sandbox/sebastien/java/vhost/modules/domain-node/src/test/java/sample/Helloworld.java create mode 100644 sandbox/sebastien/java/vhost/modules/domain-node/src/test/resources/helloworld2.composite create mode 100644 sandbox/sebastien/java/vhost/modules/domain-node/src/test/resources/helloworldNode.xml create mode 100644 sandbox/sebastien/java/vhost/modules/domain-node/src/test/resources/itest-nodes-helloworld-client-2.0-SNAPSHOT.jar create mode 100644 sandbox/sebastien/java/vhost/modules/domain-node/src/test/resources/itest-nodes-helloworld-service-2.0-SNAPSHOT.jar create mode 100644 sandbox/sebastien/java/vhost/modules/domain-node/src/test/resources/sample-helloworld-nodeployable.jar create mode 100644 sandbox/sebastien/java/vhost/modules/domain-node/src/test/resources/sample-helloworld.jar create mode 100644 sandbox/sebastien/java/vhost/modules/domain-node/src/test/resources/sca-contribution-generated.xml (limited to 'sandbox/sebastien/java/vhost/modules/domain-node/src/test') diff --git a/sandbox/sebastien/java/vhost/modules/domain-node/src/test/java/itest/nodes/Helloworld.java b/sandbox/sebastien/java/vhost/modules/domain-node/src/test/java/itest/nodes/Helloworld.java new file mode 100644 index 0000000000..76f8d4400d --- /dev/null +++ b/sandbox/sebastien/java/vhost/modules/domain-node/src/test/java/itest/nodes/Helloworld.java @@ -0,0 +1,29 @@ +/* + * 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 itest.nodes; + +import org.oasisopen.sca.annotation.Remotable; + +@Remotable +public interface Helloworld { + + String sayHello(String name); + +} diff --git a/sandbox/sebastien/java/vhost/modules/domain-node/src/test/java/org/apache/tuscany/sca/domain/node/GetServiceTestCase.java b/sandbox/sebastien/java/vhost/modules/domain-node/src/test/java/org/apache/tuscany/sca/domain/node/GetServiceTestCase.java new file mode 100644 index 0000000000..0a5d99ae7c --- /dev/null +++ b/sandbox/sebastien/java/vhost/modules/domain-node/src/test/java/org/apache/tuscany/sca/domain/node/GetServiceTestCase.java @@ -0,0 +1,84 @@ +/* + * 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.domain.node; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; +import itest.nodes.Helloworld; + +import org.junit.After; +import org.junit.Ignore; +import org.junit.Test; +import org.oasisopen.sca.ServiceRuntimeException; + +/** + * This shows how to test the Calculator service component. + */ +@Ignore("TUSCANY-3391") +public class GetServiceTestCase{ + + private static DomainNode clientNode; + private static DomainNode serviceNode; + + @Test + public void testTwoNodesSameDomain() throws Exception { + serviceNode = new DomainNode("target/test-classes/itest-nodes-helloworld-service-2.0-SNAPSHOT.jar"); + clientNode = new DomainNode("target/test-classes/itest-nodes-helloworld-client-2.0-SNAPSHOT.jar"); + + Helloworld service = serviceNode.getService(Helloworld.class, "HelloworldService"); + assertNotNull(service); + assertEquals("Hello Petra", service.sayHello("Petra")); + + Helloworld client = clientNode.getService(Helloworld.class, "HelloworldClient"); + assertNotNull(client); + assertEquals("Hi Hello Petra", client.sayHello("Petra")); + } + + @Test + public void testTwoNodesDifferentDomains() throws Exception { + serviceNode = new DomainNode("vm://fooDomain", new String[]{"target/test-classes/itest-nodes-helloworld-service-2.0-SNAPSHOT.jar"}); + Helloworld service = serviceNode.getService(Helloworld.class, "HelloworldService"); + assertNotNull(service); + assertEquals("Hello Petra", service.sayHello("Petra")); + + clientNode = new DomainNode("vm://barDomain", new String[] {"target/test-classes/itest-nodes-helloworld-client-2.0-SNAPSHOT.jar"}); + Helloworld client = clientNode.getService(Helloworld.class, "HelloworldClient"); + assertNotNull(client); + + try { + assertEquals("Hi Hello Petra", client.sayHello("Petra")); + fail(); + } catch (ServiceRuntimeException e) { + // FIXME: this gives an SCARuntimeException, would be better to be something like ServiceNotFoundException? + // expected + } + } + + @After + public void tearDownAfterClass() throws Exception { + if (clientNode != null) { + clientNode.stop(); + } + if (serviceNode != null) { + serviceNode.stop(); + } + } +} diff --git a/sandbox/sebastien/java/vhost/modules/domain-node/src/test/java/org/apache/tuscany/sca/domain/node/MultipleNodesPerJVMTestCase.java b/sandbox/sebastien/java/vhost/modules/domain-node/src/test/java/org/apache/tuscany/sca/domain/node/MultipleNodesPerJVMTestCase.java new file mode 100644 index 0000000000..617876586b --- /dev/null +++ b/sandbox/sebastien/java/vhost/modules/domain-node/src/test/java/org/apache/tuscany/sca/domain/node/MultipleNodesPerJVMTestCase.java @@ -0,0 +1,87 @@ +/* + * 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.domain.node; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; +import itest.nodes.Helloworld; + +import java.net.URI; + +import org.junit.After; +import org.junit.Ignore; +import org.junit.Test; +import org.oasisopen.sca.ServiceRuntimeException; +import org.oasisopen.sca.client.SCAClientFactory; + +/** + * This shows how to test the Calculator service component. + */ +@Ignore("TUSCANY-3391") +public class MultipleNodesPerJVMTestCase{ + + private static DomainNode clientNode; + private static DomainNode serviceNode; + + @Test + public void testTwoNodesSameDomain() throws Exception { + serviceNode = new DomainNode("target/test-classes/itest-nodes-helloworld-service-2.0-SNAPSHOT.jar"); + clientNode = new DomainNode("target/test-classes/itest-nodes-helloworld-client-2.0-SNAPSHOT.jar"); + + Helloworld service = SCAClientFactory.newInstance(URI.create("vm://defaultDomain")).getService(Helloworld.class, "HelloworldService"); + assertNotNull(service); + assertEquals("Hello Petra", service.sayHello("Petra")); + + Helloworld client = SCAClientFactory.newInstance(URI.create("vm://defaultDomain")).getService(Helloworld.class, "HelloworldClient"); + assertNotNull(client); + assertEquals("Hi Hello Petra", client.sayHello("Petra")); + } + + @Test + public void testTwoNodesDifferentDomains() throws Exception { + serviceNode = new DomainNode("vm://fooDomain", new String[]{"target/test-classes/itest-nodes-helloworld-service-2.0-SNAPSHOT.jar"}); + Helloworld service = SCAClientFactory.newInstance(URI.create("vm://fooDomain")).getService(Helloworld.class, "HelloworldService"); + assertNotNull(service); + assertEquals("Hello Petra", service.sayHello("Petra")); + + clientNode = new DomainNode("vm://barDomain", new String[]{"target/test-classes/itest-nodes-helloworld-client-2.0-SNAPSHOT.jar"}); + Helloworld client = SCAClientFactory.newInstance(URI.create("vm://barDomain")).getService(Helloworld.class, "HelloworldClient"); + assertNotNull(client); + + try { + assertEquals("Hi Hello Petra", client.sayHello("Petra")); + fail(); + } catch (ServiceRuntimeException e) { + // FIXME: this gives an SCARuntimeException, would be better to be something like ServiceNotFoundException? + // expected + } + } + + @After + public void tearDownAfterClass() throws Exception { + if (clientNode != null) { + clientNode.stop(); + } + if (serviceNode != null) { + serviceNode.stop(); + } + } +} diff --git a/sandbox/sebastien/java/vhost/modules/domain-node/src/test/java/org/apache/tuscany/sca/domain/node/OneNodeTestCase.java b/sandbox/sebastien/java/vhost/modules/domain-node/src/test/java/org/apache/tuscany/sca/domain/node/OneNodeTestCase.java new file mode 100644 index 0000000000..10803cd880 --- /dev/null +++ b/sandbox/sebastien/java/vhost/modules/domain-node/src/test/java/org/apache/tuscany/sca/domain/node/OneNodeTestCase.java @@ -0,0 +1,105 @@ +/* + * 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.domain.node; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; +import itest.nodes.Helloworld; + +import java.net.URI; + +import org.junit.After; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; +import org.oasisopen.sca.NoSuchDomainException; +import org.oasisopen.sca.NoSuchServiceException; +import org.oasisopen.sca.client.SCAClientFactory; + +/** + * This shows how to test the Calculator service component. + */ +@Ignore("TUSCANY-3391") +public class OneNodeTestCase{ + + private static DomainNode domain; + private static String serviceContributionUri; + + @Before + public void setUpBeforeClass() throws Exception { + domain = new DomainNode(); + serviceContributionUri = domain.addContribution("target/test-classes/itest-nodes-helloworld-service-2.0-SNAPSHOT.jar"); + domain.addContribution("target/test-classes/itest-nodes-helloworld-client-2.0-SNAPSHOT.jar"); + } + + @Test + public void testService() throws Exception { + Helloworld service = SCAClientFactory.newInstance(URI.create("vm://defaultDomain")).getService(Helloworld.class, "HelloworldService"); + assertNotNull(service); + assertEquals("Hello Petra", service.sayHello("Petra")); + } + + @Test + public void testClient() throws Exception { + Helloworld client = SCAClientFactory.newInstance(URI.create("vm://defaultDomain")).getService(Helloworld.class, "HelloworldClient"); + assertNotNull(client); + assertEquals("Hi Hello Petra", client.sayHello("Petra")); + } + + @Test + public void testRemovingServiceContribution() throws Exception { + domain.removeContribution(serviceContributionUri); + try { + SCAClientFactory.newInstance(URI.create("vm://defaultDomain")).getService(Helloworld.class, "HelloworldService"); + // FIXME: should this be NoSuchServiceException or ServiceNotFoundException? + } catch (NoSuchServiceException e) { + // expected + } + + Helloworld client = SCAClientFactory.newInstance(URI.create("vm://defaultDomain")).getService(Helloworld.class, "HelloworldClient"); + assertNotNull(client); + try { + assertEquals("Hi Hello Petra", client.sayHello("Petra")); + fail(); + } catch (Exception e) { + // FIXME: this gives an NPE, would be better to be something like ServiceNotFoundException + // expected + } + } + + @Test + public void testStoppingDomainNode() throws Exception { + domain.stop(); + try { + SCAClientFactory.newInstance(URI.create("vm://defaultDomain")).getService(Helloworld.class, "HelloworldClient"); + fail(); + } catch (NoSuchDomainException e) { + // expected + } + } + + @After + public void tearDownAfterClass() throws Exception { + if (domain != null) { + domain.stop(); + } + } +} diff --git a/sandbox/sebastien/java/vhost/modules/domain-node/src/test/java/org/apache/tuscany/sca/domain/node/StopStartNodesTestCase.java b/sandbox/sebastien/java/vhost/modules/domain-node/src/test/java/org/apache/tuscany/sca/domain/node/StopStartNodesTestCase.java new file mode 100644 index 0000000000..4a29822069 --- /dev/null +++ b/sandbox/sebastien/java/vhost/modules/domain-node/src/test/java/org/apache/tuscany/sca/domain/node/StopStartNodesTestCase.java @@ -0,0 +1,82 @@ +/* + * 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.domain.node; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; +import itest.nodes.Helloworld; + +import java.net.URI; + +import org.junit.After; +import org.junit.Ignore; +import org.junit.Test; +import org.oasisopen.sca.client.SCAClientFactory; + +/** + * This shows how to test the Calculator service component. + */ +@Ignore("TUSCANY-3391") +public class StopStartNodesTestCase{ + + private static DomainNode clientNode; + private static DomainNode serviceNode; + + @Test + public void testTwoNodesSameDomain() throws Exception { + serviceNode = new DomainNode("vm://fooDomain", new String[]{"target/test-classes/itest-nodes-helloworld-service-2.0-SNAPSHOT.jar"}); + clientNode = new DomainNode("vm://fooDomain", new String[]{"target/test-classes/itest-nodes-helloworld-client-2.0-SNAPSHOT.jar"}); + + Helloworld service = SCAClientFactory.newInstance(URI.create("vm://fooDomain")).getService(Helloworld.class, "HelloworldService"); + assertNotNull(service); + assertEquals("Hello Petra", service.sayHello("Petra")); + + Helloworld client = SCAClientFactory.newInstance(URI.create("vm://fooDomain")).getService(Helloworld.class, "HelloworldClient"); + assertNotNull(client); + assertEquals("Hi Hello Petra", client.sayHello("Petra")); + + serviceNode.stop(); + + client = SCAClientFactory.newInstance(URI.create("vm://fooDomain")).getService(Helloworld.class, "HelloworldClient"); + assertNotNull(client); + try { + assertEquals("Hi Hello Petra", client.sayHello("Petra")); + fail(); + } catch (Exception e) { + // expected + } + + serviceNode = new DomainNode("vm://fooDomain", new String[]{"target/test-classes/itest-nodes-helloworld-service-2.0-SNAPSHOT.jar"}); + client = SCAClientFactory.newInstance(URI.create("vm://fooDomain")).getService(Helloworld.class, "HelloworldClient"); + assertNotNull(client); + assertEquals("Hi Hello Petra", client.sayHello("Petra")); + } + + @After + public void tearDownAfterClass() throws Exception { + if (clientNode != null) { + clientNode.stop(); + } + if (serviceNode != null) { + serviceNode.stop(); + } + } +} diff --git a/sandbox/sebastien/java/vhost/modules/domain-node/src/test/java/org/apache/tuscany/sca/node2/DeployerTestCase.java b/sandbox/sebastien/java/vhost/modules/domain-node/src/test/java/org/apache/tuscany/sca/node2/DeployerTestCase.java new file mode 100644 index 0000000000..40509337c8 --- /dev/null +++ b/sandbox/sebastien/java/vhost/modules/domain-node/src/test/java/org/apache/tuscany/sca/node2/DeployerTestCase.java @@ -0,0 +1,77 @@ +/* + * 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.node2; + +import java.io.File; +import java.net.MalformedURLException; +import java.net.URI; +import java.util.List; + +import javax.xml.stream.XMLStreamException; + +import junit.framework.Assert; + +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.deployment.Deployer; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.ValidationException; +import org.apache.tuscany.sca.runtime.ActivationException; +import org.junit.Test; +import org.oasisopen.sca.NoSuchDomainException; +import org.oasisopen.sca.NoSuchServiceException; + +public class DeployerTestCase { + + @Test + public void testInstalledContribution() throws NoSuchServiceException, NoSuchDomainException, ContributionReadException, ActivationException, ValidationException, MalformedURLException { + NodeFactory nodeFactory = NodeFactory.newInstance(); + Node node = nodeFactory.createNode("myDomain"); + + Deployer deployer = nodeFactory.getDeployer(); + Monitor monitor = deployer.createMonitor(); + Contribution contribution = deployer.loadContribution(URI.create("foo"), new File("src/test/resources/sample-helloworld-nodeployable.jar").toURI().toURL(), monitor); + monitor.analyzeProblems(); + + node.installContribution(contribution, null, true); + List ics = node.getInstalledContributionURIs(); + Assert.assertEquals(1, ics.size()); + Assert.assertEquals("foo", ics.get(0)); + } + + @Test + public void testAddDeploymentComposite() throws NoSuchServiceException, NoSuchDomainException, ContributionReadException, ActivationException, ValidationException, MalformedURLException, XMLStreamException { + NodeFactory nodeFactory = NodeFactory.newInstance(); + Node node = nodeFactory.createNode("myDomain"); + + node.installContribution("foo", "src/test/resources/sample-helloworld-nodeployable.jar", null, null, true); + + Deployer deployer = nodeFactory.getDeployer(); + Monitor monitor = deployer.createMonitor(); + Composite composite = deployer.loadXMLDocument(new File("src/test/resources/helloworld2.composite").toURI().toURL(), monitor); + monitor.analyzeProblems(); + composite.setURI("helloworld2.composite"); + node.start("foo", composite); + List dcs = node.getStartedCompositeURIs("foo"); + Assert.assertEquals(1, dcs.size()); + Assert.assertEquals("helloworld2.composite", dcs.get(0)); + } + +} diff --git a/sandbox/sebastien/java/vhost/modules/domain-node/src/test/java/org/apache/tuscany/sca/node2/NodeTestCase.java b/sandbox/sebastien/java/vhost/modules/domain-node/src/test/java/org/apache/tuscany/sca/node2/NodeTestCase.java new file mode 100644 index 0000000000..6637f05979 --- /dev/null +++ b/sandbox/sebastien/java/vhost/modules/domain-node/src/test/java/org/apache/tuscany/sca/node2/NodeTestCase.java @@ -0,0 +1,141 @@ +/* + * 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.node2; + +import java.net.MalformedURLException; +import java.util.List; + +import junit.framework.Assert; + +import org.apache.tuscany.sca.contribution.processor.ContributionReadException; +import org.apache.tuscany.sca.monitor.ValidationException; +import org.apache.tuscany.sca.node2.impl.NodeImpl; +import org.apache.tuscany.sca.runtime.ActivationException; +import org.junit.Ignore; +import org.junit.Test; +import org.oasisopen.sca.NoSuchDomainException; +import org.oasisopen.sca.NoSuchServiceException; + +public class NodeTestCase { + + @Test + public void testInstallDeployable() throws NoSuchServiceException, NoSuchDomainException, ContributionReadException, ActivationException, ValidationException { + Node node = NodeFactory.newInstance().createNode("default"); + node.installContribution("helloworld", "src/test/resources/sample-helloworld.jar", null, null, true); + +// Helloworld helloworldService = node.getService(Helloworld.class, "HelloworldComponent"); +// Assert.assertEquals("Hello petra", helloworldService.sayHello("petra")); + } + + @Test + @Ignore("Depdends on itest/T3558 which isn't in the build?") + public void testInstallWithDependent() throws NoSuchServiceException, ContributionReadException, ActivationException, ValidationException { + Node node = NodeFactory.newInstance().createNode("default"); + node.installContribution("store", "../../itest/T3558/src/test/resources/sample-store.jar", null, null, true); + node.installContribution("store-client", "../../itest/T3558/src/test/resources/sample-store-client.jar", null, null, true); + +// Helloworld helloworldService = node.getService(Helloworld.class, "HelloworldComponent"); +// Assert.assertEquals("Hello petra", helloworldService.sayHello("petra")); + } + + @Test + public void testInstallNoDeployable() throws NoSuchServiceException, NoSuchDomainException, ContributionReadException, ActivationException, ValidationException { + Node node = NodeFactory.newInstance().createNode("default"); + node.installContribution("helloworld", "src/test/resources/sample-helloworld-nodeployable.jar", null, null, true); + +// SCAClientFactory scaClientFactory = node.getSCAClientFactory(); +// try { +// scaClientFactory.getService(Helloworld.class, "HelloworldComponent"); +// Assert.fail(); +// } catch (NoSuchServiceException e) { +// // expected as there is no deployables +// } + + node.start("helloworld", "helloworld.composite"); +// Helloworld helloworldService = scaClientFactory.getService(Helloworld.class, "HelloworldComponent"); +// Assert.assertEquals("Hello petra", helloworldService.sayHello("petra")); + } + + @Test + public void testGetInstalledContributions() throws NoSuchServiceException, NoSuchDomainException, ContributionReadException, ActivationException, ValidationException { + Node node = NodeFactory.newInstance().createNode("default"); + node.installContribution("foo", "src/test/resources/sample-helloworld-nodeployable.jar", null, null, true); + List ics = node.getInstalledContributionURIs(); + Assert.assertEquals(1, ics.size()); + Assert.assertEquals("foo", ics.get(0)); + } + + @Test + public void testGetDeployedCompostes() throws NoSuchServiceException, NoSuchDomainException, ContributionReadException, MalformedURLException, ActivationException, ValidationException { + Node node = NodeFactory.newInstance().createNode("default"); + node.installContribution("foo", "src/test/resources/sample-helloworld.jar", null, null, true); + List dcs = node.getStartedCompositeURIs("foo"); + Assert.assertEquals(1, dcs.size()); + Assert.assertEquals("helloworld.composite", dcs.get(0)); + } + + @Test + public void testRemoveComposte() throws NoSuchServiceException, NoSuchDomainException, ContributionReadException, MalformedURLException, ActivationException, ValidationException { + Node node = NodeFactory.newInstance().createNode("default"); + node.installContribution("foo", "src/test/resources/sample-helloworld.jar", null, null, true); + node.stop("foo", "helloworld.composite"); + List dcs = node.getStartedCompositeURIs("foo"); + Assert.assertEquals(0, dcs.size()); + } + + @Test + public void testInstallWithMetaData() throws ContributionReadException, ActivationException, ValidationException { + Node node = NodeFactory.newInstance().createNode("default"); + ((NodeImpl)node).installContribution("helloworld", "src/test/resources/sample-helloworld-nodeployable.jar", "src/test/resources/sca-contribution-generated.xml", null, true); + + List dcs = node.getStartedCompositeURIs("helloworld"); + Assert.assertEquals(1, dcs.size()); + Assert.assertEquals("helloworld.composite", dcs.get(0)); + +// Helloworld helloworldService = scaClientFactory.getService(Helloworld.class, "HelloworldComponent"); +// Assert.assertEquals("Hello petra", helloworldService.sayHello("petra")); + } + + @Test + public void testURI() throws NoSuchServiceException, NoSuchDomainException, ContributionReadException, ActivationException, ValidationException { + Node node = NodeFactory.newInstance().createNode("default"); + String uri = node.installContribution("src/test/resources/sample-helloworld.jar"); + Assert.assertEquals("sample-helloworld", uri); + } + + @Test + public void testStaticCreate() { + Node node = NodeFactory.newStandaloneNode("helloworld.composite", "src/test/resources/sample-helloworld.jar"); + List cs = node.getInstalledContributionURIs(); + Assert.assertEquals(1, cs.size()); + List dcs = node.getStartedCompositeURIs(cs.get(0)); + Assert.assertEquals(1, dcs.size()); + Assert.assertEquals("helloworld.composite", dcs.get(0)); + } + + @Test + public void testStaticCreateWithNullComposite() { + Node node = NodeFactory.newStandaloneNode(null, "src/test/resources/sample-helloworld.jar"); + List cs = node.getInstalledContributionURIs(); + Assert.assertEquals(1, cs.size()); + List dcs = node.getStartedCompositeURIs(cs.get(0)); + Assert.assertEquals(1, dcs.size()); + Assert.assertEquals("helloworld.composite", dcs.get(0)); + } +} diff --git a/sandbox/sebastien/java/vhost/modules/domain-node/src/test/java/org/apache/tuscany/sca/node2/NodeXMLTestCase.java b/sandbox/sebastien/java/vhost/modules/domain-node/src/test/java/org/apache/tuscany/sca/node2/NodeXMLTestCase.java new file mode 100644 index 0000000000..5e265a0c8a --- /dev/null +++ b/sandbox/sebastien/java/vhost/modules/domain-node/src/test/java/org/apache/tuscany/sca/node2/NodeXMLTestCase.java @@ -0,0 +1,44 @@ +/* + * 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.node2; + +import java.util.List; + +import junit.framework.Assert; + +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; + +public class NodeXMLTestCase { + + @Test + public void testHelloworldXML() throws ContributionReadException, ActivationException, ValidationException { + Node node = NodeFactory.newInstance().createNodeFromXML("src/test/resources/helloworldNode.xml"); + Assert.assertEquals("helloworld", node.getDomainName()); + List cs = node.getInstalledContributionURIs(); + Assert.assertEquals(1, cs.size()); + Assert.assertEquals("sample-helloworld", cs.get(0)); + List compsoites = node.getStartedCompositeURIs("sample-helloworld"); + Assert.assertEquals(1, compsoites.size()); + Assert.assertEquals("helloworld.composite", compsoites.get(0)); + } + +} diff --git a/sandbox/sebastien/java/vhost/modules/domain-node/src/test/java/sample/Helloworld.java b/sandbox/sebastien/java/vhost/modules/domain-node/src/test/java/sample/Helloworld.java new file mode 100644 index 0000000000..ea65a1e58c --- /dev/null +++ b/sandbox/sebastien/java/vhost/modules/domain-node/src/test/java/sample/Helloworld.java @@ -0,0 +1,24 @@ +/* + * 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 sample; + +public interface Helloworld { + String sayHello(String name); +} diff --git a/sandbox/sebastien/java/vhost/modules/domain-node/src/test/resources/helloworld2.composite b/sandbox/sebastien/java/vhost/modules/domain-node/src/test/resources/helloworld2.composite new file mode 100644 index 0000000000..8c7a789380 --- /dev/null +++ b/sandbox/sebastien/java/vhost/modules/domain-node/src/test/resources/helloworld2.composite @@ -0,0 +1,29 @@ + + + + + + + + + diff --git a/sandbox/sebastien/java/vhost/modules/domain-node/src/test/resources/helloworldNode.xml b/sandbox/sebastien/java/vhost/modules/domain-node/src/test/resources/helloworldNode.xml new file mode 100644 index 0000000000..ea2f577139 --- /dev/null +++ b/sandbox/sebastien/java/vhost/modules/domain-node/src/test/resources/helloworldNode.xml @@ -0,0 +1,27 @@ + + + + + + + \ No newline at end of file diff --git a/sandbox/sebastien/java/vhost/modules/domain-node/src/test/resources/itest-nodes-helloworld-client-2.0-SNAPSHOT.jar b/sandbox/sebastien/java/vhost/modules/domain-node/src/test/resources/itest-nodes-helloworld-client-2.0-SNAPSHOT.jar new file mode 100644 index 0000000000..3e9ae79a41 Binary files /dev/null and b/sandbox/sebastien/java/vhost/modules/domain-node/src/test/resources/itest-nodes-helloworld-client-2.0-SNAPSHOT.jar differ diff --git a/sandbox/sebastien/java/vhost/modules/domain-node/src/test/resources/itest-nodes-helloworld-service-2.0-SNAPSHOT.jar b/sandbox/sebastien/java/vhost/modules/domain-node/src/test/resources/itest-nodes-helloworld-service-2.0-SNAPSHOT.jar new file mode 100644 index 0000000000..40333cab75 Binary files /dev/null and b/sandbox/sebastien/java/vhost/modules/domain-node/src/test/resources/itest-nodes-helloworld-service-2.0-SNAPSHOT.jar differ diff --git a/sandbox/sebastien/java/vhost/modules/domain-node/src/test/resources/sample-helloworld-nodeployable.jar b/sandbox/sebastien/java/vhost/modules/domain-node/src/test/resources/sample-helloworld-nodeployable.jar new file mode 100644 index 0000000000..16dde03858 Binary files /dev/null and b/sandbox/sebastien/java/vhost/modules/domain-node/src/test/resources/sample-helloworld-nodeployable.jar differ diff --git a/sandbox/sebastien/java/vhost/modules/domain-node/src/test/resources/sample-helloworld.jar b/sandbox/sebastien/java/vhost/modules/domain-node/src/test/resources/sample-helloworld.jar new file mode 100644 index 0000000000..50e732d50b Binary files /dev/null and b/sandbox/sebastien/java/vhost/modules/domain-node/src/test/resources/sample-helloworld.jar differ diff --git a/sandbox/sebastien/java/vhost/modules/domain-node/src/test/resources/sca-contribution-generated.xml b/sandbox/sebastien/java/vhost/modules/domain-node/src/test/resources/sca-contribution-generated.xml new file mode 100644 index 0000000000..8e20561dc3 --- /dev/null +++ b/sandbox/sebastien/java/vhost/modules/domain-node/src/test/resources/sca-contribution-generated.xml @@ -0,0 +1,23 @@ + + + + + -- cgit v1.2.3