Source Code Cross Referenced for MAPCodecTest.java in  » Web-Services-apache-cxf-2.0.1 » ws-addressing » org » apache » cxf » ws » addressing » soap » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Services apache cxf 2.0.1 » ws addressing » org.apache.cxf.ws.addressing.soap 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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.soap;
019:
020:        import java.util.ArrayList;
021:        import java.util.HashMap;
022:        import java.util.List;
023:        import java.util.Map;
024:        import java.util.Set;
025:
026:        import javax.xml.bind.JAXBContext;
027:        import javax.xml.bind.JAXBElement;
028:        import javax.xml.bind.Marshaller;
029:        import javax.xml.bind.Unmarshaller;
030:        import javax.xml.namespace.QName;
031:
032:        import org.w3c.dom.Element;
033:        import org.w3c.dom.NodeList;
034:
035:        import org.apache.cxf.binding.soap.SoapFault;
036:        import org.apache.cxf.binding.soap.SoapMessage;
037:        import org.apache.cxf.binding.soap.SoapVersion;
038:        import org.apache.cxf.headers.Header;
039:        import org.apache.cxf.message.Exchange;
040:        import org.apache.cxf.message.ExchangeImpl;
041:        import org.apache.cxf.message.Message;
042:        import org.apache.cxf.message.MessageImpl;
043:        import org.apache.cxf.ws.addressing.AddressingPropertiesImpl;
044:        import org.apache.cxf.ws.addressing.AttributedURIType;
045:        import org.apache.cxf.ws.addressing.ContextUtils;
046:        import org.apache.cxf.ws.addressing.EndpointReferenceType;
047:        import org.apache.cxf.ws.addressing.Names;
048:        import org.apache.cxf.ws.addressing.RelatesToType;
049:        import org.apache.cxf.ws.addressing.v200408.AttributedURI;
050:        import org.apache.cxf.ws.addressing.v200408.Relationship;
051:        import org.apache.cxf.wsdl.EndpointReferenceUtils;
052:        import org.easymock.IArgumentMatcher;
053:        import org.easymock.classextension.EasyMock;
054:        import org.easymock.classextension.IMocksControl;
055:        import org.junit.After;
056:        import org.junit.Assert;
057:        import org.junit.Before;
058:        import org.junit.Test;
059:
060:        import static org.apache.cxf.message.Message.MIME_HEADERS;
061:        import static org.apache.cxf.message.Message.REQUESTOR_ROLE;
062:        import static org.apache.cxf.ws.addressing.JAXWSAConstants.CLIENT_ADDRESSING_PROPERTIES_INBOUND;
063:        import static org.apache.cxf.ws.addressing.JAXWSAConstants.CLIENT_ADDRESSING_PROPERTIES_OUTBOUND;
064:        import static org.apache.cxf.ws.addressing.JAXWSAConstants.SERVER_ADDRESSING_PROPERTIES_INBOUND;
065:        import static org.apache.cxf.ws.addressing.JAXWSAConstants.SERVER_ADDRESSING_PROPERTIES_OUTBOUND;
066:
067:        public class MAPCodecTest extends Assert {
068:
069:            private MAPCodec codec;
070:            private IMocksControl control;
071:            private QName[] expectedNames;
072:            private Class<?>[] expectedDeclaredTypes;
073:            private Object[] expectedValues;
074:            private int expectedIndex;
075:            private String expectedNamespaceURI;
076:            private Map<String, List<String>> mimeHeaders;
077:            private Exchange correlatedExchange;
078:            private boolean expectRelatesTo;
079:
080:            @Before
081:            public void setUp() {
082:                codec = new MAPCodec();
083:                control = EasyMock.createNiceControl();
084:            }
085:
086:            @After
087:            public void tearDown() {
088:                expectedNames = null;
089:                expectedDeclaredTypes = null;
090:                expectedValues = null;
091:                expectedIndex = 0;
092:                expectedNamespaceURI = null;
093:                mimeHeaders = null;
094:                correlatedExchange = null;
095:            }
096:
097:            @Test
098:            public void testGetHeaders() throws Exception {
099:                Set<QName> headers = codec.getUnderstoodHeaders();
100:                assertTrue("expected From header", headers
101:                        .contains(Names.WSA_FROM_QNAME));
102:                assertTrue("expected To header", headers
103:                        .contains(Names.WSA_TO_QNAME));
104:                assertTrue("expected ReplyTo header", headers
105:                        .contains(Names.WSA_REPLYTO_QNAME));
106:                assertTrue("expected FaultTo header", headers
107:                        .contains(Names.WSA_FAULTTO_QNAME));
108:                assertTrue("expected Action header", headers
109:                        .contains(Names.WSA_ACTION_QNAME));
110:                assertTrue("expected MessageID header", headers
111:                        .contains(Names.WSA_MESSAGEID_QNAME));
112:            }
113:
114:            @Test
115:            public void testRequestorOutbound() throws Exception {
116:                SoapMessage message = setUpMessage(true, true);
117:                codec.handleMessage(message);
118:                control.verify();
119:                verifyMessage(message, true, true, true);
120:            }
121:
122:            @Test
123:            public void testRequestorOutboundPreExistingSOAPAction()
124:                    throws Exception {
125:                SoapMessage message = setUpMessage(true, true, false, true);
126:                codec.handleMessage(message);
127:                verifyAction();
128:                control.verify();
129:                verifyMessage(message, true, true, true);
130:            }
131:
132:            @Test
133:            public void testRequestorOutboundNonNative() throws Exception {
134:                String uri = VersionTransformer.Names200408.WSA_NAMESPACE_NAME;
135:                SoapMessage message = setUpMessage(true, true, false, false,
136:                        uri);
137:                codec.handleMessage(message);
138:                control.verify();
139:                verifyMessage(message, true, true, false);
140:            }
141:
142:            @Test
143:            public void testResponderInbound() throws Exception {
144:                SoapMessage message = setUpMessage(false, false);
145:                codec.handleMessage(message);
146:                control.verify();
147:                verifyMessage(message, false, false, true);
148:            }
149:
150:            @Test
151:            public void testResponderOutbound() throws Exception {
152:                SoapMessage message = setUpMessage(false, true);
153:                codec.handleMessage(message);
154:                control.verify();
155:                verifyMessage(message, false, true, true);
156:            }
157:
158:            @Test
159:            public void testResponderInboundNonNative() throws Exception {
160:                String uri = VersionTransformer.Names200408.WSA_NAMESPACE_NAME;
161:                SoapMessage message = setUpMessage(false, false, false, false,
162:                        uri);
163:                codec.handleMessage(message);
164:                control.verify();
165:                verifyMessage(message, false, false, false);
166:            }
167:
168:            @Test
169:            public void testResponderOutboundInvalidMAP() throws Exception {
170:                SoapMessage message = setUpMessage(false, true, true);
171:                try {
172:                    codec.handleMessage(message);
173:                    fail("expected SOAPFaultException on invalid MAP");
174:                } catch (SoapFault sfe) {
175:                    assertEquals("unexpected fault string",
176:                            "Duplicate Message ID urn:uuid:12345", sfe
177:                                    .getMessage());
178:                }
179:                control.verify();
180:                verifyMessage(message, false, true, true);
181:            }
182:
183:            @Test
184:            public void testResponderOutboundPreExistingSOAPAction()
185:                    throws Exception {
186:                SoapMessage message = setUpMessage(false, true, false, true);
187:                codec.handleMessage(message);
188:                verifyAction();
189:                control.verify();
190:                verifyMessage(message, false, true, true);
191:            }
192:
193:            @Test
194:            public void testResponderOutboundNonNative() throws Exception {
195:                String uri = VersionTransformer.Names200408.WSA_NAMESPACE_NAME;
196:                SoapMessage message = setUpMessage(false, true, false, false,
197:                        uri);
198:                codec.handleMessage(message);
199:                control.verify();
200:                verifyMessage(message, false, true, false);
201:            }
202:
203:            @Test
204:            public void testRequestorInbound() throws Exception {
205:                SoapMessage message = setUpMessage(true, false);
206:                codec.handleMessage(message);
207:                control.verify();
208:                verifyMessage(message, true, false, true);
209:            }
210:
211:            @Test
212:            public void testRequestorInboundNonNative() throws Exception {
213:                String uri = VersionTransformer.Names200408.WSA_NAMESPACE_NAME;
214:                SoapMessage message = setUpMessage(true, false, false, false,
215:                        uri);
216:                codec.handleMessage(message);
217:                control.verify();
218:                verifyMessage(message, true, false, false);
219:            }
220:
221:            private SoapMessage setUpMessage(boolean requestor, boolean outbound)
222:                    throws Exception {
223:                return setUpMessage(requestor, outbound, false);
224:            }
225:
226:            private SoapMessage setUpMessage(boolean requestor,
227:                    boolean outbound, boolean invalidMAP) throws Exception {
228:                return setUpMessage(requestor, outbound, invalidMAP, false);
229:            }
230:
231:            private SoapMessage setUpMessage(boolean requestor,
232:                    boolean outbound, boolean invalidMAP,
233:                    boolean preExistingSOAPAction) throws Exception {
234:                return setUpMessage(requestor, outbound, invalidMAP,
235:                        preExistingSOAPAction, Names.WSA_NAMESPACE_NAME);
236:            }
237:
238:            private SoapMessage setUpMessage(boolean requestor,
239:                    boolean outbound, boolean invalidMAP,
240:                    boolean preExistingSOAPAction, String exposeAs)
241:                    throws Exception {
242:                SoapMessage message = new SoapMessage(new MessageImpl());
243:                setUpOutbound(message, outbound);
244:                expectRelatesTo = (requestor && !outbound)
245:                        || (!requestor && outbound);
246:                message.put(REQUESTOR_ROLE, Boolean.valueOf(requestor));
247:                String mapProperty = getMAPProperty(requestor, outbound);
248:                AddressingPropertiesImpl maps = getMAPs(requestor, outbound,
249:                        exposeAs);
250:                final Element header = control.createMock(Element.class);
251:                codec.setHeaderFactory(new MAPCodec.HeaderFactory() {
252:                    public Element getHeader(SoapVersion version) {
253:                        return header;
254:                    }
255:                });
256:                List<Header> headers = message.getHeaders();
257:                JAXBContext jaxbContext = control.createMock(JAXBContext.class);
258:                ContextUtils.setJAXBContext(jaxbContext);
259:                VersionTransformer.Names200408.setJAXBContext(jaxbContext);
260:                if (outbound) {
261:                    setUpEncode(requestor, message, header, maps, mapProperty,
262:                            invalidMAP, preExistingSOAPAction);
263:                } else {
264:                    setUpDecode(message, headers, maps, mapProperty, requestor);
265:                }
266:                control.replay();
267:                return message;
268:            }
269:
270:            private void setUpEncode(boolean requestor, SoapMessage message,
271:                    Element header, AddressingPropertiesImpl maps,
272:                    String mapProperty, boolean invalidMAP,
273:                    boolean preExistingSOAPAction) throws Exception {
274:                message.put(mapProperty, maps);
275:                Marshaller marshaller = control.createMock(Marshaller.class);
276:                ContextUtils.getJAXBContext().createMarshaller();
277:                EasyMock.expectLastCall().andReturn(marshaller);
278:                marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
279:                EasyMock.expectLastCall();
280:                IArgumentMatcher matcher = new JAXBEltMatcher();
281:                int expectedMarshals = requestor ? expectedValues.length - 1
282:                        : expectedValues.length;
283:                for (int i = 0; i < expectedMarshals; i++) {
284:                    EasyMock.reportMatcher(matcher);
285:                    EasyMock.eq(header);
286:                    marshaller.marshal(null, header);
287:                    EasyMock.expectLastCall();
288:                }
289:
290:                NodeList children = control.createMock(NodeList.class);
291:                header.getChildNodes();
292:                EasyMock.expectLastCall().andReturn(children);
293:                children.getLength();
294:                EasyMock.expectLastCall().andReturn(expectedMarshals)
295:                        .anyTimes();
296:                for (int i = 0; i < expectedMarshals; i++) {
297:                    Element child = control.createMock(Element.class);
298:                    children.item(i);
299:                    EasyMock.expectLastCall().andReturn(child);
300:                    /*
301:                    child.setAttributeNS(EasyMock.eq("http://www.w3.org/2000/xmlns/"),
302:                                         EasyMock.eq("xmlns:wsa"),
303:                                         EasyMock.eq(maps.getNamespaceURI()));
304:                    EasyMock.expectLastCall();
305:                     */
306:                    child.getNamespaceURI();
307:                    EasyMock.expectLastCall().andReturn(
308:                            expectedNames[i].getNamespaceURI());
309:                    child.getLocalName();
310:                    EasyMock.expectLastCall().andReturn(
311:                            expectedNames[i].getLocalPart());
312:                }
313:
314:                mimeHeaders = new HashMap<String, List<String>>();
315:                message.put(MIME_HEADERS, mimeHeaders);
316:                if (preExistingSOAPAction) {
317:                    List<String> soapAction = new ArrayList<String>();
318:                    soapAction.add("\"foobar\"");
319:                    mimeHeaders.put("SOAPAction", soapAction);
320:                }
321:                if (invalidMAP) {
322:                    message.put("org.apache.cxf.ws.addressing.map.fault.name",
323:                            Names.DUPLICATE_MESSAGE_ID_NAME);
324:                    message.put(
325:                            "org.apache.cxf.ws.addressing.map.fault.reason",
326:                            "Duplicate Message ID urn:uuid:12345");
327:                }
328:            }
329:
330:            private void setUpDecode(SoapMessage message, List<Header> headers,
331:                    AddressingPropertiesImpl maps, String mapProperty,
332:                    boolean requestor) throws Exception {
333:                Unmarshaller unmarshaller = control
334:                        .createMock(Unmarshaller.class);
335:                ContextUtils.getJAXBContext().createUnmarshaller();
336:                EasyMock.expectLastCall().andReturn(unmarshaller);
337:                String uri = maps.getNamespaceURI();
338:                boolean exposedAsNative = Names.WSA_NAMESPACE_NAME.equals(uri);
339:                boolean exposedAs200408 = VersionTransformer.Names200408.WSA_NAMESPACE_NAME
340:                        .equals(uri);
341:                assertTrue("unexpected namescape URI: " + uri, exposedAsNative
342:                        || exposedAs200408);
343:                setUpHeaderDecode(headers, uri, Names.WSA_MESSAGEID_NAME,
344:                        exposedAsNative ? AttributedURIType.class
345:                                : AttributedURI.class, 0, unmarshaller);
346:                setUpHeaderDecode(headers, uri, Names.WSA_TO_NAME,
347:                        exposedAsNative ? AttributedURIType.class
348:                                : AttributedURI.class, 1, unmarshaller);
349:                setUpHeaderDecode(headers, uri, Names.WSA_REPLYTO_NAME,
350:                        exposedAsNative ? EndpointReferenceType.class
351:                                : VersionTransformer.Names200408.EPR_TYPE, 2,
352:                        unmarshaller);
353:                setUpHeaderDecode(headers, uri, Names.WSA_FAULTTO_NAME,
354:                        exposedAsNative ? EndpointReferenceType.class
355:                                : VersionTransformer.Names200408.EPR_TYPE, 3,
356:                        unmarshaller);
357:                setUpHeaderDecode(headers, uri, Names.WSA_RELATESTO_NAME,
358:                        exposedAsNative ? RelatesToType.class
359:                                : Relationship.class, 4, unmarshaller);
360:                setUpHeaderDecode(headers, uri, Names.WSA_ACTION_NAME,
361:                        exposedAsNative ? AttributedURIType.class
362:                                : AttributedURI.class, 5, unmarshaller);
363:            }
364:
365:            private <T> void setUpHeaderDecode(List<Header> headers,
366:                    String uri, String name, Class<T> clz, int index,
367:                    Unmarshaller unmarshaller) throws Exception {
368:                Element headerElement = control.createMock(Element.class);
369:                headers.add(new Header(new QName(uri, name), headerElement));
370:                headerElement.getNamespaceURI();
371:                EasyMock.expectLastCall().andReturn(uri);
372:                headerElement.getLocalName();
373:                EasyMock.expectLastCall().andReturn(name);
374:                Object v = expectedValues[index];
375:                JAXBElement<?> jaxbElement = new JAXBElement<T>(new QName(uri,
376:                        name), clz, clz.cast(v));
377:                unmarshaller.unmarshal(headerElement, clz);
378:                EasyMock.expectLastCall().andReturn(jaxbElement);
379:            }
380:
381:            private void setUpOutbound(Message message, boolean outbound) {
382:                Exchange exchange = new ExchangeImpl();
383:                exchange.setOutMessage(outbound ? message : new MessageImpl());
384:                message.setExchange(exchange);
385:            }
386:
387:            private String getMAPProperty(boolean requestor, boolean outbound) {
388:                return requestor ? outbound ? CLIENT_ADDRESSING_PROPERTIES_OUTBOUND
389:                        : CLIENT_ADDRESSING_PROPERTIES_INBOUND
390:                        : outbound ? SERVER_ADDRESSING_PROPERTIES_OUTBOUND
391:                                : SERVER_ADDRESSING_PROPERTIES_INBOUND;
392:            }
393:
394:            private AddressingPropertiesImpl getMAPs(boolean requestor,
395:                    boolean outbound, String uri) {
396:                AddressingPropertiesImpl maps = new AddressingPropertiesImpl();
397:                boolean exposeAsNative = Names.WSA_NAMESPACE_NAME.equals(uri);
398:                boolean exposeAs200408 = VersionTransformer.Names200408.WSA_NAMESPACE_NAME
399:                        .equals(uri);
400:                AttributedURIType id = ContextUtils
401:                        .getAttributedURI("urn:uuid:12345");
402:                maps.setMessageID(id);
403:                AttributedURIType to = ContextUtils.getAttributedURI("foobar");
404:                EndpointReferenceType toEpr = EndpointReferenceUtils
405:                        .getEndpointReference(to);
406:                maps.setTo(toEpr);
407:                EndpointReferenceType replyTo = new EndpointReferenceType();
408:                String anonymous = exposeAsNative ? Names.WSA_ANONYMOUS_ADDRESS
409:                        : VersionTransformer.Names200408.WSA_ANONYMOUS_ADDRESS;
410:                replyTo.setAddress(ContextUtils.getAttributedURI(anonymous));
411:                maps.setReplyTo(replyTo);
412:                EndpointReferenceType faultTo = new EndpointReferenceType();
413:                anonymous = exposeAsNative ? Names.WSA_ANONYMOUS_ADDRESS
414:                        : VersionTransformer.Names200408.WSA_ANONYMOUS_ADDRESS;
415:                faultTo.setAddress(ContextUtils.getAttributedURI(anonymous));
416:                maps.setFaultTo(faultTo);
417:                RelatesToType relatesTo = null;
418:                if (expectRelatesTo) {
419:                    String correlationID = "urn:uuid:67890";
420:                    relatesTo = new RelatesToType();
421:                    relatesTo.setValue(correlationID);
422:                    maps.setRelatesTo(relatesTo);
423:                    correlatedExchange = new ExchangeImpl();
424:                    codec.uncorrelatedExchanges.put(correlationID,
425:                            correlatedExchange);
426:                }
427:                AttributedURIType action = ContextUtils
428:                        .getAttributedURI("http://foo/bar/SEI/opRequest");
429:                maps.setAction(action);
430:                maps.exposeAs(uri);
431:                expectedNamespaceURI = uri;
432:
433:                expectedNames = new QName[] {
434:                        new QName(uri, Names.WSA_MESSAGEID_NAME),
435:                        new QName(uri, Names.WSA_TO_NAME),
436:                        new QName(uri, Names.WSA_REPLYTO_NAME),
437:                        new QName(uri, Names.WSA_FAULTTO_NAME),
438:                        new QName(uri, Names.WSA_RELATESTO_NAME),
439:                        new QName(uri, Names.WSA_ACTION_NAME) };
440:                if (exposeAsNative) {
441:                    expectedValues = new Object[] { id, to, replyTo, faultTo,
442:                            relatesTo, action };
443:                    expectedDeclaredTypes = new Class<?>[] {
444:                            AttributedURIType.class, AttributedURIType.class,
445:                            EndpointReferenceType.class,
446:                            EndpointReferenceType.class, RelatesToType.class,
447:                            AttributedURIType.class };
448:                } else if (exposeAs200408) {
449:                    expectedValues = new Object[] {
450:                            VersionTransformer.convert(id),
451:                            VersionTransformer.convert(to),
452:                            VersionTransformer.convert(replyTo),
453:                            VersionTransformer.convert(faultTo),
454:                            VersionTransformer.convert(relatesTo),
455:                            VersionTransformer.convert(action) };
456:                    if (!outbound) {
457:                        // conversion from 2004/08 to 2005/08 anonymous address
458:                        // occurs transparently in VersionTransformer
459:                        VersionTransformer.Names200408.EPR_TYPE.cast(
460:                                expectedValues[2]).getAddress().setValue(
461:                                Names.WSA_ANONYMOUS_ADDRESS);
462:                        VersionTransformer.Names200408.EPR_TYPE.cast(
463:                                expectedValues[3]).getAddress().setValue(
464:                                Names.WSA_ANONYMOUS_ADDRESS);
465:                    }
466:                    expectedDeclaredTypes = new Class<?>[] {
467:                            AttributedURI.class, AttributedURI.class,
468:                            VersionTransformer.Names200408.EPR_TYPE,
469:                            VersionTransformer.Names200408.EPR_TYPE,
470:                            Relationship.class, AttributedURI.class };
471:                } else {
472:                    fail("unexpected namespace URI: " + uri);
473:                }
474:                return maps;
475:            }
476:
477:            private final class JAXBEltMatcher implements  IArgumentMatcher {
478:                public boolean matches(Object obj) {
479:                    QName name = expectedNames[expectedIndex];
480:                    Class<?> declaredType = expectedDeclaredTypes[expectedIndex];
481:                    Object value = expectedValues[expectedIndex];
482:                    boolean ret = false;
483:                    expectedIndex++;
484:                    if (expectedIndex == 5 && !expectRelatesTo) {
485:                        return true;
486:                    }
487:                    if (obj instanceof  JAXBElement) {
488:                        JAXBElement other = (JAXBElement) obj;
489:                        ret = name.equals(other.getName())
490:                                && declaredType.isAssignableFrom(other
491:                                        .getDeclaredType())
492:                                && compare(value, other.getValue());
493:                    }
494:                    return ret;
495:                }
496:
497:                public void appendTo(StringBuffer buffer) {
498:                    buffer.append("JAXBElements did not match[" + expectedIndex
499:                            + "]");
500:                }
501:
502:                private boolean compare(Object a, Object b) {
503:                    boolean ret = false;
504:                    if (a instanceof  AttributedURI
505:                            && b instanceof  AttributedURI) {
506:                        ret = ((AttributedURI) a).getValue().equals(
507:                                ((AttributedURI) b).getValue());
508:                    } else if (a instanceof  AttributedURIType
509:                            && b instanceof  AttributedURIType) {
510:                        ret = ((AttributedURIType) a).getValue().equals(
511:                                ((AttributedURIType) b).getValue());
512:                    } else if (a instanceof  EndpointReferenceType
513:                            && b instanceof  EndpointReferenceType) {
514:                        EndpointReferenceType aEPR = (EndpointReferenceType) a;
515:                        EndpointReferenceType bEPR = (EndpointReferenceType) b;
516:                        ret = aEPR.getAddress() != null
517:                                && bEPR.getAddress() != null
518:                                && aEPR.getAddress().getValue().equals(
519:                                        bEPR.getAddress().getValue());
520:                    } else if (VersionTransformer.Names200408.EPR_TYPE
521:                            .isInstance(a)
522:                            && VersionTransformer.Names200408.EPR_TYPE
523:                                    .isInstance(b)) {
524:                        ret = VersionTransformer.Names200408.EPR_TYPE.cast(a)
525:                                .getAddress() != null
526:                                && VersionTransformer.Names200408.EPR_TYPE
527:                                        .cast(b).getAddress() != null
528:                                && VersionTransformer.Names200408.EPR_TYPE
529:                                        .cast(a)
530:                                        .getAddress()
531:                                        .getValue()
532:                                        .equals(
533:                                                VersionTransformer.Names200408.EPR_TYPE
534:                                                        .cast(b).getAddress()
535:                                                        .getValue());
536:                    } else if (a instanceof  Relationship
537:                            && b instanceof  Relationship) {
538:                        ret = ((Relationship) a).getValue().equals(
539:                                ((Relationship) b).getValue());
540:                    } else if (a instanceof  RelatesToType
541:                            && b instanceof  RelatesToType) {
542:                        ret = ((RelatesToType) a).getValue().equals(
543:                                ((RelatesToType) b).getValue());
544:                    }
545:                    return ret;
546:                }
547:            }
548:
549:            private boolean verifyMAPs(Object obj) {
550:                if (obj instanceof  AddressingPropertiesImpl) {
551:                    AddressingPropertiesImpl other = (AddressingPropertiesImpl) obj;
552:                    return compareExpected(other);
553:                }
554:                return false;
555:            }
556:
557:            private boolean compareExpected(AddressingPropertiesImpl other) {
558:                boolean ret = false;
559:                String uri = other.getNamespaceURI();
560:                boolean exposedAsNative = Names.WSA_NAMESPACE_NAME.equals(uri);
561:                boolean exposedAs200408 = VersionTransformer.Names200408.WSA_NAMESPACE_NAME
562:                        .equals(uri);
563:                if (exposedAsNative || exposedAs200408) {
564:                    String expectedMessageID = exposedAsNative ? ((AttributedURIType) expectedValues[0])
565:                            .getValue()
566:                            : ((AttributedURI) expectedValues[0]).getValue();
567:                    String expectedTo = exposedAsNative ? ((AttributedURIType) expectedValues[1])
568:                            .getValue()
569:                            : ((AttributedURI) expectedValues[1]).getValue();
570:                    String expectedReplyTo = exposedAsNative ? ((EndpointReferenceType) expectedValues[2])
571:                            .getAddress().getValue()
572:                            : (VersionTransformer.Names200408.EPR_TYPE
573:                                    .cast(expectedValues[2])).getAddress()
574:                                    .getValue();
575:                    String expectedAction = exposedAsNative ? ((AttributedURIType) expectedValues[5])
576:                            .getValue()
577:                            : ((AttributedURI) expectedValues[5]).getValue();
578:
579:                    ret = expectedMessageID.equals(other.getMessageID()
580:                            .getValue())
581:                            && expectedTo.equals(other.getTo().getValue())
582:                            && expectedReplyTo.equals(other.getReplyTo()
583:                                    .getAddress().getValue())
584:                            && expectedAction.equals(other.getAction()
585:                                    .getValue())
586:                            && expectedNamespaceURI.equals(other
587:                                    .getNamespaceURI());
588:                    if (expectRelatesTo) {
589:                        String expectedRelatesTo = exposedAsNative ? ((RelatesToType) expectedValues[4])
590:                                .getValue()
591:                                : ((Relationship) expectedValues[4]).getValue();
592:                        ret = ret
593:                                && expectedRelatesTo.equals(other
594:                                        .getRelatesTo().getValue());
595:                    }
596:                }
597:                return ret;
598:            }
599:
600:            private void verifyAction() {
601:                List<?> soapAction = (List<?>) mimeHeaders.get("SOAPAction");
602:                assertNotNull("expected propogated action", soapAction);
603:                assertEquals("expected single action", 1, soapAction.size());
604:                String expectedAction = "\""
605:                        + ((AttributedURIType) expectedValues[5]).getValue()
606:                        + "\"";
607:                assertEquals("expected propogated action", expectedAction,
608:                        soapAction.get(0));
609:            }
610:
611:            private void verifyMessage(SoapMessage message, boolean requestor,
612:                    boolean outbound, boolean exposedAsNative) {
613:                if (requestor) {
614:                    if (outbound) {
615:                        String id = expectedValues[0] instanceof  AttributedURIType ? ((AttributedURIType) expectedValues[0])
616:                                .getValue()
617:                                : ((AttributedURI) expectedValues[0])
618:                                        .getValue();
619:                        //assertTrue("expected correlationID : " + id + " in map: " + codec.uncorrelatedExchanges,
620:                        //           codec.uncorrelatedExchanges.containsKey(id));
621:                        assertSame("unexpected correlated exchange",
622:                                codec.uncorrelatedExchanges.get(id), message
623:                                        .getExchange());
624:                    } else {
625:                        assertSame("unexpected correlated exchange",
626:                                correlatedExchange, message.getExchange());
627:                    }
628:                }
629:                if (outbound) {
630:                    int expectedMarshals = requestor ? expectedValues.length - 1
631:                            : expectedValues.length;
632:                    List<Header> headers = message.getHeaders();
633:                    assertTrue("expected holders added to header list", headers
634:                            .size() >= expectedMarshals);
635:                    for (int i = 0; i < expectedMarshals; i++) {
636:                        assertTrue("expected " + expectedNames[i]
637:                                + " added to headers", message
638:                                .hasHeader(expectedNames[i]));
639:                    }
640:                }
641:                assertTrue("unexpected MAPs", verifyMAPs(message
642:                        .get(getMAPProperty(requestor, outbound))));
643:
644:            }
645:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.