001: package org.objectweb.celtix.bus.ws.addressing.soap;
002:
003: import java.util.Iterator;
004: import java.util.Set;
005:
006: import javax.xml.bind.JAXBContext;
007: import javax.xml.bind.JAXBElement;
008: import javax.xml.bind.Marshaller;
009: import javax.xml.bind.Unmarshaller;
010: import javax.xml.namespace.QName;
011: import javax.xml.soap.MimeHeaders;
012: import javax.xml.soap.Name;
013: import javax.xml.soap.SOAPEnvelope;
014: import javax.xml.soap.SOAPHeader;
015: import javax.xml.soap.SOAPHeaderElement;
016: import javax.xml.soap.SOAPMessage;
017: import javax.xml.soap.SOAPPart;
018: import javax.xml.ws.handler.MessageContext;
019: import javax.xml.ws.handler.soap.SOAPMessageContext;
020: import javax.xml.ws.soap.SOAPFaultException;
021: import static javax.xml.ws.handler.MessageContext.MESSAGE_OUTBOUND_PROPERTY;
022:
023: import junit.framework.TestCase;
024:
025: import org.easymock.IArgumentMatcher;
026: import org.easymock.classextension.EasyMock;
027: import org.easymock.classextension.IMocksControl;
028:
029: import org.objectweb.celtix.bus.ws.addressing.AddressingPropertiesImpl;
030: import org.objectweb.celtix.bus.ws.addressing.ContextUtils;
031: import org.objectweb.celtix.bus.ws.addressing.Names;
032: import org.objectweb.celtix.ws.addressing.AttributedURIType;
033: import org.objectweb.celtix.ws.addressing.EndpointReferenceType;
034: import org.objectweb.celtix.ws.addressing.RelatesToType;
035: import org.objectweb.celtix.ws.addressing.v200408.AttributedURI;
036: import org.objectweb.celtix.ws.addressing.v200408.Relationship;
037:
038: import static org.objectweb.celtix.context.ObjectMessageContext.REQUESTOR_ROLE_PROPERTY;
039: import static org.objectweb.celtix.ws.addressing.JAXWSAConstants.CLIENT_ADDRESSING_PROPERTIES_INBOUND;
040: import static org.objectweb.celtix.ws.addressing.JAXWSAConstants.CLIENT_ADDRESSING_PROPERTIES_OUTBOUND;
041: import static org.objectweb.celtix.ws.addressing.JAXWSAConstants.SERVER_ADDRESSING_PROPERTIES_INBOUND;
042: import static org.objectweb.celtix.ws.addressing.JAXWSAConstants.SERVER_ADDRESSING_PROPERTIES_OUTBOUND;
043:
044: public class MAPCodecTest extends TestCase {
045:
046: private MAPCodec codec;
047: private IMocksControl control;
048: private QName[] expectedNames;
049: private Class<?>[] expectedDeclaredTypes;
050: private Object[] expectedValues;
051: //private JAXBElement<?>[] expectedJAXBElements;
052: private int expectedIndex;
053: private String expectedNamespaceURI;
054:
055: public void setUp() {
056: codec = new MAPCodec();
057: codec.init(null);
058: control = EasyMock.createNiceControl();
059: }
060:
061: public void tearDown() {
062: codec.destroy();
063: expectedNames = null;
064: expectedDeclaredTypes = null;
065: //expectedJAXBElements = null;
066: expectedValues = null;
067: expectedIndex = 0;
068: expectedNamespaceURI = null;
069: }
070:
071: public void testGetHeaders() throws Exception {
072: Set<QName> headers = codec.getHeaders();
073: assertTrue("expected From header", headers
074: .contains(Names.WSA_FROM_QNAME));
075: assertTrue("expected To header", headers
076: .contains(Names.WSA_TO_QNAME));
077: assertTrue("expected ReplyTo header", headers
078: .contains(Names.WSA_REPLYTO_QNAME));
079: assertTrue("expected FaultTo header", headers
080: .contains(Names.WSA_FAULTTO_QNAME));
081: assertTrue("expected Action header", headers
082: .contains(Names.WSA_ACTION_QNAME));
083: assertTrue("expected MessageID header", headers
084: .contains(Names.WSA_MESSAGEID_QNAME));
085: }
086:
087: public void testRequestorOutbound() throws Exception {
088: SOAPMessageContext context = setUpContext(true, true);
089: boolean proceed = codec.handleMessage(context);
090: assertTrue("expected dispatch to proceed", proceed);
091: control.verify();
092: codec.close(context);
093: }
094:
095: public void testRequestorOutboundFault() throws Exception {
096: SOAPMessageContext context = setUpContext(true, true);
097: boolean proceed = codec.handleFault(context);
098: assertTrue("expected dispatch to proceed", proceed);
099: control.verify();
100: codec.close(context);
101: }
102:
103: public void testRequestorOutboundPreExistingSOAPAction()
104: throws Exception {
105: SOAPMessageContext context = setUpContext(true, true, false,
106: 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 = setUpContext(true, true, false,
116: 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 = setUpContext(false, false, false,
150: 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", sfe
165: .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", sfe
187: .getFault().getFaultString());
188: }
189: control.verify();
190: codec.close(context);
191: }
192:
193: public void testResponderOutboundPreExistingSOAPAction()
194: throws Exception {
195: SOAPMessageContext context = setUpContext(false, true, false,
196: true);
197: boolean proceed = codec.handleMessage(context);
198: assertTrue("expected dispatch to proceed", proceed);
199: control.verify();
200: codec.close(context);
201: }
202:
203: public void testResponderOutboundNonNative() throws Exception {
204: String uri = VersionTransformer.Names200408.WSA_NAMESPACE_NAME;
205: SOAPMessageContext context = setUpContext(false, true, false,
206: false, uri);
207: boolean proceed = codec.handleMessage(context);
208: assertTrue("expected dispatch to proceed", proceed);
209: control.verify();
210: codec.close(context);
211: }
212:
213: public void testRequestorInbound() throws Exception {
214: SOAPMessageContext context = setUpContext(true, false);
215: boolean proceed = codec.handleMessage(context);
216: assertTrue("expected dispatch to proceed", proceed);
217: control.verify();
218: codec.close(context);
219: }
220:
221: public void testRequestorInboundFault() throws Exception {
222: SOAPMessageContext context = setUpContext(true, false);
223: boolean proceed = codec.handleFault(context);
224: assertTrue("expected dispatch to proceed", proceed);
225: control.verify();
226: codec.close(context);
227: }
228:
229: public void testRequestorInboundNonNative() throws Exception {
230: String uri = VersionTransformer.Names200408.WSA_NAMESPACE_NAME;
231: SOAPMessageContext context = setUpContext(true, false, false,
232: false, uri);
233: boolean proceed = codec.handleMessage(context);
234: assertTrue("expected dispatch to proceed", proceed);
235: control.verify();
236: codec.close(context);
237: }
238:
239: private SOAPMessageContext setUpContext(boolean requestor,
240: boolean outbound) throws Exception {
241: return setUpContext(requestor, outbound, false);
242: }
243:
244: private SOAPMessageContext setUpContext(boolean requestor,
245: boolean outbound, boolean invalidMAP) throws Exception {
246: return setUpContext(requestor, outbound, invalidMAP, false);
247: }
248:
249: private SOAPMessageContext setUpContext(boolean requestor,
250: boolean outbound, boolean invalidMAP,
251: boolean preExistingSOAPAction) throws Exception {
252: return setUpContext(requestor, outbound, invalidMAP,
253: preExistingSOAPAction, Names.WSA_NAMESPACE_NAME);
254: }
255:
256: private SOAPMessageContext setUpContext(boolean requestor,
257: boolean outbound, boolean invalidMAP,
258: boolean preExistingSOAPAction, String exposeAs)
259: throws Exception {
260: SOAPMessageContext context = control
261: .createMock(SOAPMessageContext.class);
262: context.get(MESSAGE_OUTBOUND_PROPERTY);
263: EasyMock.expectLastCall().andReturn(Boolean.valueOf(outbound));
264: context.get(REQUESTOR_ROLE_PROPERTY);
265: EasyMock.expectLastCall().andReturn(Boolean.valueOf(requestor));
266: String mapProperty = getMAPProperty(requestor, outbound);
267: AddressingPropertiesImpl maps = getMAPs(exposeAs, outbound);
268: SOAPMessage message = control.createMock(SOAPMessage.class);
269: context.getMessage();
270: EasyMock.expectLastCall().andReturn(message);
271: SOAPHeader header = setUpSOAPHeader(context, message, outbound);
272: JAXBContext jaxbContext = control.createMock(JAXBContext.class);
273: ContextUtils.setJAXBContext(jaxbContext);
274: VersionTransformer.Names200408.setJAXBContext(jaxbContext);
275: if (outbound) {
276: setUpEncode(context, message, header, maps, mapProperty,
277: invalidMAP, preExistingSOAPAction);
278: } else {
279: setUpDecode(context, header, maps, mapProperty, requestor);
280: }
281: control.replay();
282: return context;
283: }
284:
285: private SOAPHeader setUpSOAPHeader(SOAPMessageContext context,
286: SOAPMessage message, boolean outbound) throws Exception {
287: SOAPPart part = control.createMock(SOAPPart.class);
288: message.getSOAPPart();
289: EasyMock.expectLastCall().andReturn(part);
290: SOAPEnvelope env = control.createMock(SOAPEnvelope.class);
291: part.getEnvelope();
292: EasyMock.expectLastCall().andReturn(env);
293: SOAPHeader header = control.createMock(SOAPHeader.class);
294: env.getHeader();
295: EasyMock.expectLastCall().andReturn(header);
296: if (outbound) {
297: env.getHeader();
298: EasyMock.expectLastCall().andReturn(header);
299: }
300: return header;
301: }
302:
303: private void setUpEncode(SOAPMessageContext context,
304: SOAPMessage message, SOAPHeader header,
305: AddressingPropertiesImpl maps, String mapProperty,
306: boolean invalidMAP, boolean preExistingSOAPAction)
307: throws Exception {
308: context.get(mapProperty);
309: EasyMock.expectLastCall().andReturn(maps);
310: Iterator headerItr = control.createMock(Iterator.class);
311: header.examineAllHeaderElements();
312: EasyMock.expectLastCall().andReturn(headerItr);
313: headerItr.hasNext();
314: EasyMock.expectLastCall().andReturn(Boolean.FALSE);
315: header.addNamespaceDeclaration(Names.WSA_NAMESPACE_PREFIX, maps
316: .getNamespaceURI());
317: EasyMock.expectLastCall().andReturn(null);
318: Marshaller marshaller = control.createMock(Marshaller.class);
319: ContextUtils.getJAXBContext().createMarshaller();
320: EasyMock.expectLastCall().andReturn(marshaller);
321: marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
322: EasyMock.expectLastCall();
323: IArgumentMatcher matcher = new JAXBEltMatcher();
324: for (int i = 0; i < expectedValues.length; i++) {
325: EasyMock.reportMatcher(matcher);
326: EasyMock.eq(header);
327: marshaller.marshal(null, header);
328: //marshaller.marshal(expectedJAXBElements[i],
329: // header);
330: EasyMock.expectLastCall();
331: }
332: MimeHeaders mimeHeaders = control.createMock(MimeHeaders.class);
333: message.getMimeHeaders();
334: EasyMock.expectLastCall().andReturn(mimeHeaders);
335: mimeHeaders.getHeader("SOAPAction");
336: if (preExistingSOAPAction) {
337: EasyMock.expectLastCall().andReturn(
338: new String[] { "foobar" });
339: String soapAction = "\""
340: + ((AttributedURIType) expectedValues[5])
341: .getValue() + "\"";
342: mimeHeaders.setHeader("SOAPAction", soapAction);
343: EasyMock.expectLastCall();
344: } else {
345: EasyMock.expectLastCall().andReturn(null);
346: }
347: if (invalidMAP) {
348: context
349: .get("org.objectweb.celtix.ws.addressing.map.fault.name");
350: EasyMock.expectLastCall().andReturn(
351: Names.DUPLICATE_MESSAGE_ID_NAME);
352: context
353: .get("org.objectweb.celtix.ws.addressing.map.fault.reason");
354: EasyMock.expectLastCall().andReturn(
355: "Duplicate Message ID urn:uuid:12345");
356: }
357: }
358:
359: private void setUpDecode(SOAPMessageContext context,
360: SOAPHeader header, AddressingPropertiesImpl maps,
361: String mapProperty, boolean requestor) throws Exception {
362: Unmarshaller unmarshaller = control
363: .createMock(Unmarshaller.class);
364: ContextUtils.getJAXBContext().createUnmarshaller();
365: EasyMock.expectLastCall().andReturn(unmarshaller);
366: Iterator headerItr = control.createMock(Iterator.class);
367: header.examineAllHeaderElements();
368: EasyMock.expectLastCall().andReturn(headerItr);
369: String uri = maps.getNamespaceURI();
370: boolean exposedAsNative = Names.WSA_NAMESPACE_NAME.equals(uri);
371: boolean exposedAs200408 = VersionTransformer.Names200408.WSA_NAMESPACE_NAME
372: .equals(uri);
373: assertTrue("unexpected namescape URI: " + uri, exposedAsNative
374: || exposedAs200408);
375: setUpHeaderDecode(headerItr, uri, Names.WSA_MESSAGEID_NAME,
376: exposedAsNative ? AttributedURIType.class
377: : AttributedURI.class, 0, unmarshaller);
378: setUpHeaderDecode(headerItr, uri, Names.WSA_TO_NAME,
379: exposedAsNative ? AttributedURIType.class
380: : AttributedURI.class, 1, unmarshaller);
381: setUpHeaderDecode(headerItr, uri, Names.WSA_REPLYTO_NAME,
382: exposedAsNative ? EndpointReferenceType.class
383: : VersionTransformer.Names200408.EPR_TYPE, 2,
384: unmarshaller);
385: setUpHeaderDecode(headerItr, uri, Names.WSA_FAULTTO_NAME,
386: exposedAsNative ? EndpointReferenceType.class
387: : VersionTransformer.Names200408.EPR_TYPE, 3,
388: unmarshaller);
389:
390: setUpHeaderDecode(headerItr, uri, Names.WSA_RELATESTO_NAME,
391: exposedAsNative ? RelatesToType.class
392: : Relationship.class, 4, unmarshaller);
393: if (requestor) {
394: context
395: .put(
396: "org.objectweb.celtix.correlation.in",
397: exposedAsNative ? ((RelatesToType) expectedValues[4])
398: .getValue()
399: : ((Relationship) expectedValues[4])
400: .getValue());
401: EasyMock.expectLastCall().andReturn(null);
402: }
403: setUpHeaderDecode(headerItr, uri, Names.WSA_ACTION_NAME,
404: exposedAsNative ? AttributedURIType.class
405: : AttributedURI.class, 5, unmarshaller);
406: EasyMock.eq(mapProperty);
407: EasyMock.reportMatcher(new MAPMatcher());
408: context.put(mapProperty, maps);
409: EasyMock.expectLastCall().andReturn(null);
410: context.setScope(mapProperty, MessageContext.Scope.HANDLER);
411: EasyMock.expectLastCall();
412: }
413:
414: private <T> void setUpHeaderDecode(Iterator headerItr, String uri,
415: String name, Class<T> clz, int index,
416: Unmarshaller unmarshaller) throws Exception {
417: headerItr.hasNext();
418: EasyMock.expectLastCall().andReturn(Boolean.TRUE);
419: SOAPHeaderElement headerElement = control
420: .createMock(SOAPHeaderElement.class);
421: headerItr.next();
422: EasyMock.expectLastCall().andReturn(headerElement);
423: Name headerName = control.createMock(Name.class);
424: headerElement.getElementName();
425: EasyMock.expectLastCall().andReturn(headerName);
426: headerName.getURI();
427: EasyMock.expectLastCall().andReturn(uri);
428: headerName.getLocalName();
429: EasyMock.expectLastCall().andReturn(name);
430: Object v = expectedValues[index];
431: JAXBElement<?> jaxbElement = new JAXBElement<T>(new QName(uri,
432: name), clz, clz.cast(v));
433: unmarshaller.unmarshal(headerElement, clz);
434: EasyMock.expectLastCall().andReturn(jaxbElement);
435: }
436:
437: private String getMAPProperty(boolean requestor, boolean outbound) {
438: return requestor ? outbound ? CLIENT_ADDRESSING_PROPERTIES_OUTBOUND
439: : CLIENT_ADDRESSING_PROPERTIES_INBOUND
440: : outbound ? SERVER_ADDRESSING_PROPERTIES_OUTBOUND
441: : SERVER_ADDRESSING_PROPERTIES_INBOUND;
442: }
443:
444: private AddressingPropertiesImpl getMAPs(String uri,
445: boolean outbound) {
446: AddressingPropertiesImpl maps = new AddressingPropertiesImpl();
447: boolean exposeAsNative = Names.WSA_NAMESPACE_NAME.equals(uri);
448: boolean exposeAs200408 = VersionTransformer.Names200408.WSA_NAMESPACE_NAME
449: .equals(uri);
450: AttributedURIType id = ContextUtils
451: .getAttributedURI("urn:uuid:12345");
452: maps.setMessageID(id);
453: AttributedURIType to = ContextUtils.getAttributedURI("foobar");
454: maps.setTo(to);
455: EndpointReferenceType replyTo = new EndpointReferenceType();
456: String anonymous = exposeAsNative ? Names.WSA_ANONYMOUS_ADDRESS
457: : VersionTransformer.Names200408.WSA_ANONYMOUS_ADDRESS;
458: replyTo.setAddress(ContextUtils.getAttributedURI(anonymous));
459: maps.setReplyTo(replyTo);
460: EndpointReferenceType faultTo = new EndpointReferenceType();
461: anonymous = exposeAsNative ? Names.WSA_ANONYMOUS_ADDRESS
462: : VersionTransformer.Names200408.WSA_ANONYMOUS_ADDRESS;
463: faultTo.setAddress(ContextUtils.getAttributedURI(anonymous));
464: maps.setFaultTo(faultTo);
465: RelatesToType relatesTo = new RelatesToType();
466: relatesTo.setValue("urn:uuid:67890");
467: maps.setRelatesTo(relatesTo);
468: AttributedURIType action = ContextUtils
469: .getAttributedURI("http://foo/bar/SEI/opRequest");
470: maps.setAction(action);
471: maps.exposeAs(uri);
472: expectedNamespaceURI = uri;
473:
474: expectedNames = new QName[] {
475: new QName(uri, Names.WSA_MESSAGEID_NAME),
476: new QName(uri, Names.WSA_TO_NAME),
477: new QName(uri, Names.WSA_REPLYTO_NAME),
478: new QName(uri, Names.WSA_FAULTTO_NAME),
479: new QName(uri, Names.WSA_RELATESTO_NAME),
480: new QName(uri, Names.WSA_ACTION_NAME) };
481: if (exposeAsNative) {
482: expectedValues = new Object[] { id, to, replyTo, faultTo,
483: relatesTo, action };
484: expectedDeclaredTypes = new Class<?>[] {
485: AttributedURIType.class, AttributedURIType.class,
486: EndpointReferenceType.class,
487: EndpointReferenceType.class, RelatesToType.class,
488: AttributedURIType.class };
489: } else if (exposeAs200408) {
490: expectedValues = new Object[] {
491: VersionTransformer.convert(id),
492: VersionTransformer.convert(to),
493: VersionTransformer.convert(replyTo),
494: VersionTransformer.convert(faultTo),
495: VersionTransformer.convert(relatesTo),
496: VersionTransformer.convert(action) };
497: if (!outbound) {
498: // conversion from 2004/08 to 2005/08 anonymous address
499: // occurs transparently in VersionTransformer
500: VersionTransformer.Names200408.EPR_TYPE.cast(
501: expectedValues[2]).getAddress().setValue(
502: Names.WSA_ANONYMOUS_ADDRESS);
503: VersionTransformer.Names200408.EPR_TYPE.cast(
504: expectedValues[3]).getAddress().setValue(
505: Names.WSA_ANONYMOUS_ADDRESS);
506: }
507: expectedDeclaredTypes = new Class<?>[] {
508: AttributedURI.class, AttributedURI.class,
509: VersionTransformer.Names200408.EPR_TYPE,
510: VersionTransformer.Names200408.EPR_TYPE,
511: Relationship.class, AttributedURI.class };
512: } else {
513: fail("unexpected namespace URI: " + uri);
514: }
515: return maps;
516: }
517:
518: private final class JAXBEltMatcher implements IArgumentMatcher {
519: public boolean matches(Object obj) {
520: QName name = expectedNames[expectedIndex];
521: Class<?> declaredType = expectedDeclaredTypes[expectedIndex];
522: Object value = expectedValues[expectedIndex];
523: boolean ret = false;
524: expectedIndex++;
525: if (obj instanceof JAXBElement) {
526: JAXBElement other = (JAXBElement) obj;
527: ret = name.equals(other.getName())
528: && declaredType.isAssignableFrom(other
529: .getDeclaredType())
530: && compare(value, other.getValue());
531: }
532: return ret;
533: }
534:
535: public void appendTo(StringBuffer buffer) {
536: buffer.append("JAXBElements did not match");
537: }
538:
539: private boolean compare(Object a, Object b) {
540: boolean ret = false;
541: if (a instanceof AttributedURI
542: && b instanceof AttributedURI) {
543: ret = ((AttributedURI) a).getValue().equals(
544: ((AttributedURI) b).getValue());
545: } else if (a instanceof AttributedURIType
546: && b instanceof AttributedURIType) {
547: ret = ((AttributedURIType) a).getValue().equals(
548: ((AttributedURIType) b).getValue());
549: } else if (a instanceof EndpointReferenceType
550: && b instanceof EndpointReferenceType) {
551: EndpointReferenceType aEPR = (EndpointReferenceType) a;
552: EndpointReferenceType bEPR = (EndpointReferenceType) b;
553: ret = aEPR.getAddress() != null
554: && bEPR.getAddress() != null
555: && aEPR.getAddress().getValue().equals(
556: bEPR.getAddress().getValue());
557: } else if (VersionTransformer.Names200408.EPR_TYPE
558: .isInstance(a)
559: && VersionTransformer.Names200408.EPR_TYPE
560: .isInstance(b)) {
561: ret = VersionTransformer.Names200408.EPR_TYPE.cast(a)
562: .getAddress() != null
563: && VersionTransformer.Names200408.EPR_TYPE
564: .cast(b).getAddress() != null
565: && VersionTransformer.Names200408.EPR_TYPE
566: .cast(a)
567: .getAddress()
568: .getValue()
569: .equals(
570: VersionTransformer.Names200408.EPR_TYPE
571: .cast(b).getAddress()
572: .getValue());
573: } else if (a instanceof Relationship
574: && b instanceof Relationship) {
575: ret = ((Relationship) a).getValue().equals(
576: ((Relationship) b).getValue());
577: } else if (a instanceof RelatesToType
578: && b instanceof RelatesToType) {
579: ret = ((RelatesToType) a).getValue().equals(
580: ((RelatesToType) b).getValue());
581: }
582: return ret;
583: }
584: }
585:
586: private final class MAPMatcher implements IArgumentMatcher {
587: public boolean matches(Object obj) {
588: if (obj instanceof AddressingPropertiesImpl) {
589: AddressingPropertiesImpl other = (AddressingPropertiesImpl) obj;
590: return compareExpected(other);
591: }
592: return false;
593: }
594:
595: public void appendTo(StringBuffer buffer) {
596: buffer.append("MAPs did not match");
597: }
598:
599: private boolean compareExpected(AddressingPropertiesImpl other) {
600: boolean ret = false;
601: String uri = other.getNamespaceURI();
602: boolean exposedAsNative = Names.WSA_NAMESPACE_NAME
603: .equals(uri);
604: boolean exposedAs200408 = VersionTransformer.Names200408.WSA_NAMESPACE_NAME
605: .equals(uri);
606: if (exposedAsNative || exposedAs200408) {
607: String expectedMessageID = exposedAsNative ? ((AttributedURIType) expectedValues[0])
608: .getValue()
609: : ((AttributedURI) expectedValues[0])
610: .getValue();
611: String expectedTo = exposedAsNative ? ((AttributedURIType) expectedValues[1])
612: .getValue()
613: : ((AttributedURI) expectedValues[1])
614: .getValue();
615: String expectedReplyTo = exposedAsNative ? ((EndpointReferenceType) expectedValues[2])
616: .getAddress().getValue()
617: : (VersionTransformer.Names200408.EPR_TYPE
618: .cast(expectedValues[2])).getAddress()
619: .getValue();
620: String expectedRelatesTo = exposedAsNative ? ((RelatesToType) expectedValues[4])
621: .getValue()
622: : ((Relationship) expectedValues[4]).getValue();
623: String expectedAction = exposedAsNative ? ((AttributedURIType) expectedValues[5])
624: .getValue()
625: : ((AttributedURI) expectedValues[5])
626: .getValue();
627: ret = expectedMessageID.equals(other.getMessageID()
628: .getValue())
629: && expectedTo.equals(other.getTo().getValue())
630: && expectedReplyTo.equals(other.getReplyTo()
631: .getAddress().getValue())
632: && expectedRelatesTo.equals(other
633: .getRelatesTo().getValue())
634: && expectedAction.equals(other.getAction()
635: .getValue())
636: && expectedNamespaceURI.equals(other
637: .getNamespaceURI());
638: }
639: return ret;
640: }
641: }
642: }
|