You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by an...@apache.org on 2009/08/14 14:19:32 UTC

svn commit: r804182 - in /tuscany/java/sca/itest/endpoints/src/test: java/test/EndpointsTestCase.java resources/helloworld.composite

Author: antelder
Date: Fri Aug 14 12:19:32 2009
New Revision: 804182

URL: http://svn.apache.org/viewvc?rev=804182&view=rev
Log:
Add tests for WS endpoints

Modified:
    tuscany/java/sca/itest/endpoints/src/test/java/test/EndpointsTestCase.java
    tuscany/java/sca/itest/endpoints/src/test/resources/helloworld.composite

Modified: tuscany/java/sca/itest/endpoints/src/test/java/test/EndpointsTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/itest/endpoints/src/test/java/test/EndpointsTestCase.java?rev=804182&r1=804181&r2=804182&view=diff
==============================================================================
--- tuscany/java/sca/itest/endpoints/src/test/java/test/EndpointsTestCase.java (original)
+++ tuscany/java/sca/itest/endpoints/src/test/java/test/EndpointsTestCase.java Fri Aug 14 12:19:32 2009
@@ -23,6 +23,14 @@
 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 @@
     @Test
     public void testJSONP2() throws MalformedURLException, IOException {
         // <tuscany:binding.jsonp name="jsonp2"/>
-        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 {
         // <tuscany:binding.jsonp uri="jsonp3"/>
-        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 {
         // <tuscany:binding.jsonp uri="/jsonp4"/>
-        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 {
         // <tuscany:binding.jsonp name="jsonp5a" uri="/jsonp5b"/>
-        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 {
         // <tuscany:binding.jsonp name="jsonp6a" uri="jsonp6b"/>
-        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 {
+        // <tuscany:binding.WS />
+        invokeWSEndpoint("http://localhost:8085/WSComponent1/HelloWorldService");
+    }
+    @Test
+    public void testWS2() throws MalformedURLException, Exception {
+        // <tuscany:binding.WS name="WS2"/>
+        invokeWSEndpoint("http://localhost:8085/WSComponent2/HelloWorldService/ws2");
+    }
+    @Test
+    public void testWS3() throws MalformedURLException, Exception {
+        // <tuscany:binding.WS uri="WS3"/>
+        invokeWSEndpoint("http://localhost:8085/WSComponent3/HelloWorldService/ws3");
+    }
+    @Test
+    public void testWS4() throws MalformedURLException, Exception {
+        // <tuscany:binding.WS uri="/WS4"/>
+        invokeWSEndpoint("http://localhost:8085/ws4");
+    }
+    @Test
+    public void testWS5() throws MalformedURLException, Exception {
+        // <tuscany:binding.WS name="WS5a" uri="/WS5b"/>
+        invokeWSEndpoint("http://localhost:8085/ws5b");
+    }
+    @Test
+    public void testWS6() throws Exception {
+        // <tuscany:binding.ws name="ws6a" uri="ws6b"/>
+        invokeWSEndpoint("http://localhost:8085/WSComponent6/HelloWorldService/ws6a/ws6b");
     }
 
     private void invokeJSONPEndpoint(String s) throws MalformedURLException, IOException {
@@ -75,6 +114,29 @@
         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;

Modified: tuscany/java/sca/itest/endpoints/src/test/resources/helloworld.composite
URL: http://svn.apache.org/viewvc/tuscany/java/sca/itest/endpoints/src/test/resources/helloworld.composite?rev=804182&r1=804181&r2=804182&view=diff
==============================================================================
--- tuscany/java/sca/itest/endpoints/src/test/resources/helloworld.composite (original)
+++ tuscany/java/sca/itest/endpoints/src/test/resources/helloworld.composite Fri Aug 14 12:19:32 2009
@@ -71,6 +71,41 @@
         </service>
     </component>   
 
+    <component name="WSComponent1">
+        <implementation.java class="helloworld.HelloWorldImpl"/>
+        <service name="HelloWorldService" >
+            <binding.ws />
+        </service>
+    </component>   
+
+    <component name="WSComponent2">
+        <implementation.java class="helloworld.HelloWorldImpl"/>
+        <service name="HelloWorldService" >
+            <binding.ws name="ws2"/>
+        </service>
+    </component>   
+
+    <component name="WSComponent3">
+        <implementation.java class="helloworld.HelloWorldImpl"/>
+        <service name="HelloWorldService" >
+            <binding.ws uri="ws3"/>
+        </service>
+    </component>   
+
+    <component name="WSComponent4">
+        <implementation.java class="helloworld.HelloWorldImpl"/>
+        <service name="HelloWorldService" >
+            <binding.ws uri="/ws4"/>
+        </service>
+    </component>   
+
+    <component name="WSComponent5">
+        <implementation.java class="helloworld.HelloWorldImpl"/>
+        <service name="HelloWorldService" >
+            <binding.ws name="ws5a" uri="/ws5b"/>
+        </service>
+    </component>   
+
     <component name="WSComponent6">
         <implementation.java class="helloworld.HelloWorldImpl"/>
         <service name="HelloWorldService" >