1 package org.objectweb.celtix.bus.ws.addressing.soap; 2 3 4 import java.util.Iterator ; 5 import java.util.Set ; 6 7 import javax.xml.bind.JAXBContext; 8 import javax.xml.bind.JAXBElement; 9 import javax.xml.bind.Marshaller; 10 import javax.xml.bind.Unmarshaller; 11 import javax.xml.namespace.QName ; 12 import javax.xml.soap.MimeHeaders ; 13 import javax.xml.soap.Name ; 14 import javax.xml.soap.SOAPEnvelope ; 15 import javax.xml.soap.SOAPHeader ; 16 import javax.xml.soap.SOAPHeaderElement ; 17 import javax.xml.soap.SOAPMessage ; 18 import javax.xml.soap.SOAPPart ; 19 import javax.xml.ws.handler.MessageContext; 20 import javax.xml.ws.handler.soap.SOAPMessageContext; 21 import javax.xml.ws.soap.SOAPFaultException; 22 import static javax.xml.ws.handler.MessageContext.MESSAGE_OUTBOUND_PROPERTY; 23 24 import junit.framework.TestCase; 25 26 import org.easymock.IArgumentMatcher; 27 import org.easymock.classextension.EasyMock; 28 import org.easymock.classextension.IMocksControl; 29 30 import org.objectweb.celtix.bus.ws.addressing.AddressingPropertiesImpl; 31 import org.objectweb.celtix.bus.ws.addressing.ContextUtils; 32 import org.objectweb.celtix.bus.ws.addressing.Names; 33 import org.objectweb.celtix.ws.addressing.AttributedURIType; 34 import org.objectweb.celtix.ws.addressing.EndpointReferenceType; 35 import org.objectweb.celtix.ws.addressing.RelatesToType; 36 import org.objectweb.celtix.ws.addressing.v200408.AttributedURI; 37 import org.objectweb.celtix.ws.addressing.v200408.Relationship; 38 39 import static org.objectweb.celtix.context.ObjectMessageContext.REQUESTOR_ROLE_PROPERTY; 40 import static org.objectweb.celtix.ws.addressing.JAXWSAConstants.CLIENT_ADDRESSING_PROPERTIES_INBOUND; 41 import static org.objectweb.celtix.ws.addressing.JAXWSAConstants.CLIENT_ADDRESSING_PROPERTIES_OUTBOUND; 42 import static org.objectweb.celtix.ws.addressing.JAXWSAConstants.SERVER_ADDRESSING_PROPERTIES_INBOUND; 43 import static org.objectweb.celtix.ws.addressing.JAXWSAConstants.SERVER_ADDRESSING_PROPERTIES_OUTBOUND; 44 45 46 public class MAPCodecTest extends TestCase { 47 48 private MAPCodec codec; 49 private IMocksControl control; 50 private QName [] expectedNames; 51 private Class <?>[] expectedDeclaredTypes; 52 private Object [] expectedValues; 53 private int expectedIndex; 55 private String expectedNamespaceURI; 56 57 public void setUp() { 58 codec = new MAPCodec(); 59 codec.init(null); 60 control = EasyMock.createNiceControl(); 61 } 62 63 public void tearDown() { 64 codec.destroy(); 65 expectedNames = null; 66 expectedDeclaredTypes = null; 67 expectedValues = null; 69 expectedIndex = 0; 70 expectedNamespaceURI = null; 71 } 72 73 public void testGetHeaders() throws Exception { 74 Set <QName > headers = codec.getHeaders(); 75 assertTrue("expected From header", 76 headers.contains(Names.WSA_FROM_QNAME)); 77 assertTrue("expected To header", 78 headers.contains(Names.WSA_TO_QNAME)); 79 assertTrue("expected ReplyTo header", 80 headers.contains(Names.WSA_REPLYTO_QNAME)); 81 assertTrue("expected FaultTo header", 82 headers.contains(Names.WSA_FAULTTO_QNAME)); 83 assertTrue("expected Action header", 84 headers.contains(Names.WSA_ACTION_QNAME)); 85 assertTrue("expected MessageID header", 86 headers.contains(Names.WSA_MESSAGEID_QNAME)); 87 } 88 89 public void testRequestorOutbound() throws Exception { 90 SOAPMessageContext context = setUpContext(true, true); 91 boolean proceed = codec.handleMessage(context); 92 assertTrue("expected dispatch to proceed", proceed); 93 control.verify(); 94 codec.close(context); 95 } 96 97 public void testRequestorOutboundFault() throws Exception { 98 SOAPMessageContext context = setUpContext(true, true); 99 boolean proceed = codec.handleFault(context); 100 assertTrue("expected dispatch to proceed", proceed); 101 control.verify(); 102 codec.close(context); 103 } 104 105 public void testRequestorOutboundPreExistingSOAPAction() throws Exception { 106 SOAPMessageContext context = setUpContext(true, true, false, true); 107 boolean proceed = codec.handleMessage(context); 108 assertTrue("expected dispatch to proceed", proceed); 109 control.verify(); 110 codec.close(context); 111 } 112 113 public void testRequestorOutboundNonNative() throws Exception { 114 String uri = VersionTransformer.Names200408.WSA_NAMESPACE_NAME; 115 SOAPMessageContext context = 116 setUpContext(true, true, false, false, uri); 117 boolean proceed = codec.handleMessage(context); 118 assertTrue("expected dispatch to proceed", proceed); 119 control.verify(); 120 codec.close(context); 121 } 122 123 public void testResponderInbound() throws Exception { 124 SOAPMessageContext context = setUpContext(false, false); 125 boolean proceed = codec.handleMessage(context); 126 assertTrue("expected dispatch to proceed", proceed); 127 control.verify(); 128 codec.close(context); 129 } 130 131 public void testResponderInboundFault() throws Exception { 132 SOAPMessageContext context = setUpContext(false, false); 133 boolean proceed = codec.handleFault(context); 134 assertTrue("expected dispatch to proceed", proceed); 135 control.verify(); 136 codec.close(context); 137 } 138 139 public void testResponderOutbound() throws Exception { 140 SOAPMessageContext context = setUpContext(false, true); 141 boolean proceed = codec.handleMessage(context); 142 assertTrue("expected dispatch to proceed", proceed); 143 control.verify(); 144 codec.close(context); 145 } 146 147 public void testResponderInboundNonNative() throws Exception { 148 String uri = VersionTransformer.Names200408.WSA_NAMESPACE_NAME; 149 SOAPMessageContext context = 150 setUpContext(false, false, false, false, uri); 151 boolean proceed = codec.handleMessage(context); 152 assertTrue("expected dispatch to proceed", proceed); 153 control.verify(); 154 codec.close(context); 155 } 156 157 public void testResponderOutboundInvalidMAP() throws Exception { 158 SOAPMessageContext context = setUpContext(false, true, true); 159 try { 160 codec.handleMessage(context); 161 fail("expected SOAPFaultException on invalid MAP"); 162 } catch (SOAPFaultException sfe) { 163 assertEquals("unexpected fault string", 164 "Duplicate Message ID urn:uuid:12345", 165 sfe.getFault().getFaultString()); 166 } 167 control.verify(); 168 codec.close(context); 169 } 170 171 public void testResponderOutboundFault() throws Exception { 172 SOAPMessageContext context = setUpContext(false, true); 173 boolean proceed = codec.handleFault(context); 174 assertTrue("expected dispatch to proceed", proceed); 175 control.verify(); 176 codec.close(context); 177 } 178 179 public void testResponderOutboundFaultInvalidMAP() throws Exception { 180 SOAPMessageContext context = setUpContext(false, true, true); 181 try { 182 codec.handleFault(context); 183 fail("expected SOAPFaultException on invalid MAP"); 184 } catch (SOAPFaultException sfe) { 185 assertEquals("unexpected fault string", 186 "Duplicate Message ID urn:uuid:12345", 187 sfe.getFault().getFaultString()); 188 } 189 control.verify(); 190 codec.close(context); 191 } 192 193 public void testResponderOutboundPreExistingSOAPAction() throws Exception { 194 SOAPMessageContext context = setUpContext(false, true, false, true); 195 boolean proceed = codec.handleMessage(context); 196 assertTrue("expected dispatch to proceed", proceed); 197 control.verify(); 198 codec.close(context); 199 } 200 201 public void testResponderOutboundNonNative() throws Exception { 202 String uri = VersionTransformer.Names200408.WSA_NAMESPACE_NAME; 203 SOAPMessageContext context = 204 setUpContext(false, true, false, false, uri); 205 boolean proceed = codec.handleMessage(context); 206 assertTrue("expected dispatch to proceed", proceed); 207 control.verify(); 208 codec.close(context); 209 } 210 211 public void testRequestorInbound() throws Exception { 212 SOAPMessageContext context = setUpContext(true, false); 213 boolean proceed = codec.handleMessage(context); 214 assertTrue("expected dispatch to proceed", proceed); 215 control.verify(); 216 codec.close(context); 217 } 218 219 public void testRequestorInboundFault() throws Exception { 220 SOAPMessageContext context = setUpContext(true, false); 221 boolean proceed = codec.handleFault(context); 222 assertTrue("expected dispatch to proceed", proceed); 223 control.verify(); 224 codec.close(context); 225 } 226 227 public void testRequestorInboundNonNative() throws Exception { 228 String uri = VersionTransformer.Names200408.WSA_NAMESPACE_NAME; 229 SOAPMessageContext context = 230 setUpContext(true, false, false, false, uri); 231 boolean proceed = codec.handleMessage(context); 232 assertTrue("expected dispatch to proceed", proceed); 233 control.verify(); 234 codec.close(context); 235 } 236 237 private SOAPMessageContext setUpContext(boolean requestor, 238 boolean outbound) 239 throws Exception { 240 return setUpContext(requestor, outbound, false); 241 } 242 243 private SOAPMessageContext setUpContext(boolean requestor, 244 boolean outbound, 245 boolean invalidMAP) 246 throws Exception { 247 return setUpContext(requestor, 248 outbound, 249 invalidMAP, 250 false); 251 } 252 253 private SOAPMessageContext setUpContext(boolean requestor, 254 boolean outbound, 255 boolean invalidMAP, 256 boolean preExistingSOAPAction) 257 throws Exception { 258 return setUpContext(requestor, 259 outbound, 260 invalidMAP, 261 preExistingSOAPAction, 262 Names.WSA_NAMESPACE_NAME); 263 } 264 265 private SOAPMessageContext setUpContext(boolean requestor, 266 boolean outbound, 267 boolean invalidMAP, 268 boolean preExistingSOAPAction, 269 String exposeAs) 270 throws Exception { 271 SOAPMessageContext context = 272 control.createMock(SOAPMessageContext.class); 273 context.get(MESSAGE_OUTBOUND_PROPERTY); 274 EasyMock.expectLastCall().andReturn(Boolean.valueOf(outbound)); 275 context.get(REQUESTOR_ROLE_PROPERTY); 276 EasyMock.expectLastCall().andReturn(Boolean.valueOf(requestor)); 277 String mapProperty = getMAPProperty(requestor, outbound); 278 AddressingPropertiesImpl maps = getMAPs(exposeAs, outbound); 279 SOAPMessage message = control.createMock(SOAPMessage .class); 280 context.getMessage(); 281 EasyMock.expectLastCall().andReturn(message); 282 SOAPHeader header = setUpSOAPHeader(context, message, outbound); 283 JAXBContext jaxbContext = control.createMock(JAXBContext.class); 284 ContextUtils.setJAXBContext(jaxbContext); 285 VersionTransformer.Names200408.setJAXBContext(jaxbContext); 286 if (outbound) { 287 setUpEncode(context, 288 message, 289 header, 290 maps, 291 mapProperty, 292 invalidMAP, 293 preExistingSOAPAction); 294 } else { 295 setUpDecode(context, header, maps, mapProperty, requestor); 296 } 297 control.replay(); 298 return context; 299 } 300 301 private SOAPHeader setUpSOAPHeader(SOAPMessageContext context, 302 SOAPMessage message, 303 boolean outbound) 304 throws Exception { 305 SOAPPart part = control.createMock(SOAPPart .class); 306 message.getSOAPPart(); 307 EasyMock.expectLastCall().andReturn(part); 308 SOAPEnvelope env = control.createMock(SOAPEnvelope .class); 309 part.getEnvelope(); 310 EasyMock.expectLastCall().andReturn(env); 311 SOAPHeader header = control.createMock(SOAPHeader .class); 312 env.getHeader(); 313 EasyMock.expectLastCall().andReturn(header); 314 if (outbound) { 315 env.getHeader(); 316 EasyMock.expectLastCall().andReturn(header); 317 } 318 return header; 319 } 320 321 private void setUpEncode(SOAPMessageContext context, 322 SOAPMessage message, 323 SOAPHeader header, 324 AddressingPropertiesImpl maps, 325 String mapProperty, 326 boolean invalidMAP, 327 boolean preExistingSOAPAction) throws Exception { 328 context.get(mapProperty); 329 EasyMock.expectLastCall().andReturn(maps); 330 Iterator headerItr = control.createMock(Iterator .class); 331 header.examineAllHeaderElements(); 332 EasyMock.expectLastCall().andReturn(headerItr); 333 headerItr.hasNext(); 334 EasyMock.expectLastCall().andReturn(Boolean.FALSE); 335 header.addNamespaceDeclaration(Names.WSA_NAMESPACE_PREFIX, 336 maps.getNamespaceURI()); 337 EasyMock.expectLastCall().andReturn(null); 338 Marshaller marshaller = control.createMock(Marshaller.class); 339 ContextUtils.getJAXBContext().createMarshaller(); 340 EasyMock.expectLastCall().andReturn(marshaller); 341 marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE); 342 EasyMock.expectLastCall(); 343 IArgumentMatcher matcher = new JAXBEltMatcher(); 344 for (int i = 0; i < expectedValues.length; i++) { 345 EasyMock.reportMatcher(matcher); 346 EasyMock.eq(header); 347 marshaller.marshal(null, header); 348 EasyMock.expectLastCall(); 351 } 352 MimeHeaders mimeHeaders = control.createMock(MimeHeaders .class); 353 message.getMimeHeaders(); 354 EasyMock.expectLastCall().andReturn(mimeHeaders); 355 mimeHeaders.getHeader("SOAPAction"); 356 if (preExistingSOAPAction) { 357 EasyMock.expectLastCall().andReturn(new String [] {"foobar"}); 358 String soapAction = 359 "\"" + ((AttributedURIType)expectedValues[5]).getValue() + "\""; 360 mimeHeaders.setHeader("SOAPAction", soapAction); 361 EasyMock.expectLastCall(); 362 } else { 363 EasyMock.expectLastCall().andReturn(null); 364 } 365 if (invalidMAP) { 366 context.get("org.objectweb.celtix.ws.addressing.map.fault.name"); 367 EasyMock.expectLastCall().andReturn(Names.DUPLICATE_MESSAGE_ID_NAME); 368 context.get("org.objectweb.celtix.ws.addressing.map.fault.reason"); 369 EasyMock.expectLastCall().andReturn("Duplicate Message ID urn:uuid:12345"); 370 } 371 } 372 373 private void setUpDecode(SOAPMessageContext context, 374 SOAPHeader header, 375 AddressingPropertiesImpl maps, 376 String mapProperty, 377 boolean requestor) throws Exception { 378 Unmarshaller unmarshaller = control.createMock(Unmarshaller.class); 379 ContextUtils.getJAXBContext().createUnmarshaller(); 380 EasyMock.expectLastCall().andReturn(unmarshaller); 381 Iterator headerItr = control.createMock(Iterator .class); 382 header.examineAllHeaderElements(); 383 EasyMock.expectLastCall().andReturn(headerItr); 384 String uri = maps.getNamespaceURI(); 385 boolean exposedAsNative = Names.WSA_NAMESPACE_NAME.equals(uri); 386 boolean exposedAs200408 = 387 VersionTransformer.Names200408.WSA_NAMESPACE_NAME.equals(uri); 388 assertTrue("unexpected namescape URI: " + uri, 389 exposedAsNative || exposedAs200408); 390 setUpHeaderDecode(headerItr, 391 uri, 392 Names.WSA_MESSAGEID_NAME, 393 exposedAsNative 394 ? AttributedURIType.class 395 : AttributedURI.class, 396 0, 397 unmarshaller); 398 setUpHeaderDecode(headerItr, 399 uri, 400 Names.WSA_TO_NAME, 401 exposedAsNative 402 ? AttributedURIType.class 403 : AttributedURI.class, 404 1, 405 unmarshaller); 406 setUpHeaderDecode(headerItr, 407 uri, 408 Names.WSA_REPLYTO_NAME, 409 exposedAsNative 410 ? EndpointReferenceType.class 411 : VersionTransformer.Names200408.EPR_TYPE, 412 2, 413 unmarshaller); 414 setUpHeaderDecode(headerItr, 415 uri, 416 Names.WSA_FAULTTO_NAME, 417 exposedAsNative 418 ? EndpointReferenceType.class 419 : VersionTransformer.Names200408.EPR_TYPE, 420 3, 421 unmarshaller); 422 423 setUpHeaderDecode(headerItr, 424 uri, 425 Names.WSA_RELATESTO_NAME, 426 exposedAsNative 427 ? RelatesToType.class 428 : Relationship.class, 429 4, 430 unmarshaller); 431 if (requestor) { 432 context.put("org.objectweb.celtix.correlation.in", 433 exposedAsNative 434 ? ((RelatesToType)expectedValues[4]).getValue() 435 : ((Relationship)expectedValues[4]).getValue()); 436 EasyMock.expectLastCall().andReturn(null); 437 } 438 setUpHeaderDecode(headerItr, 439 uri, 440 Names.WSA_ACTION_NAME, 441 exposedAsNative 442 ? AttributedURIType.class 443 : AttributedURI.class, 444 5, 445 unmarshaller); 446 EasyMock.eq(mapProperty); 447 EasyMock.reportMatcher(new MAPMatcher()); 448 context.put(mapProperty, maps); 449 EasyMock.expectLastCall().andReturn(null); 450 context.setScope(mapProperty, MessageContext.Scope.HANDLER); 451 EasyMock.expectLastCall(); 452 } 453 454 private <T> void setUpHeaderDecode(Iterator headerItr, 455 String uri, 456 String name, 457 Class <T> clz, 458 int index, 459 Unmarshaller unmarshaller) 460 throws Exception { 461 headerItr.hasNext(); 462 EasyMock.expectLastCall().andReturn(Boolean.TRUE); 463 SOAPHeaderElement headerElement = 464 control.createMock(SOAPHeaderElement .class); 465 headerItr.next(); 466 EasyMock.expectLastCall().andReturn(headerElement); 467 Name headerName = control.createMock(Name .class); 468 headerElement.getElementName(); 469 EasyMock.expectLastCall().andReturn(headerName); 470 headerName.getURI(); 471 EasyMock.expectLastCall().andReturn(uri); 472 headerName.getLocalName(); 473 EasyMock.expectLastCall().andReturn(name); 474 Object v = expectedValues[index]; 475 JAXBElement<?> jaxbElement = 476 new JAXBElement<T>(new QName (uri, name), clz, clz.cast(v)); 477 unmarshaller.unmarshal(headerElement, clz); 478 EasyMock.expectLastCall().andReturn(jaxbElement); 479 } 480 481 private String getMAPProperty(boolean requestor, boolean outbound) { 482 return requestor 483 ? outbound 484 ? CLIENT_ADDRESSING_PROPERTIES_OUTBOUND 485 : CLIENT_ADDRESSING_PROPERTIES_INBOUND 486 : outbound 487 ? SERVER_ADDRESSING_PROPERTIES_OUTBOUND 488 : SERVER_ADDRESSING_PROPERTIES_INBOUND; 489 } 490 491 private AddressingPropertiesImpl getMAPs(String uri, boolean outbound) { 492 AddressingPropertiesImpl maps = new AddressingPropertiesImpl(); 493 boolean exposeAsNative = Names.WSA_NAMESPACE_NAME.equals(uri); 494 boolean exposeAs200408 = 495 VersionTransformer.Names200408.WSA_NAMESPACE_NAME.equals(uri); 496 AttributedURIType id = 497 ContextUtils.getAttributedURI("urn:uuid:12345"); 498 maps.setMessageID(id); 499 AttributedURIType to = 500 ContextUtils.getAttributedURI("foobar"); 501 maps.setTo(to); 502 EndpointReferenceType replyTo = new EndpointReferenceType(); 503 String anonymous = 504 exposeAsNative 505 ? Names.WSA_ANONYMOUS_ADDRESS 506 : VersionTransformer.Names200408.WSA_ANONYMOUS_ADDRESS; 507 replyTo.setAddress( 508 ContextUtils.getAttributedURI(anonymous)); 509 maps.setReplyTo(replyTo); 510 EndpointReferenceType faultTo = new EndpointReferenceType(); 511 anonymous = 512 exposeAsNative 513 ? Names.WSA_ANONYMOUS_ADDRESS 514 : VersionTransformer.Names200408.WSA_ANONYMOUS_ADDRESS; 515 faultTo.setAddress( 516 ContextUtils.getAttributedURI(anonymous)); 517 maps.setFaultTo(faultTo); 518 RelatesToType relatesTo = new RelatesToType(); 519 relatesTo.setValue("urn:uuid:67890"); 520 maps.setRelatesTo(relatesTo); 521 AttributedURIType action = 522 ContextUtils.getAttributedURI("http://foo/bar/SEI/opRequest"); 523 maps.setAction(action); 524 maps.exposeAs(uri); 525 expectedNamespaceURI = uri; 526 527 expectedNames = 528 new QName [] {new QName (uri, Names.WSA_MESSAGEID_NAME), 529 new QName (uri, Names.WSA_TO_NAME), 530 new QName (uri, Names.WSA_REPLYTO_NAME), 531 new QName (uri, Names.WSA_FAULTTO_NAME), 532 new QName (uri, Names.WSA_RELATESTO_NAME), 533 new QName (uri, Names.WSA_ACTION_NAME)}; 534 if (exposeAsNative) { 535 expectedValues = new Object [] {id, to, replyTo, faultTo, relatesTo, action}; 536 expectedDeclaredTypes = 537 new Class <?>[] {AttributedURIType.class, 538 AttributedURIType.class, 539 EndpointReferenceType.class, 540 EndpointReferenceType.class, 541 RelatesToType.class, 542 AttributedURIType.class}; 543 } else if (exposeAs200408) { 544 expectedValues = new Object [] {VersionTransformer.convert(id), 545 VersionTransformer.convert(to), 546 VersionTransformer.convert(replyTo), 547 VersionTransformer.convert(faultTo), 548 VersionTransformer.convert(relatesTo), 549 VersionTransformer.convert(action)}; 550 if (!outbound) { 551 VersionTransformer.Names200408.EPR_TYPE.cast(expectedValues[2]). 554 getAddress().setValue(Names.WSA_ANONYMOUS_ADDRESS); 555 VersionTransformer.Names200408.EPR_TYPE.cast(expectedValues[3]). 556 getAddress().setValue(Names.WSA_ANONYMOUS_ADDRESS); 557 } 558 expectedDeclaredTypes = 559 new Class <?>[] {AttributedURI.class, 560 AttributedURI.class, 561 VersionTransformer.Names200408.EPR_TYPE, 562 VersionTransformer.Names200408.EPR_TYPE, 563 Relationship.class, 564 AttributedURI.class}; 565 } else { 566 fail("unexpected namespace URI: " + uri); 567 } 568 return maps; 569 } 570 571 private final class JAXBEltMatcher implements IArgumentMatcher { 572 public boolean matches(Object obj) { 573 QName name = expectedNames[expectedIndex]; 574 Class <?> declaredType = expectedDeclaredTypes[expectedIndex]; 575 Object value = expectedValues[expectedIndex]; 576 boolean ret = false; 577 expectedIndex++; 578 if (obj instanceof JAXBElement) { 579 JAXBElement other = (JAXBElement)obj; 580 ret = name.equals(other.getName()) 581 && declaredType.isAssignableFrom(other.getDeclaredType()) 582 && compare(value, other.getValue()); 583 } 584 return ret; 585 } 586 587 public void appendTo(StringBuffer buffer) { 588 buffer.append("JAXBElements did not match"); 589 } 590 591 private boolean compare(Object a, Object b) { 592 boolean ret = false; 593 if (a instanceof AttributedURI && b instanceof AttributedURI) { 594 ret = ((AttributedURI)a).getValue().equals(((AttributedURI)b).getValue()); 595 } else if (a instanceof AttributedURIType && b instanceof AttributedURIType) { 596 ret = ((AttributedURIType)a).getValue().equals(((AttributedURIType)b).getValue()); 597 } else if (a instanceof EndpointReferenceType && b instanceof EndpointReferenceType) { 598 EndpointReferenceType aEPR = (EndpointReferenceType)a; 599 EndpointReferenceType bEPR = (EndpointReferenceType)b; 600 ret = aEPR.getAddress() != null 601 && bEPR.getAddress() != null 602 && aEPR.getAddress().getValue().equals(bEPR.getAddress().getValue()); 603 } else if (VersionTransformer.Names200408.EPR_TYPE.isInstance(a) 604 && VersionTransformer.Names200408.EPR_TYPE.isInstance(b)) { 605 ret = VersionTransformer.Names200408.EPR_TYPE.cast(a).getAddress() != null 606 && VersionTransformer.Names200408.EPR_TYPE.cast(b).getAddress() != null 607 && VersionTransformer.Names200408.EPR_TYPE.cast(a).getAddress().getValue().equals( 608 VersionTransformer.Names200408.EPR_TYPE.cast(b).getAddress().getValue()); 609 } else if (a instanceof Relationship && b instanceof Relationship) { 610 ret = ((Relationship)a).getValue().equals(((Relationship)b).getValue()); 611 } else if (a instanceof RelatesToType && b instanceof RelatesToType) { 612 ret = ((RelatesToType)a).getValue().equals(((RelatesToType)b).getValue()); 613 } 614 return ret; 615 } 616 } 617 618 private final class MAPMatcher implements IArgumentMatcher { 619 public boolean matches(Object obj) { 620 if (obj instanceof AddressingPropertiesImpl) { 621 AddressingPropertiesImpl other = (AddressingPropertiesImpl)obj; 622 return compareExpected(other); 623 } 624 return false; 625 } 626 627 public void appendTo(StringBuffer buffer) { 628 buffer.append("MAPs did not match"); 629 } 630 631 private boolean compareExpected(AddressingPropertiesImpl other) { 632 boolean ret = false; 633 String uri = other.getNamespaceURI(); 634 boolean exposedAsNative = Names.WSA_NAMESPACE_NAME.equals(uri); 635 boolean exposedAs200408 = 636 VersionTransformer.Names200408.WSA_NAMESPACE_NAME.equals(uri); 637 if (exposedAsNative || exposedAs200408) { 638 String expectedMessageID = 639 exposedAsNative 640 ? ((AttributedURIType)expectedValues[0]).getValue() 641 : ((AttributedURI)expectedValues[0]).getValue(); 642 String expectedTo = 643 exposedAsNative 644 ? ((AttributedURIType)expectedValues[1]).getValue() 645 : ((AttributedURI)expectedValues[1]).getValue(); 646 String expectedReplyTo = 647 exposedAsNative 648 ? ((EndpointReferenceType)expectedValues[2]).getAddress().getValue() 649 : (VersionTransformer.Names200408.EPR_TYPE.cast(expectedValues[2])). 650 getAddress().getValue(); 651 String expectedRelatesTo = 652 exposedAsNative 653 ? ((RelatesToType)expectedValues[4]).getValue() 654 : ((Relationship)expectedValues[4]).getValue(); 655 String expectedAction = 656 exposedAsNative 657 ? ((AttributedURIType)expectedValues[5]).getValue() 658 : ((AttributedURI)expectedValues[5]).getValue(); 659 ret = expectedMessageID.equals(other.getMessageID().getValue()) 660 && expectedTo.equals(other.getTo().getValue()) 661 && expectedReplyTo.equals( 662 other.getReplyTo().getAddress().getValue()) 663 && expectedRelatesTo.equals(other.getRelatesTo().getValue()) 664 && expectedAction.equals(other.getAction().getValue()) 665 && expectedNamespaceURI.equals(other.getNamespaceURI()); 666 } 667 return ret; 668 } 669 } 670 } 671 672 673 | Popular Tags |