001: package org.objectweb.celtix.geronimo.container;
002:
003: import javax.xml.namespace.QName;
004:
005: import junit.framework.TestCase;
006:
007: import org.apache.geronimo.webservices.WebServiceContainer;
008: import org.apache.geronimo.webservices.WebServiceContainer.Request;
009: import org.apache.geronimo.webservices.WebServiceContainer.Response;
010: import org.easymock.classextension.EasyMock;
011: import org.objectweb.celtix.Bus;
012: import org.objectweb.celtix.bindings.BindingFactory;
013: import org.objectweb.celtix.bindings.ServerBinding;
014: import org.objectweb.celtix.bindings.ServerBindingEndpointCallback;
015: import org.objectweb.celtix.geronimo.MockBusFactory;
016: import org.objectweb.celtix.geronimo.builder.PortInfo;
017: import org.objectweb.celtix.transports.TransportFactoryManager;
018: import org.objectweb.celtix.ws.addressing.EndpointReferenceType;
019:
020: public class CeltixWebServiceContainerTest extends TestCase {
021:
022: Request req = EasyMock.createNiceMock(Request.class);
023: Response resp = EasyMock.createNiceMock(Response.class);
024:
025: GeronimoServerTransport transport = EasyMock
026: .createMock(GeronimoServerTransport.class);
027: Bus mockBus;
028: MockBusFactory mockBusFactory;
029: PortInfo portInfo;
030:
031: public void setUp() throws Exception {
032: mockBusFactory = new MockBusFactory();
033: mockBus = mockBusFactory.createMockBus();
034:
035: portInfo = new PortInfo();
036: portInfo.setWsdlFile("file:/tmp/foo.wsdl");
037: portInfo
038: .setServiceName(new QName("", "TestService").toString());
039:
040: }
041:
042: public void testInvoke() throws Exception {
043:
044: // setup test fixture
045: //
046: BindingFactory bindingFact = mockBusFactory
047: .getMock(BindingFactory.class);
048: assertNotNull("could not get binding factory", bindingFact);
049: transport.invoke(req, resp);
050: EasyMock.replay(transport);
051:
052: ServerBinding mockServerBinding = EasyMock
053: .createMock(ServerBinding.class);
054:
055: bindingFact.createServerBinding(
056: (EndpointReferenceType) EasyMock.notNull(),
057: (ServerBindingEndpointCallback) EasyMock.notNull());
058: EasyMock.expectLastCall().andReturn(mockServerBinding);
059: mockServerBinding.activate();
060:
061: CeltixWebServiceContainer container = new CeltixWebServiceContainer(
062: portInfo);
063: container.setBus(mockBus);
064:
065: req.getAttribute(WebServiceContainer.POJO_INSTANCE);
066: EasyMock.expectLastCall().andReturn(new TargetObject());
067: EasyMock.replay(req);
068:
069: EasyMock.replay(mockServerBinding);
070: mockBusFactory.replay();
071: container.setServerTransport(transport);
072:
073: // invoke the method under test
074: container.invoke(req, resp);
075:
076: // verify expectations
077: //
078: EasyMock.verify(transport);
079: EasyMock.verify(mockBus);
080: // TODO : fix this
081: // EasyMock.verify(bindingFact);
082: // EasyMock.verify(mockServerBinding);
083:
084: }
085:
086: public void testStart() throws Exception {
087:
088: GeronimoTransportFactory factory = new GeronimoTransportFactory();
089:
090: TransportFactoryManager tfm = mockBusFactory
091: .getMock(TransportFactoryManager.class);
092: assertNotNull("could not get TransportFactoryManager", tfm);
093:
094: tfm
095: .getTransportFactory("http://schemas.xmlsoap.org/wsdl/soap/");
096: EasyMock.expectLastCall().andReturn(factory);
097: tfm
098: .getTransportFactory("http://schemas.xmlsoap.org/wsdl/soap/http");
099: EasyMock.expectLastCall().andReturn(factory);
100: tfm
101: .getTransportFactory("http://celtix.objectweb.org/transports/http/configuration");
102: EasyMock.expectLastCall().andReturn(factory);
103:
104: mockBusFactory.replay();
105:
106: CeltixWebServiceContainer cntr = new CeltixWebServiceContainer(
107: null);
108: cntr.setBus(mockBusFactory.getBus());
109: cntr.doStart();
110:
111: EasyMock.verify(mockBus);
112: }
113:
114: static class TargetObject {
115: public String sayHi() {
116: // TODO Auto-generated method stub
117: return null;
118: }
119: }
120: }
|