001: package org.objectweb.celtix.geronimo;
002:
003: import java.io.IOException;
004: import java.util.HashMap;
005: import java.util.Map;
006:
007: import javax.wsdl.WSDLException;
008: import javax.wsdl.extensions.ExtensionRegistry;
009: import javax.xml.ws.Binding;
010:
011: import org.easymock.classextension.EasyMock;
012: import org.objectweb.celtix.Bus;
013: import org.objectweb.celtix.BusException;
014: import org.objectweb.celtix.bindings.BindingFactory;
015: import org.objectweb.celtix.bindings.BindingManager;
016: import org.objectweb.celtix.bindings.ServerBinding;
017: import org.objectweb.celtix.bindings.ServerBindingEndpointCallback;
018: import org.objectweb.celtix.buslifecycle.BusLifeCycleManager;
019: import org.objectweb.celtix.configuration.Configuration;
020: import org.objectweb.celtix.jaxws.EndpointRegistry;
021: import org.objectweb.celtix.resource.ResourceManager;
022: import org.objectweb.celtix.transports.TransportFactoryManager;
023: import org.objectweb.celtix.ws.addressing.EndpointReferenceType;
024: import org.objectweb.celtix.wsdl.WSDLManager;
025:
026: public final class MockBusFactory {
027:
028: private Bus mockBus;
029: private Configuration mockConfiguration;
030: private BindingManager mockBindingMgr;
031: private ServerBinding mockServerBinding;
032: private BindingFactory mockBindingFactory;
033: private WSDLManager mockWsdlManager;
034: private ExtensionRegistry mockExtensionRegistry;
035: private BusLifeCycleManager mockLifeCycleManager;
036: private EndpointRegistry mockEndpointRegistry;
037: private Binding mockBinding;
038: private ResourceManager mockResourceManager;
039: private TransportFactoryManager mockTransportFactoryManager;
040:
041: private Map mocks = new HashMap();
042:
043: public void replay() {
044: EasyMock.replay(mockBus);
045: EasyMock.replay(mockConfiguration);
046: EasyMock.replay(mockBindingMgr);
047: EasyMock.replay(mockServerBinding);
048: EasyMock.replay(mockBindingFactory);
049: EasyMock.replay(mockWsdlManager);
050: EasyMock.replay(mockExtensionRegistry);
051: EasyMock.replay(mockLifeCycleManager);
052: EasyMock.replay(mockEndpointRegistry);
053: EasyMock.replay(mockBinding);
054: EasyMock.replay(mockResourceManager);
055: EasyMock.replay(mockTransportFactoryManager);
056: }
057:
058: public <T> T getMock(Class<T> type) {
059: return type.cast(mocks.get(type));
060: }
061:
062: public Bus createMockBus() throws BusException, WSDLException,
063: IOException {
064:
065: mockBus = createNiceMock(Bus.class);
066: mockConfiguration = createNiceMock(Configuration.class);
067: mockBindingMgr = createNiceMock(BindingManager.class);
068: mockBindingFactory = createNiceMock(BindingFactory.class);
069: mockServerBinding = createNiceMock(ServerBinding.class);
070: mockWsdlManager = createNiceMock(WSDLManager.class);
071: mockExtensionRegistry = createNiceMock(ExtensionRegistry.class);
072: mockLifeCycleManager = createNiceMock(BusLifeCycleManager.class);
073: mockEndpointRegistry = createNiceMock(EndpointRegistry.class);
074: mockBinding = createNiceMock(Binding.class);
075: mockResourceManager = createNiceMock(ResourceManager.class);
076: mockTransportFactoryManager = createNiceMock(TransportFactoryManager.class);
077:
078: EasyMock.expect(mockBus.getResourceManager()).andReturn(
079: mockResourceManager).anyTimes();
080: EasyMock.expect(mockBus.getConfiguration()).andReturn(
081: mockConfiguration).anyTimes();
082: EasyMock.expect(mockBus.getBindingManager()).andReturn(
083: mockBindingMgr).anyTimes();
084:
085: EasyMock.expect(mockBus.getEndpointRegistry()).andReturn(
086: mockEndpointRegistry).anyTimes();
087:
088: EasyMock.expect(
089: mockBindingMgr.getBindingFactory((String) EasyMock
090: .anyObject())).andReturn(mockBindingFactory)
091: .anyTimes();
092:
093: EasyMock.expect(
094: mockBindingFactory.createServerBinding(
095: (EndpointReferenceType) EasyMock.anyObject(),
096: (ServerBindingEndpointCallback) EasyMock
097: .anyObject())).andReturn(
098: mockServerBinding);
099:
100: EasyMock.expect(mockServerBinding.getBinding()).andReturn(
101: mockBinding).anyTimes();
102:
103: EasyMock.expect(mockBus.getWSDLManager()).andReturn(
104: mockWsdlManager).anyTimes();
105: EasyMock.expect(mockWsdlManager.getExtenstionRegistry())
106: .andReturn(mockExtensionRegistry).anyTimes();
107: EasyMock.expect(mockBus.getLifeCycleManager()).andReturn(
108: mockLifeCycleManager).anyTimes();
109: EasyMock.expect(mockBus.getTransportFactoryManager())
110: .andReturn(mockTransportFactoryManager).anyTimes();
111:
112: return mockBus;
113: }
114:
115: public Configuration addChildConfig(String namespaceURI, Object id,
116: Configuration childConfig) {
117:
118: if (childConfig == null) {
119: childConfig = EasyMock.createNiceMock(Configuration.class);
120: }
121:
122: EasyMock.expect(
123: mockConfiguration.getChild(EasyMock.eq(namespaceURI),
124: id != null ? EasyMock.eq(id) : EasyMock
125: .anyObject())).andReturn(childConfig)
126: .anyTimes();
127: return childConfig;
128: }
129:
130: public Bus getBus() {
131: return mockBus;
132: }
133:
134: @SuppressWarnings("unchecked")
135: private <T> T createNiceMock(Class<T> type) {
136: T ret = EasyMock.createNiceMock(type);
137: mocks.put(type, ret);
138: return ret;
139: }
140:
141: }
|