01: package org.objectweb.celtix.routing;
02:
03: import java.net.URL;
04: import java.util.HashMap; //import java.util.List;
05: import java.util.Map;
06:
07: import javax.wsdl.Definition;
08: import javax.xml.namespace.QName;
09: import javax.xml.transform.stream.StreamSource;
10: import javax.xml.ws.Dispatch;
11: import javax.xml.ws.Service;
12:
13: import junit.framework.TestCase;
14: import org.objectweb.celtix.Bus;
15: import org.objectweb.celtix.routing.configuration.RouteType;
16:
17: public class MessageProviderTest extends TestCase {
18:
19: private Map<String, Object> properties;
20:
21: public void setUp() {
22: properties = new HashMap<String, Object>();
23: }
24:
25: public void tearDown() throws Exception {
26: Bus bus = Bus.getCurrent();
27: bus.shutdown(true);
28: Bus.setCurrent(null);
29: }
30:
31: public void testServiceCreation() throws Exception {
32: properties.put("org.objectweb.celtix.BusId", "MPT1");
33: Bus bus = Bus.init(null, properties);
34: Bus.setCurrent(bus);
35:
36: URL wsdlUrl = getClass().getResource("resources/router.wsdl");
37: Definition def = bus.getWSDLManager().getDefinition(wsdlUrl);
38:
39: QName sourceSrv = new QName("http://objectweb.org/HWRouter",
40: "HTTPSoapServiceSource");
41: String sourcePort = new String("HTTPSoapPortSource");
42: QName destSrv = new QName("http://objectweb.org/HWRouter",
43: "HTTPSoapServiceDestination");
44: String destPort = new String("HTTPSoapPortDestination");
45:
46: RouteType rt = RouteTypeUtil.createRouteType("route_0",
47: sourceSrv, sourcePort, destSrv, destPort);
48: TestProvider tp = new TestProvider(def, rt);
49:
50: Service s = tp.createService(wsdlUrl, destSrv);
51: assertNotNull("Service should not be null", s);
52: assertEquals(destSrv, s.getServiceName());
53: assertEquals(wsdlUrl, s.getWSDLDocumentLocation());
54:
55: Dispatch<StreamSource> d = tp.createDispatch(s, destPort);
56: assertNotNull("Dispatch instance should be present", d);
57:
58: tp.init();
59:
60: tp.testDispatchList(1);
61: }
62:
63: public static void main(String[] args) {
64: junit.textui.TestRunner.run(MessageProviderTest.class);
65: }
66:
67: class TestProvider extends StreamSourceMessageProvider {
68:
69: public TestProvider(Definition def, RouteType rt) {
70: super (def, rt);
71: }
72:
73: public void testDispatchList(int expectedCount) {
74: assertEquals(expectedCount, this.dList.size());
75: }
76: }
77: }
|