01: package org.objectweb.celtix.bus.jaxws;
02:
03: import java.lang.reflect.Proxy;
04: import java.util.Iterator;
05:
06: import javax.xml.namespace.QName;
07: import javax.xml.soap.SOAPMessage;
08: import javax.xml.transform.dom.DOMSource;
09: import javax.xml.ws.Dispatch;
10: import javax.xml.ws.Service;
11: import javax.xml.ws.spi.Provider;
12:
13: import junit.framework.TestCase;
14:
15: import org.objectweb.celtix.Bus;
16: import org.objectweb.celtix.bus.jaxws.spi.ProviderImpl;
17: import org.objectweb.hello_world_soap_http.Greeter;
18: import org.objectweb.hello_world_soap_http.SOAPService;
19:
20: public class ServiceTest extends TestCase {
21:
22: public ServiceTest(String arg0) {
23: super (arg0);
24: }
25:
26: public static void main(String[] args) {
27: junit.textui.TestRunner.run(ServiceTest.class);
28: }
29:
30: public void setUp() {
31: System.setProperty(Provider.JAXWSPROVIDER_PROPERTY,
32: ProviderImpl.JAXWS_PROVIDER);
33: }
34:
35: /*
36: * Test method for 'javax.xml.ws.Service.getPorts()'
37: */
38: public void testGetPorts() throws Exception {
39: Bus bus = Bus.init();
40: QName endpoint = new QName(
41: "http://objectweb.org/hello_world_soap_http",
42: "SoapPort");
43:
44: try {
45: SOAPService hwService = new SOAPService();
46: assertNotNull(hwService);
47: Iterator iter = hwService.getPorts();
48: assertFalse("Should have no element", iter.hasNext());
49:
50: Greeter port = hwService.getSoapPort();
51: assertNotNull(port);
52: assertTrue("Should be a proxy class. "
53: + port.getClass().getName(), Proxy
54: .isProxyClass(port.getClass()));
55:
56: iter = hwService.getPorts();
57: assertTrue("Should have one element", iter.hasNext());
58: assertEquals("Activated EndPoints are not the same",
59: endpoint, iter.next());
60: } finally {
61: bus.shutdown(true);
62: }
63: }
64:
65: public void testCreateDispatch() throws Exception {
66: QName endpoint = new QName(
67: "http://objectweb.org/hello_world_soap_http",
68: "SoapPort");
69:
70: SOAPService service = new SOAPService();
71: assertNotNull(service);
72: Dispatch<SOAPMessage> disp = service.createDispatch(endpoint,
73: SOAPMessage.class, Service.Mode.MESSAGE);
74: assertNotNull(disp);
75: assertTrue("Should be DispatchImpl class", disp.getClass()
76: .isAssignableFrom(DispatchImpl.class));
77:
78: Dispatch<DOMSource> disp2 = service.createDispatch(endpoint,
79: DOMSource.class, Service.Mode.PAYLOAD);
80: assertNotNull(disp2);
81: assertTrue("Should be DispatchImpl class", disp2.getClass()
82: .isAssignableFrom(DispatchImpl.class));
83: }
84:
85: }
|