diff options
author | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2009-08-04 17:43:02 +0000 |
---|---|---|
committer | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2009-08-04 17:43:02 +0000 |
commit | 9cbac5c80f21f18158ffbf3f38babcec94110e3b (patch) | |
tree | c32e2c3deb5471b6a5db59547841b6ca6503538b /java | |
parent | e34effd8b8183e8c8ab9fe42b22553183788a185 (diff) |
Bring up the builder tests with the new builders. Includes simplification of results testing. Only scenario 2 enabled.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@800887 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java')
6 files changed, 89 insertions, 102 deletions
diff --git a/java/sca/itest/builder/src/main/resources/scenario2/META-INF/sca-contribution.xml b/java/sca/itest/builder/src/main/resources/scenario2/META-INF/sca-contribution.xml index 6f174a4504..b1d01afafb 100644 --- a/java/sca/itest/builder/src/main/resources/scenario2/META-INF/sca-contribution.xml +++ b/java/sca/itest/builder/src/main/resources/scenario2/META-INF/sca-contribution.xml @@ -17,8 +17,7 @@ * specific language governing permissions and limitations * under the License. --> -<contribution xmlns="http://www.osoa.org/xmlns/sca/1.0" - targetNamespace="http://scenario2" +<contribution xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200903" xmlns:ns2="http://scenario2"> <deployable composite="ns2:CompositeA" /> </contribution> diff --git a/java/sca/itest/builder/src/main/resources/scenario2/scenario2.composite b/java/sca/itest/builder/src/main/resources/scenario2/scenario2.composite index 7c4eeda4bd..7672595959 100644 --- a/java/sca/itest/builder/src/main/resources/scenario2/scenario2.composite +++ b/java/sca/itest/builder/src/main/resources/scenario2/scenario2.composite @@ -17,10 +17,10 @@ * specific language governing permissions and limitations * under the License. --> -<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" - targetNamespace="http://scenario2" - xmlns:tns="http://scenario2" - name="CompositeA"> +<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200903" + targetNamespace="http://scenario2" + xmlns:tns="http://scenario2" + name="CompositeA"> <service name="Service1" promote="ComponentB/Service2"> <!-- bindings and/or interfaces may or may not be specified explicitly here --> diff --git a/java/sca/itest/builder/src/main/resources/scenario2/scenario2a.composite b/java/sca/itest/builder/src/main/resources/scenario2/scenario2a.composite index 5e97d7eea0..2fe3592d12 100644 --- a/java/sca/itest/builder/src/main/resources/scenario2/scenario2a.composite +++ b/java/sca/itest/builder/src/main/resources/scenario2/scenario2a.composite @@ -17,10 +17,10 @@ * specific language governing permissions and limitations * under the License. --> -<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" - targetNamespace="http://scenario2" - xmlns:tns="http://scenario2" - name="CompositeC"> +<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200903" + targetNamespace="http://scenario2" + xmlns:tns="http://scenario2" + name="CompositeC"> <service name="Service2" promote="ComponentD/Service3"> <!-- bindings and/or interfaces may or may not be specified explicitly here --> diff --git a/java/sca/itest/builder/src/test/java/org/apache/tuscany/sca/itest/builder/BuilderTestCase.java b/java/sca/itest/builder/src/test/java/org/apache/tuscany/sca/itest/builder/BuilderTestCase.java index cdeb355f8b..66dfa96bb4 100644 --- a/java/sca/itest/builder/src/test/java/org/apache/tuscany/sca/itest/builder/BuilderTestCase.java +++ b/java/sca/itest/builder/src/test/java/org/apache/tuscany/sca/itest/builder/BuilderTestCase.java @@ -28,6 +28,9 @@ 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.Endpoint; +import org.apache.tuscany.sca.assembly.EndpointReference; +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.binding.ws.WebServiceBinding; @@ -54,6 +57,8 @@ public class BuilderTestCase { public void tearDown() throws Exception { } + /* OASIS doesn't take notice of top level composite services + * // Scenario 1: <binding.ws> on outer composite service CompositeA/Service1 @Ignore @Test @@ -152,8 +157,10 @@ public class BuilderTestCase { Assert.assertEquals(expectedEndpoints, actualEndpoints); } -/* +*/ + // Scenario 2: <binding.ws> on outer component service ComponentB/Service2 + @Test public void testScenario2() throws Exception { System.out.println("====>Running testScenario2"); customBuilder = new CustomCompositeBuilder(false); @@ -171,14 +178,29 @@ public class BuilderTestCase { TestUtils.checkProblems(customBuilder); checkScenario2and3Results("http://scenario2", true); } - + private void checkScenario2and3Results(String namespace, boolean nonWiring) { Composite domainComposite = customBuilder.getDomainComposite(); - + + // Test that endpoint structure matches expected + String structure = TestUtils.printStructure(domainComposite, ""); + System.out.println(structure); + + String expectedStructure = "Component URI - ComponentB\n" + + " Component URI - ComponentB/ComponentD\n" + + " Endpoint: URI = ComponentB/ComponentD#service-binding(Service3/Service3) org.apache.tuscany.sca.assembly.impl.SCABindingImpl\n" + + " Endpoint: URI = ComponentB/ComponentD#service-binding(Service3a/Service3a) org.apache.tuscany.sca.assembly.impl.SCABindingImpl\n" + + "Endpoint: URI = ComponentB#service-binding(Service3/Service2) org.apache.tuscany.sca.binding.ws.impl.WebServiceBindingImpl\n" + + "Endpoint: URI = ComponentB#service-binding(Service3a/Service2a) org.apache.tuscany.sca.assembly.impl.SCABindingImpl\n"; + + Assert.assertEquals(expectedStructure, structure); + + // Test that generated WSDL matches expected // Should create WSDL document for ComponentB/Service2 with endpoint uri="/ComponentB/Service2" // No other services on ComponentB should have <binding.ws> Component componentB = TestUtils.getComponent(domainComposite, "ComponentB"); WebServiceBinding wsBinding = null; + for (ComponentService service : componentB.getServices()) { WebServiceBinding wsb = service.getBinding(WebServiceBinding.class); if ("Service2".equals(service.getName())) { @@ -187,91 +209,16 @@ public class BuilderTestCase { assert wsb == null; } } + Definition def = wsBinding.getWSDLDocument(); + TestUtils.writeWSDL(def); + javax.wsdl.Service svc = def.getService(new QName("http://builder.itest.sca.tuscany.apache.org/", "Service3Service")); Port port = svc.getPort("Service3Port"); - assert "/ComponentB/Service2".equals(TestUtils.getPortAddress(port)); - - Component componentD = TestUtils.getComponent(domainComposite, "ComponentD"); - if (!nonWiring) { - // Should create component service $promoted$ComponentB$slash$Service2 on innermost component - // ComponentD, with <binding.ws> and uri="/ComponentB/Service2" - wsBinding = null; - for (ComponentService service : componentD.getServices()) { - if ("$promoted$ComponentB$slash$Service2".equals(service.getName())) { - wsBinding = service.getBinding(WebServiceBinding.class); - } - } - assert "/ComponentB/Service2".equals(wsBinding.getURI()); - - // Should create WSDL document for ComponentD/$promoted$ComponentB$slash$Service2 with endpoint uri="/ComponentB/Service2" - def = wsBinding.getWSDLDocument(); - svc = def.getService(new QName("http://builder.itest.sca.tuscany.apache.org/", "Service3Service")); - port = svc.getPort("Service3Port"); - assert "/ComponentB/Service2".equals(TestUtils.getPortAddress(port)); - } else { - // Should not create component service $promoted$ComponentB$slash$Service2 on innermost component ComponentD - for (ComponentService service : componentD.getServices()) { - assert !"$promoted$ComponentB$slash$Service2".equals(service.getName()); - } - } - - // Should add <binding.ws> to outer composite service CompositeA/Service1 - wsBinding = null; - for (Service service : domainComposite.getServices()) { - if ("Service1".equals(service.getName())) { - wsBinding = service.getBinding(WebServiceBinding.class); - } - } - assert wsBinding != null; - if (nonWiring) { - // Should not add a WSDL document to domain composite service Service1 - assert wsBinding.getWSDLDocument() == null; - } - - if (!nonWiring) { - // Should create component service $promoted$Service1 on innermost component - // ComponentD, with <binding.ws> and uri="/Service1" - wsBinding = null; - for (ComponentService service : componentD.getServices()) { - if ("$promoted$Service1".equals(service.getName())) { - wsBinding = service.getBinding(WebServiceBinding.class); - } - } - assert "/Service1".equals(wsBinding.getURI()); - - // Should create WSDL document for ComponentD/$promoted$Service1 with endpoint uri="/Service1" - def = wsBinding.getWSDLDocument(); - svc = def.getService(new QName("http://builder.itest.sca.tuscany.apache.org/", "Service3Service")); - port = svc.getPort("Service3Port"); - assert "/Service1".equals(TestUtils.getPortAddress(port)); - } else { - // Should not create component service $promoted$.Service1 on innermost component ComponentD - for (ComponentService service : componentD.getServices()) { - assert !"$promoted$Service1".equals(service.getName()); - } - } - - // No services on ComponentD should have <binding.ws>, except for $promoted$Service1 - // and $promoted$ComponentB$slash$Service2 - for (ComponentService service : componentD.getServices()) { - if (!"$promoted$Service1".equals(service.getName()) && - !"$promoted$ComponentB$slash$Service2".equals(service.getName())) { - assert service.getBinding(WebServiceBinding.class) == null; - } - } - - // No services on CompositeC should have <binding.ws>, except for Service2 in Scenario 3 - Composite compositeC = TestUtils.getComposite(domainComposite, new QName(namespace, "CompositeC")); - for (Service service : compositeC.getServices()) { - if ("http://scenario3".equals(namespace) && "Service2".equals(service.getName())) { - assert service.getBinding(WebServiceBinding.class) != null; - } else { - assert service.getBinding(WebServiceBinding.class) == null; - } - } + Assert.assertEquals("/ComponentB/Service2",TestUtils.getPortAddress(port)); + } - +/* // Scenario 3: <binding.ws> on inner composite service CompositeC/Service2 public void testScenario3() throws Exception { System.out.println("====>Running testScenario3"); @@ -514,9 +461,10 @@ public class BuilderTestCase { Assert.assertEquals(expectedEndpoints, actualEndpoints); } -*/ + // Scenario 6: <binding.ws> and <interface.wsdl> on outer component reference ComponentB/reference2 + @Ignore @Test public void testScenario6() throws Exception { System.out.println("====>Running testScenario6"); @@ -646,7 +594,7 @@ public class BuilderTestCase { Assert.assertEquals(expectedEndpoints, actualEndpoints); } -/* + // Scenario 7: <binding.ws> and <interface.wsdl> on inner composite reference CompositeC/reference2 public void testScenario7() throws Exception { System.out.println("====>Running testScenario7"); diff --git a/java/sca/itest/builder/src/test/java/org/apache/tuscany/sca/itest/builder/CustomCompositeBuilder.java b/java/sca/itest/builder/src/test/java/org/apache/tuscany/sca/itest/builder/CustomCompositeBuilder.java index da8a46067a..2e06c845f2 100644 --- a/java/sca/itest/builder/src/test/java/org/apache/tuscany/sca/itest/builder/CustomCompositeBuilder.java +++ b/java/sca/itest/builder/src/test/java/org/apache/tuscany/sca/itest/builder/CustomCompositeBuilder.java @@ -49,7 +49,8 @@ public class CustomCompositeBuilder { } public void loadContribution(String compositeURL, String sourceURI, String sourceURL) throws Exception { - node = NodeFactory.newInstance().createNode(compositeURL, new Contribution(sourceURI, sourceURL)); + NodeFactory nodeFactory = NodeFactory.newInstance(); + node = nodeFactory.createNode(compositeURL, new Contribution(sourceURI, sourceURL)); node.start(); // get some things out of the extension registry @@ -87,7 +88,7 @@ public class CustomCompositeBuilder { * @return the domain composite model object */ public Composite getDomainComposite() { - return (Composite) domainComposite.getIncludes().get(0); + return (Composite) ((NodeImpl)node).getDomainComposite(); } /** diff --git a/java/sca/itest/builder/src/test/java/org/apache/tuscany/sca/itest/builder/TestUtils.java b/java/sca/itest/builder/src/test/java/org/apache/tuscany/sca/itest/builder/TestUtils.java index f4d8b094c7..997cbff1e5 100644 --- a/java/sca/itest/builder/src/test/java/org/apache/tuscany/sca/itest/builder/TestUtils.java +++ b/java/sca/itest/builder/src/test/java/org/apache/tuscany/sca/itest/builder/TestUtils.java @@ -71,13 +71,18 @@ public class TestUtils { protected static String getPortAddress(Port port) { Object ext = port.getExtensibilityElements().get(0); + String returnAddress = null; if (ext instanceof SOAPAddress) { - return ((SOAPAddress)ext).getLocationURI(); + returnAddress = ((SOAPAddress)ext).getLocationURI(); } if (ext instanceof SOAP12Address) { - return ((SOAP12Address)ext).getLocationURI(); + returnAddress = ((SOAP12Address)ext).getLocationURI(); } - return null; + + returnAddress = returnAddress.substring(returnAddress.indexOf("//") + 2); + returnAddress = returnAddress.substring(returnAddress.indexOf("/")); + + return returnAddress; } protected static Component getComponent(Composite composite, String name) { @@ -202,6 +207,40 @@ public class TestUtils { } } + protected static void writeWSDL(Definition definition) { + try { + WSDLWriter writer = WSDLFactory.newInstance().newWSDLWriter(); + writer.writeWSDL(definition, System.out); + } catch (WSDLException e) { + // ignore + } + } + + protected static String printStructure(Composite composite, String indent){ + String structure = ""; + for (Component component : composite.getComponents()){ + structure += indent + "Component URI - " + component.getURI() + "\n"; + + // recurse for composite implementations + Implementation implementation = component.getImplementation(); + if (implementation instanceof Composite) { + structure += printStructure((Composite)implementation, indent + " "); + } + + for (Service service : component.getServices()){ + for (Endpoint endpoint : service.getEndpoints()){ + structure += indent + endpoint + " " + endpoint.getBinding().getClass().getName() + "\n"; + } + } + for (Reference reference : component.getReferences()){ + for (EndpointReference endpointReference : reference.getEndpointReferences()){ + structure += indent + endpointReference + " " + endpointReference.getBinding().getClass().getName() + "\n"; + } + } + } + return structure; + } +/* protected static String printEndpoints(Composite composite){ return printEndpoints(composite, ""); } @@ -272,5 +311,5 @@ public class TestUtils { return buffer; } - +*/ } |