Source Code Cross Referenced for MAPTest.java in  » ESB » celtix-1.0 » org » objectweb » celtix » systest » ws » addressing » jms » 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 » ESB » celtix 1.0 » org.objectweb.celtix.systest.ws.addressing.jms 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.objectweb.celtix.systest.ws.addressing.jms;
002:
003:        import java.lang.reflect.UndeclaredThrowableException;
004:        import java.net.URL;
005:        import java.util.HashMap;
006:        import java.util.List;
007:        import java.util.Map;
008:
009:        import javax.xml.namespace.QName;
010:        import javax.xml.ws.BindingProvider;
011:        import javax.xml.ws.ProtocolException;
012:        import javax.xml.ws.handler.Handler;
013:
014:        import junit.framework.Test;
015:        import junit.framework.TestSuite;
016:
017:        import org.objectweb.celtix.bus.ws.addressing.AddressingPropertiesImpl;
018:        import org.objectweb.celtix.bus.ws.addressing.ContextUtils;
019:        import org.objectweb.celtix.bus.ws.addressing.Names;
020:        import org.objectweb.celtix.bus.ws.addressing.soap.VersionTransformer;
021:        import org.objectweb.celtix.hello_world_jms.HelloWorldPortType;
022:        import org.objectweb.celtix.hello_world_jms.JMSSOAPServiceAddressing;
023:        import org.objectweb.celtix.systest.common.ClientServerSetupBase;
024:        import org.objectweb.celtix.systest.common.ClientServerTestBase;
025:        import org.objectweb.celtix.systest.jms.EmbeddedJMSBrokerLauncher;
026:        import org.objectweb.celtix.systest.ws.addressing.HeaderVerifier;
027:        import org.objectweb.celtix.systest.ws.addressing.MAPVerifier;
028:        import org.objectweb.celtix.systest.ws.addressing.VerificationCache;
029:        import org.objectweb.celtix.ws.addressing.AddressingProperties;
030:        import org.objectweb.celtix.ws.addressing.AttributedURIType;
031:
032:        import static org.objectweb.celtix.ws.addressing.JAXWSAConstants.CLIENT_ADDRESSING_PROPERTIES;
033:
034:        /**
035:         * Tests the addition of WS-Addressing Message Addressing Properties.
036:         */
037:        public class MAPTest extends ClientServerTestBase implements 
038:                VerificationCache {
039:
040:            static final String INBOUND_KEY = "inbound";
041:            static final String OUTBOUND_KEY = "outbound";
042:            private static final QName SERVICE_NAME = new QName(
043:                    "http://celtix.objectweb.org/hello_world_jms",
044:                    "JMSSOAPServiceAddressing");
045:            private static final QName PORT_NAME = new QName(
046:                    "http://celtix.objectweb.org/hello_world_jms",
047:                    "HWJMSAddressingPort");
048:            private static Map<Object, Map<String, String>> messageIDs = new HashMap<Object, Map<String, String>>();
049:            private HelloWorldPortType greeter;
050:            private String verified;
051:            private MAPVerifier mapVerifier;
052:
053:            public static void main(String[] args) {
054:                junit.textui.TestRunner.run(MAPTest.class);
055:            }
056:
057:            public static Test suite() throws Exception {
058:                TestSuite suite = new TestSuite(MAPTest.class);
059:                return new ClientServerSetupBase(suite) {
060:                    public void startServers() throws Exception {
061:                        Map<String, String> props = new HashMap<String, String>();
062:                        if (System.getProperty("activemq.store.dir") != null) {
063:                            props.put("activemq.store.dir", System
064:                                    .getProperty("activemq.store.dir"));
065:                        }
066:                        props.put("java.util.logging.config.file", System
067:                                .getProperty("java.util.logging.config.file"));
068:
069:                        assertTrue("server did not launch correctly",
070:                                launchServer(EmbeddedJMSBrokerLauncher.class,
071:                                        props, null));
072:                        // special case handling for WS-Addressing system test to avoid
073:                        // UUID related issue when server is run as separate process
074:                        // via maven on Win2k
075:                        boolean inProcess = "Windows 2000".equals(System
076:                                .getProperty("os.name"));
077:                        assertTrue("server did not launch correctly",
078:                                launchServer(Server.class, inProcess));
079:                    }
080:
081:                    public void setUp() throws Exception {
082:                        // set up configuration for decoupled response
083:                        // endpoint
084:                        URL url = getClass().getResource("client.xml");
085:                        assertNotNull("cannot find test resource", url);
086:                        configFileName = url.toString();
087:                        super .setUp();
088:                    }
089:                };
090:            }
091:
092:            public void setUp() throws Exception {
093:                super .setUp();
094:                URL wsdl = getClass().getResource("/wsdl/jms_test.wsdl");
095:                JMSSOAPServiceAddressing service = new JMSSOAPServiceAddressing(
096:                        wsdl, SERVICE_NAME);
097:                greeter = (HelloWorldPortType) service.getPort(PORT_NAME,
098:                        HelloWorldPortType.class);
099:                BindingProvider provider = (BindingProvider) greeter;
100:
101:                List<Handler> handlerChain = provider.getBinding()
102:                        .getHandlerChain();
103:                for (Object h : handlerChain) {
104:                    if (h instanceof  MAPVerifier) {
105:                        mapVerifier = (MAPVerifier) h;
106:                        mapVerifier.setVerificationCache(this );
107:                    } else if (h instanceof  HeaderVerifier) {
108:                        ((HeaderVerifier) h).setVerificationCache(this );
109:                    }
110:                }
111:            }
112:
113:            public void tearDown() {
114:                verified = null;
115:            }
116:
117:            //--Tests
118:
119:            public void testImplicitMAPs() throws Exception {
120:                try {
121:                    String greeting = greeter.greetMe("implicit1");
122:                    assertEquals("unexpected response received from service",
123:                            "Hello implicit1", greeting);
124:                    checkVerification();
125:                    greeting = greeter.greetMe("implicit2");
126:                    assertEquals("unexpected response received from service",
127:                            "Hello implicit2", greeting);
128:                    checkVerification();
129:                } catch (UndeclaredThrowableException ex) {
130:                    throw (Exception) ex.getCause();
131:                }
132:            }
133:
134:            public void testExplicitMAPs() throws Exception {
135:                try {
136:                    Map<String, Object> requestContext = ((BindingProvider) greeter)
137:                            .getRequestContext();
138:                    AddressingProperties maps = new AddressingPropertiesImpl();
139:                    AttributedURIType id = ContextUtils
140:                            .getAttributedURI("urn:uuid:12345");
141:                    maps.setMessageID(id);
142:                    requestContext.put(CLIENT_ADDRESSING_PROPERTIES, maps);
143:                    String greeting = greeter.greetMe("explicit1");
144:                    assertEquals("unexpected response received from service",
145:                            "Hello explicit1", greeting);
146:                    checkVerification();
147:
148:                    // the previous addition to the request context impacts
149:                    // on all subsequent invocations on this proxy => a duplicate
150:                    // message ID fault is expected
151:                    try {
152:                        greeter.greetMe("explicit2");
153:                        fail("expected ProtocolException on duplicate message ID");
154:                    } catch (ProtocolException pe) {
155:                        assertTrue("expected duplicate message ID failure",
156:                                "Duplicate Message ID urn:uuid:12345".equals(pe
157:                                        .getMessage()));
158:                        checkVerification();
159:                    }
160:
161:                    // clearing the message ID ensure a duplicate is not sent
162:                    maps.setMessageID(null);
163:                    maps.setRelatesTo(ContextUtils.getRelatesTo(id.getValue()));
164:                    greeting = greeter.greetMe("explicit3");
165:                    assertEquals("unexpected response received from service",
166:                            "Hello explicit3", greeting);
167:                } catch (UndeclaredThrowableException ex) {
168:                    throw (Exception) ex.getCause();
169:                }
170:            }
171:
172:            public void testOneway() throws Exception {
173:                try {
174:                    greeter.greetMeOneWay("implicit_oneway1");
175:                    checkVerification();
176:                } catch (UndeclaredThrowableException ex) {
177:                    throw (Exception) ex.getCause();
178:                }
179:            }
180:
181:            public void testVersioning() throws Exception {
182:                try {
183:                    // expect two MAPs instances versioned with 200408, i.e. for both 
184:                    // the partial and full responses
185:                    mapVerifier
186:                            .addToExpectedExposedAs(VersionTransformer.Names200408.WSA_NAMESPACE_NAME);
187:                    mapVerifier
188:                            .addToExpectedExposedAs(VersionTransformer.Names200408.WSA_NAMESPACE_NAME);
189:                    String greeting = greeter.greetMe("versioning1");
190:                    assertEquals("unexpected response received from service",
191:                            "Hello versioning1", greeting);
192:                    checkVerification();
193:                    greeting = greeter.greetMe("versioning2");
194:                    assertEquals("unexpected response received from service",
195:                            "Hello versioning2", greeting);
196:                    checkVerification();
197:                } catch (UndeclaredThrowableException ex) {
198:                    throw (Exception) ex.getCause();
199:                }
200:            }
201:
202:            //--VerificationCache implementation
203:
204:            public void put(String verification) {
205:                if (verification != null) {
206:                    verified = verified == null ? verification : verified
207:                            + "; " + verification;
208:                }
209:            }
210:
211:            //--Verification methods called by handlers
212:
213:            /**
214:             * Verify presence of expected MAPs.
215:             *
216:             * @param maps the MAPs to verify
217:             * @param checkPoint the check point
218:             * @return null if all expected MAPs present, otherwise an error string.
219:             */
220:            protected static String verifyMAPs(AddressingProperties maps,
221:                    Object checkPoint) {
222:                if (maps == null) {
223:                    return "expected MAPs";
224:                }
225:                //String rt = maps.getReplyTo() != null ? maps.getReplyTo().getAddress().getValue() : "null"; 
226:                //System.out.println("verifying MAPs: " + maps
227:                //                   + " id: " + maps.getMessageID().getValue() 
228:                //                   + " to: " + maps.getTo().getValue()
229:                //                   + " reply to: " + rt);
230:                // MessageID
231:                String id = maps.getMessageID().getValue();
232:                if (id == null) {
233:                    return "expected MessageID MAP";
234:                }
235:                if (!id.startsWith("urn:uuid")) {
236:                    return "bad URN format in MessageID MAP: " + id;
237:                }
238:                // ensure MessageID is unique for this check point
239:                Map<String, String> checkPointMessageIDs = messageIDs
240:                        .get(checkPoint);
241:                if (checkPointMessageIDs != null) {
242:                    if (checkPointMessageIDs.containsKey(id)) {
243:                        //return "MessageID MAP duplicate: " + id;
244:                        return null;
245:                    }
246:                } else {
247:                    checkPointMessageIDs = new HashMap<String, String>();
248:                    messageIDs.put(checkPoint, checkPointMessageIDs);
249:                }
250:                checkPointMessageIDs.put(id, id);
251:                // To
252:                if (maps.getTo() == null) {
253:                    return "expected To MAP";
254:                }
255:                return null;
256:            }
257:
258:            /**
259:             * Verify presence of expected MAP headers.
260:             *
261:             * @param wsaHeaders a list of the wsa:* headers present in the SOAP
262:             * message
263:             * @param parial true if partial response
264:             * @return null if all expected headers present, otherwise an error string.
265:             */
266:            protected static String verifyHeaders(List<String> wsaHeaders,
267:                    boolean partial) {
268:                //System.out.println("verifying headers: " + wsaHeaders);
269:                if (!wsaHeaders.contains(Names.WSA_MESSAGEID_NAME)) {
270:                    return "expected MessageID header";
271:                }
272:                if (!wsaHeaders.contains(Names.WSA_TO_NAME)) {
273:                    return "expected To header";
274:                }
275:                if (!(wsaHeaders.contains(Names.WSA_REPLYTO_NAME) || wsaHeaders
276:                        .contains(Names.WSA_RELATESTO_NAME))) {
277:                    return "expected ReplyTo or RelatesTo header";
278:                }
279:                if (partial) {
280:                    if (!wsaHeaders.contains(Names.WSA_FROM_NAME)) {
281:                        return "expected From header";
282:                    }
283:                } else {
284:                    if (!wsaHeaders.contains(Names.WSA_ACTION_NAME)) {
285:                        return "expected Action header";
286:                    }
287:                }
288:                return null;
289:            }
290:
291:            private void checkVerification() {
292:                assertNull("MAP/Header verification failed: " + verified,
293:                        verified);
294:            }
295:        }
w_w_w__._ja_v_a__2__s.c__o_m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.