01: package org.objectweb.celtix.systest.xml_wrapped;
02:
03: import java.lang.reflect.UndeclaredThrowableException;
04: import java.net.*;
05: import javax.xml.namespace.QName;
06:
07: import junit.framework.Test;
08: import junit.framework.TestSuite;
09:
10: import org.objectweb.celtix.systest.common.ClientServerSetupBase;
11: import org.objectweb.celtix.systest.common.ClientServerTestBase;
12: import org.objectweb.hello_world_xml_http.wrapped.Greeter;
13: import org.objectweb.hello_world_xml_http.wrapped.PingMeFault;
14: import org.objectweb.hello_world_xml_http.wrapped.XMLService;
15:
16: public class XMLWrappedSystemTest extends ClientServerTestBase {
17:
18: private static final String TEST_NAMESPACE = "http://objectweb.org/hello_world_xml_http/wrapped";
19: private final QName serviceName = new QName(TEST_NAMESPACE,
20: "XMLService");
21: private final QName portName = new QName(TEST_NAMESPACE, "XMLPort");
22:
23: public static Test suite() throws Exception {
24: TestSuite suite = new TestSuite(XMLWrappedSystemTest.class);
25: return new ClientServerSetupBase(suite) {
26: public void startServers() throws Exception {
27: assertTrue("server did not launch correctly",
28: launchServer(Server.class));
29: }
30: };
31: }
32:
33: public void testBasicConnection() throws Exception {
34: URL wsdl = getClass().getResource(
35: "/wsdl/hello_world_xml_wrapped.wsdl");
36: assertNotNull(wsdl);
37:
38: XMLService service = new XMLService(wsdl, serviceName);
39: assertNotNull(service);
40:
41: Greeter greeter = service.getPort(portName, Greeter.class);
42:
43: String response1 = new String("Hello Milestone-");
44: String response2 = new String("Bonjour");
45: try {
46: for (int idx = 0; idx < 5; idx++) {
47: String greeting = greeter.greetMe("Milestone-" + idx);
48: assertNotNull("no response received from service",
49: greeting);
50: String exResponse = response1 + idx;
51: assertEquals(exResponse, greeting);
52:
53: String reply = greeter.sayHi();
54: assertNotNull("no response received from service",
55: reply);
56: assertEquals(response2, reply);
57:
58: greeter.greetMeOneWay("Milestone-" + idx);
59: }
60: } catch (UndeclaredThrowableException ex) {
61: throw (Exception) ex.getCause();
62: }
63: }
64:
65: public void testFaults() throws Exception {
66: URL wsdl = getClass().getResource(
67: "/wsdl/hello_world_xml_wrapped.wsdl");
68: assertNotNull(wsdl);
69:
70: XMLService service = new XMLService(wsdl, serviceName);
71: assertNotNull(service);
72:
73: Greeter greeter = service.getPort(portName, Greeter.class);
74: for (int idx = 0; idx < 2; idx++) {
75: try {
76: greeter.pingMe();
77: fail("Should have thrown PingMeFault exception");
78: } catch (PingMeFault nslf) {
79: assertNotNull(nslf.getFaultInfo());
80: assertEquals(1, nslf.getFaultInfo().getMinor());
81: assertEquals(2, nslf.getFaultInfo().getMajor());
82: }
83: }
84: }
85:
86: public static void main(String[] args) {
87: junit.textui.TestRunner.run(XMLWrappedSystemTest.class);
88: }
89: }
|