01: package org.objectweb.celtix.bus.transports;
02:
03: import java.util.Map;
04: import java.util.WeakHashMap;
05:
06: import junit.framework.TestCase;
07:
08: import org.easymock.classextension.EasyMock;
09:
10: import org.objectweb.celtix.Bus;
11: import org.objectweb.celtix.BusException;
12: import org.objectweb.celtix.configuration.Configuration;
13: import org.objectweb.celtix.configuration.types.ClassNamespaceMappingListType;
14: import org.objectweb.celtix.configuration.types.ObjectFactory;
15: import org.objectweb.celtix.transports.TransportFactoryManager;
16:
17: public class TransportFactoryManagerTest extends TestCase {
18:
19: public TransportFactoryManagerTest(String arg0) {
20: super (arg0);
21: }
22:
23: public static void main(String[] args) {
24: junit.textui.TestRunner.run(TransportFactoryManagerTest.class);
25: }
26:
27: public void testPlugableTransportFactoryManager() throws Exception {
28: TransportFactoryManagerImpl transportFactoryManagerImpl = createTransportFactory();
29: Map<String, Object> properties = new WeakHashMap<String, Object>();
30: properties.put("celtix.TRANSPORTFACTORYMANAGER",
31: transportFactoryManagerImpl);
32: Bus bus = Bus.init(new String[0], properties);
33:
34: TransportFactoryManager transportFactoryManagerImplNew = bus
35: .getTransportFactoryManager();
36:
37: //Verify that the TransportFactoryManager is the one we plugged into bus previously,
38: //other than the one created inside Bus
39: assertEquals("wsdlManager is the one we expected",
40: transportFactoryManagerImpl,
41: transportFactoryManagerImplNew);
42: }
43:
44: private TransportFactoryManagerImpl createTransportFactory()
45: throws BusException {
46: Bus bus = EasyMock.createMock(Bus.class);
47: Configuration bc = EasyMock.createMock(Configuration.class);
48:
49: ObjectFactory of = new ObjectFactory();
50: ClassNamespaceMappingListType mappings = of
51: .createClassNamespaceMappingListType();
52: bus.getConfiguration();
53: EasyMock.expectLastCall().andReturn(bc);
54: bc.getObject("transportFactories");
55: EasyMock.expectLastCall().andReturn(mappings);
56: EasyMock.replay(bus);
57: EasyMock.replay(bc);
58:
59: return new TransportFactoryManagerImpl(bus);
60: }
61: }
|