1 package org.objectweb.celtix.geronimo.container; 2 3 4 import javax.xml.namespace.QName ; 5 6 import junit.framework.TestCase; 7 8 import org.apache.geronimo.webservices.WebServiceContainer; 9 import org.apache.geronimo.webservices.WebServiceContainer.Request; 10 import org.apache.geronimo.webservices.WebServiceContainer.Response; 11 import org.easymock.classextension.EasyMock; 12 import org.objectweb.celtix.Bus; 13 import org.objectweb.celtix.bindings.BindingFactory; 14 import org.objectweb.celtix.bindings.ServerBinding; 15 import org.objectweb.celtix.bindings.ServerBindingEndpointCallback; 16 import org.objectweb.celtix.geronimo.MockBusFactory; 17 import org.objectweb.celtix.geronimo.builder.PortInfo; 18 import org.objectweb.celtix.transports.TransportFactoryManager; 19 import org.objectweb.celtix.ws.addressing.EndpointReferenceType; 20 21 public class CeltixWebServiceContainerTest extends TestCase { 22 23 Request req = EasyMock.createNiceMock(Request.class); 24 Response resp = EasyMock.createNiceMock(Response.class); 25 26 GeronimoServerTransport transport = EasyMock.createMock(GeronimoServerTransport.class); 27 Bus mockBus; 28 MockBusFactory mockBusFactory; 29 PortInfo portInfo; 30 31 public void setUp() throws Exception { 32 mockBusFactory = new MockBusFactory(); 33 mockBus = mockBusFactory.createMockBus(); 34 35 portInfo = new PortInfo(); 36 portInfo.setWsdlFile("file:/tmp/foo.wsdl"); 37 portInfo.setServiceName(new QName ("", "TestService").toString()); 38 39 } 40 41 42 public void testInvoke() throws Exception { 43 44 BindingFactory bindingFact = mockBusFactory.getMock(BindingFactory.class); 47 assertNotNull("could not get binding factory", bindingFact); 48 transport.invoke(req, resp); 49 EasyMock.replay(transport); 50 51 52 ServerBinding mockServerBinding = EasyMock.createMock(ServerBinding.class); 53 54 bindingFact.createServerBinding((EndpointReferenceType)EasyMock.notNull(), 55 (ServerBindingEndpointCallback)EasyMock.notNull()); 56 EasyMock.expectLastCall().andReturn(mockServerBinding); 57 mockServerBinding.activate(); 58 59 60 CeltixWebServiceContainer container = new CeltixWebServiceContainer(portInfo); 61 container.setBus(mockBus); 62 63 req.getAttribute(WebServiceContainer.POJO_INSTANCE); 64 EasyMock.expectLastCall().andReturn(new TargetObject()); 65 EasyMock.replay(req); 66 67 EasyMock.replay(mockServerBinding); 68 mockBusFactory.replay(); 69 container.setServerTransport(transport); 70 71 container.invoke(req, resp); 73 74 EasyMock.verify(transport); 77 EasyMock.verify(mockBus); 78 82 } 83 84 85 public void testStart() throws Exception { 86 87 GeronimoTransportFactory factory = new GeronimoTransportFactory(); 88 89 TransportFactoryManager tfm = mockBusFactory.getMock(TransportFactoryManager.class); 90 assertNotNull("could not get TransportFactoryManager", tfm); 91 92 tfm.getTransportFactory("http://schemas.xmlsoap.org/wsdl/soap/"); 93 EasyMock.expectLastCall().andReturn(factory); 94 tfm.getTransportFactory("http://schemas.xmlsoap.org/wsdl/soap/http"); 95 EasyMock.expectLastCall().andReturn(factory); 96 tfm.getTransportFactory("http://celtix.objectweb.org/transports/http/configuration"); 97 EasyMock.expectLastCall().andReturn(factory); 98 99 mockBusFactory.replay(); 100 101 CeltixWebServiceContainer cntr = new CeltixWebServiceContainer(null); 102 cntr.setBus(mockBusFactory.getBus()); 103 cntr.doStart(); 104 105 EasyMock.verify(mockBus); 106 } 107 108 static class TargetObject { 109 public String sayHi() { 110 return null; 112 } 113 } 114 } 115 | Popular Tags |