1 package org.objectweb.celtix.systest.xml_wrapped; 2 3 import java.lang.reflect.UndeclaredThrowableException ; 4 import java.net.*; 5 import javax.xml.namespace.QName ; 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 TEST_NAMESPACE = "http://objectweb.org/hello_world_xml_http/wrapped"; 19 private final QName serviceName = new QName (TEST_NAMESPACE, "XMLService"); 20 private final QName portName = new QName (TEST_NAMESPACE, "XMLPort"); 21 22 public static Test suite() throws Exception { 23 TestSuite suite = new TestSuite(XMLWrappedSystemTest.class); 24 return new ClientServerSetupBase(suite) { 25 public void startServers() throws Exception { 26 assertTrue("server did not launch correctly", launchServer(Server.class)); 27 } 28 }; 29 } 30 31 public void testBasicConnection() throws Exception { 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 response1 = new String ("Hello Milestone-"); 41 String response2 = new String ("Bonjour"); 42 try { 43 for (int idx = 0; idx < 5; idx++) { 44 String greeting = greeter.greetMe("Milestone-" + idx); 45 assertNotNull("no response received from service", greeting); 46 String exResponse = response1 + idx; 47 assertEquals(exResponse, greeting); 48 49 String 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 ex) { 56 throw (Exception )ex.getCause(); 57 } 58 } 59 60 public void testFaults() throws Exception { 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 [] args) { 81 junit.textui.TestRunner.run(XMLWrappedSystemTest.class); 82 } 83 } 84 | Popular Tags |