KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > celtix > systest > xml_wrapped > XMLWrappedSystemTest


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