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: */package org.apache.cxf.tools.validator;
019:
020: import java.io.File;
021: import java.net.URL;
022: import java.util.Enumeration;
023:
024: import org.apache.cxf.tools.common.ToolTestBase;
025: import org.junit.Before;
026: import org.junit.Test;
027:
028: public class WSDLValidationTest extends ToolTestBase {
029: @Before
030: public void setUp() {
031: super .setUp();
032: }
033:
034: @Test
035: public void testValidateUniqueBody() {
036: try {
037:
038: String[] args = new String[] { "-verbose",
039: getLocation("/validator_wsdl/doc_lit_bare.wsdl") };
040: WSDLValidator.main(args);
041: assertTrue(
042: "Non Unique Body Parts Error should be discovered: "
043: + getStdErr(), getStdErr().indexOf(
044: "Non unique body part") > -1);
045: } catch (Exception e) {
046: e.printStackTrace();
047: }
048: }
049:
050: @Test
051: public void testValidateMixedStyle() {
052: try {
053:
054: String[] args = new String[] {
055: "-verbose",
056: getLocation("/validator_wsdl/hello_world_mixed_style.wsdl") };
057: WSDLValidator.main(args);
058: assertTrue(
059: "Mixed style. Error should have been discovered: "
060: + getStdErr(), getStdErr().indexOf(
061: "Mixed style, invalid WSDL") > -1);
062:
063: } catch (Exception e) {
064: e.printStackTrace();
065: }
066: }
067:
068: @Test
069: public void testValidateTypeElement() {
070: try {
071:
072: String[] args = new String[] {
073: "-verbose",
074: getLocation("/validator_wsdl/hello_world_doc_lit_type.wsdl") };
075: WSDLValidator.main(args);
076: assertTrue(
077: "Must refer to type element error should have been discovered: "
078: + getStdErr(), getStdErr().indexOf(
079: "using the element attribute") > -1);
080: } catch (Exception e) {
081: e.printStackTrace();
082: }
083: }
084:
085: @Test
086: public void testValidateAttribute() {
087: try {
088:
089: String[] args = new String[] {
090: "-verbose",
091: getLocation("/validator_wsdl/hello_world_error_attribute.wsdl") };
092: WSDLValidator.main(args);
093: String expected = "WSDLException (at /wsdl:definitions/wsdl:message[1]/wsdl:part): "
094: + "faultCode=INVALID_WSDL: Encountered illegal extension attribute 'test'. "
095: + "Extension attributes must be in a namespace other than WSDL's";
096: assertTrue("Attribute error should be discovered: "
097: + getStdErr(), getStdErr().indexOf(expected) > -1);
098:
099: } catch (Exception e) {
100: e.printStackTrace();
101: }
102: }
103:
104: @Test
105: public void testValidateReferenceError() throws Exception {
106:
107: try {
108:
109: String[] args = new String[] {
110: "-verbose",
111: getLocation("/validator_wsdl/hello_world_error_reference.wsdl") };
112: WSDLValidator.main(args);
113: assertTrue(getStdErr().indexOf("[147,3]") != -1);
114: assertTrue(getStdErr()
115: .indexOf(
116: "Caused by {http://apache.org/hello_world_soap_http}"
117: + "[binding:Greeter_SOAPBinding1] not exist.") != -1);
118: } catch (Exception e) {
119: e.printStackTrace();
120: }
121: }
122:
123: @Test
124: public void testBug305872() throws Exception {
125: try {
126: String[] args = new String[] { "-verbose",
127: getLocation("/validator_wsdl/bug305872/http.xsd") };
128: WSDLValidator.main(args);
129: String expected = "Expected element '{http://schemas.xmlsoap.org/wsdl/}definitions'.";
130: assertTrue(
131: "Tools should check if this file is a wsdl file: "
132: + getStdErr(), getStdErr()
133: .indexOf(expected) > -1);
134: } catch (Exception e) {
135: e.printStackTrace();
136: }
137:
138: }
139:
140: @Test
141: public void testImportWsdlValidation() throws Exception {
142: try {
143: String[] args = new String[] {
144: "-verbose",
145: getLocation("/validator_wsdl/hello_world_import.wsdl") };
146: WSDLValidator.main(args);
147:
148: assertTrue("Is not valid wsdl!: " + getStdOut(),
149: getStdOut().indexOf("Passed Validation") > -1);
150: } catch (Exception e) {
151: e.printStackTrace();
152: }
153:
154: }
155:
156: @Test
157: public void testImportSchemaValidation() throws Exception {
158: try {
159: String[] args = new String[] {
160: "-verbose",
161: getLocation("/validator_wsdl/hello_world_schema_import.wsdl") };
162: WSDLValidator.main(args);
163:
164: assertTrue("Is not valid wsdl: " + getStdOut(), getStdOut()
165: .indexOf("Passed Validation") > -1);
166: } catch (Exception e) {
167: e.printStackTrace();
168: }
169:
170: }
171:
172: @Test
173: public void testWSIBP2210() throws Exception {
174: try {
175: String[] args = new String[] { "-verbose",
176: getLocation("/validator_wsdl/soapheader.wsdl") };
177: WSDLValidator.main(args);
178: assertTrue(getStdErr().indexOf("WSI-BP-1.0 R2210") > -1);
179: } catch (Exception e) {
180: e.printStackTrace();
181: }
182: }
183:
184: @Test
185: public void testWSIBPR2726() throws Exception {
186: try {
187: String[] args = new String[] { "-verbose",
188: getLocation("/validator_wsdl/jms_test.wsdl") };
189: WSDLValidator.main(args);
190: assertTrue(getStdErr().indexOf("WSI-BP-1.0 R2726") > -1);
191: } catch (Exception e) {
192: e.printStackTrace();
193: }
194: }
195:
196: @Test
197: public void testWSIBPR2205() throws Exception {
198: try {
199: String[] args = new String[] { "-verbose",
200: getLocation("/validator_wsdl/jms_test2.wsdl") };
201: WSDLValidator.main(args);
202: assertTrue(getStdErr().indexOf("WSI-BP-1.0 R2205") > -1);
203: } catch (Exception e) {
204: e.printStackTrace();
205: }
206: }
207:
208: @Test
209: public void testWSIBPR2203() throws Exception {
210: try {
211: String[] args = new String[] { "-verbose",
212: getLocation("/validator_wsdl/header_rpc_lit.wsdl") };
213: WSDLValidator.main(args);
214: assertTrue(getStdOut().indexOf(
215: "Passed Validation : Valid WSDL") > -1);
216: } catch (Exception e) {
217: e.printStackTrace();
218: fail("No exception expected here, header_rpc_lit is a valid wsdl");
219: }
220:
221: try {
222: String[] args = new String[] {
223: "-verbose",
224: getLocation("/validator_wsdl/header_rpc_lit_2203_in.wsdl") };
225: WSDLValidator.main(args);
226: assertTrue(getStdErr()
227: .indexOf(
228: "soapbind:body element(s), only to wsdl:part element(s)") > -1);
229: } catch (Exception e) {
230: e.printStackTrace();
231: }
232:
233: try {
234: String[] args = new String[] {
235: "-verbose",
236: getLocation("/validator_wsdl/header_rpc_lit_2203_out.wsdl") };
237: WSDLValidator.main(args);
238: assertTrue(getStdErr()
239: .indexOf(
240: "soapbind:body element(s), only to wsdl:part element(s)") > -1);
241: } catch (Exception e) {
242: e.printStackTrace();
243: }
244: }
245:
246: @Override
247: protected String getLocation(String wsdlFile) throws Exception {
248: Enumeration<URL> e = WSDLValidationTest.class.getClassLoader()
249: .getResources(wsdlFile);
250: while (e.hasMoreElements()) {
251: URL u = e.nextElement();
252: File f = new File(u.toURI());
253: if (f.exists() && f.isDirectory()) {
254: return f.toString();
255: }
256: }
257:
258: return WSDLValidationTest.class.getResource(wsdlFile).toURI()
259: .getPath();
260: }
261: }
|