From c791fd804344b8719fb69be84b8174c84cc4f4dc Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Mon, 10 Jan 2011 19:51:07 +0000 Subject: Sandbox to experiment with Databinding automatic wrapper transformations. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1057335 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/test/java/sample/impl/EmbedTestCase.java | 151 +++++++++++++++++++++ .../test/java/sample/impl/ReadWriteTestCase.java | 93 +++++++++++++ .../src/test/java/sample/impl/RunTestCase.java | 75 ++++++++++ .../src/test/java/sample/impl/RunWSTestCase.java | 120 ++++++++++++++++ .../sample/impl/SampleNativeAsyncBareTestCase.java | 66 +++++++++ .../sample/impl/SampleNativeAsyncTestCase.java | 64 +++++++++ .../sample/impl/SampleNativeJMSAsyncTestCase.java | 64 +++++++++ .../src/test/java/sample/impl/TestUtil.java | 31 +++++ 8 files changed, 664 insertions(+) create mode 100644 sandbox/sebastien/java/wrapped/samples/extending-tuscany/implementation-sample/src/test/java/sample/impl/EmbedTestCase.java create mode 100644 sandbox/sebastien/java/wrapped/samples/extending-tuscany/implementation-sample/src/test/java/sample/impl/ReadWriteTestCase.java create mode 100644 sandbox/sebastien/java/wrapped/samples/extending-tuscany/implementation-sample/src/test/java/sample/impl/RunTestCase.java create mode 100644 sandbox/sebastien/java/wrapped/samples/extending-tuscany/implementation-sample/src/test/java/sample/impl/RunWSTestCase.java create mode 100644 sandbox/sebastien/java/wrapped/samples/extending-tuscany/implementation-sample/src/test/java/sample/impl/SampleNativeAsyncBareTestCase.java create mode 100644 sandbox/sebastien/java/wrapped/samples/extending-tuscany/implementation-sample/src/test/java/sample/impl/SampleNativeAsyncTestCase.java create mode 100644 sandbox/sebastien/java/wrapped/samples/extending-tuscany/implementation-sample/src/test/java/sample/impl/SampleNativeJMSAsyncTestCase.java create mode 100644 sandbox/sebastien/java/wrapped/samples/extending-tuscany/implementation-sample/src/test/java/sample/impl/TestUtil.java (limited to 'sandbox/sebastien/java/wrapped/samples/extending-tuscany/implementation-sample/src/test/java/sample/impl') diff --git a/sandbox/sebastien/java/wrapped/samples/extending-tuscany/implementation-sample/src/test/java/sample/impl/EmbedTestCase.java b/sandbox/sebastien/java/wrapped/samples/extending-tuscany/implementation-sample/src/test/java/sample/impl/EmbedTestCase.java new file mode 100644 index 0000000000..406dbabee0 --- /dev/null +++ b/sandbox/sebastien/java/wrapped/samples/extending-tuscany/implementation-sample/src/test/java/sample/impl/EmbedTestCase.java @@ -0,0 +1,151 @@ +/* + * 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.build; +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.embedContext; +import static sample.impl.EmbedUtil.extensionPoints; +import static sample.impl.EmbedUtil.implementation; +import static sample.impl.EmbedUtil.node; +import static sample.impl.EmbedUtil.providerFactories; +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.apache.tuscany.sca.node.NodeFactory; +import org.apache.tuscany.sca.provider.ImplementationProvider; +import org.apache.tuscany.sca.provider.ProviderFactory; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +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 how to assemble a contribution, a SCDL composite and run it on an embedded + * Tuscany runtime node. Also shows how pass in a ProviderFactory instead of having + * it loaded and constructed by the runtime node. + * + * @version $Rev$ $Date$ + */ +public class EmbedTestCase { + static NodeFactory nf; + static EmbedUtil.Context ec; + static Node node; + + @SuppressWarnings("unchecked") + @BeforeClass + public static void setUp() throws Exception { + nf = NodeFactory.newInstance(); + ec = embedContext(nf); + + // 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 = build(contrib("test", here()), ec); + WSDLInterface Hello_wsdl = build(wsdli("Hello.wsdl", "http://sample/hello", "Hello", contrib), ec); + WSDLInterface Upper_wsdl = build(wsdli("Upper.wsdl", "http://sample/upper", "Upper", contrib), ec); + + // 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 = + build(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)))), ec); + + // Register a test instance of our sample implementation ProviderFactory + providerFactories(ec).addProviderFactory(testProviderFactory()); + + // Run with it + node = node(nf, deploy(contrib, comp)); + node.start(); + } + + static ProviderFactory testProviderFactory() { + // This shows how to get called when a provider is created + return new SampleProviderFactory(extensionPoints(ec)) { + public ImplementationProvider createImplementationProvider(RuntimeComponent comp, SampleImplementation impl) { + out.println("Creating a provider for component " + comp.getName()); + return super.createImplementationProvider(comp, impl); + }}; + } + + @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/sandbox/sebastien/java/wrapped/samples/extending-tuscany/implementation-sample/src/test/java/sample/impl/ReadWriteTestCase.java b/sandbox/sebastien/java/wrapped/samples/extending-tuscany/implementation-sample/src/test/java/sample/impl/ReadWriteTestCase.java new file mode 100644 index 0000000000..c165fcd94a --- /dev/null +++ b/sandbox/sebastien/java/wrapped/samples/extending-tuscany/implementation-sample/src/test/java/sample/impl/ReadWriteTestCase.java @@ -0,0 +1,93 @@ +/* + * 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 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; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.DefaultContributionFactory; +import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * Test read/write Sample SCDL implementation elements. + * + * @version $Rev$ $Date$ + */ +public class ReadWriteTestCase { + static XMLInputFactory xif; + static XMLOutputFactory xof; + static StAXArtifactProcessor xproc; + static ProcessorContext ctx; + + @BeforeClass + public static void setUp() throws Exception { + final DefaultExtensionPointRegistry ep = new DefaultExtensionPointRegistry(); + final Contribution contrib = new DefaultContributionFactory().createContribution(); + contrib.setLocation(here()); + ctx = new ProcessorContext(contrib, null); + xif = XMLInputFactory.newInstance(); + xof = XMLOutputFactory.newInstance(); + final StAXArtifactProcessorExtensionPoint xpep = new DefaultStAXArtifactProcessorExtensionPoint(ep); + xproc = new ExtensibleStAXArtifactProcessor(xpep, xif, xof); + } + + @Test + public void testRead() throws Exception { + final InputStream is = getClass().getClassLoader().getResourceAsStream("test.composite"); + final Composite c = (Composite)xproc.read(xif.createXMLStreamReader(is), ctx); + assertNotNull(c); + assertEquals("sample.ClientTest", ((SampleImplementation)c.getComponents().get(0).getImplementation()).name); + } + + @Test + public void testReadWrite() throws Exception { + final InputStream is = getClass().getClassLoader().getResourceAsStream("test.composite"); + final Composite c = (Composite)xproc.read(xif.createXMLStreamReader(is), ctx); + System.out.println("Composite : " + c.getURI()); + for (Component component : c.getComponents()){ + System.out.println(" Component : " + component.getName()); + } + final ByteArrayOutputStream bos = new ByteArrayOutputStream(); + XMLStreamWriter writer = xof.createXMLStreamWriter(bos); + xproc.write(c, writer, ctx); + writer.close(); + System.out.println("Written XML = " + bos.toString()); + assertTrue(bos.toString().contains("class=\"sample.WelloTest\"")); + } +} diff --git a/sandbox/sebastien/java/wrapped/samples/extending-tuscany/implementation-sample/src/test/java/sample/impl/RunTestCase.java b/sandbox/sebastien/java/wrapped/samples/extending-tuscany/implementation-sample/src/test/java/sample/impl/RunTestCase.java new file mode 100644 index 0000000000..1faa5b2ca6 --- /dev/null +++ b/sandbox/sebastien/java/wrapped/samples/extending-tuscany/implementation-sample/src/test/java/sample/impl/RunTestCase.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 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; +import org.apache.tuscany.sca.node.NodeFactory; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +import sample.Client; + +/** + * Test how to run an SCA contribution containing a test composite on a + * Tuscany runtime node. + * + * @version $Rev$ $Date$ + */ +public class RunTestCase { + static Node node; + + @BeforeClass + public static void setUp() throws Exception { + final NodeFactory nf = NodeFactory.newInstance(); + node = nf.createNode("test.composite", new Contribution("test", here())); + 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/sandbox/sebastien/java/wrapped/samples/extending-tuscany/implementation-sample/src/test/java/sample/impl/RunWSTestCase.java b/sandbox/sebastien/java/wrapped/samples/extending-tuscany/implementation-sample/src/test/java/sample/impl/RunWSTestCase.java new file mode 100644 index 0000000000..dcade6a818 --- /dev/null +++ b/sandbox/sebastien/java/wrapped/samples/extending-tuscany/implementation-sample/src/test/java/sample/impl/RunWSTestCase.java @@ -0,0 +1,120 @@ +/* + * 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.assertTrue; +import static sample.impl.TestUtil.here; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.net.Socket; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.http.jetty.JettyServer; +import org.apache.tuscany.sca.node.Contribution; +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.node.NodeFactory; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * Test a component that provides and consumes SOAP Web services. + * + * @version $Rev$ $Date$ + */ +public class RunWSTestCase { + static Node node; + static JettyServer jetty; + + @BeforeClass + public static void setUp() throws Exception { + // Start test composite on a Tuscany node + final NodeFactory nf = NodeFactory.newInstance(); + node = nf.createNode("test.composite", new Contribution("test", here())); + node.start(); + + // Mock up a test Web service on http://localhost:8086/wsupper + jetty = new JettyServer((ExtensionPointRegistry)nf.getExtensionPointRegistry()); + jetty.start(); + jetty.addServletMapping("http://localhost:8086/wsupper", new HttpServlet() { + private static final long serialVersionUID = 1L; + protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + assertTrue(read(req.getInputStream()).contains("Hello SOAP")); + final String soapresp = + "" + + "" + + "HELLO SOAP" + + ""; + + write(soapresp, resp.getOutputStream()); + } + }); + } + + @AfterClass + public static void tearDown() throws Exception { + jetty.stop(); + node.stop(); + } + + @Test + public void wsello() throws Exception { + out.println("RunWSTestCase.wsello"); + // Send a SOAP request to the Web service provided by SCA component wsello-test + // on http://localhost:8085/wsello + final Socket s = new Socket("localhost", 8085); + final String soapreq = + "POST /wsello HTTP/1.0\r\n" + + "Content-Type: text/xml; charset=UTF-8\r\n" + + "Content-length: 231\r\n\r\n" + + "" + + "" + + "SOAP" + + ""; + write(soapreq, s.getOutputStream()); + assertTrue(read(s.getInputStream()).contains("HELLO SOAP")); + } + + static void write(final String s, final OutputStream o) throws IOException { + final OutputStreamWriter w = new OutputStreamWriter(o); + w.write(s); + w.flush(); + } + + static String read(final InputStream i) throws IOException { + return read(new BufferedReader(new InputStreamReader(i))); + } + + static String read(final BufferedReader r) throws IOException { + final String s = r.readLine(); + return s == null? "" : s + read(r); + } +} diff --git a/sandbox/sebastien/java/wrapped/samples/extending-tuscany/implementation-sample/src/test/java/sample/impl/SampleNativeAsyncBareTestCase.java b/sandbox/sebastien/java/wrapped/samples/extending-tuscany/implementation-sample/src/test/java/sample/impl/SampleNativeAsyncBareTestCase.java new file mode 100644 index 0000000000..d40fdbf6b3 --- /dev/null +++ b/sandbox/sebastien/java/wrapped/samples/extending-tuscany/implementation-sample/src/test/java/sample/impl/SampleNativeAsyncBareTestCase.java @@ -0,0 +1,66 @@ +/* + * 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 org.junit.Assert.assertEquals; + +import org.apache.tuscany.sca.node.Contribution; +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.node.NodeFactory; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; + +import sample.Upper; + +/** + * Test how to run an SCA contribution containing a test composite on a + * Tuscany runtime node. + * + * @version $Rev$ $Date$ + */ +public class SampleNativeAsyncBareTestCase { + static Node node; + + @BeforeClass + public static void setUp() throws Exception { + final NodeFactory nf = NodeFactory.newInstance(); + String here = SampleNativeAsyncBareTestCase.class.getProtectionDomain().getCodeSource().getLocation().toString(); + // Create the node using the pattern "name of composite file to start" / Contribution to use + node = nf.createNode("testnativeasyncbare.composite", new Contribution("test", here)); + node.start(); + } + + @AfterClass + public static void tearDown() throws Exception { + node.stop(); + } + + @Test + @Ignore + public void testReference() { + System.out.println("SampleNaiveAsyncBareTestCase.testReference"); + Upper upper = node.getService(Upper.class, "SampleNativeAsyncReference"); + final String r = upper.upper("async"); + System.out.println(r); + assertEquals("ASYNC", r); + } +} diff --git a/sandbox/sebastien/java/wrapped/samples/extending-tuscany/implementation-sample/src/test/java/sample/impl/SampleNativeAsyncTestCase.java b/sandbox/sebastien/java/wrapped/samples/extending-tuscany/implementation-sample/src/test/java/sample/impl/SampleNativeAsyncTestCase.java new file mode 100644 index 0000000000..f5198e7df0 --- /dev/null +++ b/sandbox/sebastien/java/wrapped/samples/extending-tuscany/implementation-sample/src/test/java/sample/impl/SampleNativeAsyncTestCase.java @@ -0,0 +1,64 @@ +/* + * 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 org.junit.Assert.assertEquals; + +import org.apache.tuscany.sca.node.Contribution; +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.node.NodeFactory; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +import sample.Upper; + +/** + * Test how to run an SCA contribution containing a test composite on a + * Tuscany runtime node. + * + * @version $Rev$ $Date$ + */ +public class SampleNativeAsyncTestCase { + static Node node; + + @BeforeClass + public static void setUp() throws Exception { + final NodeFactory nf = NodeFactory.newInstance(); + String here = SampleNativeAsyncTestCase.class.getProtectionDomain().getCodeSource().getLocation().toString(); + // Create the node using the pattern "name of composite file to start" / Contribution to use + node = nf.createNode("testnativeasync.composite", new Contribution("test", here)); + node.start(); + } + + @AfterClass + public static void tearDown() throws Exception { + node.stop(); + } + + @Test + public void testReference() { + System.out.println("SampleNaiveAsyncTestCase.testReference"); + Upper upper = node.getService(Upper.class, "SampleNativeAsyncReference"); + final String r = upper.upper("async"); + System.out.println(r); + assertEquals("ASYNC", r); + } +} diff --git a/sandbox/sebastien/java/wrapped/samples/extending-tuscany/implementation-sample/src/test/java/sample/impl/SampleNativeJMSAsyncTestCase.java b/sandbox/sebastien/java/wrapped/samples/extending-tuscany/implementation-sample/src/test/java/sample/impl/SampleNativeJMSAsyncTestCase.java new file mode 100644 index 0000000000..ea988981ce --- /dev/null +++ b/sandbox/sebastien/java/wrapped/samples/extending-tuscany/implementation-sample/src/test/java/sample/impl/SampleNativeJMSAsyncTestCase.java @@ -0,0 +1,64 @@ +/* + * 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 org.junit.Assert.assertEquals; + +import org.apache.tuscany.sca.node.Contribution; +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.node.NodeFactory; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +import sample.Upper; + +/** + * Test how to run an SCA contribution containing a test composite on a + * Tuscany runtime node. + * + * @version $Rev$ $Date$ + */ +public class SampleNativeJMSAsyncTestCase { + static Node node; + + @BeforeClass + public static void setUp() throws Exception { + final NodeFactory nf = NodeFactory.newInstance(); + String here = SampleNativeJMSAsyncTestCase.class.getProtectionDomain().getCodeSource().getLocation().toString(); + // Create the node using the pattern "name of composite file to start" / Contribution to use + node = nf.createNode("testnativejmsasync.composite", new Contribution("test", here)); + node.start(); + } + + @AfterClass + public static void tearDown() throws Exception { + node.stop(); + } + + @Test + public void testReference() { + System.out.println("SampleNaiveAsyncTestCase.testReference"); + Upper upper = node.getService(Upper.class, "SampleNativeAsyncReference"); + final String r = upper.upper("async"); + System.out.println(r); + assertEquals("ASYNC", r); + } +} diff --git a/sandbox/sebastien/java/wrapped/samples/extending-tuscany/implementation-sample/src/test/java/sample/impl/TestUtil.java b/sandbox/sebastien/java/wrapped/samples/extending-tuscany/implementation-sample/src/test/java/sample/impl/TestUtil.java new file mode 100644 index 0000000000..6dcfb33912 --- /dev/null +++ b/sandbox/sebastien/java/wrapped/samples/extending-tuscany/implementation-sample/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(); + } + +} -- cgit v1.2.3