1 22 package org.objectweb.petals.jbi.messaging; 23 24 import java.lang.reflect.Method ; 25 26 import javax.jbi.messaging.ExchangeStatus; 27 import javax.jbi.messaging.MessageExchange; 28 import javax.jbi.messaging.MessagingException; 29 import javax.jbi.messaging.MessageExchange.Role; 30 import javax.jbi.servicedesc.ServiceEndpoint; 31 import javax.xml.namespace.QName ; 32 33 import junit.framework.TestCase; 34 35 import org.easymock.classextension.EasyMock; 36 import org.objectweb.petals.jbi.registry.InternalEndpoint; 37 38 43 public class MessageExchangeDecoratorTest extends TestCase { 44 45 private MessageExchangeDecorator messageExchangeDecorator; 46 47 public void setUp() throws MessagingException { 48 MessageExchangeImpl me = new MessageExchangeImpl(null); 49 me.setExchangeId("test01"); 50 me.setOperation(new QName ("operationname")); 51 me.setService(new QName ("servicename")); 52 me.setInterfaceName(new QName ("interfacename")); 53 me.setStatus(ExchangeStatus.ERROR); 54 me.setEndpoint(new InternalEndpoint(new QName ("servicename"), 55 "endpoint", "compo", null, null)); 56 me.setError(new RuntimeException ("test")); 57 me.setProperty("test", "value"); 58 messageExchangeDecorator = new MessageExchangeDecorator(me, 59 Role.CONSUMER); 60 } 61 62 public void testCreateFault() throws MessagingException { 63 assertNotNull(messageExchangeDecorator.createFault()); 64 } 65 66 public void testCreateMessage() throws MessagingException { 67 assertNotNull(messageExchangeDecorator.createMessage()); 68 } 69 70 public void testGetEndpoint() { 71 ServiceEndpoint endpoint = messageExchangeDecorator.getEndpoint(); 72 assertEquals(endpoint.getServiceName(), new QName ("servicename")); 73 } 74 75 public void testGetError() { 76 Exception exception = messageExchangeDecorator.getError(); 77 assertEquals(exception.getMessage(), "test"); 78 } 79 80 public void testGetError1() { 81 messageExchangeDecorator.setError(new RuntimeException ("test1")); 82 Exception exception = messageExchangeDecorator.getError(); 83 assertEquals(exception.getMessage(), "test1"); 84 } 85 86 public void testGetExchangeId() { 87 assertEquals(messageExchangeDecorator.getExchangeId(), "test01"); 88 } 89 90 public void testGetProperty() { 91 assertEquals(messageExchangeDecorator.getProperty("test"), "value"); 92 } 93 94 public void testGetProperty1() { 95 messageExchangeDecorator.setProperty("test1", "value"); 96 assertEquals(messageExchangeDecorator.getProperty("test1"), "value"); 97 } 98 99 public void testGetPropertyNames() { 100 assertEquals(messageExchangeDecorator.getPropertyNames().iterator() 101 .next(), "test"); 102 } 103 104 public void testGetInterfaceName1() { 105 messageExchangeDecorator.setInterfaceName(new QName ("interfacename1")); 106 assertEquals(messageExchangeDecorator.getInterfaceName(), new QName ( 107 "interfacename1")); 108 } 109 110 public void testGetInterfaceName() { 111 assertEquals(messageExchangeDecorator.getInterfaceName(), new QName ( 112 "interfacename")); 113 } 114 115 public void testGetOperation() { 116 assertEquals(messageExchangeDecorator.getOperation(), new QName ( 117 "operationname")); 118 } 119 120 public void testGetOperation1() { 121 messageExchangeDecorator.setOperation(new QName ("operationname1")); 122 assertEquals(messageExchangeDecorator.getOperation(), new QName ( 123 "operationname1")); 124 } 125 126 public void testGetService() { 127 assertEquals(messageExchangeDecorator.getService(), new QName ( 128 "servicename")); 129 } 130 131 public void testGetService1() { 132 messageExchangeDecorator.setService(new QName ("servicename1")); 133 assertEquals(messageExchangeDecorator.getService(), new QName ( 134 "servicename1")); 135 } 136 137 public void testGetStatus() { 138 assertEquals(messageExchangeDecorator.getStatus(), ExchangeStatus.ERROR); 139 } 140 141 public void testGetStatus1() throws MessagingException { 142 messageExchangeDecorator.setStatus(ExchangeStatus.DONE); 143 assertEquals(messageExchangeDecorator.getStatus(), ExchangeStatus.DONE); 144 } 145 146 public void testGetFault() throws SecurityException , NoSuchMethodException { 147 MessageExchangeDecorator messageExchangeDecorator = EasyMock 148 .createMock(MessageExchangeDecorator.class, 149 new Method [] {MessageExchangeDecorator.class.getDeclaredMethod( 150 "checkComponentOwnsExchange", new Class [0])}); 151 MessageExchangeImpl messageExchangeImpl = EasyMock 152 .createMock(MessageExchangeImpl.class); 153 FaultImpl faultImpl = EasyMock.createMock(FaultImpl.class); 154 155 messageExchangeDecorator.checkComponentOwnsExchange(); 156 EasyMock.expect(messageExchangeImpl.getFault()).andReturn(faultImpl); 157 158 EasyMock.replay(messageExchangeDecorator); 159 EasyMock.replay(faultImpl); 160 EasyMock.replay(messageExchangeImpl); 161 162 messageExchangeDecorator.messageExchange = messageExchangeImpl; 163 164 assertEquals(messageExchangeDecorator.getFault(), faultImpl); 165 } 166 167 public void testGetMessageExchange() { 168 MessageExchangeImpl messageExchangeImpl = EasyMock 169 .createMock(MessageExchangeImpl.class); 170 171 EasyMock.replay(messageExchangeImpl); 172 messageExchangeDecorator.messageExchange = messageExchangeImpl; 173 174 assertEquals(messageExchangeDecorator.getMessageExchange(), 175 messageExchangeImpl); 176 } 177 178 public void testGetObserverRole() { 179 messageExchangeDecorator.observerRole = MessageExchange.Role.CONSUMER; 180 assertEquals(messageExchangeDecorator.getObserverRole(), 181 MessageExchange.Role.CONSUMER); 182 } 183 184 public void testGetRole() throws SecurityException , NoSuchMethodException { 185 MessageExchangeDecorator messageExchangeDecorator = EasyMock 186 .createMock(MessageExchangeDecorator.class, 187 new Method [] {MessageExchangeDecorator.class.getDeclaredMethod( 188 "checkComponentOwnsExchange", new Class [0])}); 189 MessageExchangeImpl messageExchangeImpl = EasyMock 190 .createMock(MessageExchangeImpl.class); 191 192 EasyMock.expect(messageExchangeImpl.getRole()).andReturn( 193 MessageExchange.Role.PROVIDER); 194 messageExchangeDecorator.checkComponentOwnsExchange(); 195 196 EasyMock.replay(messageExchangeDecorator); 197 EasyMock.replay(messageExchangeImpl); 198 199 messageExchangeDecorator.messageExchange = messageExchangeImpl; 200 201 assertEquals(messageExchangeDecorator.getRole(), 202 MessageExchange.Role.PROVIDER); 203 } 204 205 public void testIsTransacted() throws SecurityException , 206 NoSuchMethodException { 207 MessageExchangeDecorator messageExchangeDecorator = EasyMock 208 .createMock(MessageExchangeDecorator.class, 209 new Method [] {MessageExchangeDecorator.class.getDeclaredMethod( 210 "checkComponentOwnsExchange", new Class [0])}); 211 MessageExchangeImpl messageExchangeImpl = EasyMock 212 .createMock(MessageExchangeImpl.class); 213 214 EasyMock.expect(messageExchangeImpl.isTransacted()).andReturn(true); 215 messageExchangeDecorator.checkComponentOwnsExchange(); 216 217 EasyMock.replay(messageExchangeDecorator); 218 EasyMock.replay(messageExchangeImpl); 219 220 messageExchangeDecorator.messageExchange = messageExchangeImpl; 221 222 assertEquals(messageExchangeDecorator.isTransacted(), true); 223 } 224 225 public void testSetEndpoint() throws SecurityException , 226 NoSuchMethodException { 227 MessageExchangeDecorator messageExchangeDecorator = EasyMock 228 .createMock(MessageExchangeDecorator.class, 229 new Method [] {MessageExchangeDecorator.class.getDeclaredMethod( 230 "checkComponentOwnsExchange", new Class [0])}); 231 MessageExchangeImpl messageExchangeImpl = EasyMock 232 .createMock(MessageExchangeImpl.class); 233 ServiceEndpoint serviceEndpoint = EasyMock 234 .createMock(ServiceEndpoint.class); 235 236 messageExchangeDecorator.checkComponentOwnsExchange(); 237 messageExchangeImpl.setEndpoint(serviceEndpoint); 238 239 EasyMock.replay(messageExchangeDecorator); 240 EasyMock.replay(messageExchangeImpl); 241 242 messageExchangeDecorator.messageExchange = messageExchangeImpl; 243 244 messageExchangeDecorator.setEndpoint(serviceEndpoint); 245 } 246 247 public void testSetFault() throws SecurityException , NoSuchMethodException , 248 MessagingException { 249 MessageExchangeDecorator messageExchangeDecorator = EasyMock 250 .createMock(MessageExchangeDecorator.class, 251 new Method [] {MessageExchangeDecorator.class.getDeclaredMethod( 252 "checkComponentOwnsExchange", new Class [0])}); 253 MessageExchangeImpl messageExchangeImpl = EasyMock 254 .createMock(MessageExchangeImpl.class); 255 FaultImpl faultImpl = EasyMock.createMock(FaultImpl.class); 256 257 messageExchangeDecorator.checkComponentOwnsExchange(); 258 messageExchangeImpl.setFault(faultImpl); 259 260 EasyMock.replay(messageExchangeDecorator); 261 EasyMock.replay(messageExchangeImpl); 262 263 messageExchangeDecorator.messageExchange = messageExchangeImpl; 264 265 messageExchangeDecorator.setFault(faultImpl); 266 } 267 268 public void testSetWaitingOnSynchronousSend() { 269 messageExchangeDecorator.setWaitingOnSynchronousSend(true); 270 assertTrue(messageExchangeDecorator.waitingOnSynchronousSend); 271 } 272 273 public void testSetMessageExchange() { 274 MessageExchangeImpl messageExchangeImpl = EasyMock 275 .createMock(MessageExchangeImpl.class); 276 277 messageExchangeDecorator.setMessageExchange(messageExchangeImpl); 278 279 assertEquals(messageExchangeImpl, 280 messageExchangeDecorator.messageExchange); 281 } 282 283 public void testCheckComponentOwnsExchangeException() throws SecurityException , 284 NoSuchMethodException { 285 MessageExchangeDecorator messageExchangeDecorator = EasyMock 286 .createMock(MessageExchangeDecorator.class, 287 new Method [] {MessageExchangeDecorator.class.getDeclaredMethod( 288 "hasOwnership", new Class [0])}); 289 290 EasyMock.expect(messageExchangeDecorator.hasOwnership()).andReturn( 291 false); 292 293 EasyMock.replay(messageExchangeDecorator); 294 295 try { 296 messageExchangeDecorator.checkComponentOwnsExchange(); 297 fail(); 298 } catch (Exception e) { 299 } 301 } 302 } 303 | Popular Tags |