001: package org.objectweb.celtix.bus.bindings;
002:
003: import java.util.Properties;
004: import java.util.concurrent.Executor;
005:
006: import javax.xml.ws.Binding;
007: import javax.xml.ws.Endpoint;
008: import javax.xml.ws.spi.Provider;
009:
010: import junit.framework.TestCase;
011:
012: import org.objectweb.celtix.Bus;
013: import org.objectweb.celtix.bindings.BindingManager;
014: import org.objectweb.celtix.bindings.ServerBinding;
015: import org.objectweb.celtix.bus.jaxws.EndpointImpl;
016: import org.objectweb.celtix.transports.ServerTransport;
017: import org.objectweb.celtix.ws.addressing.EndpointReferenceType;
018: import org.objectweb.celtix.wsdl.EndpointReferenceUtils;
019: import org.objectweb.hello_world_soap_http.DerivedGreeterImpl;
020:
021: public class ServerBindingTest extends TestCase {
022:
023: private String epfClassName;
024: private Bus bus;
025: private EndpointImpl ei;
026: private DerivedGreeterImpl implementor;
027:
028: public void setUp() throws Exception {
029: epfClassName = System
030: .getProperty(Provider.JAXWSPROVIDER_PROPERTY);
031: System.setProperty(Provider.JAXWSPROVIDER_PROPERTY,
032: "org.objectweb.celtix.bus.jaxws.spi.ProviderImpl");
033: bus = Bus.init();
034: BindingManager bm = bus.getBindingManager();
035: bm.registerBinding("http://celtix.objectweb.org/bindings/test",
036: new TestBindingFactory(bus));
037: implementor = new DerivedGreeterImpl();
038: Endpoint ep = Endpoint.create(TestBinding.TEST_BINDING,
039: implementor);
040: ei = (EndpointImpl) ep;
041: }
042:
043: public void tearDown() throws Exception {
044: bus.shutdown(true);
045: if (null == epfClassName) {
046: Properties properties = System.getProperties();
047: properties.remove(Provider.JAXWSPROVIDER_PROPERTY);
048: System.setProperties(properties);
049: } else {
050: System.setProperty(Provider.JAXWSPROVIDER_PROPERTY,
051: epfClassName);
052: }
053: }
054:
055: public void testConstruction() {
056: ServerBinding sb = ei.getServerBinding();
057: assertNotNull(sb);
058: assertTrue(sb instanceof TestServerBinding);
059: Binding b = sb.getBinding();
060: assertNotNull(b);
061: TestServerBinding tsb = (TestServerBinding) sb;
062: ServerTransport st = tsb.getTransport();
063: assertNull(st);
064: EndpointReferenceType ref = ei.getEndpointReferenceType();
065: assertNull(ref.getAddress());
066:
067: }
068:
069: public void testActivate() throws Exception {
070: ServerBinding sb = ei.getServerBinding();
071: try {
072: sb.activate();
073: } catch (NullPointerException ex) {
074: // ignore
075: }
076: EndpointReferenceType ref = ei.getEndpointReferenceType();
077: EndpointReferenceUtils.setAddress(ref,
078: "test://localhost:7777/test");
079: sb.activate();
080: TestServerBinding tsb = (TestServerBinding) sb;
081: ServerTransport st = tsb.getTransport();
082: assertNotNull(st);
083:
084: }
085:
086: public void testDispatch() throws Exception {
087: ServerBinding sb = ei.getServerBinding();
088: EndpointReferenceType ref = ei.getEndpointReferenceType();
089: EndpointReferenceUtils.setAddress(ref,
090: "test://localhost:7777/test");
091: sb.activate();
092: TestServerBinding tsb = (TestServerBinding) sb;
093: ei.setExecutor(new Executor() {
094: public void execute(Runnable command) {
095: command.run();
096: }
097: });
098:
099: tsb.triggerTransport();
100: assertEquals(0, implementor.getInvocationCount("sayHi"));
101: assertEquals(0, implementor
102: .getInvocationCount("overloadedSayHi"));
103: assertEquals(0, implementor.getInvocationCount("greetMe"));
104:
105: // method without annotation
106: tsb.currentOperation = "sayHi";
107: tsb.triggerTransport();
108: assertEquals(1, implementor.getInvocationCount("sayHi"));
109: assertEquals(0, implementor
110: .getInvocationCount("overloadedSayHi"));
111: assertEquals(0, implementor.getInvocationCount("greetMe"));
112:
113: // method with parameter
114: tsb.currentOperation = "greetMe";
115: tsb.triggerTransport();
116: assertEquals(1, implementor.getInvocationCount("sayHi"));
117: assertEquals(0, implementor
118: .getInvocationCount("overloadedSayHi"));
119: assertEquals(1, implementor.getInvocationCount("greetMe"));
120: }
121: }
|