summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x
diff options
context:
space:
mode:
authorantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2012-08-17 11:39:29 +0000
committerantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2012-08-17 11:39:29 +0000
commit6adb50f1e762044f947036c14304eedc31f0d9d0 (patch)
tree1a1aaa961b4386542cfe2940b3907201ec0f1f17 /sca-java-2.x
parent0311cb3720748d4481d1122db551ca084629e230 (diff)
Change the dynamically added endpoint tests to use wsdl resource from a contribution and simplify the endpoint creation helper
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1374206 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x')
-rw-r--r--sca-java-2.x/trunk/testing/itest/dynamic/src/test/java/sample/HelloworldDynamicWSImpl.java48
-rw-r--r--sca-java-2.x/trunk/testing/itest/dynamic/src/test/java/test/DynamicEndpointTestCase.java9
-rw-r--r--sca-java-2.x/trunk/testing/itest/dynamic/src/test/java/test/EndpointHelper.java70
-rw-r--r--sca-java-2.x/trunk/testing/itest/dynamic/src/test/resources/helloworld.wsdl44
-rw-r--r--sca-java-2.x/trunk/testing/itest/dynamic/src/test/resources/resources.zipbin0 -> 742 bytes
5 files changed, 61 insertions, 110 deletions
diff --git a/sca-java-2.x/trunk/testing/itest/dynamic/src/test/java/sample/HelloworldDynamicWSImpl.java b/sca-java-2.x/trunk/testing/itest/dynamic/src/test/java/sample/HelloworldDynamicWSImpl.java
index 03e2f06ad3..a68474b18d 100644
--- a/sca-java-2.x/trunk/testing/itest/dynamic/src/test/java/sample/HelloworldDynamicWSImpl.java
+++ b/sca-java-2.x/trunk/testing/itest/dynamic/src/test/java/sample/HelloworldDynamicWSImpl.java
@@ -18,15 +18,20 @@
*/
package sample;
-import java.io.File;
import java.io.IOException;
import javax.xml.namespace.QName;
import org.apache.tuscany.sca.Node;
+import org.apache.tuscany.sca.assembly.Endpoint;
import org.apache.tuscany.sca.common.xml.dom.DOMHelper;
+import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
+import org.apache.tuscany.sca.impl.NodeImpl;
+import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException;
+import org.apache.tuscany.sca.monitor.ValidationException;
import org.apache.tuscany.sca.runtime.DOMInvoker;
import org.apache.tuscany.sca.runtime.TuscanyComponentContext;
+import org.oasisopen.sca.NoSuchServiceException;
import org.oasisopen.sca.annotation.Context;
import org.oasisopen.sca.annotation.Init;
import org.xml.sax.SAXException;
@@ -37,31 +42,42 @@ import test.EndpointHelper;
public class HelloworldDynamicWSImpl implements Helloworld {
@Context
- TuscanyComponentContext context;
+ private TuscanyComponentContext context;
+
private DOMHelper domHelper;
- private DOMInvoker domInvoker;
+ private Node node;
@Init
public void init() {
+ domHelper = DOMHelper.getInstance(context.getExtensionPointRegistry());
+ node = context.getNode();
+ }
+
+ public String sayHello(String name) {
try {
+
+ String curi = node.installContribution("src/test/resources/resources.zip");
+
+ Endpoint endpoint = EndpointHelper.createWSEndpoint("SomeEndpointName", new QName("http://sample/", "Helloworld"), "http://localhost:8080/testComponent/Helloworld", curi, node);
- domHelper = DOMHelper.getInstance(context.getExtensionPointRegistry());
- Node node = context.getNode();
- EndpointHelper.addWSEndpoint(node, "SomeEndpointName", new File("src/test/resources/helloworld.wsdl").toURI().toURL(), new QName("http://sample/", "Helloworld"), "http://localhost:8089/testComponent/Helloworld");
+ ((NodeImpl)node).getEndpointRegistry().addEndpoint(endpoint);
- domInvoker = node.getDOMInvoker("SomeEndpointName");
-
- } catch (Exception e) {
+ DOMInvoker domInvoker = node.getDOMInvoker("SomeEndpointName");
+
+ org.w3c.dom.Node arg = getRequestDOM(name);
+ org.w3c.dom.Node response = domInvoker.invoke("sayHello", arg);
+ return "Remote WS says: " + getResponseString(response);
+
+ } catch (ContributionReadException e) {
+ throw new RuntimeException(e);
+ } catch (ValidationException e) {
+ throw new RuntimeException(e);
+ } catch (NoSuchServiceException e) {
+ throw new RuntimeException(e);
+ } catch (InvalidInterfaceException e) {
throw new RuntimeException(e);
}
}
-
- public String sayHello(String name) {
- org.w3c.dom.Node arg = getRequestDOM(name);
- org.w3c.dom.Node response = domInvoker.invoke("sayHello", arg);
- return "Remote WS says: " + getResponseString(response);
-
- }
private String getResponseString(org.w3c.dom.Node responseDOM) {
String xml = domHelper.saveAsString(responseDOM);
diff --git a/sca-java-2.x/trunk/testing/itest/dynamic/src/test/java/test/DynamicEndpointTestCase.java b/sca-java-2.x/trunk/testing/itest/dynamic/src/test/java/test/DynamicEndpointTestCase.java
index cf2d5cb454..9ca2ec8aab 100644
--- a/sca-java-2.x/trunk/testing/itest/dynamic/src/test/java/test/DynamicEndpointTestCase.java
+++ b/sca-java-2.x/trunk/testing/itest/dynamic/src/test/java/test/DynamicEndpointTestCase.java
@@ -18,7 +18,6 @@
*/
package test;
-import java.io.File;
import java.io.IOException;
import javax.xml.namespace.QName;
@@ -28,8 +27,10 @@ import junit.framework.TestCase;
import org.apache.tuscany.sca.Node;
import org.apache.tuscany.sca.TuscanyRuntime;
+import org.apache.tuscany.sca.assembly.Endpoint;
import org.apache.tuscany.sca.common.xml.dom.DOMHelper;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.impl.NodeImpl;
import org.apache.tuscany.sca.runtime.DOMInvoker;
import org.junit.Test;
import org.xml.sax.SAXException;
@@ -64,7 +65,11 @@ public class DynamicEndpointTestCase extends TestCase {
@Test
public void testInvoke() throws Exception {
- EndpointHelper.addWSEndpoint(node, "SomeEndpointName", new File("src/test/resources/helloworld.wsdl").toURI().toURL(), new QName("http://sample/", "Helloworld"), "http://localhost:8089/testComponent/Helloworld");
+ String curi = node.installContribution("src/test/resources/resources.zip");
+
+ Endpoint endpoint = EndpointHelper.createWSEndpoint("SomeEndpointName", new QName("http://sample/", "Helloworld"), "http://localhost:8080/testComponent/Helloworld", curi, node);
+
+ ((NodeImpl)node).getEndpointRegistry().addEndpoint(endpoint);
DOMInvoker domInvoker = node.getDOMInvoker("SomeEndpointName");
diff --git a/sca-java-2.x/trunk/testing/itest/dynamic/src/test/java/test/EndpointHelper.java b/sca-java-2.x/trunk/testing/itest/dynamic/src/test/java/test/EndpointHelper.java
index 2c02fc152c..2c7fd65a9d 100644
--- a/sca-java-2.x/trunk/testing/itest/dynamic/src/test/java/test/EndpointHelper.java
+++ b/sca-java-2.x/trunk/testing/itest/dynamic/src/test/java/test/EndpointHelper.java
@@ -1,8 +1,5 @@
package test;
-import java.net.URI;
-import java.net.URL;
-
import javax.wsdl.PortType;
import javax.wsdl.Service;
import javax.xml.namespace.QName;
@@ -15,27 +12,22 @@ import org.apache.tuscany.sca.assembly.Endpoint;
import org.apache.tuscany.sca.binding.ws.WebServiceBinding;
import org.apache.tuscany.sca.binding.ws.WebServiceBindingFactory;
import org.apache.tuscany.sca.contribution.Contribution;
-import org.apache.tuscany.sca.contribution.ContributionFactory;
-import org.apache.tuscany.sca.contribution.processor.ContributionResolveException;
-import org.apache.tuscany.sca.contribution.processor.ExtensibleURLArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
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.ModelResolver;
-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.impl.NodeImpl;
+import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException;
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 org.apache.tuscany.sca.interfacedef.wsdl.WSDLObject;
+import org.apache.tuscany.sca.monitor.ValidationException;
public class EndpointHelper {
- // TODO: change this to be a method on Node that takes a configured Binding to add a new endpoint
- public static void addWSEndpoint(Node node, String endpointName, URL wsdlURL, QName portTypeQN, String targetURL) {
+ public static Endpoint createWSEndpoint(String endpointName, QName wsdlPortQN, String targetURL, String curi, Node node) throws ContributionReadException, ValidationException, InvalidInterfaceException {
ExtensionPointRegistry extensionPoints = ((NodeImpl)node).getExtensionPointRegistry();
FactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class);
AssemblyFactory assemblyFactory = modelFactories.getFactory(AssemblyFactory.class);
@@ -47,7 +39,23 @@ public class EndpointHelper {
WebServiceBinding wsBinding = webServiceBindingFactory.createWebServiceBinding();
wsBinding.setURI(targetURL);
- WSDLInterfaceContract wsdlIC = getWSDLInterfaceContract(wsdlURL, portTypeQN, modelFactories, extensionPoints);
+ WSDLFactory wif = modelFactories.getFactory(WSDLFactory.class);
+
+ Contribution c = node.getContribution(curi);
+ WSDLDefinition wd = wif.createWSDLDefinition();
+ wd.setUnresolved(true);
+ wd.setNamespace(wsdlPortQN.getNamespaceURI());
+ wd.setNameOfPortTypeToResolve(wsdlPortQN);
+ ProcessorContext ctx = new ProcessorContext();
+ wd = c.getModelResolver().resolveModel(WSDLDefinition.class, wd, ctx);
+ WSDLObject<PortType> pt = wd.getWSDLObject(PortType.class, wsdlPortQN);
+
+ WSDLInterface nwi = wif.createWSDLInterface(pt.getElement(), wd, c.getModelResolver(), null);
+ nwi.setWsdlDefinition(wd);
+
+ WSDLInterfaceContract wsdlIC = wif.createWSDLInterfaceContract();
+ wsdlIC.setInterface(nwi);
+
wsBinding.setBindingInterfaceContract(wsdlIC);
wsBinding.setGeneratedWSDLDocument(((WSDLInterface)wsdlIC.getInterface()).getWsdlDefinition().getDefinition());
@@ -61,41 +69,7 @@ public class EndpointHelper {
newEndpoint.setBinding(wsBinding);
newEndpoint.setURI(endpointName);
newEndpoint.setRemote(true);
-
- ((NodeImpl)node).getEndpointRegistry().addEndpoint(newEndpoint);
+ return newEndpoint;
}
- private static WSDLInterfaceContract getWSDLInterfaceContract(URL wsdlURL, QName portTypeQN, FactoryExtensionPoint modelFactories, ExtensionPointRegistry extensionPoints) {
- try {
-
- ContributionFactory contributionFactory = modelFactories.getFactory(ContributionFactory.class);
- Contribution contribution = contributionFactory.createContribution();
- ModelResolverExtensionPoint modelResolvers = extensionPoints.getExtensionPoint(ModelResolverExtensionPoint.class);
- ModelResolver modelResolver = new ExtensibleModelResolver(contribution, modelResolvers, modelFactories);
- contribution.setModelResolver(modelResolver);
-
- ExtensibleURLArtifactProcessor aproc = new ExtensibleURLArtifactProcessor(extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class));
-
- ProcessorContext ctx = new ProcessorContext();
- WSDLDefinition wd = aproc.read(null, new URI("anything.wsdl"), wsdlURL, ctx, WSDLDefinition.class);
- modelResolver.addModel(wd, ctx);
- modelResolver.resolveModel(WSDLDefinition.class, wd, ctx);
- final WSDLObject<PortType> pt = wd.getWSDLObject(PortType.class, portTypeQN);
- if(pt == null)
- throw new ContributionResolveException("Couldn't find " + portTypeQN);
-
- WSDLFactory wif = modelFactories.getFactory(WSDLFactory.class);
- final WSDLInterface nwi = wif.createWSDLInterface(pt.getElement(), wd, modelResolver, null);
- nwi.setWsdlDefinition(wd);
-
- WSDLInterfaceContract wsdlIC = wif.createWSDLInterfaceContract();
- wsdlIC.setInterface(nwi);
-
- return wsdlIC;
-
- } catch(Exception e) {
- throw new RuntimeException(e);
- }
- }
-
}
diff --git a/sca-java-2.x/trunk/testing/itest/dynamic/src/test/resources/helloworld.wsdl b/sca-java-2.x/trunk/testing/itest/dynamic/src/test/resources/helloworld.wsdl
deleted file mode 100644
index fb260fe853..0000000000
--- a/sca-java-2.x/trunk/testing/itest/dynamic/src/test/resources/helloworld.wsdl
+++ /dev/null
@@ -1,44 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<wsdl:definitions name="HelloworldService" targetNamespace="http://sample/" xmlns="http://sample/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:SOAP="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:SOAP11="http://schemas.xmlsoap.org/wsdl/soap/">
- <wsdl:types>
- <xs:schema targetNamespace="http://sample/" version="1.0" xmlns:tns="http://sample/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
-<xs:element name="sayHello" type="tns:sayHello"/>
-<xs:element name="sayHelloResponse" type="tns:sayHelloResponse"/>
-<xs:complexType name="sayHelloResponse"><xs:sequence><xs:element minOccurs="0" name="return" type="xs:string"/></xs:sequence></xs:complexType>
-<xs:complexType name="sayHello"><xs:sequence><xs:element minOccurs="0" name="arg0" type="xs:string"/></xs:sequence></xs:complexType>
-</xs:schema>
- </wsdl:types>
- <wsdl:message name="sayHelloResponse">
- <wsdl:part name="sayHelloResponse" element="sayHelloResponse">
- </wsdl:part>
- </wsdl:message>
- <wsdl:message name="sayHello">
- <wsdl:part name="sayHello" element="sayHello">
- </wsdl:part>
- </wsdl:message>
- <wsdl:portType name="Helloworld">
- <wsdl:operation name="sayHello">
- <wsdl:input message="sayHello">
- </wsdl:input>
- <wsdl:output message="sayHelloResponse">
- </wsdl:output>
- </wsdl:operation>
- </wsdl:portType>
- <wsdl:binding name="HelloworldBinding" type="Helloworld">
- <SOAP:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
- <wsdl:operation name="sayHello">
- <SOAP:operation soapAction=""/>
- <wsdl:input>
- <SOAP:body use="literal"/>
- </wsdl:input>
- <wsdl:output>
- <SOAP:body use="literal"/>
- </wsdl:output>
- </wsdl:operation>
- </wsdl:binding>
- <wsdl:service name="HelloworldComponent_Helloworld">
- <wsdl:port name="HelloworldSOAP11Port" binding="HelloworldBinding">
- <SOAP:address location="http://9.167.203.149:8080/HelloworldComponent/Helloworld"/>
- </wsdl:port>
- </wsdl:service>
-</wsdl:definitions> \ No newline at end of file
diff --git a/sca-java-2.x/trunk/testing/itest/dynamic/src/test/resources/resources.zip b/sca-java-2.x/trunk/testing/itest/dynamic/src/test/resources/resources.zip
new file mode 100644
index 0000000000..9983c454b4
--- /dev/null
+++ b/sca-java-2.x/trunk/testing/itest/dynamic/src/test/resources/resources.zip
Binary files differ