diff options
Diffstat (limited to 'sca-java-2.x/trunk/samples/implementation-extension/src/test')
4 files changed, 169 insertions, 9 deletions
diff --git a/sca-java-2.x/trunk/samples/implementation-extension/src/test/java/sample/impl/EmbedTestCase.java b/sca-java-2.x/trunk/samples/implementation-extension/src/test/java/sample/impl/EmbedTestCase.java new file mode 100644 index 0000000000..98057bf34e --- /dev/null +++ b/sca-java-2.x/trunk/samples/implementation-extension/src/test/java/sample/impl/EmbedTestCase.java @@ -0,0 +1,124 @@ +/* + * 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.impl; + +import static java.lang.System.out; +import static org.junit.Assert.assertEquals; +import static sample.impl.EmbedUtil.component; +import static sample.impl.EmbedUtil.composite; +import static sample.impl.EmbedUtil.contrib; +import static sample.impl.EmbedUtil.deploy; +import static sample.impl.EmbedUtil.implementation; +import static sample.impl.EmbedUtil.node; +import static sample.impl.EmbedUtil.reference; +import static sample.impl.EmbedUtil.service; +import static sample.impl.EmbedUtil.wsdli; +import static sample.impl.TestUtil.here; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface; +import org.apache.tuscany.sca.node.Node; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +import sample.Client; +import sample.ClientTest; +import sample.Hello; +import sample.JelloTest; +import sample.Upper; +import sample.UpperTest; +import sample.WelloTest; + +/** + * Test assemble and run SCDL. + * + * @version $Rev$ $Date$ + */ +public class EmbedTestCase { + static Node node; + + @BeforeClass + public static void setUp() throws Exception { + + // Load the test WSDL definitions (could also construct + // the WSDL and XSD models in code but that'd be quite + // painful, so just load them from XML for now) + final Contribution contrib = contrib("test", here()); + WSDLInterface Hello_wsdl = wsdli("Hello.wsdl", "http://sample", "Hello", contrib); + WSDLInterface Upper_wsdl = wsdli("Upper.wsdl", "http://sample", "Upper", contrib); + + // Assemble a test composite model (see EmbedUtil + // for the little DSL used here, much more concise + // than using the assembly model interfaces) + final Composite comp = + composite("http://sample", "test", + component("client-test", + implementation(ClientTest.class, + service(Client.class), + reference("jello", Hello.class), + reference("wello", Hello_wsdl)), + reference("jello", "jello-test"), + reference("wello", "wello-test")), + component("wello-test", + implementation(WelloTest.class, + service(Hello_wsdl), + reference("upper", Upper_wsdl)), + reference("upper", "upper-test")), + component("jello-test", + implementation(JelloTest.class, + service(Hello.class), + reference("upper", Upper.class)), + reference("upper", "upper-test")), + component("upper-test", + implementation(UpperTest.class, + service(Upper.class)))); + + // Run with it + node = node("test", deploy(contrib, comp)); + node.start(); + } + + @AfterClass + public static void tearDown() throws Exception { + node.stop(); + } + + @Test + public void jello() { + out.println("RunTestCase.jello"); + final String r = client().jello("Java"); + out.println(r); + assertEquals("HELLO JAVA", r); + } + + @Test + public void wello() { + out.println("RunTestCase.wello"); + final String r = client().wello("WSDL"); + out.println(r); + assertEquals("HELLO WSDL", r); + } + + static Client client() { + return node.getService(Client.class, "client-test/Client"); + } +} diff --git a/sca-java-2.x/trunk/samples/implementation-extension/src/test/java/sample/impl/ReadWriteTestCase.java b/sca-java-2.x/trunk/samples/implementation-extension/src/test/java/sample/impl/ReadWriteTestCase.java index 8d01c82edf..ad507f80ac 100644 --- a/sca-java-2.x/trunk/samples/implementation-extension/src/test/java/sample/impl/ReadWriteTestCase.java +++ b/sca-java-2.x/trunk/samples/implementation-extension/src/test/java/sample/impl/ReadWriteTestCase.java @@ -22,6 +22,7 @@ package sample.impl; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import static sample.impl.TestUtil.here; import java.io.ByteArrayOutputStream; import java.io.InputStream; @@ -56,7 +57,7 @@ public class ReadWriteTestCase { public static void setUp() throws Exception { final DefaultExtensionPointRegistry ep = new DefaultExtensionPointRegistry(); final Contribution contrib = new DefaultContributionFactory().createContribution(); - contrib.setLocation(ReadWriteTestCase.class.getProtectionDomain().getCodeSource().getLocation().toString()); + contrib.setLocation(here()); ctx = new ProcessorContext(contrib, null); xif = XMLInputFactory.newInstance(); xof = XMLOutputFactory.newInstance(); diff --git a/sca-java-2.x/trunk/samples/implementation-extension/src/test/java/sample/impl/RunTestCase.java b/sca-java-2.x/trunk/samples/implementation-extension/src/test/java/sample/impl/RunTestCase.java index 26cbd5d3e4..a2e1f9ed45 100644 --- a/sca-java-2.x/trunk/samples/implementation-extension/src/test/java/sample/impl/RunTestCase.java +++ b/sca-java-2.x/trunk/samples/implementation-extension/src/test/java/sample/impl/RunTestCase.java @@ -20,6 +20,8 @@ package sample.impl; import static java.lang.System.out; +import static org.junit.Assert.assertEquals; +import static sample.impl.TestUtil.here; import org.apache.tuscany.sca.node.Contribution; import org.apache.tuscany.sca.node.Node; @@ -41,8 +43,7 @@ public class RunTestCase { @BeforeClass public static void setUp() throws Exception { final NodeFactory nf = NodeFactory.newInstance(); - final String here = RunTestCase.class.getProtectionDomain().getCodeSource().getLocation().toString(); - node = nf.createNode(new Contribution("test", here)); + node = nf.createNode(new Contribution("test", here())); node.start(); } @@ -51,20 +52,23 @@ public class RunTestCase { node.stop(); } - Client client() { - return node.getService(Client.class, "client-test/Client"); - } - @Test public void jello() { out.println("RunTestCase.jello"); - out.println(client().jello("Java")); + final String r = client().jello("Java"); + out.println(r); + assertEquals("HELLO JAVA", r); } @Test public void wello() { out.println("RunTestCase.wello"); - out.println(client().wello("WSDL")); + final String r = client().wello("WSDL"); + out.println(r); + assertEquals("HELLO WSDL", r); } + static Client client() { + return node.getService(Client.class, "client-test/Client"); + } } diff --git a/sca-java-2.x/trunk/samples/implementation-extension/src/test/java/sample/impl/TestUtil.java b/sca-java-2.x/trunk/samples/implementation-extension/src/test/java/sample/impl/TestUtil.java new file mode 100644 index 0000000000..6dcfb33912 --- /dev/null +++ b/sca-java-2.x/trunk/samples/implementation-extension/src/test/java/sample/impl/TestUtil.java @@ -0,0 +1,31 @@ +/* + * 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.impl; + +/** + * A hack to determine the test contribution location. + */ +public class TestUtil { + + static String here() { + return TestUtil.class.getProtectionDomain().getCodeSource().getLocation().toString(); + } + +} |