diff options
author | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2010-08-30 17:18:15 +0000 |
---|---|---|
committer | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2010-08-30 17:18:15 +0000 |
commit | 5e04cf7908c2be7a07b15e8ffa0f8bd5caf2cff0 (patch) | |
tree | df240da682464a287ed5d065f2debf3e8640d913 /sandbox/sebastien/java/embed/samples/implementation-extension/src/test | |
parent | f85505727a6ae0926cae88e8aa8b486b01622acf (diff) |
Add a test case showing how to register a ProviderFactory instance. Minor cleanup, add a createNode method that takes a list of contributions and remove reference to NodeFactory implementation class.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@990870 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
11 files changed, 172 insertions, 8 deletions
diff --git a/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/Client.java b/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/Client.java index 4c473c987f..1b7e11c786 100644 --- a/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/Client.java +++ b/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/Client.java @@ -21,6 +21,11 @@ package sample; import org.oasisopen.sca.annotation.Remotable; +/** + * Sample service interface. + * + * @version $Rev$ $Date$ + */ @Remotable public interface Client { diff --git a/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/ClientTest.java b/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/ClientTest.java index 6b5c3983d1..3b635708ec 100644 --- a/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/ClientTest.java +++ b/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/ClientTest.java @@ -36,7 +36,7 @@ import sample.api.WSDL; import sample.api.WSDLReference; /** - * Sample component implementation. + * Sample component implementation that uses a mix of Java and WSDL interfaces. * * @version $Rev$ $Date$ */ diff --git a/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/Hello.java b/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/Hello.java index f6e02591e5..247fc8aa78 100644 --- a/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/Hello.java +++ b/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/Hello.java @@ -21,6 +21,11 @@ package sample; import org.oasisopen.sca.annotation.Remotable; +/** + * Sample service interface. + * + * @version $Rev$ $Date$ + */ @Remotable public interface Hello { diff --git a/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/JelloTest.java b/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/JelloTest.java index 53ed006132..5c999a6c80 100644 --- a/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/JelloTest.java +++ b/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/JelloTest.java @@ -23,7 +23,7 @@ import static java.lang.System.out; import sample.api.Java; /** - * Sample component implementation. + * Sample component implementation that uses Java interfaces. * * @version $Rev$ $Date$ */ diff --git a/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/Upper.java b/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/Upper.java index 04e929ade7..9c772b3487 100644 --- a/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/Upper.java +++ b/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/Upper.java @@ -21,6 +21,11 @@ package sample; import org.oasisopen.sca.annotation.Remotable; +/** + * Sample service interface. + * + * @version $Rev$ $Date$ + */ @Remotable public interface Upper { diff --git a/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/UpperTest.java b/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/UpperTest.java index fe90097efa..5399e4410d 100644 --- a/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/UpperTest.java +++ b/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/UpperTest.java @@ -23,7 +23,7 @@ import static java.lang.System.out; import sample.api.Java; /** - * Sample component implementation. + * Sample component implementation that uses Java interfaces. * * @version $Rev$ $Date$ */ diff --git a/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/WelloTest.java b/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/WelloTest.java index 9da5083dda..3b3a6a4566 100644 --- a/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/WelloTest.java +++ b/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/WelloTest.java @@ -36,7 +36,7 @@ import sample.api.WSDL; import sample.api.WSDLReference; /** - * Sample component implementation. + * Sample component implementation that uses WSDL interfaces. * * @version $Rev$ $Date$ */ diff --git a/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/impl/EmbedTestCase.java b/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/impl/EmbedTestCase.java index 98057bf34e..41f6d95f3c 100644 --- a/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/impl/EmbedTestCase.java +++ b/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/impl/EmbedTestCase.java @@ -49,7 +49,8 @@ import sample.UpperTest; import sample.WelloTest; /** - * Test assemble and run SCDL. + * Test how to assemble a contribution, a SCDL composite and run it on an embedded + * Tuscany runtime node. * * @version $Rev$ $Date$ */ @@ -93,7 +94,7 @@ public class EmbedTestCase { service(Upper.class)))); // Run with it - node = node("test", deploy(contrib, comp)); + node = node(deploy(contrib, comp)); node.start(); } diff --git a/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/impl/InControlTestCase.java b/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/impl/InControlTestCase.java new file mode 100644 index 0000000000..6523e0b233 --- /dev/null +++ b/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/impl/InControlTestCase.java @@ -0,0 +1,147 @@ +/* + * 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.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.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. Same as EmbedTestCase but shows how stay in control and + * pass in a ProviderFactory instead of having it loaded and constructed by the + * runtime node. + * + * @version $Rev$ $Date$ + */ +public class InControlTestCase { + 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)))); + + // Register a test instance of our sample implementation ProviderFactory + providerFactories().addProviderFactory(testProviderFactory()); + + // Run with it + node = node(deploy(contrib, comp)); + node.start(); + } + + static ProviderFactory<SampleImplementation> testProviderFactory() { + // This shows that the embedder can take control and get called + // when a provider is created, and return whatever provider, then + // invoker, implementation instance etc + return new SampleProviderFactory(extensionPoints()) { + 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/embed/samples/implementation-extension/src/test/java/sample/impl/ReadWriteTestCase.java b/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/impl/ReadWriteTestCase.java index ad507f80ac..8a4768cd9e 100644 --- a/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/impl/ReadWriteTestCase.java +++ b/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/impl/ReadWriteTestCase.java @@ -43,7 +43,7 @@ import org.junit.BeforeClass; import org.junit.Test; /** - * Test reading/writing Sample implementations. + * Test read/write Sample SCDL implementation elements. * * @version $Rev$ $Date$ */ diff --git a/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/impl/RunTestCase.java b/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/impl/RunTestCase.java index a2e1f9ed45..29bf02d26b 100644 --- a/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/impl/RunTestCase.java +++ b/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/impl/RunTestCase.java @@ -33,7 +33,8 @@ import org.junit.Test; import sample.Client; /** - * Test run. + * Test how to run an SCA contribution containing a test composite on a + * Tuscany runtime node. * * @version $Rev$ $Date$ */ |