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


001:        /*
002:         * Copyright 2007 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.server.endpoint.adapter;
018:
019:        import java.util.Properties;
020:        import javax.xml.parsers.DocumentBuilder;
021:        import javax.xml.parsers.DocumentBuilderFactory;
022:        import javax.xml.transform.Source;
023:        import javax.xml.transform.dom.DOMSource;
024:
025:        import junit.framework.TestCase;
026:        import static org.easymock.EasyMock.*;
027:        import org.springframework.ws.WebServiceMessage;
028:        import org.springframework.ws.WebServiceMessageFactory;
029:        import org.springframework.ws.context.DefaultMessageContext;
030:        import org.springframework.ws.context.MessageContext;
031:        import org.springframework.ws.server.endpoint.MethodEndpoint;
032:        import org.springframework.ws.server.endpoint.annotation.XPathParam;
033:        import org.springframework.xml.transform.StringResult;
034:        import org.springframework.xml.transform.StringSource;
035:        import org.w3c.dom.Document;
036:        import org.w3c.dom.Element;
037:        import org.w3c.dom.Node;
038:        import org.w3c.dom.NodeList;
039:        import org.w3c.dom.Text;
040:
041:        public class XPathParamAnnotationMethodEndpointAdapterTest extends
042:                TestCase {
043:
044:            private static final String CONTENTS = "<root><child><text>text</text><number>42.0</number></child></root>";
045:
046:            private XPathParamAnnotationMethodEndpointAdapter adapter;
047:
048:            private boolean supportedTypesInvoked = false;
049:
050:            private boolean supportedSourceInvoked;
051:
052:            private boolean namespacesInvoked;
053:
054:            protected void setUp() throws Exception {
055:                adapter = new XPathParamAnnotationMethodEndpointAdapter();
056:                adapter.afterPropertiesSet();
057:            }
058:
059:            public void testUnsupportedInvalidParam()
060:                    throws NoSuchMethodException {
061:                MethodEndpoint endpoint = new MethodEndpoint(this ,
062:                        "unsupportedInvalidParamType",
063:                        new Class[] { Integer.TYPE });
064:                assertFalse("Method supported", adapter.supports(endpoint));
065:            }
066:
067:            public void testUnsupportedInvalidReturnType()
068:                    throws NoSuchMethodException {
069:                MethodEndpoint endpoint = new MethodEndpoint(this ,
070:                        "unsupportedInvalidReturnType",
071:                        new Class[] { String.class });
072:                assertFalse("Method supported", adapter.supports(endpoint));
073:            }
074:
075:            public void testUnsupportedInvalidParams()
076:                    throws NoSuchMethodException {
077:                MethodEndpoint endpoint = new MethodEndpoint(this ,
078:                        "unsupportedInvalidParams", new Class[] { String.class,
079:                                String.class });
080:                assertFalse("Method supported", adapter.supports(endpoint));
081:            }
082:
083:            public void testSupportedTypes() throws NoSuchMethodException {
084:                MethodEndpoint endpoint = new MethodEndpoint(this ,
085:                        "supportedTypes", new Class[] { Boolean.TYPE,
086:                                Double.TYPE, Node.class, NodeList.class,
087:                                String.class });
088:                assertTrue("Not all types supported", adapter
089:                        .supports(endpoint));
090:            }
091:
092:            public void testSupportsStringSource() throws NoSuchMethodException {
093:                MethodEndpoint endpoint = new MethodEndpoint(this ,
094:                        "supportedStringSource", new Class[] { String.class });
095:                assertTrue("StringSource method not supported", adapter
096:                        .supports(endpoint));
097:            }
098:
099:            public void testSupportsSource() throws NoSuchMethodException {
100:                MethodEndpoint endpoint = new MethodEndpoint(this ,
101:                        "supportedSource", new Class[] { String.class });
102:                assertTrue("Source method not supported", adapter
103:                        .supports(endpoint));
104:            }
105:
106:            public void testSupportsVoid() throws NoSuchMethodException {
107:                MethodEndpoint endpoint = new MethodEndpoint(this ,
108:                        "supportedVoid", new Class[] { String.class });
109:                assertTrue("void method not supported", adapter
110:                        .supports(endpoint));
111:            }
112:
113:            public void testInvokeTypes() throws Exception {
114:                WebServiceMessage messageMock = createMock(WebServiceMessage.class);
115:                expect(messageMock.getPayloadSource()).andReturn(
116:                        new StringSource(CONTENTS));
117:                WebServiceMessageFactory factoryMock = createMock(WebServiceMessageFactory.class);
118:                replay(messageMock, factoryMock);
119:
120:                MessageContext messageContext = new DefaultMessageContext(
121:                        messageMock, factoryMock);
122:                MethodEndpoint endpoint = new MethodEndpoint(this ,
123:                        "supportedTypes", new Class[] { Boolean.TYPE,
124:                                Double.TYPE, Node.class, NodeList.class,
125:                                String.class });
126:                adapter.invoke(messageContext, endpoint);
127:                assertTrue("Method not invoked", supportedTypesInvoked);
128:
129:                verify(messageMock, factoryMock);
130:            }
131:
132:            public void testInvokeSource() throws Exception {
133:                WebServiceMessage requestMock = createMock(WebServiceMessage.class);
134:                WebServiceMessage responseMock = createMock(WebServiceMessage.class);
135:                expect(requestMock.getPayloadSource()).andReturn(
136:                        new StringSource(CONTENTS));
137:                expect(responseMock.getPayloadResult()).andReturn(
138:                        new StringResult());
139:                WebServiceMessageFactory factoryMock = createMock(WebServiceMessageFactory.class);
140:                expect(factoryMock.createWebServiceMessage()).andReturn(
141:                        responseMock);
142:                replay(requestMock, responseMock, factoryMock);
143:
144:                MessageContext messageContext = new DefaultMessageContext(
145:                        requestMock, factoryMock);
146:                MethodEndpoint endpoint = new MethodEndpoint(this ,
147:                        "supportedSource", new Class[] { String.class });
148:                adapter.invoke(messageContext, endpoint);
149:                assertTrue("Method not invoked", supportedSourceInvoked);
150:
151:                verify(requestMock, responseMock, factoryMock);
152:            }
153:
154:            public void testInvokeVoidDom() throws Exception {
155:                DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory
156:                        .newInstance();
157:                DocumentBuilder documentBuilder = documentBuilderFactory
158:                        .newDocumentBuilder();
159:                Document document = documentBuilder.newDocument();
160:                String rootNamespace = "http://rootnamespace";
161:                Element rootElement = document.createElementNS(rootNamespace,
162:                        "root");
163:                document.appendChild(rootElement);
164:                String childNamespace = "http://childnamespace";
165:                Element first = document.createElementNS(childNamespace,
166:                        "child");
167:                rootElement.appendChild(first);
168:                Text text = document.createTextNode("value");
169:                first.appendChild(text);
170:                Element second = document.createElementNS(rootNamespace,
171:                        "other-child");
172:                rootElement.appendChild(second);
173:                text = document.createTextNode("other-value");
174:                second.appendChild(text);
175:
176:                WebServiceMessage requestMock = createMock(WebServiceMessage.class);
177:                expect(requestMock.getPayloadSource()).andReturn(
178:                        new DOMSource(first));
179:                WebServiceMessageFactory factoryMock = createMock(WebServiceMessageFactory.class);
180:
181:                replay(requestMock, factoryMock);
182:
183:                Properties namespaces = new Properties();
184:                namespaces.setProperty("root", rootNamespace);
185:                namespaces.setProperty("child", childNamespace);
186:                adapter.setNamespaces(namespaces);
187:
188:                MessageContext messageContext = new DefaultMessageContext(
189:                        requestMock, factoryMock);
190:                MethodEndpoint endpoint = new MethodEndpoint(this ,
191:                        "namespaces", new Class[] { Node.class });
192:                adapter.invoke(messageContext, endpoint);
193:                assertTrue("Method not invoked", namespacesInvoked);
194:            }
195:
196:            public void supportedVoid(@XPathParam("/")
197:            String param1) {
198:            }
199:
200:            public Source supportedSource(@XPathParam("/")
201:            String param1) {
202:                supportedSourceInvoked = true;
203:                return new StringSource("<response/>");
204:            }
205:
206:            public StringSource supportedStringSource(@XPathParam("/")
207:            String param1) {
208:                return null;
209:            }
210:
211:            public void supportedTypes(@XPathParam("/root/child")
212:            boolean param1, @XPathParam("/root/child/number")
213:            double param2, @XPathParam("/root/child")
214:            Node param3, @XPathParam("/root/*")
215:            NodeList param4, @XPathParam("/root/child/text")
216:            String param5) {
217:                supportedTypesInvoked = true;
218:                assertTrue("Invalid boolean value", param1);
219:                assertEquals("Invalid double value", 42D, param2, 0.00001D);
220:                assertEquals("Invalid Node value", "child", param3
221:                        .getLocalName());
222:                assertEquals("Invalid NodeList value", 1, param4.getLength());
223:                assertEquals("Invalid Node value", "child", param4.item(0)
224:                        .getLocalName());
225:                assertEquals("Invalid Node value", "text", param5);
226:            }
227:
228:            public void unsupportedInvalidParams(@XPathParam("/")
229:            String param1, String param2) {
230:
231:            }
232:
233:            public String unsupportedInvalidReturnType(@XPathParam("/")
234:            String param1) {
235:                return null;
236:            }
237:
238:            public void unsupportedInvalidParamType(@XPathParam("/")
239:            int param1) {
240:            }
241:
242:            public void namespaces(@XPathParam(".")
243:            Node param) {
244:                namespacesInvoked = true;
245:                assertEquals("Invalid parameter", "child", param.getLocalName());
246:            }
247:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.