Source Code Cross Referenced for SAAJConverterTests.java in  » Web-Services-AXIS2 » jax-ws » org » apache » axis2 » jaxws » message » 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.message 
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.message;
020:
021:        import java.io.StringReader;
022:
023:        import javax.xml.soap.MessageFactory;
024:        import javax.xml.soap.SOAPBody;
025:        import javax.xml.soap.SOAPBodyElement;
026:        import javax.xml.soap.SOAPElement;
027:        import javax.xml.soap.SOAPEnvelope;
028:        import javax.xml.soap.SOAPFactory;
029:        import javax.xml.soap.SOAPMessage;
030:        import javax.xml.stream.XMLInputFactory;
031:        import javax.xml.stream.XMLStreamReader;
032:
033:        import junit.framework.TestCase;
034:        import org.apache.axiom.om.OMAbstractFactory;
035:        import org.apache.axiom.om.OMElement;
036:        import org.apache.axiom.om.OMFactory;
037:        import org.apache.axiom.om.OMNamespace;
038:        import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
039:        import org.apache.axis2.jaxws.message.factory.SAAJConverterFactory;
040:        import org.apache.axis2.jaxws.message.util.SAAJConverter;
041:        import org.apache.axis2.jaxws.registry.FactoryRegistry;
042:
043:        /**
044:         * SAAJConverterTests
045:         * 
046:         * Test the basic functionality of the SAAJConverter.
047:         * You can also use these tests to as sample code on how to use
048:         * the converter.
049:         *
050:         */
051:        public class SAAJConverterTests extends TestCase {
052:
053:            private static final String sampleText = "<pre:a xmlns:pre=\"urn://sample\">"
054:                    + "<b>Hello</b>" + "<c>World</c>" + "</pre:a>";
055:
056:            private static final String sampleEnvelope = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">"
057:                    + "<soapenv:Header /><soapenv:Body>"
058:                    + sampleText
059:                    + "</soapenv:Body></soapenv:Envelope>";
060:
061:            private static XMLInputFactory inputFactory = XMLInputFactory
062:                    .newInstance();
063:
064:            public SAAJConverterTests() {
065:                super ();
066:            }
067:
068:            public SAAJConverterTests(String arg0) {
069:                super (arg0);
070:            }
071:
072:            /**
073:             * @testStrategy Tests conversions between SAAJ and OM SOAPEnvelopes
074:             */
075:            public void test1() throws Exception {
076:
077:                // Bootstrap: Create an OM SOAPEnvelope from the sample text
078:                StringReader sr = new StringReader(sampleEnvelope);
079:                XMLStreamReader inflow = inputFactory.createXMLStreamReader(sr);
080:                StAXSOAPModelBuilder builder = new StAXSOAPModelBuilder(inflow,
081:                        null);
082:                org.apache.axiom.soap.SOAPEnvelope omEnvelope = builder
083:                        .getSOAPEnvelope();
084:
085:                // Step 1: Get the SAAJConverter object from the Factory
086:                SAAJConverterFactory f = (SAAJConverterFactory) FactoryRegistry
087:                        .getFactory(SAAJConverterFactory.class);
088:                SAAJConverter converter = f.getSAAJConverter();
089:
090:                // Step 2: Convert the OM SOAPEnvelope to an SAAJ SOAPEnvelope
091:                SOAPEnvelope saajEnvelope = converter.toSAAJ(omEnvelope);
092:
093:                // Step 2a: Simple assertion check to ensure correctness.
094:                String name = saajEnvelope.getBody().getFirstChild()
095:                        .getLocalName();
096:                assertTrue("a".equals(name));
097:
098:                // Step 3: Convert the SAAJ SOAPEnvelope to an OM SOAPEnvelope
099:                omEnvelope = converter.toOM(saajEnvelope);
100:
101:                // Step 3a: Simple assertion check to ensure correctness
102:                name = omEnvelope.getBody().getFirstElement().getLocalName();
103:                assertTrue("a".equals(name));
104:
105:                // Step 4: Rinse and repeat
106:                saajEnvelope = converter.toSAAJ(omEnvelope);
107:                name = saajEnvelope.getBody().getFirstChild().getLocalName();
108:                assertTrue("a".equals(name));
109:                omEnvelope = converter.toOM(saajEnvelope);
110:                name = omEnvelope.getBody().getFirstElement().getLocalName();
111:                assertTrue("a".equals(name));
112:            }
113:
114:            /**
115:             * @testStrategy Tests conversions between SAAJ and OM for normal element
116:             */
117:            public void test2() throws Exception {
118:
119:                // Bootstrap: Create an OM SOAPEnvelope from the sample text.
120:                StringReader sr = new StringReader(sampleEnvelope);
121:                XMLStreamReader inflow = inputFactory.createXMLStreamReader(sr);
122:                StAXSOAPModelBuilder builder = new StAXSOAPModelBuilder(inflow,
123:                        null);
124:                org.apache.axiom.soap.SOAPEnvelope omEnvelope = builder
125:                        .getSOAPEnvelope();
126:
127:                // Bootstrap: Get an OMElement from the body
128:                OMElement om = omEnvelope.getBody().getFirstElement();
129:
130:                // Bootstrap: Get an SAAJ Body to hold the target SOAPElement
131:                MessageFactory msgFactory = MessageFactory.newInstance();
132:                SOAPMessage message = msgFactory.createMessage();
133:                SOAPBody body = message.getSOAPBody();
134:
135:                // Step 1: Get the SAAJConverter object from the Factory
136:                SAAJConverterFactory f = (SAAJConverterFactory) FactoryRegistry
137:                        .getFactory(SAAJConverterFactory.class);
138:                SAAJConverter converter = f.getSAAJConverter();
139:
140:                // Step 2: Convert OM to SAAJ
141:                SOAPElement se = converter.toSAAJ(om, body);
142:
143:                // Step 2a: Verify
144:                assertTrue(se instanceof  SOAPBodyElement);
145:                assertTrue(se.getLocalName().equals("a"));
146:
147:                // Step 3: Convert SAAJ to OM
148:                om = converter.toOM(se);
149:
150:                // Step 3a: Verify
151:                assertTrue(om.getLocalName().equals("a"));
152:
153:                // Step 4: Rinse and Repeat
154:                se = converter.toSAAJ(om, body);
155:                assertTrue(se instanceof  SOAPBodyElement);
156:                assertTrue(se.getLocalName().equals("a"));
157:                om = converter.toOM(se);
158:                assertTrue(om.getLocalName().equals("a"));
159:            }
160:
161:            /**
162:             * @testStrategy: Create an OMElement, without using a builder.  Verification of AXIS2-970
163:             */
164:            public void test3() throws Exception {
165:
166:                //    	 Step 1: Get the SAAJConverter object from the Factory
167:                SAAJConverterFactory f = (SAAJConverterFactory) FactoryRegistry
168:                        .getFactory(SAAJConverterFactory.class);
169:                SAAJConverter converter = f.getSAAJConverter();
170:
171:                // Stept 2: Create OM and parent SOAPElement
172:                OMFactory fac = OMAbstractFactory.getOMFactory();
173:                OMNamespace wrapNs = fac.createOMNamespace("namespace",
174:                        "prefix");
175:                OMElement ome = fac.createOMElement("localname", wrapNs);
176:                SOAPFactory sf = SOAPFactory.newInstance();
177:                SOAPElement se = sf.createElement("name");
178:
179:                // Step 3: Do the conversion
180:                converter.toSAAJ(ome, se, sf);
181:            }
182:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.