Source Code Cross Referenced for SourceProviderTests.java in  » Web-Services-AXIS2 » jax-ws » org » apache » axis2 » jaxws » provider » 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 AXIS2 » jax ws » org.apache.axis2.jaxws.provider 
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:         */
019:        package org.apache.axis2.jaxws.provider;
020:
021:        import org.apache.axis2.jaxws.TestLogger;
022:
023:        import java.io.ByteArrayInputStream;
024:        import java.io.File;
025:        import java.io.FileInputStream;
026:        import java.io.InputStream;
027:        import java.io.StringWriter;
028:
029:        import javax.xml.namespace.QName;
030:        import javax.xml.soap.SOAPFault;
031:        import javax.xml.transform.Result;
032:        import javax.xml.transform.Source;
033:        import javax.xml.transform.Transformer;
034:        import javax.xml.transform.TransformerFactory;
035:        import javax.xml.transform.stream.StreamResult;
036:        import javax.xml.transform.stream.StreamSource;
037:        import javax.xml.ws.BindingProvider;
038:        import javax.xml.ws.Dispatch;
039:        import javax.xml.ws.Service;
040:        import javax.xml.ws.soap.SOAPFaultException;
041:
042:        public class SourceProviderTests extends ProviderTestCase {
043:
044:            private String endpointUrl = "http://localhost:8080/axis2/services/SourceProviderService";
045:            private QName serviceName = new QName("http://ws.apache.org/axis2",
046:                    "SourceProviderService");
047:            private String xmlDir = "xml";
048:
049:            protected void setUp() throws Exception {
050:                super .setUp();
051:            }
052:
053:            protected void tearDown() throws Exception {
054:                super .tearDown();
055:            }
056:
057:            public SourceProviderTests(String name) {
058:                super (name);
059:            }
060:
061:            private Dispatch<Source> getDispatch() {
062:                Service svc = Service.create(serviceName);
063:                svc.addPort(portName, null, endpointUrl);
064:
065:                Dispatch<Source> dispatch = svc.createDispatch(portName,
066:                        Source.class, Service.Mode.PAYLOAD);
067:
068:                // Force soap action because we are passing junk over the wire
069:                dispatch.getRequestContext().put(
070:                        BindingProvider.SOAPACTION_USE_PROPERTY, Boolean.TRUE);
071:                dispatch.getRequestContext().put(
072:                        BindingProvider.SOAPACTION_URI_PROPERTY, "test");
073:
074:                return dispatch;
075:
076:            }
077:
078:            private Source getSource(String text) {
079:                if (text == null) {
080:                    return null;
081:                } else {
082:                    ByteArrayInputStream stream = new ByteArrayInputStream(text
083:                            .getBytes());
084:                    return new StreamSource((InputStream) stream);
085:                }
086:
087:            }
088:
089:            private String getString(Source source) throws Exception {
090:                if (source == null) {
091:                    return null;
092:                }
093:                StringWriter writer = new StringWriter();
094:                Transformer t = TransformerFactory.newInstance()
095:                        .newTransformer();
096:                Result result = new StreamResult(writer);
097:                t.transform(source, result);
098:                return writer.getBuffer().toString();
099:
100:            }
101:
102:            public void testNormal() throws Exception {
103:                TestLogger.logger
104:                        .debug("---------------------------------------");
105:                TestLogger.logger.debug("test: " + getName());
106:
107:                Dispatch<Source> dispatch = getDispatch();
108:
109:                String request = "<test>hello world</test>";
110:                Source requestSource = getSource(request);
111:                Source responseSource = dispatch.invoke(requestSource);
112:                String response = getString(responseSource);
113:
114:                assertTrue(response.contains(request));
115:            }
116:
117:            public void testEmptyString() throws Exception {
118:                TestLogger.logger
119:                        .debug("---------------------------------------");
120:                TestLogger.logger.debug("test: " + getName());
121:
122:                Dispatch<Source> dispatch = getDispatch();
123:
124:                String request = "";
125:                Source requestSource = getSource(request);
126:                Source responseSource = dispatch.invoke(requestSource);
127:                String response = getString(responseSource);
128:
129:                // The current belief is that this should return a null indicating
130:                // the nothing is echo'ed 
131:                assertTrue(response == null);
132:
133:                //assertTrue(request.equals(response));
134:            }
135:
136:            public void testNullSource() throws Exception {
137:                TestLogger.logger
138:                        .debug("---------------------------------------");
139:                TestLogger.logger.debug("test: " + getName());
140:
141:                Dispatch<Source> dispatch = getDispatch();
142:
143:                Source responseSource = dispatch.invoke(null);
144:                String response = getString(responseSource);
145:
146:                // The current belief is that this should return a null indicating
147:                // the nothing is echo'ed 
148:                assertTrue(response == null);
149:            }
150:
151:            public void testEmptySource() throws Exception {
152:                TestLogger.logger
153:                        .debug("---------------------------------------");
154:                TestLogger.logger.debug("test: " + getName());
155:
156:                Dispatch<Source> dispatch = getDispatch();
157:
158:                Source responseSource = dispatch.invoke(new StreamSource());
159:                String response = getString(responseSource);
160:
161:                // The current belief is that this should return a null indicating
162:                // the nothing is echo'ed 
163:                assertTrue(response == null);
164:            }
165:
166:            public void testNonNullString() throws Exception {
167:                TestLogger.logger
168:                        .debug("---------------------------------------");
169:                TestLogger.logger.debug("test: " + getName());
170:
171:                Dispatch<Source> dispatch = getDispatch();
172:
173:                String request = "mixedContent";
174:                Source requestSource = getSource(request);
175:                Source responseSource = dispatch.invoke(requestSource);
176:                String response = getString(responseSource);
177:
178:                // The current implementation does not send the mixedContent over the wire, so the
179:                // expectation is that the echo'd response is null
180:                assertTrue(response == null);
181:            }
182:
183:            public void testCommentString() throws Exception {
184:                TestLogger.logger
185:                        .debug("---------------------------------------");
186:                TestLogger.logger.debug("test: " + getName());
187:
188:                Dispatch<Source> dispatch = getDispatch();
189:
190:                String request = "<!--comment-->";
191:                Source requestSource = getSource(request);
192:                Source responseSource = dispatch.invoke(requestSource);
193:                String response = getString(responseSource);
194:                // The current implementation does not send the comment over the wire, so the
195:                // expectation is that the echo'd response is null
196:                assertTrue(response == null);
197:            }
198:
199:            public void testTwoElementsString() throws Exception {
200:                TestLogger.logger
201:                        .debug("---------------------------------------");
202:                TestLogger.logger.debug("test: " + getName());
203:
204:                Dispatch<Source> dispatch = getDispatch();
205:
206:                String request = "<a>hello</a><b>world</b>";
207:                Source requestSource = getSource(request);
208:                Source responseSource = dispatch.invoke(requestSource);
209:                String response = getString(responseSource);
210:
211:                // The current implementatin only sends the first element
212:                // So the echo'd response is just the first one.
213:                assertTrue(response.contains("<a>hello</a>"));
214:            }
215:
216:            public void testTwoElementsAndMixedContentString() throws Exception {
217:                TestLogger.logger
218:                        .debug("---------------------------------------");
219:                TestLogger.logger.debug("test: " + getName());
220:
221:                Dispatch<Source> dispatch = getDispatch();
222:
223:                String request = "mixed1<a>hello</a>mixed2<b>world</b>mixed3";
224:                Source requestSource = getSource(request);
225:                Source responseSource = dispatch.invoke(requestSource);
226:                String response = getString(responseSource);
227:                // The current implementation only sends the first element.
228:                // The mixed content (mixed1) interferes and thus nothing is sent.
229:                assertTrue(response == null);
230:            }
231:
232:            public void testException() throws Exception {
233:                TestLogger.logger
234:                        .debug("---------------------------------------");
235:                TestLogger.logger.debug("test: " + getName());
236:
237:                Dispatch<Source> dispatch = getDispatch();
238:
239:                String request = "<test>throwWebServiceException</test>";
240:                try {
241:                    Source requestSource = getSource(request);
242:                    Source responseSource = dispatch.invoke(requestSource);
243:                    String response = getString(responseSource);
244:                    fail("Expected Exception");
245:                } catch (SOAPFaultException e) {
246:                    SOAPFault sf = e.getFault();
247:                    assertTrue(sf.getFaultString().equals("provider"));
248:                }
249:            }
250:
251:            public void testProviderSource() {
252:                try {
253:                    String resourceDir = new File(providerResourceDir, xmlDir)
254:                            .getAbsolutePath();
255:                    String fileName = resourceDir + File.separator + "web.xml";
256:
257:                    File file = new File(fileName);
258:                    InputStream inputStream = new FileInputStream(file);
259:                    StreamSource xmlStreamSource = new StreamSource(inputStream);
260:
261:                    Service svc = Service.create(serviceName);
262:                    svc.addPort(portName, null, endpointUrl);
263:                    Dispatch<Source> dispatch = svc.createDispatch(portName,
264:                            Source.class, null);
265:                    TestLogger.logger
266:                            .debug(">> Invoking Source Provider Dispatch");
267:                    Source response = dispatch.invoke(xmlStreamSource);
268:
269:                    TestLogger.logger.debug(">> Response ["
270:                            + response.toString() + "]");
271:
272:                } catch (Exception e) {
273:                    e.printStackTrace();
274:                    fail("Caught exception " + e);
275:                }
276:
277:            }
278:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.