Source Code Cross Referenced for SOAPFactoryTest.java in  » Web-Services-AXIS2 » saaj » org » apache » axis2 » saaj » 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 » saaj » org.apache.axis2.saaj 
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.saaj;
020:
021:        import junit.framework.TestCase;
022:        import org.apache.commons.logging.Log;
023:        import org.apache.commons.logging.LogFactory;
024:        import org.w3c.dom.Document;
025:        import org.w3c.dom.Element;
026:
027:        import javax.xml.namespace.QName;
028:        import javax.xml.parsers.DocumentBuilder;
029:        import javax.xml.parsers.DocumentBuilderFactory;
030:        import javax.xml.soap.Detail;
031:        import javax.xml.soap.SOAPConstants;
032:        import javax.xml.soap.SOAPElement;
033:        import javax.xml.soap.SOAPException;
034:        import javax.xml.soap.SOAPFactory;
035:        import javax.xml.soap.SOAPFault;
036:        import java.util.Iterator;
037:
038:        /**
039:         * 
040:         */
041:        public class SOAPFactoryTest extends TestCase {
042:            private static final Log log = LogFactory
043:                    .getLog(SOAPFactoryTest.class);
044:
045:            public void testCreateDetail() {
046:                try {
047:                    SOAPFactory sf = SOAPFactory.newInstance();
048:                    if (sf == null) {
049:                        fail("SOAPFactory was null");
050:                    }
051:                    Detail d = sf.createDetail();
052:                    if (d == null) {
053:                        fail("Detail was null");
054:                    }
055:                } catch (Exception e) {
056:                    e.printStackTrace();
057:                    fail("Unexpected Exception " + e);
058:                }
059:            }
060:
061:            public void testCreateElement() {
062:                try {
063:                    //SOAPFactory sf = SOAPFactory.newInstance();
064:                    SOAPFactory sf = SOAPFactory
065:                            .newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
066:                    if (sf == null) {
067:                        fail("createElementTest4() could not create SOAPFactory object");
068:                    }
069:                    //Create QName object with localName=MyName1,prefix=MyPrefix1, uri=MyUri1
070:                    QName name = new QName("MyUri1", "MyName1", "MyPrefix1");
071:                    SOAPElement se = sf.createElement(name);
072:                    assertNotNull(se);
073:                    name = se.getElementQName();
074:                    String localName = name.getLocalPart();
075:                    String prefix = name.getPrefix();
076:                    String uri = name.getNamespaceURI();
077:                    if (localName == null) {
078:                        fail("localName is null (expected MyName1)");
079:                    } else if (!localName.equals("MyName1")) {
080:                        fail("localName is wrong (expected MyName1)");
081:                    } else if (prefix == null) {
082:                        fail("prefix is null (expected MyPrefix1)");
083:                    } else if (!prefix.equals("MyPrefix1")) {
084:                        fail("prefix is wrong (expected MyPrefix1)");
085:                    } else if (uri == null) {
086:                        fail("uri is null (expected MyUri1)");
087:                    } else if (!uri.equals("MyUri1")) {
088:                        fail("uri is wrong (expected MyUri1)");
089:                    }
090:                } catch (Exception e) {
091:                    fail();
092:                }
093:            }
094:
095:            public void testCreateElement2() {
096:                try {
097:                    SOAPFactory sf = SOAPFactory.newInstance();
098:                    //SOAPFactory sf = SOAPFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
099:                    if (sf == null) {
100:                        fail("could not create SOAPFactory object");
101:                    }
102:                    log.info("Create a DOMElement");
103:                    DocumentBuilderFactory dbfactory = DocumentBuilderFactory
104:                            .newInstance();
105:                    DocumentBuilder builder = dbfactory.newDocumentBuilder();
106:                    Document document = builder.newDocument();
107:                    Element de = document.createElementNS(
108:                            "http://MyNamespace.org/", "MyTag");
109:                    //Calling SOAPFactory.createElement(org.w3c.dom.Element)
110:                    SOAPElement se = sf.createElement(de);
111:                    if (!de.getNodeName().equals(se.getNodeName())
112:                            || !de.getNamespaceURI().equals(
113:                                    se.getNamespaceURI())) {
114:                        //Node names are not equal
115:                        fail("Got: <URI=" + se.getNamespaceURI() + ", PREFIX="
116:                                + se.getPrefix() + ", NAME=" + se.getNodeName()
117:                                + ">" + "Expected: <URI="
118:                                + de.getNamespaceURI() + ", PREFIX="
119:                                + de.getPrefix() + ", NAME=" + de.getNodeName()
120:                                + ">");
121:                    }
122:                } catch (Exception e) {
123:                    fail("Exception: " + e);
124:                }
125:            }
126:
127:            public void testCreateElement3() {
128:                try {
129:                    SOAPFactory factory = SOAPFactory.newInstance();
130:                    if (factory == null) {
131:                        fail("createFaultTest1() could not create SOAPFactory object");
132:                    }
133:                    SOAPFault sf = factory.createFault();
134:                    if (sf == null) {
135:                        fail("createFault() returned null");
136:                    } else if (!(sf instanceof  SOAPFault)) {
137:                        fail("createFault() did not create a SOAPFault object");
138:                    }
139:                } catch (Exception e) {
140:                    fail();
141:                }
142:            }
143:
144:            public void testCreateElement4() {
145:                try {
146:                    SOAPFactory sf = SOAPFactory.newInstance();
147:                    if (sf == null) {
148:                        fail("createElementTest6() could not create SOAPFactory object");
149:                    }
150:                    QName qname = new QName("http://MyNamespace.org/", "MyTag");
151:                    SOAPElement se1 = sf.createElement(qname);
152:                    //Create second SOAPElement from first SOAPElement
153:                    SOAPElement se2 = sf.createElement(se1);
154:                    //commented to support jdk 1.4 build
155:                    //    		if(!se1.isEqualNode(se2) && !se1.isSameNode(se2)) {
156:                    //    			fail("The SOAPElement's are not equal and not the same (unexpected)");
157:                    //    		}
158:                    if (!se1.getNodeName().equals(se2.getNodeName())
159:                            || !se1.getNamespaceURI().equals(
160:                                    se2.getNamespaceURI())) {
161:                        fail("Got: <URI=" + se1.getNamespaceURI() + ", PREFIX="
162:                                + se1.getPrefix() + ", NAME="
163:                                + se1.getNodeName() + ">" + "Expected: <URI="
164:                                + se2.getNamespaceURI() + ", PREFIX="
165:                                + se2.getPrefix() + ", NAME="
166:                                + se2.getNodeName() + ">");
167:                    }
168:                } catch (Exception e) {
169:                    fail();
170:                }
171:            }
172:
173:            public void testCreateFault() {
174:                try {
175:                    SOAPFactory factory = SOAPFactory
176:                            .newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
177:                    //SOAPFactory factory = SOAPFactory.newInstance();
178:                    SOAPFault sf = factory.createFault(
179:                            "This is the fault reason.",
180:                            SOAPConstants.SOAP_RECEIVER_FAULT);
181:                    assertNotNull(sf);
182:                    assertTrue(sf instanceof  SOAPFault);
183:                    QName fc = sf.getFaultCodeAsQName();
184:                    //Expect FaultCode="+SOAPConstants.SOAP_RECEIVER_FAULT
185:                    Iterator i = sf.getFaultReasonTexts();
186:                    if (i == null) {
187:                        log
188:                                .info("Call to getFaultReasonTexts() returned null iterator");
189:                    }
190:                    String reason = "";
191:                    while (i.hasNext()) {
192:                        reason += (String) i.next();
193:                    }
194:                    assertNotNull(reason);
195:                    assertTrue(reason.indexOf("This is the fault reason.") > -1);
196:                    assertTrue(fc.equals(SOAPConstants.SOAP_RECEIVER_FAULT));
197:                } catch (SOAPException e) {
198:                    fail("Caught unexpected SOAPException");
199:                }
200:            }
201:
202:            public void testCreateFault1() {
203:                try {
204:                    //SOAPFactory factory = SOAPFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
205:                    SOAPFactory factory = SOAPFactory.newInstance();
206:                    SOAPFault sf = factory.createFault(
207:                            "This is the fault reason.",
208:                            SOAPConstants.SOAP_RECEIVER_FAULT);
209:                    assertNotNull(sf);
210:                    QName fc = sf.getFaultCodeAsQName();
211:                    Iterator i = sf.getFaultReasonTexts();
212:
213:                    String reason = "";
214:                    while (i.hasNext()) {
215:                        reason += (String) i.next();
216:                    }
217:                    log.info("Actual ReasonText=" + reason);
218:                    assertNotNull(reason);
219:                    assertTrue(reason.indexOf("This is the fault reason.") > -1);
220:                    assertTrue(fc.equals(SOAPConstants.SOAP_RECEIVER_FAULT));
221:                } catch (SOAPException e) {
222:                    //Caught expected SOAPException
223:                } catch (Exception e) {
224:                    fail("Exception: " + e);
225:                }
226:            }
227:
228:            /** for soap 1.1 */
229:            public void testSOAPFaultException1() {
230:                try {
231:                    SOAPFactory factory = SOAPFactory
232:                            .newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
233:                    SOAPFault fault = factory.createFault(
234:                            "This is the fault reason.", new QName(
235:                                    "http://MyNamespaceURI.org/",
236:                                    "My Fault Code"));
237:                } catch (UnsupportedOperationException e) {
238:                    //Caught expected UnsupportedOperationException
239:                } catch (SOAPException e) {
240:                    //Caught expected SOAPException
241:                } catch (IllegalArgumentException e) {
242:                    //Caught expected IllegalArgumentException
243:                } catch (Exception e) {
244:                    fail("Exception: " + e);
245:                }
246:            }
247:
248:            /** for soap 1.2 */
249:            public void testSOAPFaultException2() {
250:                try {
251:                    SOAPFactory factory = SOAPFactory
252:                            .newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
253:                    SOAPFault sf = factory.createFault(
254:                            "This is the fault reason.", new QName(
255:                                    "http://MyNamespaceURI.org/",
256:                                    "My Fault Code"));
257:                    fail("Did not throw expected SOAPException");
258:                } catch (UnsupportedOperationException e) {
259:                    //Caught expected UnsupportedOperationException
260:                } catch (SOAPException e) {
261:                    //Caught expected SOAPException
262:                } catch (IllegalArgumentException e) {
263:                    //Caught expected IllegalArgumentException
264:                } catch (Exception e) {
265:                    fail("Exception: " + e);
266:                }
267:            }
268:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.