001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)TestWsdlReader.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.sun.jbi.wsdl2.impl;
030:
031: import com.sun.jbi.wsdl2.Description;
032: import com.sun.jbi.wsdl2.Definitions;
033: import com.sun.jbi.wsdl2.WsdlException;
034:
035: /**
036: * Unit tests for the WSDL factory.
037: *
038: * @author Sun Microsystems Inc.
039: */
040: public class TestWsdlReader extends junit.framework.TestCase {
041: /** Reader to be used in various tests */
042: private com.sun.jbi.wsdl2.WsdlReader mReader = null;
043:
044: /** Old system property value for java.protocol.handler.pkgs */
045: private String mOldJavaProtocolHandlerPkgs = null;
046:
047: /**
048: * Set up for each test.
049: *
050: * @exception Exception when set up fails for any reason. This tells JUnit
051: * that it cannot run the test.
052: */
053: public void setUp() throws Exception {
054: super .setUp();
055:
056: com.sun.jbi.wsdl2.WsdlFactory factory = WsdlFactory
057: .newInstance();
058:
059: this .mReader = factory.newWsdlReader();
060:
061: this .mOldJavaProtocolHandlerPkgs = System.setProperty(
062: "java.protocol.handler.pkgs", "com.sun.jbi.wsdl2.impl");
063: }
064:
065: /**
066: * Clean up after each test case.
067: *
068: * @exception Exception when clean up fails for any reason.
069: */
070: public void tearDown() throws Exception {
071: if (this .mOldJavaProtocolHandlerPkgs != null) {
072: System.setProperty("java.protocol.handler.pkgs",
073: this .mOldJavaProtocolHandlerPkgs);
074: }
075: }
076:
077: /**
078: * Test creation of a WsldFactory instance.
079: *
080: * @exception Exception when any unexpected error occurs.
081: */
082: public void testReadFromUri() throws Exception {
083: //
084: // First pass -- read a non-WSDL (but still XML) file.
085: //
086: try {
087: Description defs = mReader
088: .readDescription("test:///notwsdl.wsdl");
089: assertTrue(false); // If we get here, the reader failed to object.
090:
091: Definitions defs1 = mReader
092: .readWsdl("test:///notwsdl.wsdl");
093: assertTrue(false); // If we get here, the reader failed to object.
094: } catch (WsdlException ex) {
095: String msg = ex.getMessage();
096: ex.printStackTrace();
097: assertTrue(true); // We got some sort of objection!
098: System.out.println(msg);
099: assertTrue(msg
100: .indexOf("The document is not a description@http://www.w3.org/") != -1);
101: }
102:
103: //
104: // Second pass -- read a valid WSDL file
105: //
106: Description defs = mReader
107: .readDescription("test:///test1.wsdl");
108: assertTrue(defs != null);
109:
110: Definitions defs1 = mReader.readWsdl("test:///test1.wsdl");
111: assertTrue(defs1 != null);
112: }
113:
114: /**
115: * Test reading a WSDL document from the wrong namespace.
116: *
117: * @exception Exception when any unexpected error occurs.
118: */
119: public void testReadFromWrongNamespace() throws Exception {
120: try {
121: Description defs = mReader
122: .readDescription("test:///test2.wsdl");
123: assertTrue(false); // If we get here, the reader failed to object
124:
125: Definitions defs1 = mReader.readWsdl("test:///test2.wsdl");
126: assertTrue(false); // If we get here, the reader failed to object
127: } catch (WsdlException ex) {
128: String msg = ex.getMessage();
129:
130: assertTrue(true); // We got some sort of objection!
131: System.out.println(msg);
132: assertTrue(msg
133: .indexOf("document element namespace mismatch") != -1);
134: }
135: }
136:
137: /**
138: * Test reading an ill-formed WSDL document.
139: *
140: * @exception Exception when any unexpected error occurs.
141: */
142: public void testReadIllFormed() throws Exception {
143: try {
144: Description defs = mReader
145: .readDescription("test:///test3.wsdl");
146: assertTrue(false); // If we get here, the reader failed to object
147:
148: // Definitions defs1 = mReader.readWsdl("test:///test3.wsdl");
149: // assertTrue(false); // If we get here, the reader failed to object
150: } catch (WsdlException ex) {
151: String msg = ex.getMessage();
152: assertTrue(true); // We got some sort of objection!
153: System.out.println(msg);
154: assertTrue(msg.indexOf("</service>") != -1);
155: }
156: }
157:
158: /**
159: * Test reading an invalid WSDL document.
160: *
161: * @exception Exception when any unexpected error occurs.
162: */
163: public void testInvalid() throws Exception {
164: try {
165: Description defs = mReader
166: .readDescription("test:///test4.wsdl");
167: assertTrue(false); // If we get here, the reader failed to object
168:
169: Definitions defs1 = mReader.readWsdl("test:///test4.wsdl");
170: assertTrue(false); // If we get here, the reader failed to object
171: } catch (WsdlException ex) {
172: String msg = ex.getMessage();
173:
174: assertTrue(true); // We got some sort of objection!
175: System.out.println(msg);
176: assertTrue(msg
177: .indexOf("instead of 'operation@http://www.w3.org/ns/wsdl'") != -1);
178: }
179: }
180:
181: /**
182: * Test creation of a WsldFactory instance.
183: *
184: * @exception Exception when any unexpected error occurs.
185: */
186: public void testReadFromUriForBackwardCompatibility()
187: throws Exception {
188: //
189: // pass -- read a valid WSDL file, but with namespace of x2006x01 version
190: //
191: Description defs = mReader
192: .readDescription("test:///test5.wsdl");
193: assertTrue(defs != null);
194:
195: Definitions defs1 = mReader.readWsdl("test:///test5.wsdl");
196: assertTrue(defs1 != null);
197: }
198: }
|