Add tests for WS endpoints
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@804182 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
64bf5f7f93
commit
5cb022f9ae
2 changed files with 102 additions and 5 deletions
|
@ -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 {
|
||||
// <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 @@ 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;
|
||||
|
|
|
@ -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" >
|
||||
|
|
Loading…
Add table
Reference in a new issue