Source Code Cross Referenced for SoapFaultMappingExceptionResolverTest.java in  » Web-Services » spring-ws-1.0.0 » org » springframework » ws » soap » server » endpoint » 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 » spring ws 1.0.0 » org.springframework.ws.soap.server.endpoint 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2005 the original author or authors.
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:
017:        package org.springframework.ws.soap.server.endpoint;
018:
019:        import java.util.Locale;
020:        import java.util.Properties;
021:        import javax.xml.soap.MessageFactory;
022:        import javax.xml.soap.SOAPConstants;
023:        import javax.xml.soap.SOAPMessage;
024:
025:        import org.custommonkey.xmlunit.XMLTestCase;
026:        import org.springframework.ws.context.DefaultMessageContext;
027:        import org.springframework.ws.context.MessageContext;
028:        import org.springframework.ws.soap.SoapMessage;
029:        import org.springframework.ws.soap.SoapMessageException;
030:        import org.springframework.ws.soap.SoapMessageFactory;
031:        import org.springframework.ws.soap.SoapVersion;
032:        import org.springframework.ws.soap.saaj.SaajSoapMessage;
033:        import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;
034:        import org.springframework.ws.soap.soap11.Soap11Fault;
035:        import org.springframework.ws.soap.soap12.Soap12Fault;
036:
037:        public class SoapFaultMappingExceptionResolverTest extends XMLTestCase {
038:
039:            private SoapFaultMappingExceptionResolver resolver;
040:
041:            protected void setUp() throws Exception {
042:                resolver = new SoapFaultMappingExceptionResolver();
043:            }
044:
045:            public void testGetDepth() throws Exception {
046:                assertEquals("Invalid depth for Exception", 0, resolver
047:                        .getDepth("java.lang.Exception", new Exception()));
048:                assertEquals("Invalid depth for IllegalArgumentException", 2,
049:                        resolver.getDepth("java.lang.Exception",
050:                                new IllegalArgumentException()));
051:                assertEquals("Invalid depth for IllegalStateException", -1,
052:                        resolver.getDepth("IllegalArgumentException",
053:                                new IllegalStateException()));
054:            }
055:
056:            public void testResolveExceptionClientSoap11() throws Exception {
057:                Properties mappings = new Properties();
058:                mappings.setProperty(Exception.class.getName(),
059:                        "SERVER, Server error");
060:                mappings.setProperty(RuntimeException.class.getName(),
061:                        "CLIENT, Client error");
062:                resolver.setExceptionMappings(mappings);
063:
064:                MessageFactory messageFactory = MessageFactory
065:                        .newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
066:                SOAPMessage message = messageFactory.createMessage();
067:                SoapMessageFactory factory = new SaajSoapMessageFactory(
068:                        messageFactory);
069:                MessageContext context = new DefaultMessageContext(
070:                        new SaajSoapMessage(message), factory);
071:
072:                boolean result = resolver.resolveException(context, null,
073:                        new IllegalArgumentException("bla"));
074:                assertTrue("resolveException returns false", result);
075:                assertTrue("Context has no response", context.hasResponse());
076:                SoapMessage response = (SoapMessage) context.getResponse();
077:                assertTrue("Response has no fault", response.getSoapBody()
078:                        .hasFault());
079:                Soap11Fault fault = (Soap11Fault) response.getSoapBody()
080:                        .getFault();
081:                assertEquals("Invalid fault code on fault", SoapVersion.SOAP_11
082:                        .getClientOrSenderFaultName(), fault.getFaultCode());
083:                assertEquals("Invalid fault string on fault", "Client error",
084:                        fault.getFaultStringOrReason());
085:                assertNull("Detail on fault", fault.getFaultDetail());
086:            }
087:
088:            public void testResolveExceptionSenderSoap12() throws Exception {
089:                Properties mappings = new Properties();
090:                mappings.setProperty(Exception.class.getName(),
091:                        "RECEIVER, Receiver error, en");
092:                mappings.setProperty(RuntimeException.class.getName(),
093:                        "SENDER, Sender error, en");
094:                resolver.setExceptionMappings(mappings);
095:
096:                MessageFactory messageFactory = MessageFactory
097:                        .newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
098:                SOAPMessage message = messageFactory.createMessage();
099:                SoapMessageFactory factory = new SaajSoapMessageFactory(
100:                        messageFactory);
101:                MessageContext context = new DefaultMessageContext(
102:                        new SaajSoapMessage(message), factory);
103:
104:                boolean result = resolver.resolveException(context, null,
105:                        new IllegalArgumentException("bla"));
106:                assertTrue("resolveException returns false", result);
107:                assertTrue("Context has no response", context.hasResponse());
108:                SoapMessage response = (SoapMessage) context.getResponse();
109:                assertTrue("Response has no fault", response.getSoapBody()
110:                        .hasFault());
111:                Soap12Fault fault = (Soap12Fault) response.getSoapBody()
112:                        .getFault();
113:                assertEquals("Invalid fault code on fault", SoapVersion.SOAP_12
114:                        .getClientOrSenderFaultName(), fault.getFaultCode());
115:                assertEquals("Invalid fault string on fault", "Sender error",
116:                        fault.getFaultReasonText(Locale.ENGLISH));
117:                assertNull("Detail on fault", fault.getFaultDetail());
118:            }
119:
120:            public void testResolveExceptionServerSoap11() throws Exception {
121:                Properties mappings = new Properties();
122:                mappings.setProperty(Exception.class.getName(),
123:                        "CLIENT, Client error");
124:                mappings.setProperty(RuntimeException.class.getName(),
125:                        "SERVER, Server error");
126:                resolver.setExceptionMappings(mappings);
127:
128:                MessageFactory messageFactory = MessageFactory
129:                        .newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
130:                SOAPMessage message = messageFactory.createMessage();
131:                SoapMessageFactory factory = new SaajSoapMessageFactory(
132:                        messageFactory);
133:                MessageContext context = new DefaultMessageContext(
134:                        new SaajSoapMessage(message), factory);
135:
136:                boolean result = resolver.resolveException(context, null,
137:                        new IllegalArgumentException("bla"));
138:                assertTrue("resolveException returns false", result);
139:                assertTrue("Context has no response", context.hasResponse());
140:                SoapMessage response = (SoapMessage) context.getResponse();
141:                assertTrue("Response has no fault", response.getSoapBody()
142:                        .hasFault());
143:                Soap11Fault fault = (Soap11Fault) response.getSoapBody()
144:                        .getFault();
145:                assertEquals("Invalid fault code on fault", SoapVersion.SOAP_11
146:                        .getServerOrReceiverFaultName(), fault.getFaultCode());
147:                assertEquals("Invalid fault string on fault", "Server error",
148:                        fault.getFaultStringOrReason());
149:                assertNull("Detail on fault", fault.getFaultDetail());
150:            }
151:
152:            public void testResolveExceptionReceiverSoap12() throws Exception {
153:                Properties mappings = new Properties();
154:                mappings.setProperty(Exception.class.getName(),
155:                        "SENDER, Sender error");
156:                mappings.setProperty(RuntimeException.class.getName(),
157:                        "RECEIVER, Receiver error");
158:                resolver.setExceptionMappings(mappings);
159:
160:                MessageFactory messageFactory = MessageFactory
161:                        .newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
162:                SOAPMessage message = messageFactory.createMessage();
163:                SoapMessageFactory factory = new SaajSoapMessageFactory(
164:                        messageFactory);
165:                MessageContext context = new DefaultMessageContext(
166:                        new SaajSoapMessage(message), factory);
167:
168:                boolean result = resolver.resolveException(context, null,
169:                        new IllegalArgumentException("bla"));
170:                assertTrue("resolveException returns false", result);
171:                assertTrue("Context has no response", context.hasResponse());
172:                SoapMessage response = (SoapMessage) context.getResponse();
173:                assertTrue("Response has no fault", response.getSoapBody()
174:                        .hasFault());
175:                Soap12Fault fault = (Soap12Fault) response.getSoapBody()
176:                        .getFault();
177:                assertEquals("Invalid fault code on fault", SoapVersion.SOAP_12
178:                        .getServerOrReceiverFaultName(), fault.getFaultCode());
179:                assertEquals("Invalid fault string on fault", "Receiver error",
180:                        fault.getFaultReasonText(Locale.ENGLISH));
181:                assertNull("Detail on fault", fault.getFaultDetail());
182:            }
183:
184:            public void testResolveExceptionDefault() throws Exception {
185:                Properties mappings = new Properties();
186:                mappings.setProperty(SoapMessageException.class.getName(),
187:                        "SERVER,Server error");
188:                resolver.setExceptionMappings(mappings);
189:                SoapFaultDefinition defaultFault = new SoapFaultDefinition();
190:                defaultFault.setFaultCode(SoapFaultDefinition.CLIENT);
191:                defaultFault.setFaultStringOrReason("faultstring");
192:                resolver.setDefaultFault(defaultFault);
193:                MessageFactory messageFactory = MessageFactory
194:                        .newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
195:                SOAPMessage message = messageFactory.createMessage();
196:                SoapMessageFactory factory = new SaajSoapMessageFactory(
197:                        messageFactory);
198:                MessageContext context = new DefaultMessageContext(
199:                        new SaajSoapMessage(message), factory);
200:
201:                boolean result = resolver.resolveException(context, null,
202:                        new IllegalArgumentException("bla"));
203:                assertTrue("resolveException returns false", result);
204:                assertTrue("Context has no response", context.hasResponse());
205:                SoapMessage response = (SoapMessage) context.getResponse();
206:                assertTrue("Response has no fault", response.getSoapBody()
207:                        .hasFault());
208:                Soap11Fault fault = (Soap11Fault) response.getSoapBody()
209:                        .getFault();
210:                assertEquals("Invalid fault code on fault", SoapVersion.SOAP_11
211:                        .getClientOrSenderFaultName(), fault.getFaultCode());
212:                assertEquals("Invalid fault string on fault", "faultstring",
213:                        fault.getFaultStringOrReason());
214:                assertNull("Detail on fault", fault.getFaultDetail());
215:            }
216:
217:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.