From f268110a560328e32d39782851b5d0f9190b8231 Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Mon, 30 Aug 2010 00:24:38 +0000 Subject: Show how to embed a runtime, load WSDL, assemble a SCDL composite in memory and then run it. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@990676 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/main/java/sample/impl/EmbedUtil.java | 198 +++++++++++++++++++++ .../src/main/java/sample/impl/ImplUtil.java | 148 +++++++++++++++ .../sample/impl/SampleImplementationProcessor.java | 14 +- .../src/main/java/sample/impl/SampleUtil.java | 148 --------------- .../src/test/java/sample/impl/EmbedTestCase.java | 124 +++++++++++++ .../test/java/sample/impl/ReadWriteTestCase.java | 3 +- .../src/test/java/sample/impl/RunTestCase.java | 20 ++- .../src/test/java/sample/impl/TestUtil.java | 31 ++++ 8 files changed, 522 insertions(+), 164 deletions(-) create mode 100644 sandbox/sebastien/java/embed/samples/implementation-extension/src/main/java/sample/impl/EmbedUtil.java create mode 100644 sandbox/sebastien/java/embed/samples/implementation-extension/src/main/java/sample/impl/ImplUtil.java delete mode 100644 sandbox/sebastien/java/embed/samples/implementation-extension/src/main/java/sample/impl/SampleUtil.java create mode 100644 sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/impl/EmbedTestCase.java create mode 100644 sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/impl/TestUtil.java (limited to 'sandbox/sebastien') diff --git a/sandbox/sebastien/java/embed/samples/implementation-extension/src/main/java/sample/impl/EmbedUtil.java b/sandbox/sebastien/java/embed/samples/implementation-extension/src/main/java/sample/impl/EmbedUtil.java new file mode 100644 index 0000000000..079df6b15e --- /dev/null +++ b/sandbox/sebastien/java/embed/samples/implementation-extension/src/main/java/sample/impl/EmbedUtil.java @@ -0,0 +1,198 @@ +/* + * 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 java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.util.Arrays; + +import javax.wsdl.PortType; +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.Contract; +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.contribution.Artifact; +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.ContributionFactory; +import org.apache.tuscany.sca.contribution.processor.ContributionException; +import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; +import org.apache.tuscany.sca.contribution.processor.ExtensibleURLArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.resolver.ExtensibleModelResolver; +import org.apache.tuscany.sca.contribution.resolver.ModelResolverExtensionPoint; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; +import org.apache.tuscany.sca.databinding.xml.DOMDataBinding; +import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLObject; +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.node.configuration.NodeConfiguration; +import org.apache.tuscany.sca.node.configuration.impl.NodeConfigurationImpl; +import org.apache.tuscany.sca.node.impl.NodeFactoryImpl; +import org.apache.tuscany.sca.node.impl.NodeImpl; + +/** + * Simple DSL functions to help assemble and run SCDL. + */ +public class EmbedUtil { + + static final NodeFactoryImpl nf; + static final ExtensionPointRegistry epr; + static final FactoryExtensionPoint fep; + static final ContributionFactory cf; + static final AssemblyFactory af; + static final JavaInterfaceFactory jif; + static final WSDLFactory wif; + static final URLArtifactProcessorExtensionPoint apep; + static final ExtensibleURLArtifactProcessor aproc; + static final ModelResolverExtensionPoint mrep; + static { + nf = new NodeFactoryImpl(); + epr = nf.getExtensionPointRegistry(); + fep = epr.getExtensionPoint(FactoryExtensionPoint.class); + cf = fep.getFactory(ContributionFactory.class); + af = fep.getFactory(AssemblyFactory.class); + jif = fep.getFactory(JavaInterfaceFactory.class); + wif = fep.getFactory(WSDLFactory.class); + apep = epr.getExtensionPoint(URLArtifactProcessorExtensionPoint.class); + aproc = new ExtensibleURLArtifactProcessor(apep); + mrep = epr.getExtensionPoint(ModelResolverExtensionPoint.class); + } + + static Contribution contrib(final String uri, final String loc, final Artifact... artifacts) { + final Contribution c = cf.createContribution(); + c.setURI(uri); + c.setLocation(loc); + c.setModelResolver(new ExtensibleModelResolver(c, mrep, fep)); + for(Artifact a: artifacts) + c.getArtifacts().add(a); + return c; + } + + static Artifact artifact(final String uri, final Object model) { + final Artifact a = cf.createArtifact(); + a.setURI(uri); + a.setModel(model); + return a; + } + + static Composite composite(final String ns, final String name, final Component... components) { + final Composite compos = af.createComposite(); + compos.setName(new QName(ns, name)); + for(final Component c: components) + compos.getComponents().add(c); + return compos; + } + + static Component component(final String name, final Implementation impl, final ComponentReference... references) { + final Component c = af.createComponent(); + c.setName(name); + c.setImplementation(impl); + for(ComponentReference r: references) + c.getReferences().add(r); + return c; + } + + static SampleImplementation implementation(final Class clazz, final Contract... contracts) { + final SampleImplementation impl = ImplUtil.implementation(clazz.getName()); + impl.clazz = clazz; + impl.setUnresolved(false); + for(final Contract c: contracts) { + if(c instanceof Service) + impl.getServices().add((Service)c); + else + impl.getReferences().add((Reference)c); + } + return impl; + } + + static WSDLInterface wsdli(final String uri, final String ns, final String name, final Contribution c) throws InvalidInterfaceException, ContributionException, IOException, URISyntaxException { + final ProcessorContext ctx = new ProcessorContext(); + final WSDLDefinition wd = aproc.read(null, new URI(uri), new URL(new URL(c.getLocation()), uri), ctx, WSDLDefinition.class); + c.getModelResolver().addModel(wd, ctx); + c.getModelResolver().resolveModel(WSDLDefinition.class, wd, ctx); + final WSDLObject pt = wd.getWSDLObject(PortType.class, new QName(ns, name)); + if(pt == null) + throw new ContributionResolveException("Couldn't find " + name); + final WSDLInterface nwi = wif.createWSDLInterface(pt.getElement(), wd, c.getModelResolver(), null); + nwi.setWsdlDefinition(wd); + nwi.resetDataBinding(DOMDataBinding.NAME); + return nwi; + } + + static Reference reference(final String name, final Class c) throws InvalidInterfaceException { + return ImplUtil.reference(name, c, jif, af); + } + + static Reference reference(final String name, final WSDLInterface c) { + return ImplUtil.reference(name, c, wif, af); + } + + static ComponentReference reference(final String name, final String target) { + final ComponentReference r = af.createComponentReference(); + r.setName(name); + final ComponentService s = af.createComponentService(); + s.setUnresolved(true); + s.setName(target); + r.getTargets().add(s); + return r; + } + + static Service service(final Class c) throws InvalidInterfaceException { + return ImplUtil.service(c, jif, af); + } + + static Service service(final WSDLInterface c) { + return ImplUtil.service(c, wif, af); + } + + /** + * Add a deployable composite to a contribution. + */ + static Contribution deploy(final Contribution contrib, final Composite... comps) { + for(Composite c: comps) + contrib.getDeployables().add(c); + return contrib; + } + + /** + * Configure a node with a list of contributions. + */ + static Node node(final String uri, final Contribution... contributions) { + final NodeConfiguration cfg = new NodeConfigurationImpl(); + cfg.setURI(uri); + return new NodeImpl(nf, cfg, Arrays.asList(contributions)); + } + +} diff --git a/sandbox/sebastien/java/embed/samples/implementation-extension/src/main/java/sample/impl/ImplUtil.java b/sandbox/sebastien/java/embed/samples/implementation-extension/src/main/java/sample/impl/ImplUtil.java new file mode 100644 index 0000000000..abd4cd7ab0 --- /dev/null +++ b/sandbox/sebastien/java/embed/samples/implementation-extension/src/main/java/sample/impl/ImplUtil.java @@ -0,0 +1,148 @@ +/* + * 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 java.lang.annotation.Annotation; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterfaceContract; + +import sample.api.Java; +import sample.api.WSDL; + +/** + * Utility functions to help develop a component implementation extension. + */ +class ImplUtil { + + /** + * Return a Sample implementation with the given name. + */ + static SampleImplementation implementation(String name) { + final SampleImplementation impl = new SampleImplementation(name); + impl.setUnresolved(true); + return impl; + } + + /** + * Return the Java class configured on an annotation. + */ + static Class clazz(final Annotation a) { + return ((Java)a).value(); + } + + /** + * Return the WSDL QName configured on an annotation. + */ + static QName qname(final Annotation a) { + final String uri = ((WSDL)a).value(); + final int h = uri.indexOf('#'); + return new QName(uri.substring(0, h), uri.substring(h + 1)); + } + + /** + * Convert a Java class to an interface contract. + */ + static JavaInterfaceContract contract(final Class c, final JavaInterfaceFactory jif) throws InvalidInterfaceException { + final JavaInterfaceContract ic = jif.createJavaInterfaceContract(); + ic.setInterface(jif.createJavaInterface(c)); + return ic; + } + + /** + * Convert a WSDL interface to an interface contract. + */ + static WSDLInterfaceContract contract(final WSDLInterface wi, final WSDLFactory wf) { + final WSDLInterfaceContract ic = wf.createWSDLInterfaceContract(); + ic.setInterface(wi); + return ic; + } + + /** + * Convert a Java class to a service. + */ + static Service service(final Class c, final JavaInterfaceFactory jif, final AssemblyFactory af) throws InvalidInterfaceException { + Service s = af.createService(); + s.setName(c.getSimpleName()); + s.setInterfaceContract(contract(c, jif)); + return s; + } + + /** + * Convert a WSDL interface to a service. + */ + static Service service(final WSDLInterface wi, final WSDLFactory wf, final AssemblyFactory af) { + Service s = af.createService(); + s.setName(wi.getName().getLocalPart()); + s.setInterfaceContract(contract(wi, wf)); + return s; + } + + /** + * Convert a name and Java class to a reference. + */ + static Reference reference(final String name, final Class c, final JavaInterfaceFactory jif, final AssemblyFactory af) throws InvalidInterfaceException { + final Reference r = af.createReference(); + r.setName(name); + r.setInterfaceContract(contract(c, jif)); + return r; + } + + /** + * Convert a name and WSDL interface to a reference. + */ + static Reference reference(final String name, final WSDLInterface wi, final WSDLFactory wf, final AssemblyFactory af) { + final Reference r = af.createReference(); + r.setName(name); + r.setInterfaceContract(contract(wi, wf)); + return r; + } + + /** + * Convert a WSDL qname to a WSDL interface. + */ + static WSDLInterface interfaze(final QName name, final WSDLFactory wif) { + final WSDLInterface wir = wif.createWSDLInterface(); + wir.setUnresolved(true); + wir.setName(name); + return wir; + } + + /** + * Convert a WSDL qname to a WSDL definition. + */ + static WSDLDefinition definition(final QName name, final WSDLFactory wif) { + final WSDLDefinition wdr = wif.createWSDLDefinition(); + wdr.setUnresolved(true); + wdr.setNamespace(name.getNamespaceURI()); + wdr.setNameOfPortTypeToResolve(name); + return wdr; + } +} diff --git a/sandbox/sebastien/java/embed/samples/implementation-extension/src/main/java/sample/impl/SampleImplementationProcessor.java b/sandbox/sebastien/java/embed/samples/implementation-extension/src/main/java/sample/impl/SampleImplementationProcessor.java index 95f4655131..cd7767672f 100644 --- a/sandbox/sebastien/java/embed/samples/implementation-extension/src/main/java/sample/impl/SampleImplementationProcessor.java +++ b/sandbox/sebastien/java/embed/samples/implementation-extension/src/main/java/sample/impl/SampleImplementationProcessor.java @@ -20,13 +20,13 @@ package sample.impl; import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; import static sample.impl.SampleImplementation.QN; -import static sample.impl.SampleUtil.clazz; -import static sample.impl.SampleUtil.definition; -import static sample.impl.SampleUtil.implementation; -import static sample.impl.SampleUtil.interfaze; -import static sample.impl.SampleUtil.qname; -import static sample.impl.SampleUtil.reference; -import static sample.impl.SampleUtil.service; +import static sample.impl.ImplUtil.clazz; +import static sample.impl.ImplUtil.definition; +import static sample.impl.ImplUtil.implementation; +import static sample.impl.ImplUtil.interfaze; +import static sample.impl.ImplUtil.qname; +import static sample.impl.ImplUtil.reference; +import static sample.impl.ImplUtil.service; import java.lang.annotation.Annotation; import java.lang.reflect.Field; diff --git a/sandbox/sebastien/java/embed/samples/implementation-extension/src/main/java/sample/impl/SampleUtil.java b/sandbox/sebastien/java/embed/samples/implementation-extension/src/main/java/sample/impl/SampleUtil.java deleted file mode 100644 index 5425431a99..0000000000 --- a/sandbox/sebastien/java/embed/samples/implementation-extension/src/main/java/sample/impl/SampleUtil.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * 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 java.lang.annotation.Annotation; - -import javax.xml.namespace.QName; - -import org.apache.tuscany.sca.assembly.AssemblyFactory; -import org.apache.tuscany.sca.assembly.Reference; -import org.apache.tuscany.sca.assembly.Service; -import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; -import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract; -import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; -import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition; -import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory; -import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface; -import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterfaceContract; - -import sample.api.Java; -import sample.api.WSDL; - -/** - * Utility functions. - */ -class SampleUtil { - - /** - * Return a Sample implementation with the given name. - */ - static SampleImplementation implementation(String name) { - final SampleImplementation impl = new SampleImplementation(name); - impl.setUnresolved(true); - return impl; - } - - /** - * Return the Java class configured on an annotation. - */ - static Class clazz(final Annotation a) { - return ((Java)a).value(); - } - - /** - * Return the WSDL QName configured on an annotation. - */ - static QName qname(final Annotation a) { - final String uri = ((WSDL)a).value(); - final int h = uri.indexOf('#'); - return new QName(uri.substring(0, h), uri.substring(h + 1)); - } - - /** - * Convert a Java class to an interface contract. - */ - static JavaInterfaceContract contract(final Class c, final JavaInterfaceFactory jif) throws InvalidInterfaceException { - final JavaInterfaceContract ic = jif.createJavaInterfaceContract(); - ic.setInterface(jif.createJavaInterface(c)); - return ic; - } - - /** - * Convert a WSDL interface to an interface contract. - */ - static WSDLInterfaceContract contract(final WSDLInterface wi, final WSDLFactory wf) { - final WSDLInterfaceContract ic = wf.createWSDLInterfaceContract(); - ic.setInterface(wi); - return ic; - } - - /** - * Convert a Java class to a service. - */ - static Service service(final Class c, final JavaInterfaceFactory jif, final AssemblyFactory af) throws InvalidInterfaceException { - Service s = af.createService(); - s.setName(c.getSimpleName()); - s.setInterfaceContract(contract(c, jif)); - return s; - } - - /** - * Convert a WSDL interface to a service. - */ - static Service service(final WSDLInterface wi, final WSDLFactory wf, final AssemblyFactory af) { - Service s = af.createService(); - s.setName(wi.getName().getLocalPart()); - s.setInterfaceContract(contract(wi, wf)); - return s; - } - - /** - * Convert a name and Java class to a reference. - */ - static Reference reference(final String name, final Class c, final JavaInterfaceFactory jif, final AssemblyFactory af) throws InvalidInterfaceException { - final Reference r = af.createReference(); - r.setName(name); - r.setInterfaceContract(contract(c, jif)); - return r; - } - - /** - * Convert a name and WSDL interface to a reference. - */ - static Reference reference(final String name, final WSDLInterface wi, final WSDLFactory wf, final AssemblyFactory af) { - final Reference r = af.createReference(); - r.setName(name); - r.setInterfaceContract(contract(wi, wf)); - return r; - } - - /** - * Convert a WSDL qname to a WSDL interface. - */ - static WSDLInterface interfaze(final QName name, final WSDLFactory wif) { - final WSDLInterface wir = wif.createWSDLInterface(); - wir.setUnresolved(true); - wir.setName(name); - return wir; - } - - /** - * Convert a WSDL qname to a WSDL definition. - */ - static WSDLDefinition definition(final QName name, final WSDLFactory wif) { - final WSDLDefinition wdr = wif.createWSDLDefinition(); - wdr.setUnresolved(true); - wdr.setNamespace(name.getNamespaceURI()); - wdr.setNameOfPortTypeToResolve(name); - return wdr; - } -} 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 new file mode 100644 index 0000000000..98057bf34e --- /dev/null +++ b/sandbox/sebastien/java/embed/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/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 8d01c82edf..ad507f80ac 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 @@ -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/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 26cbd5d3e4..a2e1f9ed45 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 @@ -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/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/impl/TestUtil.java b/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/impl/TestUtil.java new file mode 100644 index 0000000000..6dcfb33912 --- /dev/null +++ b/sandbox/sebastien/java/embed/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(); + } + +} -- cgit v1.2.3