From 5cb022f9ae588bc213d0ed1e69a3a1ae84f99a33 Mon Sep 17 00:00:00 2001 From: antelder Date: Fri, 14 Aug 2009 12:19:32 +0000 Subject: Add tests for WS endpoints git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@804182 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/test/java/test/EndpointsTestCase.java | 72 ++++++++++++++++++++-- .../src/test/resources/helloworld.composite | 35 +++++++++++ 2 files changed, 102 insertions(+), 5 deletions(-) diff --git a/java/sca/itest/endpoints/src/test/java/test/EndpointsTestCase.java b/java/sca/itest/endpoints/src/test/java/test/EndpointsTestCase.java index 82723085d0..7739a4b335 100644 --- a/java/sca/itest/endpoints/src/test/java/test/EndpointsTestCase.java +++ b/java/sca/itest/endpoints/src/test/java/test/EndpointsTestCase.java @@ -23,6 +23,14 @@ import java.io.IOException; import java.io.InputStreamReader; import java.net.MalformedURLException; import java.net.URL; +import java.util.List; + +import javax.wsdl.Definition; +import javax.wsdl.Port; +import javax.wsdl.Service; +import javax.wsdl.extensions.soap.SOAPAddress; +import javax.wsdl.factory.WSDLFactory; +import javax.wsdl.xml.WSDLReader; import junit.framework.Assert; @@ -45,27 +53,58 @@ public class EndpointsTestCase { @Test public void testJSONP2() throws MalformedURLException, IOException { // - invokeJSONPEndpoint("http://IBM-B4ADCA311EA:8085/JSONPComponent2/HelloWorldService/jsonp2/sayHello?name=petra&callback=foo"); + invokeJSONPEndpoint("http://localhost:8085/JSONPComponent2/HelloWorldService/jsonp2/sayHello?name=petra&callback=foo"); } @Test public void testJSONP3() throws MalformedURLException, IOException { // - invokeJSONPEndpoint("http://IBM-B4ADCA311EA:8085/JSONPComponent3/HelloWorldService/jsonp3/sayHello?name=petra&callback=foo"); + invokeJSONPEndpoint("http://localhost:8085/JSONPComponent3/HelloWorldService/jsonp3/sayHello?name=petra&callback=foo"); } @Test public void testJSONP4() throws MalformedURLException, IOException { // - invokeJSONPEndpoint("http://IBM-B4ADCA311EA:8085/jsonp4/sayHello?name=petra&callback=foo"); + invokeJSONPEndpoint("http://localhost:8085/jsonp4/sayHello?name=petra&callback=foo"); } @Test public void testJSONP5() throws MalformedURLException, IOException { // - invokeJSONPEndpoint("http://IBM-B4ADCA311EA:8085/jsonp5b/sayHello?name=petra&callback=foo"); + invokeJSONPEndpoint("http://localhost:8085/jsonp5b/sayHello?name=petra&callback=foo"); } @Test public void testJSONP6() throws MalformedURLException, IOException { // - invokeJSONPEndpoint("http://IBM-B4ADCA311EA:8085/JSONPComponent6/HelloWorldService/jsonp6a/jsonp6b/sayHello?name=petra&callback=foo"); + invokeJSONPEndpoint("http://localhost:8085/JSONPComponent6/HelloWorldService/jsonp6a/jsonp6b/sayHello?name=petra&callback=foo"); + } + + @Test + public void testWS1() throws MalformedURLException, Exception { + // + invokeWSEndpoint("http://localhost:8085/WSComponent1/HelloWorldService"); + } + @Test + public void testWS2() throws MalformedURLException, Exception { + // + invokeWSEndpoint("http://localhost:8085/WSComponent2/HelloWorldService/ws2"); + } + @Test + public void testWS3() throws MalformedURLException, Exception { + // + invokeWSEndpoint("http://localhost:8085/WSComponent3/HelloWorldService/ws3"); + } + @Test + public void testWS4() throws MalformedURLException, Exception { + // + invokeWSEndpoint("http://localhost:8085/ws4"); + } + @Test + public void testWS5() throws MalformedURLException, Exception { + // + invokeWSEndpoint("http://localhost:8085/ws5b"); + } + @Test + public void testWS6() throws Exception { + // + invokeWSEndpoint("http://localhost:8085/WSComponent6/HelloWorldService/ws6a/ws6b"); } private void invokeJSONPEndpoint(String s) throws MalformedURLException, IOException { @@ -75,6 +114,29 @@ public class EndpointsTestCase { Assert.assertEquals("foo(\"Hello petra\");", response); } + public void invokeWSEndpoint(String endpoint) throws Exception { + WSDLReader wsdlReader = WSDLFactory.newInstance().newWSDLReader(); + wsdlReader.setFeature("javax.wsdl.verbose",false); + wsdlReader.setFeature("javax.wsdl.importDocuments",true); + + Definition definition = wsdlReader.readWSDL(endpoint + "?wsdl"); + Assert.assertNotNull(definition); + Service service = (Service)definition.getServices().values().iterator().next(); + Port port = (Port)service.getPorts().values().iterator().next(); + + Assert.assertEquals(new URL(endpoint).getPath(), new URL(getEndpoint(port)).getPath()); + } + + protected String getEndpoint(Port port) { + List wsdlPortExtensions = port.getExtensibilityElements(); + for (final Object extension : wsdlPortExtensions) { + if (extension instanceof SOAPAddress) { + return ((SOAPAddress) extension).getLocationURI(); + } + } + throw new RuntimeException("no SOAPAddress"); + } + @BeforeClass public static void init() throws Exception { JettyServer.portDefault = 8085; diff --git a/java/sca/itest/endpoints/src/test/resources/helloworld.composite b/java/sca/itest/endpoints/src/test/resources/helloworld.composite index a533e0cfaf..081804b34e 100644 --- a/java/sca/itest/endpoints/src/test/resources/helloworld.composite +++ b/java/sca/itest/endpoints/src/test/resources/helloworld.composite @@ -71,6 +71,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.2.3