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.internal;
019:
020: import java.io.File;
021: import java.util.HashSet;
022: import java.util.Set;
023:
024: import org.apache.cxf.common.i18n.Message;
025: import org.apache.cxf.tools.common.ToolException;
026: import org.apache.cxf.tools.validator.internal.model.XNode;
027: import org.junit.Assert;
028: import org.junit.Test;
029:
030: public class WSDLRefValidatorTest extends Assert {
031:
032: @Test
033: public void testNoService() throws Exception {
034: String wsdl = getClass().getResource("resources/b.wsdl")
035: .toURI().toString();
036: WSDLRefValidator validator = new WSDLRefValidator(wsdl);
037: assertFalse(validator.isValid());
038: ValidationResult results = validator.getValidationResults();
039: assertEquals(1, results.getWarnings().size());
040: String t = results.getWarnings().pop();
041: assertEquals("WSDL document does not define any services", t);
042: }
043:
044: @Test
045: public void testWSDLImport1() throws Exception {
046: String wsdl = getClass().getResource("resources/a.wsdl")
047: .toURI().toString();
048: WSDLRefValidator validator = new WSDLRefValidator(wsdl);
049: validator.isValid();
050: ValidationResult results = validator.getValidationResults();
051: assertEquals(2, results.getErrors().size());
052: String t = results.getErrors().pop();
053: String text = "{http://apache.org/hello_world/messages}[portType:GreeterA][operation:sayHi]";
054: Message msg = new Message("FAILED_AT_POINT",
055: WSDLRefValidator.LOG, 27, 2, new File(new java.net.URI(
056: wsdl)).toString(), text);
057: assertEquals(msg.toString(), t);
058: }
059:
060: @Test
061: public void testWSDLImport2() throws Exception {
062: String wsdl = getClass().getResource(
063: "resources/physicalpt.wsdl").toURI().toString();
064: WSDLRefValidator validator = new WSDLRefValidator(wsdl);
065: assertTrue(validator.isValid());
066: String expected = "/wsdl:definitions[@targetNamespace='http://schemas.apache.org/yoko/idl/OptionsPT']"
067: + "/wsdl:portType[@name='foo.bar']";
068:
069: Set<String> xpath = new HashSet<String>();
070:
071: for (XNode node : validator.vNodes) {
072: xpath.add(node.toString());
073: }
074: assertTrue(xpath.contains(expected));
075: }
076:
077: @Test
078: public void testNoTypeRef() throws Exception {
079: String wsdl = getClass()
080: .getResource("resources/NoTypeRef.wsdl").toURI()
081: .toString();
082: WSDLRefValidator validator = new WSDLRefValidator(wsdl);
083: assertFalse(validator.isValid());
084: assertEquals(3, validator.getValidationResults().getErrors()
085: .size());
086:
087: String expected = "Part <header_info> in Message "
088: + "<{http://apache.org/samples/headers}inHeaderRequest>"
089: + " referenced Type <{http://apache.org/samples/headers}SOAPHeaderInfo> "
090: + "can not be found in the schemas";
091: String t = null;
092: while (!validator.getValidationResults().getErrors().empty()) {
093: t = validator.getValidationResults().getErrors().pop();
094: if (expected.equals(t)) {
095: break;
096: }
097: }
098: assertEquals(expected, t);
099: }
100:
101: @Test
102: public void testNoBindingWSDL() throws Exception {
103: String wsdl = getClass()
104: .getResource("resources/nobinding.wsdl").toURI()
105: .toString();
106: WSDLRefValidator validator = new WSDLRefValidator(wsdl);
107: validator.isValid();
108: ValidationResult results = validator.getValidationResults();
109:
110: assertEquals(1, results.getWarnings().size());
111: String t = results.getWarnings().pop();
112: assertEquals("WSDL document does not define any services", t);
113:
114: WSDLRefValidator v = new WSDLRefValidator(wsdl);
115: v.setSuppressWarnings(true);
116: assertTrue(v.isValid());
117: }
118:
119: @Test
120: public void testLogicalWSDL() throws Exception {
121: String wsdl = getClass().getResource("resources/logical.wsdl")
122: .toURI().toString();
123: WSDLRefValidator validator = new WSDLRefValidator(wsdl);
124: validator.isValid();
125: ValidationResult results = validator.getValidationResults();
126:
127: assertEquals(1, results.getErrors().size());
128: String text = "{http://schemas.apache.org/yoko/idl/OptionsPT}[message:getEmployee]";
129: Message msg = new Message("FAILED_AT_POINT",
130: WSDLRefValidator.LOG, 42, 6, new File(new java.net.URI(
131: wsdl)).toString(), text);
132: assertEquals(msg.toString(), results.getErrors().pop());
133: }
134:
135: @Test
136: public void testNotAWsdl() throws Exception {
137: String wsdl = getClass().getResource("resources/c.xsd").toURI()
138: .toString();
139: try {
140: WSDLRefValidator validator = new WSDLRefValidator(wsdl);
141: validator.isValid();
142: } catch (Exception e) {
143: assertTrue(e instanceof ToolException);
144: String expected = "WSDLException (at /xs:schema): faultCode=INVALID_WSDL: "
145: + "Expected element '{http://schemas.xmlsoap.org/wsdl/}definitions'.";
146: assertEquals(expected, e.getMessage());
147: }
148: }
149: }
|