1 22 package org.objectweb.petals.jbi.routing; 23 24 import java.lang.reflect.Method ; 25 26 import javax.jbi.JBIException; 27 import javax.jbi.servicedesc.ServiceEndpoint; 28 import javax.xml.namespace.QName ; 29 30 import junit.framework.TestCase; 31 32 import org.easymock.classextension.EasyMock; 33 import org.objectweb.petals.jbi.component.context.ComponentContextImpl; 34 import org.objectweb.petals.jbi.component.lifecycle.mock.MockJBIDescriptorBuilder; 35 import org.objectweb.petals.jbi.component.mock.MockEndpointService; 36 import org.objectweb.petals.jbi.management.service.EndpointServiceImpl; 37 import org.objectweb.petals.jbi.management.service.LifeCycleManagerImpl; 38 import org.objectweb.petals.jbi.messaging.MessageExchangeImpl; 39 import org.objectweb.petals.jbi.registry.ConsumerEndpoint; 40 import org.objectweb.petals.jbi.registry.InternalEndpoint; 41 import org.objectweb.petals.jbi.routing.mock.ComponentMock; 42 import org.objectweb.petals.jbi.routing.mock.MBeanNamesMock; 43 import org.objectweb.petals.jbi.routing.mock.MBeanServerMock; 44 45 50 public class AddressResolverTest extends TestCase { 51 52 private MessageExchangeImpl messageExchangeImpl; 53 54 private AddressResolver addressResolver; 55 56 private ComponentContextImpl componentContextImpl; 57 58 private LifeCycleManagerImpl lifeCycleManagerImpl; 59 60 private MockEndpointService mockEndpointService; 61 62 63 public void setUp() throws Exception { 64 lifeCycleManagerImpl = new LifeCycleManagerImpl(); 65 66 addressResolver = new AddressResolver(mockEndpointService); 68 mockEndpointService = new MockEndpointService(); 69 addressResolver.endpointService = mockEndpointService; 70 componentContextImpl = new ComponentContextImpl( 71 MockJBIDescriptorBuilder.buildComponentDescriptor(), "install", 72 "work", new MBeanNamesMock(), new MBeanServerMock(), 73 lifeCycleManagerImpl, new ConsumerEndpoint("test", "petals1"), 74 null, null, null, null); 75 messageExchangeImpl = new MessageExchangeImpl(null); 76 } 77 78 83 public void testResolveAddressEverythingNull() throws Exception { 84 messageExchangeImpl.setEndpoint(null); 85 addressResolver.resolveAddress(componentContextImpl, 86 messageExchangeImpl); 87 assertNull(messageExchangeImpl.getEndpoint()); 88 } 89 90 95 public void testResolveAddressEverythingNull1() throws Exception { 96 addressResolver.resolveAddress(componentContextImpl, 97 messageExchangeImpl); 98 assertNull(messageExchangeImpl.getEndpoint()); 99 } 100 101 104 public void testResolveAddressWithUnregisteredService() { 105 componentContextImpl.setComponent(new ComponentMock()); 106 messageExchangeImpl.setEndpoint(null); 107 messageExchangeImpl.setService(new QName ("foo")); 108 try { 109 addressResolver.resolveAddress(componentContextImpl, 110 messageExchangeImpl); 111 fail(); 112 } catch (Exception e) { 113 114 } 115 } 116 117 122 131 137 147 152 165 public void testresolveAddressEndpointNotNullServiceNotNullButNoConnection() 166 throws SecurityException , NoSuchMethodException , RoutingException { 167 addressResolver = EasyMock.createMock(AddressResolver.class, 168 new Method [] {AddressResolver.class.getDeclaredMethod( 169 "resolveLinkedAddressForEndpoint", new Class [] {QName .class, 170 String .class})}); 171 ComponentContextImpl componentContextImpl = EasyMock 172 .createMock(ComponentContextImpl.class); 173 MessageExchangeImpl messageExchangeImpl = EasyMock 174 .createMock(MessageExchangeImpl.class); 175 EndpointServiceImpl endpointServiceImpl = EasyMock 176 .createMock(EndpointServiceImpl.class); 177 178 EasyMock.expect(messageExchangeImpl.getEndpoint()).andReturn( 179 new InternalEndpoint(new QName ("service"), "endpoint", "compo", 180 "0", null)); 181 EasyMock.expect(messageExchangeImpl.getService()).andReturn( 182 new QName ("service")); 183 EasyMock.expect(messageExchangeImpl.getInterfaceName()).andReturn(null); 184 EasyMock.expect( 185 addressResolver.resolveLinkedAddressForEndpoint( 186 new QName ("service"), "endpoint")).andReturn(null); 187 EasyMock.expect( 188 endpointServiceImpl.getEndpoint(new QName ("service"), "endpoint")) 189 .andReturn(null); 190 191 EasyMock.replay(messageExchangeImpl); 192 EasyMock.replay(componentContextImpl); 193 EasyMock.replay(endpointServiceImpl); 194 EasyMock.replay(addressResolver); 195 196 addressResolver.endpointService = endpointServiceImpl; 197 198 try { 199 addressResolver.resolveAddress(componentContextImpl, 200 messageExchangeImpl); 201 fail(); 202 } catch (RoutingException e) { 203 } 205 } 206 207 public void testresolveAddressInterfaceNotNullButNoConnection() 208 throws SecurityException , NoSuchMethodException , RoutingException { 209 addressResolver = EasyMock 210 .createMock(AddressResolver.class, 211 new Method [] {AddressResolver.class.getDeclaredMethod( 212 "resolveLinkedAddressForInterface", 213 new Class [] {QName .class})}); 214 ComponentContextImpl componentContextImpl = EasyMock 215 .createMock(ComponentContextImpl.class); 216 MessageExchangeImpl messageExchangeImpl = EasyMock 217 .createMock(MessageExchangeImpl.class); 218 EndpointServiceImpl endpointServiceImpl = EasyMock 219 .createMock(EndpointServiceImpl.class); 220 221 EasyMock.expect(messageExchangeImpl.getEndpoint()).andReturn(null); 222 EasyMock.expect(messageExchangeImpl.getService()).andReturn(null); 223 EasyMock.expect(messageExchangeImpl.getInterfaceName()).andReturn( 224 new QName ("interface")); 225 EasyMock.expect( 226 addressResolver.resolveLinkedAddressForInterface(new QName ( 227 "interface"))).andReturn(null); 228 EasyMock.expect( 229 endpointServiceImpl.getInternalEndpointsForInterface(new QName ( 230 "interface"))).andReturn(null); 231 232 EasyMock.replay(messageExchangeImpl); 233 EasyMock.replay(componentContextImpl); 234 EasyMock.replay(endpointServiceImpl); 235 EasyMock.replay(addressResolver); 236 237 addressResolver.endpointService = endpointServiceImpl; 238 239 try { 240 addressResolver.resolveAddress(componentContextImpl, 241 messageExchangeImpl); 242 fail(); 243 } catch (RoutingException e) { 244 } 246 } 247 248 public void testResolveLinkedAddressForInterfaceNull() { 249 EndpointServiceImpl endpointServiceImpl = EasyMock 250 .createMock(EndpointServiceImpl.class); 251 252 EasyMock.expect( 253 endpointServiceImpl.getInternalEndpointsForInterface(new QName ( 254 "test"))).andReturn(new ServiceEndpoint[0]); 255 256 EasyMock.replay(endpointServiceImpl); 257 258 addressResolver.endpointService = endpointServiceImpl; 259 assertNull(addressResolver.resolveLinkedAddressForInterface(new QName ( 260 "test"))); 261 } 262 } | Popular Tags |