001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */package org.apache.cxf.ws.addressing;
019:
020: import java.lang.reflect.Method;
021: import java.util.ArrayList;
022: import java.util.Collections;
023: import java.util.List;
024:
025: import javax.wsdl.extensions.ExtensibilityElement;
026: import javax.xml.namespace.QName;
027: import javax.xml.ws.RequestWrapper;
028: import javax.xml.ws.ResponseWrapper;
029:
030: import org.apache.cxf.binding.Binding;
031: import org.apache.cxf.endpoint.Endpoint;
032: import org.apache.cxf.message.Exchange;
033: import org.apache.cxf.message.Message;
034: import org.apache.cxf.message.MessageImpl;
035: import org.apache.cxf.service.model.BindingInfo;
036: import org.apache.cxf.service.model.BindingMessageInfo;
037: import org.apache.cxf.service.model.BindingOperationInfo;
038: import org.apache.cxf.service.model.EndpointInfo;
039: import org.apache.cxf.service.model.OperationInfo;
040: import org.apache.cxf.service.model.ServiceInfo;
041: import org.apache.cxf.transport.Conduit;
042: import org.apache.cxf.transport.Destination;
043: import org.easymock.classextension.EasyMock;
044: import org.easymock.classextension.IMocksControl;
045: import org.junit.After;
046: import org.junit.Assert;
047: import org.junit.Before;
048: import org.junit.Test;
049:
050: import static org.apache.cxf.binding.soap.Soap11.SOAP_NAMESPACE;
051: import static org.apache.cxf.message.Message.REQUESTOR_ROLE;
052: import static org.apache.cxf.ws.addressing.JAXWSAConstants.CLIENT_ADDRESSING_PROPERTIES;
053: import static org.apache.cxf.ws.addressing.JAXWSAConstants.CLIENT_ADDRESSING_PROPERTIES_INBOUND;
054: import static org.apache.cxf.ws.addressing.JAXWSAConstants.CLIENT_ADDRESSING_PROPERTIES_OUTBOUND;
055: import static org.apache.cxf.ws.addressing.JAXWSAConstants.SERVER_ADDRESSING_PROPERTIES_INBOUND;
056: import static org.apache.cxf.ws.addressing.JAXWSAConstants.SERVER_ADDRESSING_PROPERTIES_OUTBOUND;
057:
058: public class MAPAggregatorTest extends Assert {
059:
060: private MAPAggregator aggregator;
061: private IMocksControl control;
062: private AddressingPropertiesImpl expectedMAPs;
063: private String expectedTo;
064: private String expectedReplyTo;
065: private String expectedRelatesTo;
066: private String expectedAction;
067:
068: @Before
069: public void setUp() {
070: aggregator = new MAPAggregator();
071: control = EasyMock.createNiceControl();
072: }
073:
074: @After
075: public void tearDown() {
076: expectedMAPs = null;
077: expectedTo = null;
078: expectedReplyTo = null;
079: expectedRelatesTo = null;
080: expectedAction = null;
081: }
082:
083: @Test
084: public void testRequestorOutboundUsingAddressingMAPsInContext()
085: throws Exception {
086: Message message = setUpMessage(true, true, false, true, true);
087: aggregator.mediate(message, false);
088: control.verify();
089: verifyMessage(message, true, true, true);
090: }
091:
092: @Test
093: public void testRequestorOutboundUsingAddressingMAPsInContextZeroLengthAction()
094: throws Exception {
095: Message message = setUpMessage(true, true, false, true, true,
096: true);
097: aggregator.mediate(message, false);
098: control.verify();
099: verifyMessage(message, true, true, true);
100: }
101:
102: @Test
103: public void testRequestorOutboundUsingAddressingMAPsInContextFault()
104: throws Exception {
105: Message message = setUpMessage(true, true, false, true, true);
106: aggregator.mediate(message, true);
107: control.verify();
108: verifyMessage(message, true, true, true);
109: }
110:
111: @Test
112: public void testRequestorOutboundUsingAddressingNoMAPsInContext()
113: throws Exception {
114: Message message = setUpMessage(true, true, false, true, false);
115: aggregator.mediate(message, false);
116: control.verify();
117: verifyMessage(message, true, true, true);
118: }
119:
120: @Test
121: public void testRequestorOutboundUsingAddressingNoMAPsInContextFault()
122: throws Exception {
123: Message message = setUpMessage(true, true, false, true, false);
124: aggregator.mediate(message, true);
125: control.verify();
126: verifyMessage(message, true, true, true);
127: }
128:
129: @Test
130: public void testRequestorOutboundNotUsingAddressing()
131: throws Exception {
132: Message message = setUpMessage(true, true, false, false);
133: aggregator.mediate(message, false);
134: control.verify();
135: verifyMessage(message, true, true, false);
136: }
137:
138: @Test
139: public void testRequestorOutboundNotUsingAddressingFault()
140: throws Exception {
141: Message message = setUpMessage(true, true, false, false);
142: aggregator.mediate(message, true);
143: control.verify();
144: verifyMessage(message, true, true, false);
145: }
146:
147: @Test
148: public void testRequestorOutboundOnewayUsingAddressingMAPsInContext()
149: throws Exception {
150: Message message = setUpMessage(true, true, true, true, true);
151: aggregator.mediate(message, false);
152: control.verify();
153: verifyMessage(message, true, true, true);
154: }
155:
156: @Test
157: public void testRequestorOutboundOnewayUsingAddressingMAPsInContextFault()
158: throws Exception {
159: Message message = setUpMessage(true, true, true, true, true);
160: aggregator.mediate(message, true);
161: control.verify();
162: verifyMessage(message, true, true, true);
163: }
164:
165: @Test
166: public void testRequestorOutboundOnewayUsingAddressingNoMAPsInContext()
167: throws Exception {
168: Message message = setUpMessage(true, true, true, true, false);
169: aggregator.mediate(message, false);
170: control.verify();
171: verifyMessage(message, true, true, true);
172: }
173:
174: @Test
175: public void testRequestorOutboundOnewayUsingAddressingNoMAPsInContextFault()
176: throws Exception {
177: Message message = setUpMessage(true, true, true, true, false);
178: aggregator.mediate(message, true);
179: control.verify();
180: verifyMessage(message, true, true, true);
181: }
182:
183: @Test
184: public void testRequestorOutboundOnewayNotUsingAddressing()
185: throws Exception {
186: Message message = setUpMessage(true, true, true, false);
187: aggregator.mediate(message, false);
188: control.verify();
189: verifyMessage(message, true, true, false);
190: }
191:
192: @Test
193: public void testRequestorOutboundOnewayNotUsingAddressingFault()
194: throws Exception {
195: Message message = setUpMessage(true, true, true, false);
196: aggregator.mediate(message, true);
197: control.verify();
198: verifyMessage(message, true, true, false);
199: }
200:
201: @Test
202: public void testResponderInboundValidMAPs() throws Exception {
203: Message message = setUpMessage(false, false, false);
204: aggregator.mediate(message, false);
205: control.verify();
206: verifyMessage(message, false, false, false);
207: }
208:
209: @Test
210: public void testResponderInboundDecoupled() throws Exception {
211: Message message = setUpMessage(false, false, false, true,
212: false, true);
213: aggregator.mediate(message, false);
214: control.verify();
215: verifyMessage(message, false, false, true);
216: }
217:
218: @Test
219: public void testResponderInboundOneway() throws Exception {
220: Message message = setUpMessage(false, false, true, true, false,
221: true);
222: aggregator.mediate(message, false);
223: control.verify();
224: verifyMessage(message, false, false, true);
225: }
226:
227: @Test
228: public void testResponderInboundValidMAPsFault() throws Exception {
229: Message message = setUpMessage(false, false, false);
230: aggregator.mediate(message, true);
231: control.verify();
232: verifyMessage(message, false, false, true);
233: }
234:
235: @Test
236: public void testResponderInboundInvalidMAPs() throws Exception {
237: aggregator.messageIDs.put("urn:uuid:12345", "urn:uuid:12345");
238: Message message = setUpMessage(false, false, false);
239: aggregator.setAllowDuplicates(false);
240: aggregator.mediate(message, false);
241: control.verify();
242: verifyMessage(message, false, false, false /*check*/);
243: }
244:
245: @Test
246: public void testResponderInboundInvalidMAPsFault() throws Exception {
247: aggregator.messageIDs.put("urn:uuid:12345", "urn:uuid:12345");
248: Message message = setUpMessage(false, false, false);
249: aggregator.setAllowDuplicates(false);
250: aggregator.mediate(message, true);
251: control.verify();
252: verifyMessage(message, false, false, false /*check*/);
253: }
254:
255: @Test
256: public void testResponderOutbound() throws Exception {
257: Message message = setUpMessage(false, true, false);
258: aggregator.mediate(message, false);
259: control.verify();
260: verifyMessage(message, false, true, true);
261: }
262:
263: @Test
264: public void testResponderOutboundZeroLengthAction()
265: throws Exception {
266: Message message = setUpMessage(false, true, false, false,
267: false, false, false);
268: aggregator.mediate(message, false);
269: control.verify();
270: verifyMessage(message, false, true, true);
271: }
272:
273: @Test
274: public void testResponderOutboundFault() throws Exception {
275: Message message = setUpMessage(new boolean[] { false, true,
276: false, false, false, true, false, true });
277: aggregator.mediate(message, true);
278: control.verify();
279: verifyMessage(message, false, true, true);
280: }
281:
282: @Test
283: public void testRequestorInbound() throws Exception {
284: Message message = setUpMessage(true, false, false);
285: aggregator.mediate(message, false);
286: control.verify();
287: verifyMessage(message, true, false, false /*check*/);
288: }
289:
290: @Test
291: public void testRequestorInboundFault() throws Exception {
292: Message message = setUpMessage(true, false, false);
293: aggregator.mediate(message, true);
294: control.verify();
295: verifyMessage(message, true, false, false /*check*/);
296: }
297:
298: private Message setUpMessage(boolean requestor, boolean outbound,
299: boolean oneway) throws Exception {
300: return setUpMessage(requestor, outbound, oneway, false, false,
301: false);
302: }
303:
304: private Message setUpMessage(boolean requestor, boolean outbound,
305: boolean oneway, boolean usingAddressing) throws Exception {
306: return setUpMessage(requestor, outbound, oneway,
307: usingAddressing, false, false);
308: }
309:
310: private Message setUpMessage(boolean requestor, boolean outbound,
311: boolean oneway, boolean usingAddressing,
312: boolean mapsInContext) throws Exception {
313: return setUpMessage(requestor, outbound, oneway,
314: usingAddressing, mapsInContext, false);
315: }
316:
317: private Message setUpMessage(boolean requestor, boolean outbound,
318: boolean oneway, boolean usingAddressing,
319: boolean mapsInContext, boolean decoupled) throws Exception {
320: return setUpMessage(requestor, outbound, oneway,
321: usingAddressing, mapsInContext, decoupled, false);
322: }
323:
324: private Message setUpMessage(boolean requestor, boolean outbound,
325: boolean oneway, boolean usingAddressing,
326: boolean mapsInContext, boolean decoupled,
327: boolean zeroLengthAction) throws Exception {
328: boolean[] params = { requestor, outbound, oneway,
329: usingAddressing, mapsInContext, decoupled,
330: zeroLengthAction, false };
331: return setUpMessage(params);
332: }
333:
334: /**
335: * Boolean array is used to work around checkstyle rule limiting
336: * parameter cardinality to 7.
337: */
338: private Message setUpMessage(boolean[] params) throws Exception {
339: boolean requestor = params[0];
340: boolean outbound = params[1];
341: boolean oneway = params[2];
342: boolean usingAddressing = params[3];
343: boolean mapsInContext = params[4];
344: boolean decoupled = params[5];
345: boolean zeroLengthAction = params[6];
346: boolean fault = params[7];
347:
348: Message message = getMessage();
349: Exchange exchange = getExchange();
350: setUpOutbound(message, exchange, outbound);
351: setUpMessageProperty(message, REQUESTOR_ROLE, Boolean
352: .valueOf(requestor));
353: if (outbound && requestor) {
354: if (usingAddressing) {
355: setUpConduit(message, exchange);
356: }
357: setUpUsingAddressing(message, exchange, usingAddressing);
358: if (usingAddressing) {
359: setUpRequestor(message, exchange, oneway,
360: mapsInContext, decoupled, zeroLengthAction);
361: }
362: } else if (!requestor) {
363: setUpResponder(message, exchange, oneway, outbound,
364: decoupled, zeroLengthAction, fault);
365: }
366: control.replay();
367: return message;
368: }
369:
370: private void setUpUsingAddressing(Message message,
371: Exchange exchange, boolean usingAddressing) {
372: setUpMessageExchange(message, exchange);
373: Endpoint endpoint = control.createMock(Endpoint.class);
374: setUpExchangeGet(exchange, Endpoint.class, endpoint);
375: EndpointInfo endpointInfo = control
376: .createMock(EndpointInfo.class);
377: endpoint.getEndpointInfo();
378: EasyMock.expectLastCall().andReturn(endpointInfo);
379: List<ExtensibilityElement> endpointExts = new ArrayList<ExtensibilityElement>();
380: endpointInfo.getExtensors(EasyMock
381: .eq(ExtensibilityElement.class));
382: EasyMock.expectLastCall().andReturn(endpointExts);
383: BindingInfo bindingInfo = control.createMock(BindingInfo.class);
384: endpointInfo.getBinding();
385: EasyMock.expectLastCall().andReturn(bindingInfo).times(2);
386: bindingInfo.getExtensors(EasyMock
387: .eq(ExtensibilityElement.class));
388: EasyMock.expectLastCall().andReturn(Collections.EMPTY_LIST);
389: ServiceInfo serviceInfo = control.createMock(ServiceInfo.class);
390: endpointInfo.getService();
391: EasyMock.expectLastCall().andReturn(serviceInfo).times(2);
392: serviceInfo.getExtensors(EasyMock
393: .eq(ExtensibilityElement.class));
394: EasyMock.expectLastCall().andReturn(Collections.EMPTY_LIST);
395: ExtensibilityElement ext = control
396: .createMock(ExtensibilityElement.class);
397: if (usingAddressing) {
398: QName elementType = usingAddressing ? Names.WSAW_USING_ADDRESSING_QNAME
399: : new QName(SOAP_NAMESPACE, "encodingStyle");
400: ext.getElementType();
401: EasyMock.expectLastCall().andReturn(elementType);
402: endpointExts.add(ext);
403: }
404: }
405:
406: private void setUpRequestor(Message message, Exchange exchange,
407: boolean oneway, boolean mapsInContext, boolean decoupled,
408: boolean zeroLengthAction) throws Exception {
409: setUpMessageProperty(message, REQUESTOR_ROLE, Boolean
410: .valueOf(Boolean.TRUE));
411: AddressingPropertiesImpl maps = mapsInContext ? new AddressingPropertiesImpl()
412: : null;
413: if (zeroLengthAction) {
414: maps.setAction(ContextUtils.getAttributedURI(""));
415: }
416: setUpMessageProperty(message, CLIENT_ADDRESSING_PROPERTIES,
417: maps);
418: Method method = SEI.class.getMethod("op", new Class[0]);
419: if (!zeroLengthAction) {
420: setUpMethod(message, exchange, method);
421: setUpMessageProperty(message, REQUESTOR_ROLE, Boolean.TRUE);
422: expectedAction = "http://foo/bar/SEI/opRequest";
423: }
424: setUpMessageProperty(message, REQUESTOR_ROLE, Boolean.TRUE);
425: setUpOneway(message, exchange, oneway);
426: expectedMAPs = maps;
427: expectedTo = Names.WSA_NONE_ADDRESS;
428: expectedReplyTo = oneway ? Names.WSA_NONE_ADDRESS
429: : Names.WSA_ANONYMOUS_ADDRESS;
430: // Now verified via verifyMessage()
431: //EasyMock.eq(CLIENT_ADDRESSING_PROPERTIES_OUTBOUND);
432: //EasyMock.reportMatcher(new MAPMatcher());
433: //message.put(CLIENT_ADDRESSING_PROPERTIES_OUTBOUND,
434: // mapsInContext
435: // ? maps
436: // : new AddressingPropertiesImpl());
437: //EasyMock.expectLastCall().andReturn(null);
438: }
439:
440: private void setUpResponder(Message message, Exchange exchange,
441: boolean oneway, boolean outbound, boolean decoupled,
442: boolean zeroLengthAction, boolean fault) throws Exception {
443: setUpMessageProperty(message, REQUESTOR_ROLE, Boolean.FALSE);
444: AddressingPropertiesImpl maps = new AddressingPropertiesImpl();
445: EndpointReferenceType replyTo = new EndpointReferenceType();
446: replyTo
447: .setAddress(ContextUtils
448: .getAttributedURI(decoupled ? "http://localhost:9999/decoupled"
449: : Names.WSA_ANONYMOUS_ADDRESS));
450: maps.setReplyTo(replyTo);
451: EndpointReferenceType faultTo = new EndpointReferenceType();
452: faultTo
453: .setAddress(ContextUtils
454: .getAttributedURI(decoupled ? "http://localhost:9999/fault"
455: : Names.WSA_ANONYMOUS_ADDRESS));
456: maps.setFaultTo(faultTo);
457: AttributedURIType id = ContextUtils
458: .getAttributedURI("urn:uuid:12345");
459: maps.setMessageID(id);
460: if (zeroLengthAction) {
461: maps.setAction(ContextUtils.getAttributedURI(""));
462: }
463: setUpMessageProperty(message,
464: SERVER_ADDRESSING_PROPERTIES_INBOUND, maps);
465: if (!outbound) {
466: setUpOneway(message, exchange, oneway);
467: if (oneway || decoupled) {
468: setUpRebase(message, exchange);
469: }
470: }
471: if (outbound || aggregator.messageIDs.size() > 0) {
472: if (!zeroLengthAction) {
473: Method method = SEI.class.getMethod("op", new Class[0]);
474: setUpMethod(message, exchange, method);
475: setUpMessageProperty(message, REQUESTOR_ROLE,
476: Boolean.FALSE);
477: expectedAction = "http://foo/bar/SEI/opResponse";
478: }
479: setUpMessageProperty(message, REQUESTOR_ROLE, Boolean.FALSE);
480: setUpMessageProperty(message,
481: SERVER_ADDRESSING_PROPERTIES_INBOUND, maps);
482: if (fault) {
483: // REVISIT test double rebase does not occur
484: setUpRebase(message, exchange);
485: }
486: expectedTo = decoupled ? fault ? "http://localhost:9999/fault"
487: : "http://localhost:9999/decoupled"
488: : Names.WSA_ANONYMOUS_ADDRESS;
489: expectedRelatesTo = maps.getMessageID().getValue();
490: // Now verified via verifyMessage()
491: //EasyMock.eq(SERVER_ADDRESSING_PROPERTIES_OUTBOUND);
492: //EasyMock.reportMatcher(new MAPMatcher());
493: //message.put(SERVER_ADDRESSING_PROPERTIES_OUTBOUND,
494: // new AddressingPropertiesImpl());
495: //EasyMock.expectLastCall().andReturn(null);
496: }
497: }
498:
499: private void setUpRebase(Message message, Exchange exchange)
500: throws Exception {
501: setUpMessageProperty(message,
502: "org.apache.cxf.ws.addressing.partial.response.sent",
503: Boolean.FALSE);
504: Endpoint endpoint = control.createMock(Endpoint.class);
505: exchange.get(Endpoint.class);
506: EasyMock.expectLastCall().andReturn(endpoint);
507: Binding binding = control.createMock(Binding.class);
508: endpoint.getBinding();
509: EasyMock.expectLastCall().andReturn(binding);
510: Message partialResponse = getMessage();
511: binding.createMessage();
512: EasyMock.expectLastCall().andReturn(partialResponse);
513:
514: Destination target = control.createMock(Destination.class);
515: setUpMessageDestination(message, target);
516: Conduit backChannel = control.createMock(Conduit.class);
517: target.getBackChannel(EasyMock.eq(message), EasyMock
518: .isA(Message.class), EasyMock
519: .isA(EndpointReferenceType.class));
520: EasyMock.expectLastCall().andReturn(backChannel);
521: // REVISIT test interceptor chain setup & send
522: }
523:
524: private void setUpOneway(Message message, Exchange exchange,
525: boolean oneway) {
526: setUpMessageExchange(message, exchange);
527: setUpExchangeOneway(exchange, oneway);
528: }
529:
530: private void setUpOutbound(Message message, Exchange exchange,
531: boolean outbound) {
532: setUpMessageExchange(message, exchange);
533: setUpExchangeOutbound(exchange, message, outbound);
534: }
535:
536: private void setUpConduit(Message message, Exchange exchange) {
537: setUpMessageExchange(message, exchange);
538: Conduit conduit = EasyMock.createMock(Conduit.class);
539: setUpExchangeConduit(message, exchange, conduit);
540: EndpointReferenceType to = ContextUtils.WSA_OBJECT_FACTORY
541: .createEndpointReferenceType();
542: to.setAddress(ContextUtils.getAttributedURI(expectedTo));
543: conduit.getTarget();
544: EasyMock.expectLastCall().andReturn(to);
545: }
546:
547: private void setUpMethod(Message message, Exchange exchange,
548: Method method) {
549: setUpMessageExchange(message, exchange);
550: OperationInfo opInfo = new OperationInfo();
551: opInfo.setProperty(Method.class.getName(), method);
552: BindingOperationInfo bindingOpInfo = new TestBindingOperationInfo(
553: opInfo);
554: setUpExchangeGet(exchange, BindingOperationInfo.class,
555: bindingOpInfo, 2);
556: // Usual fun with EasyMock not always working as expected
557: //BindingOperationInfo bindingOpInfo =
558: // EasyMock.createMock(BindingOperationInfo.class);
559: //OperationInfo opInfo = EasyMock.createMock(OperationInfo.class);
560: //bindingOpInfo.getOperationInfo();
561: //EasyMock.expectLastCall().andReturn(opInfo);
562: //opInfo.getProperty(EasyMock.eq(Method.class.getName()));
563: //EasyMock.expectLastCall().andReturn(method);
564: }
565:
566: private Message getMessage() {
567: //return control.createMock(Message.class);
568: return new MessageImpl();
569: }
570:
571: private Exchange getExchange() {
572: Exchange exchange = control.createMock(Exchange.class);
573: //Exchange exchange = new ExchangeImpl();
574: return exchange;
575: }
576:
577: private void setUpMessageProperty(Message message, String key,
578: Object value) {
579: //message.get(key);
580: //EasyMock.expectLastCall().andReturn(value);
581: message.put(key, value);
582: }
583:
584: private void setUpMessageExchange(Message message, Exchange exchange) {
585: //message.getExchange();
586: //EasyMock.expectLastCall().andReturn(exchange);
587: message.setExchange(exchange);
588: }
589:
590: private void setUpMessageDestination(Message message,
591: Destination target) {
592: //message.getDestination();
593: //EasyMock.expectLastCall().andReturn(target);
594: ((MessageImpl) message).setDestination(target);
595: }
596:
597: private <T> void setUpExchangeGet(Exchange exchange, Class<T> clz,
598: T value) {
599: setUpExchangeGet(exchange, clz, value, 1);
600: }
601:
602: private <T> void setUpExchangeGet(Exchange exchange, Class<T> clz,
603: T value, int n) {
604: exchange.get(clz);
605: EasyMock.expectLastCall().andReturn(value).times(n);
606: //exchange.put(Endpoint.class, value);
607: }
608:
609: private void setUpExchangeOneway(Exchange exchange, boolean oneway) {
610: exchange.isOneWay();
611: EasyMock.expectLastCall().andReturn(oneway);
612: //exchange.setOneWay(oneway);
613: }
614:
615: private void setUpExchangeOutbound(Exchange exchange,
616: Message message, boolean outbound) {
617: exchange.getOutMessage();
618: EasyMock.expectLastCall().andReturn(outbound ? message : null);
619: //exchange.setOutMessage(outbound ? message : new MessageImpl());
620: }
621:
622: private void setUpExchangeConduit(Message message,
623: Exchange exchange, Conduit conduit) {
624: exchange.getConduit(message);
625: EasyMock.expectLastCall().andReturn(conduit);
626: //exchange.setConduit(conduit);
627: }
628:
629: private boolean verifyMAPs(Object obj) {
630: if (obj instanceof AddressingPropertiesImpl) {
631: AddressingPropertiesImpl other = (AddressingPropertiesImpl) obj;
632: return compareExpected(other);
633: }
634: return false;
635: }
636:
637: private boolean compareExpected(AddressingPropertiesImpl other) {
638: boolean ret = false;
639: if (expectedMAPs == null || expectedMAPs == other) {
640: boolean toOK = expectedTo == null
641: || expectedTo.equals(other.getTo().getValue());
642: boolean replyToOK = expectedReplyTo == null
643: || expectedReplyTo.equals(other.getReplyTo()
644: .getAddress().getValue());
645: boolean relatesToOK = expectedRelatesTo == null
646: || expectedRelatesTo.equals(other.getRelatesTo()
647: .getValue());
648: boolean actionOK = expectedAction == null
649: || expectedAction.equals(other.getAction()
650: .getValue());
651: boolean messageIdOK = other.getMessageID() != null;
652: ret = toOK && replyToOK && relatesToOK && actionOK
653: && messageIdOK;
654: }
655: return ret;
656: }
657:
658: private String getMAPProperty(boolean requestor, boolean outbound) {
659: return requestor ? outbound ? CLIENT_ADDRESSING_PROPERTIES_OUTBOUND
660: : CLIENT_ADDRESSING_PROPERTIES_INBOUND
661: : outbound ? SERVER_ADDRESSING_PROPERTIES_OUTBOUND
662: : SERVER_ADDRESSING_PROPERTIES_INBOUND;
663: }
664:
665: private void verifyMessage(Message message, boolean requestor,
666: boolean outbound, boolean expectMapsInContext) {
667: if (expectMapsInContext) {
668: assertTrue("unexpected MAPs", verifyMAPs(message
669: .get(getMAPProperty(requestor, outbound))));
670: }
671: }
672:
673: private static interface SEI {
674: @RequestWrapper(targetNamespace="http://foo/bar",className="SEI",localName="opRequest")
675: @ResponseWrapper(targetNamespace="http://foo/bar",className="SEI",localName="opResponse")
676: String op();
677: }
678:
679: private static class TestBindingMessageInfo extends
680: BindingMessageInfo {
681: }
682:
683: private static class TestBindingOperationInfo extends
684: BindingOperationInfo {
685: public TestBindingOperationInfo(OperationInfo oi) {
686: opInfo = oi;
687: }
688:
689: public BindingMessageInfo getInput() {
690: return new TestBindingMessageInfo();
691: }
692:
693: public BindingMessageInfo getOutput() {
694: return new TestBindingMessageInfo();
695: }
696: }
697: }
|