You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by mm...@apache.org on 2007/05/21 04:12:45 UTC
svn commit: r539994 [1/2] - in /incubator/cxf/trunk:
common/common/src/main/java/org/apache/cxf/helpers/
tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/
tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/...
Author: mmao
Date: Sun May 20 19:12:43 2007
New Revision: 539994
URL: http://svn.apache.org/viewvc?view=rev&rev=539994
Log:
CXF-647, CXF-645, CXF-513
* wsdlvalidator improvement
* wsdlValidator support wsdl import, schema import
* Fix stax2dom util, which previous not support attribute namespace, and has duplicate wsdl:definitions
* Introduce a validation model which is XPath based, and will report the failure point also based on XPath
* Fix an NEP in WSIBPValidator
* WSDLRefValidator support both errors and warnings
Added:
incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/ValidationResult.java
incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/WSDLRefValidator.java
incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/
incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/FailureLocation.java
incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XBinding.java
incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XDef.java
incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XFault.java
incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XInput.java
incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XMessage.java
incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XNode.java
incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XOperation.java
incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XOutput.java
incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XPort.java
incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XPortType.java
incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XService.java
incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XWsdl.java
incubator/cxf/trunk/tools/validator/src/test/java/org/apache/cxf/tools/validator/internal/
incubator/cxf/trunk/tools/validator/src/test/java/org/apache/cxf/tools/validator/internal/SchemaValidatorTest.java.bak
incubator/cxf/trunk/tools/validator/src/test/java/org/apache/cxf/tools/validator/internal/Stax2DOMTest.java
incubator/cxf/trunk/tools/validator/src/test/java/org/apache/cxf/tools/validator/internal/WSDL11ValidatorTest.java
incubator/cxf/trunk/tools/validator/src/test/java/org/apache/cxf/tools/validator/internal/WSDLRefValidatorTest.java
incubator/cxf/trunk/tools/validator/src/test/java/org/apache/cxf/tools/validator/internal/model/
incubator/cxf/trunk/tools/validator/src/test/java/org/apache/cxf/tools/validator/internal/model/XNodeTest.java
incubator/cxf/trunk/tools/validator/src/test/java/org/apache/cxf/tools/validator/internal/resources/
incubator/cxf/trunk/tools/validator/src/test/java/org/apache/cxf/tools/validator/internal/resources/NoTypeRef.wsdl
incubator/cxf/trunk/tools/validator/src/test/java/org/apache/cxf/tools/validator/internal/resources/a.wsdl
incubator/cxf/trunk/tools/validator/src/test/java/org/apache/cxf/tools/validator/internal/resources/b.wsdl
incubator/cxf/trunk/tools/validator/src/test/java/org/apache/cxf/tools/validator/internal/resources/c.xsd
incubator/cxf/trunk/tools/validator/src/test/java/org/apache/cxf/tools/validator/internal/resources/optionspt.wsdl
incubator/cxf/trunk/tools/validator/src/test/java/org/apache/cxf/tools/validator/internal/resources/physicalpt.wsdl
incubator/cxf/trunk/tools/validator/src/test/java/org/apache/cxf/tools/validator/internal/resources/schemapt.xsd
Removed:
incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/WSDLElementReferenceValidator.java
Modified:
incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/XPathUtils.java
incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/Messages.properties
incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/SchemaValidator.java
incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/Stax2DOM.java
incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/WSDL11Validator.java
incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/WSIBPValidator.java
incubator/cxf/trunk/tools/validator/src/test/java/org/apache/cxf/tools/validator/WSDLValidationTest.java
Modified: incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/XPathUtils.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/XPathUtils.java?view=diff&rev=539994&r1=539993&r2=539994
==============================================================================
--- incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/XPathUtils.java (original)
+++ incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/XPathUtils.java Sun May 20 19:12:43 2007
@@ -52,6 +52,10 @@
return null;
}
}
+
+ public boolean isExist(String xpathExpression, Node node, QName type) {
+ return getValue(xpathExpression, node, type) != null;
+ }
class MapNamespaceContext implements NamespaceContext {
private Map<String, String> namespaces;
Modified: incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/Messages.properties
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/Messages.properties?view=diff&rev=539994&r1=539993&r2=539994
==============================================================================
--- incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/Messages.properties (original)
+++ incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/Messages.properties Sun May 20 19:12:43 2007
@@ -25,4 +25,12 @@
RESOLVE_SCHEMA = Resolve schema {1} from baseURI: {2}, namespace: {0}
RESOLVE_FROM_REMOTE = Load and resolve schema from remote host {0}
-RESOLVE_FROM_LOCAL = Load and resolve schema from local file {0}
\ No newline at end of file
+RESOLVE_FROM_LOCAL = Load and resolve schema from local file {0}
+
+PART_NO_TYPES = The part does not have a type defined. Every part must specify a type from some type system. The type can be specified using the built in 'element' or 'type' attributes or may be specified using an extension attribute.
+
+PART_NOT_UNIQUE = The part has both an element and a type defined. Every part must only have an element or a type defined.
+
+TYPE_REF_NOT_FOUND = Part <{1}> in Message <{0}> referenced Type <{2}> can not be found in the schemas
+
+FAILED_AT_POINT = {2}:[{0},{1}] \n Caused by {3} not exist.
\ No newline at end of file
Modified: incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/SchemaValidator.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/SchemaValidator.java?view=diff&rev=539994&r1=539993&r2=539994
==============================================================================
--- incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/SchemaValidator.java (original)
+++ incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/SchemaValidator.java Sun May 20 19:12:43 2007
@@ -31,6 +31,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Stack;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.wsdl.WSDLException;
@@ -212,6 +213,7 @@
SAXSource saxSource = new SAXSource(saxParser.getXMLReader(), wsdlsource);
validator.validate(saxSource);
+
if (!errHandler.isValid()) {
throw new ToolException(errHandler.getErrorMessages());
}
@@ -229,14 +231,34 @@
throw new ToolException(e);
}
- WSDLElementReferenceValidator wsdlRefValidator = new
- WSDLElementReferenceValidator(def, this,
- wsdlsource.getSystemId(), document);
-
+ WSDLRefValidator wsdlRefValidator = new WSDLRefValidator(wsdlsource.getSystemId(), document);
isValid = wsdlRefValidator.isValid();
if (!isValid) {
- throw new ToolException(this.getErrorMessage());
+ StringBuffer sb = new StringBuffer();
+ sb.append(wsdlRefValidator.getClass().getName());
+ sb.append("\n Summary: ");
+ sb.append(" Failures: ");
+ Stack<String> errors = wsdlRefValidator.getValidationResults().getErrors();
+ sb.append(errors.size());
+ Stack<String> warnings = wsdlRefValidator.getValidationResults().getWarnings();
+ sb.append(", Warnings: ");
+ sb.append(warnings.size());
+ if (errors.size() > 0) {
+ sb.append("\n\n <<< ERROR! \n");
+ while (!errors.empty()) {
+ sb.append(errors.pop());
+ sb.append("\n");
+ }
+ }
+ if (warnings.size() > 0) {
+ sb.append("\n <<< WARNING! \n");
+ while (!warnings.empty()) {
+ sb.append(warnings.pop());
+ sb.append("\n");
+ }
+ }
+ throw new ToolException(sb.toString());
}
isValid = true;
Modified: incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/Stax2DOM.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/Stax2DOM.java?view=diff&rev=539994&r1=539993&r2=539994
==============================================================================
--- incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/Stax2DOM.java (original)
+++ incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/Stax2DOM.java Sun May 20 19:12:43 2007
@@ -19,20 +19,26 @@
package org.apache.cxf.tools.validator.internal;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
import java.util.Iterator;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
import javax.xml.stream.events.Attribute;
+import javax.xml.stream.events.Namespace;
import javax.xml.stream.events.StartElement;
import javax.xml.stream.events.XMLEvent;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.apache.cxf.common.util.StringUtils;
+import org.apache.cxf.helpers.XMLUtils;
import org.apache.cxf.tools.common.ToolException;
import org.apache.cxf.tools.common.WSDLConstants;
@@ -40,62 +46,106 @@
private Element currentElement;
private Document doc;
-
+ private XMLInputFactory factory;
+ private XMLEventReader reader;
+
+ public Stax2DOM() {
+ }
- public Document getDocument(XMLEventReader xmlEventReader) throws ToolException {
+ private void init() {
+ try {
+ factory = XMLInputFactory.newInstance();
+ factory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, true);
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new ToolException(e);
+ }
+ }
+
+ public Document getDocument(File wsdl) throws ToolException {
+ if (reader == null) {
+ init();
+ try {
+ reader = factory.createXMLEventReader(new FileReader(wsdl));
+ } catch (FileNotFoundException fe) {
+ throw new ToolException("Cannot get the wsdl " + wsdl, fe);
+ } catch (XMLStreamException e) {
+ throw new ToolException(e);
+ }
- DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
- builderFactory.setNamespaceAware(true);
- DocumentBuilder builder = null;
+ }
+ return getDocument(reader, wsdl);
+ }
+
+ public Document getDocument(XMLEventReader xmlEventReader) throws ToolException {
+ return getDocument(xmlEventReader, null);
+ }
+
+ public Document getDocument(XMLEventReader xmlEventReader, File wsdlurl) throws ToolException {
try {
- builder = builderFactory.newDocumentBuilder();
- } catch (ParserConfigurationException e1) {
- throw new ToolException(e1);
- }
- doc = builder.newDocument();
-
- Element ele = doc.createElement("definitions");
- doc.appendChild(ele);
- currentElement = ele;
+ doc = XMLUtils.newDocument();
+ } catch (ParserConfigurationException e) {
+ throw new ToolException(e);
+ }
+ doc.setDocumentURI(wsdlurl.toString());
+
+ currentElement = doc.getDocumentElement();
while (xmlEventReader.hasNext()) {
XMLEvent xmleve = (XMLEvent)xmlEventReader.next();
if (xmleve.getEventType() == XMLStreamConstants.END_ELEMENT) {
-
endElement();
-
}
if (xmleve.getEventType() == XMLStreamConstants.START_ELEMENT) {
- StartElement element = (StartElement)xmleve;
- startElement(element);
-
+ startElement((StartElement)xmleve);
}
-
}
-
return doc;
}
public void startElement(StartElement ele) {
-
- Element element = doc.createElementNS(ele.getName().getNamespaceURI(), ele.getName().getLocalPart());
+ Element element = null;
+ element = doc.createElementNS(ele.getName().getNamespaceURI(), ele.getName().getLocalPart());
+
Iterator ite = ele.getAttributes();
while (ite.hasNext()) {
Attribute attr = (Attribute)ite.next();
element.setAttribute(attr.getName().getLocalPart(), attr.getValue());
}
-
- currentElement.appendChild(element);
+
+ String xmlns = "http://schemas.xmlsoap.org/wsdl/";
+ ite = ele.getNamespaces();
+ while (ite.hasNext()) {
+ Namespace ns = (Namespace) ite.next();
+ String name = ns.getPrefix();
+ if (!StringUtils.isEmpty(name)) {
+ element.setAttributeNS(xmlns, name, ns.getNamespaceURI());
+ } else {
+ xmlns = ns.getNamespaceURI();
+ }
+ }
+
+ if (currentElement == null) {
+ doc.appendChild(element);
+ } else {
+ currentElement.appendChild(element);
+ }
+
currentElement = element;
element.setUserData(WSDLConstants.NODE_LOCATION, ele.getLocation(), null);
}
public void endElement() {
- currentElement = (Element)currentElement.getParentNode();
+ Node node = currentElement.getParentNode();
+ if (node instanceof Document) {
+ currentElement = ((Document)node).getDocumentElement();
+ } else {
+ currentElement = (Element)currentElement.getParentNode();
+ }
}
}
Added: incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/ValidationResult.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/ValidationResult.java?view=auto&rev=539994
==============================================================================
--- incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/ValidationResult.java (added)
+++ incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/ValidationResult.java Sun May 20 19:12:43 2007
@@ -0,0 +1,53 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.tools.validator.internal;
+
+import java.util.Stack;
+import org.apache.cxf.common.i18n.Message;
+
+public final class ValidationResult {
+
+ private Stack<String> errors = new Stack<String>();
+ private Stack<String> warnings = new Stack<String>();
+
+ public Stack<String> getErrors() {
+ return this.errors;
+ }
+
+ public Stack<String> getWarnings() {
+ return this.warnings;
+ }
+
+ public void addError(final Message msg) {
+ addError(msg.toString());
+ }
+
+ public void addError(final String error) {
+ this.errors.push(error);
+ }
+
+ public void addWarning(final String warning) {
+ this.warnings.push(warning);
+ }
+
+ public boolean isSuccessful() {
+ return errors.size() == 0 && warnings.size() == 0;
+ }
+}
Modified: incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/WSDL11Validator.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/WSDL11Validator.java?view=diff&rev=539994&r1=539993&r2=539994
==============================================================================
--- incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/WSDL11Validator.java (original)
+++ incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/WSDL11Validator.java Sun May 20 19:12:43 2007
@@ -87,7 +87,6 @@
validators.add(new UniqueBodyPartsValidator(this.def));
validators.add(new WSIBPValidator(this.def));
validators.add(new MIMEBindingValidator(this.def));
- //validators.add(new XMLFormatValidator(this.def));
for (AbstractValidator validator : validators) {
if (!validator.isValid()) {
Added: incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/WSDLRefValidator.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/WSDLRefValidator.java?view=auto&rev=539994
==============================================================================
--- incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/WSDLRefValidator.java (added)
+++ incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/WSDLRefValidator.java Sun May 20 19:12:43 2007
@@ -0,0 +1,508 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.tools.validator.internal;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.logging.Logger;
+import javax.wsdl.Binding;
+import javax.wsdl.BindingOperation;
+import javax.wsdl.Definition;
+import javax.wsdl.Fault;
+import javax.wsdl.Operation;
+import javax.wsdl.Part;
+import javax.wsdl.Port;
+import javax.wsdl.PortType;
+import javax.wsdl.Service;
+import javax.xml.namespace.QName;
+import javax.xml.stream.Location;
+import javax.xml.xpath.XPathConstants;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+
+import org.apache.cxf.common.i18n.Message;
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.common.util.StringUtils;
+import org.apache.cxf.helpers.XPathUtils;
+import org.apache.cxf.tools.common.ToolException;
+import org.apache.cxf.tools.common.WSDLConstants;
+import org.apache.cxf.tools.util.URIParserUtil;
+import org.apache.cxf.tools.validator.internal.model.FailureLocation;
+import org.apache.cxf.tools.validator.internal.model.XBinding;
+import org.apache.cxf.tools.validator.internal.model.XDef;
+import org.apache.cxf.tools.validator.internal.model.XFault;
+import org.apache.cxf.tools.validator.internal.model.XInput;
+import org.apache.cxf.tools.validator.internal.model.XMessage;
+import org.apache.cxf.tools.validator.internal.model.XNode;
+import org.apache.cxf.tools.validator.internal.model.XOperation;
+import org.apache.cxf.tools.validator.internal.model.XOutput;
+import org.apache.cxf.tools.validator.internal.model.XPort;
+import org.apache.cxf.tools.validator.internal.model.XPortType;
+import org.apache.cxf.tools.validator.internal.model.XService;
+import org.apache.cxf.wsdl11.WSDLDefinitionBuilder;
+import org.apache.ws.commons.schema.XmlSchemaCollection;
+import org.apache.ws.commons.schema.XmlSchemaElement;
+import org.apache.ws.commons.schema.XmlSchemaType;
+
+
+public class WSDLRefValidator {
+ protected static final Logger LOG = LogUtils.getL7dLogger(WSDLRefValidator.class);
+ protected List<XNode> vNodes = new ArrayList<XNode>();
+
+ private Set<QName> portTypeRefNames = new HashSet<QName>();
+ private Set<QName> messageRefNames = new HashSet<QName>();
+
+ private ValidationResult vResults = new ValidationResult();
+
+ private Definition definition;
+
+ private List<Definition> importedDefinitions;
+ private List<XmlSchemaCollection> schemas;
+ private XmlSchemaCollection schemaCollection = new XmlSchemaCollection();
+
+ public WSDLRefValidator() {
+ }
+
+ public WSDLRefValidator(final String wsdl) {
+ this(wsdl, null);
+ }
+
+ public WSDLRefValidator(final String wsdl, final Document doc) {
+ WSDLDefinitionBuilder wsdlBuilder = new WSDLDefinitionBuilder();
+ try {
+ this.definition = wsdlBuilder.build(wsdl);
+
+ if (wsdlBuilder.getImportedDefinitions().size() > 0) {
+ importedDefinitions = new ArrayList<Definition>();
+ importedDefinitions.addAll(wsdlBuilder.getImportedDefinitions());
+ }
+ } catch (Exception e) {
+ throw new ToolException(e);
+ }
+
+ try {
+ Document document = doc == null ? getWSDLDocument() : doc;
+ schemas = ValidatorUtil.getSchemaList(document, definition.getDocumentBaseURI());
+ } catch (IOException ex) {
+ throw new ToolException("Cannot get schema list " + definition.getDocumentBaseURI(), ex);
+ } catch (Exception ex) {
+ throw new ToolException(ex);
+ }
+ }
+
+ public ValidationResult getValidationResults() {
+ return this.vResults;
+ }
+
+ private File getWSDLFile(String location) throws URISyntaxException {
+ return new File(new URI(URIParserUtil.getAbsoluteURI(location)));
+ }
+
+ private Document getWSDLDocument(final String wsdl) throws URISyntaxException {
+ return new Stax2DOM().getDocument(getWSDLFile(wsdl));
+ }
+
+ private Document getWSDLDocument() throws Exception {
+ return getWSDLDocument(this.definition.getDocumentBaseURI());
+ }
+
+ private List<Document> getWSDLDocuments() {
+ List<Document> docs = new ArrayList<Document>();
+ try {
+ docs.add(getWSDLDocument());
+
+ if (null != importedDefinitions) {
+ for (Definition d : importedDefinitions) {
+ docs.add(getWSDLDocument(d.getDocumentBaseURI()));
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ // ignore
+ }
+
+ return docs;
+ }
+
+ private boolean isExist(List<Document> docs, XNode vNode) {
+ XPathUtils xpather = new XPathUtils(vNode.getNSMap());
+ String expression = vNode.toString();
+ for (Document doc : docs) {
+ if (xpather.isExist(expression, doc, XPathConstants.NODE)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private FailureLocation getFailureLocation(List<Document> docs, XNode fNode) {
+ if (fNode == null) {
+ return null;
+ }
+
+ XPathUtils xpather = new XPathUtils(fNode.getNSMap());
+ for (Document doc : docs) {
+ Node node = (Node) xpather.getValue(fNode.toString(), doc, XPathConstants.NODE);
+ if (null != node) {
+ return new FailureLocation((Location)node.getUserData(WSDLConstants.NODE_LOCATION),
+ doc.getBaseURI());
+ }
+ }
+ return null;
+ }
+
+ public boolean isValid() {
+ try {
+
+ collectValidationPoints();
+
+ List<Document> wsdlDocs = getWSDLDocuments();
+
+ for (XNode vNode : vNodes) {
+
+ if (!isExist(wsdlDocs, vNode)) {
+ FailureLocation loc = getFailureLocation(wsdlDocs, vNode.getFailurePoint());
+ vResults.addError(new Message("FAILED_AT_POINT",
+ LOG,
+ loc.getLocation().getLineNumber(),
+ loc.getLocation().getColumnNumber(),
+ loc.getDocumentURI(),
+ vNode.getPlainText()));
+ }
+ }
+ } catch (ToolException e) {
+ this.vResults.addError(e.getMessage());
+ return false;
+ }
+ return vResults.isSuccessful();
+ }
+
+ public void setDefinition(final Definition def) {
+ this.definition = def;
+ }
+
+ private Map<QName, Service> getServices() {
+ Map<QName, Service> services = new HashMap<QName, Service>();
+ Iterator sNames = definition.getAllServices().keySet().iterator();
+ while (sNames.hasNext()) {
+ QName sName = (QName) sNames.next();
+ services.put(sName, definition.getService(sName));
+ }
+ return services;
+ }
+
+ private Map<QName, XNode> getBindings(Service service) {
+ Map<QName, XNode> bindings = new HashMap<QName, XNode>();
+
+ if (service.getPorts().values().size() == 0) {
+ throw new ToolException("Service " + service.getQName() + " does not contain any usable ports");
+ }
+ Iterator portIte = service.getPorts().values().iterator();
+ while (portIte.hasNext()) {
+ Port port = (Port)portIte.next();
+ Binding binding = port.getBinding();
+ bindings.put(binding.getQName(), getXNode(service, port));
+ if (WSDLConstants.NS_WSDL.equals(binding.getQName().getNamespaceURI())) {
+ throw new ToolException("Binding "
+ + binding.getQName().getLocalPart()
+ + " namespace set improperly.");
+ }
+ }
+
+ return bindings;
+ }
+
+ private Map<QName, Operation> getOperations(PortType portType) {
+ Map<QName, Operation> operations = new HashMap<QName, Operation>();
+ for (Iterator iter = portType.getOperations().iterator(); iter.hasNext();) {
+ Operation op = (Operation) iter.next();
+ operations.put(new QName(portType.getQName().getNamespaceURI(), op.getName()), op);
+ }
+ return operations;
+ }
+
+ private XNode getXNode(Service service, Port port) {
+ XNode vService = getXNode(service);
+
+ XPort pNode = new XPort();
+ pNode.setName(port.getName());
+ pNode.setParentNode(vService);
+ return pNode;
+ }
+
+ private XNode getXNode(Service service) {
+ XDef xdef = new XDef();
+ xdef.setTargetNamespace(service.getQName().getNamespaceURI());
+
+ XService sNode = new XService();
+ sNode.setName(service.getQName().getLocalPart());
+ sNode.setParentNode(xdef);
+ return sNode;
+ }
+
+ private XNode getXNode(Binding binding) {
+ XDef xdef = new XDef();
+ xdef.setTargetNamespace(binding.getQName().getNamespaceURI());
+
+ XBinding bNode = new XBinding();
+ bNode.setName(binding.getQName().getLocalPart());
+ bNode.setParentNode(xdef);
+ return bNode;
+ }
+
+ private XNode getXNode(PortType portType) {
+ XDef xdef = new XDef();
+ xdef.setTargetNamespace(portType.getQName().getNamespaceURI());
+
+ XPortType pNode = new XPortType();
+ pNode.setName(portType.getQName().getLocalPart());
+ pNode.setParentNode(xdef);
+ return pNode;
+ }
+
+ private XNode getOperationXNode(XNode pNode, String opName) {
+ XOperation node = new XOperation();
+ node.setName(opName);
+ node.setParentNode(pNode);
+ return node;
+ }
+
+ private XNode getInputXNode(XNode opVNode, String name) {
+ XInput oNode = new XInput();
+ oNode.setName(name);
+ oNode.setParentNode(opVNode);
+ return oNode;
+ }
+
+ private XNode getOutputXNode(XNode opVNode, String name) {
+ XOutput oNode = new XOutput();
+ oNode.setName(name);
+ oNode.setParentNode(opVNode);
+ return oNode;
+ }
+
+ private XNode getFaultXNode(XNode opVNode, String name) {
+ XFault oNode = new XFault();
+ oNode.setName(name);
+ oNode.setParentNode(opVNode);
+ return oNode;
+ }
+
+ private XNode getXNode(javax.wsdl.Message msg) {
+ XDef xdef = new XDef();
+ xdef.setTargetNamespace(msg.getQName().getNamespaceURI());
+
+ XMessage mNode = new XMessage();
+ mNode.setName(msg.getQName().getLocalPart());
+ mNode.setParentNode(xdef);
+ return mNode;
+ }
+
+ private void collectValidationPoints() {
+ if (getServices().size() == 0) {
+ throw new ToolException("WSDL document does not define any services");
+ }
+ Map<QName, XNode> vBindingNodes = new HashMap<QName, XNode>();
+ for (Service service : getServices().values()) {
+ vBindingNodes.putAll(getBindings(service));
+ }
+
+ for (QName bName : vBindingNodes.keySet()) {
+ Binding binding = this.definition.getBinding(bName);
+ XNode vBindingNode = getXNode(binding);
+ vBindingNode.setFailurePoint(vBindingNodes.get(bName));
+ vNodes.add(vBindingNode);
+
+ if (binding.getPortType() == null) {
+ continue;
+ }
+ portTypeRefNames.add(binding.getPortType().getQName());
+
+ XNode vPortTypeNode = getXNode(binding.getPortType());
+ vPortTypeNode.setFailurePoint(vBindingNode);
+ vNodes.add(vPortTypeNode);
+ for (Iterator iter = binding.getBindingOperations().iterator(); iter.hasNext();) {
+ BindingOperation bop = (BindingOperation) iter.next();
+ XNode vOpNode = getOperationXNode(vPortTypeNode, bop.getName());
+ XNode vBopNode = getOperationXNode(vBindingNode, bop.getName());
+ vOpNode.setFailurePoint(vBopNode);
+ vNodes.add(vOpNode);
+ String inName = bop.getBindingInput().getName();
+ if (!StringUtils.isEmpty(inName)) {
+ XNode vInputNode = getInputXNode(vOpNode, inName);
+ vInputNode.setFailurePoint(getInputXNode(vBopNode, inName));
+ vNodes.add(vInputNode);
+ }
+ if (bop.getBindingOutput() != null) {
+ String outName = bop.getBindingOutput().getName();
+ if (!StringUtils.isEmpty(outName)) {
+ XNode vOutputNode = getOutputXNode(vOpNode, outName);
+ vOutputNode.setFailurePoint(getOutputXNode(vBopNode, outName));
+ vNodes.add(vOutputNode);
+ }
+ }
+ for (Iterator iter1 = bop.getBindingFaults().keySet().iterator(); iter1.hasNext();) {
+ String faultName = (String) iter1.next();
+ XNode vFaultNode = getFaultXNode(vOpNode, faultName);
+ vFaultNode.setFailurePoint(getFaultXNode(vBopNode, faultName));
+ vNodes.add(vFaultNode);
+ }
+ }
+ }
+
+ collectValidationPointsForPortTypes();
+ collectValidationPointsForMessages();
+ }
+
+ private void collectValidationPointsForMessages() {
+ for (QName msgName : messageRefNames) {
+ javax.wsdl.Message message = this.definition.getMessage(msgName);
+ for (Iterator iter = message.getParts().values().iterator(); iter.hasNext();) {
+ Part part = (Part) iter.next();
+ QName elementName = part.getElementName();
+ QName typeName = part.getTypeName();
+
+ if (elementName == null && typeName == null) {
+ vResults.addError(new Message("PART_NO_TYPES", LOG));
+ continue;
+ }
+
+ if (elementName != null && typeName != null) {
+ vResults.addError(new Message("PART_NOT_UNIQUE", LOG));
+ continue;
+ }
+
+ if (elementName != null && typeName == null) {
+ boolean valid = validatePartType(elementName.getNamespaceURI(),
+ elementName.getLocalPart(), true);
+ if (!valid) {
+ vResults.addError(new Message("TYPE_REF_NOT_FOUND", LOG, message.getQName(),
+ part.getName(), elementName));
+ }
+
+ }
+ if (typeName != null && elementName == null) {
+
+ boolean valid = validatePartType(typeName.getNamespaceURI(),
+ typeName.getLocalPart(),
+ false);
+
+ if (!valid) {
+ vResults.addError(new Message("TYPE_REF_NOT_FOUND", LOG, message.getQName(),
+ part.getName(), typeName));
+ }
+
+ }
+
+
+ }
+ }
+ }
+
+ private void collectValidationPointsForPortTypes() {
+ for (QName ptName : portTypeRefNames) {
+ PortType portType = this.definition.getPortType(ptName);
+ XNode vPortTypeNode = getXNode(portType);
+ for (Operation operation : getOperations(portType).values()) {
+ XNode vOperationNode = getOperationXNode(vPortTypeNode, operation.getName());
+ javax.wsdl.Message inMsg = operation.getInput().getMessage();
+ if (inMsg == null) {
+ vResults.addWarning("Operation " + operation.getName() + " in PortType: "
+ + portType.getQName() + " has no input message");
+ } else {
+ XNode vInMsgNode = getXNode(inMsg);
+ vInMsgNode.setFailurePoint(getInputXNode(vOperationNode, operation.getInput().getName()));
+ vNodes.add(vInMsgNode);
+ messageRefNames.add(inMsg.getQName());
+ }
+
+ if (operation.getOutput() != null) {
+ javax.wsdl.Message outMsg = operation.getOutput().getMessage();
+
+ if (outMsg == null) {
+ vResults.addWarning("Operation " + operation.getName() + " in PortType: "
+ + portType.getQName() + " has no output message");
+ } else {
+ XNode vOutMsgNode = getXNode(outMsg);
+ vOutMsgNode.setFailurePoint(getOutputXNode(vOperationNode,
+ operation.getOutput().getName()));
+ vNodes.add(vOutMsgNode);
+ messageRefNames.add(outMsg.getQName());
+ }
+ }
+ for (Iterator iter = operation.getFaults().values().iterator(); iter.hasNext();) {
+ Fault fault = (Fault) iter.next();
+ javax.wsdl.Message faultMsg = fault.getMessage();
+ XNode vFaultMsgNode = getXNode(faultMsg);
+ vFaultMsgNode.setFailurePoint(getFaultXNode(vOperationNode, fault.getName()));
+ vNodes.add(vFaultMsgNode);
+ messageRefNames.add(faultMsg.getQName());
+ }
+ }
+ }
+ }
+
+ private boolean validatePartType(String namespace, String name, boolean isElement) {
+
+ boolean partvalid = false;
+
+ if (namespace.equals(WSDLConstants.NS_XMLNS)) {
+ if (isElement) {
+ XmlSchemaElement schemaEle =
+ schemaCollection.getElementByQName(new QName(WSDLConstants.NS_XMLNS, name));
+ partvalid = schemaEle != null ? true : false;
+ } else {
+ XmlSchemaType schemaType =
+ schemaCollection.getTypeByQName(new QName(WSDLConstants.NS_XMLNS, name));
+ partvalid = schemaType != null ? true : false;
+ }
+
+ } else {
+ if (isElement) {
+ for (XmlSchemaCollection schema : schemas) {
+ if (schema != null && schema.getElementByQName(
+ new QName(namespace, name)) != null) {
+ partvalid = true;
+ break;
+ }
+ }
+ } else {
+ for (XmlSchemaCollection schema : schemas) {
+ if (schema != null && schema.getTypeByQName(
+ new QName(namespace, name)) != null) {
+ partvalid = true;
+ break;
+ }
+ }
+ }
+ }
+ return partvalid;
+ }
+}
Modified: incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/WSIBPValidator.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/WSIBPValidator.java?view=diff&rev=539994&r1=539993&r2=539994
==============================================================================
--- incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/WSIBPValidator.java (original)
+++ incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/WSIBPValidator.java Sun May 20 19:12:43 2007
@@ -104,6 +104,9 @@
}
private boolean checkR2717AndR2726(final BindingOperation bop) {
+ if (null == bop) {
+ return true;
+ }
SoapBody inSoapBody = SOAPBindingUtil.getBindingInputSOAPBody(bop);
SoapBody outSoapBody = SOAPBindingUtil.getBindingOutputSOAPBody(bop);
if (inSoapBody != null && StringUtils.isEmpty(inSoapBody.getNamespaceURI())
Added: incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/FailureLocation.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/FailureLocation.java?view=auto&rev=539994
==============================================================================
--- incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/FailureLocation.java (added)
+++ incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/FailureLocation.java Sun May 20 19:12:43 2007
@@ -0,0 +1,50 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.tools.validator.internal.model;
+
+import javax.xml.stream.Location;
+
+public final class FailureLocation {
+
+ private Location location;
+
+ private String documentURI;
+
+ public FailureLocation(Location loc, String docURI) {
+ this.location = loc;
+ this.documentURI = docURI;
+ }
+
+ public Location getLocation() {
+ return location;
+ }
+
+ public void setLocation(final Location newLocation) {
+ this.location = newLocation;
+ }
+
+ public String getDocumentURI() {
+ return documentURI;
+ }
+
+ public void setDocumentURI(final String newDocumentURI) {
+ this.documentURI = newDocumentURI;
+ }
+}
Added: incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XBinding.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XBinding.java?view=auto&rev=539994
==============================================================================
--- incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XBinding.java (added)
+++ incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XBinding.java Sun May 20 19:12:43 2007
@@ -0,0 +1,30 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.tools.validator.internal.model;
+
+import org.apache.cxf.tools.common.WSDLConstants;
+
+public final class XBinding extends XWsdl {
+
+ public XBinding() {
+ super();
+ setQName(WSDLConstants.QNAME_BINDING);
+ }
+}
Added: incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XDef.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XDef.java?view=auto&rev=539994
==============================================================================
--- incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XDef.java (added)
+++ incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XDef.java Sun May 20 19:12:43 2007
@@ -0,0 +1,44 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.tools.validator.internal.model;
+
+import org.apache.cxf.tools.common.WSDLConstants;
+
+public final class XDef extends XWsdl {
+
+ public XDef() {
+ super();
+ setQName(WSDLConstants.QNAME_DEFINITIONS);
+ }
+
+ public void setTargetNamespace(final String newTargetNamespace) {
+ setAttributeName("targetNamespace");
+ setAttributeValue(newTargetNamespace);
+ }
+
+ @Override
+ public String getText() {
+ StringBuffer sb = new StringBuffer();
+ sb.append("{");
+ sb.append(getAttributeValue());
+ sb.append("}");
+ return sb.toString();
+ }
+}
Added: incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XFault.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XFault.java?view=auto&rev=539994
==============================================================================
--- incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XFault.java (added)
+++ incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XFault.java Sun May 20 19:12:43 2007
@@ -0,0 +1,29 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.tools.validator.internal.model;
+
+import org.apache.cxf.tools.common.WSDLConstants;
+
+public final class XFault extends XWsdl {
+ public XFault() {
+ super();
+ setQName(WSDLConstants.QNAME_FAULT);
+ }
+}
Added: incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XInput.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XInput.java?view=auto&rev=539994
==============================================================================
--- incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XInput.java (added)
+++ incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XInput.java Sun May 20 19:12:43 2007
@@ -0,0 +1,29 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.tools.validator.internal.model;
+
+import org.apache.cxf.tools.common.WSDLConstants;
+
+public final class XInput extends XWsdl {
+ public XInput() {
+ super();
+ setQName(WSDLConstants.QNAME_INPUT);
+ }
+}
Added: incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XMessage.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XMessage.java?view=auto&rev=539994
==============================================================================
--- incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XMessage.java (added)
+++ incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XMessage.java Sun May 20 19:12:43 2007
@@ -0,0 +1,29 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.tools.validator.internal.model;
+
+import org.apache.cxf.tools.common.WSDLConstants;
+
+public final class XMessage extends XWsdl {
+ public XMessage() {
+ super();
+ setQName(WSDLConstants.QNAME_MESSAGE);
+ }
+}
Added: incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XNode.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XNode.java?view=auto&rev=539994
==============================================================================
--- incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XNode.java (added)
+++ incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XNode.java Sun May 20 19:12:43 2007
@@ -0,0 +1,153 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.tools.validator.internal.model;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Stack;
+import javax.xml.namespace.QName;
+
+import org.apache.cxf.common.util.StringUtils;
+
+public class XNode {
+
+ private String prefix;
+ private QName name;
+ private String attributeName;
+ private String attributeValue;
+ private XNode parentNode;
+
+ private XNode failurePoint;
+
+ private Map<String, String> nsMap = new HashMap<String, String>();
+
+ public void setFailurePoint(XNode point) {
+ this.failurePoint = point;
+ }
+
+ public XNode getFailurePoint() {
+ return this.failurePoint;
+ }
+
+ public String getPrefix() {
+ return prefix;
+ }
+
+ public void setPrefix(final String newPrefix) {
+ this.prefix = newPrefix;
+ }
+
+ public QName getQName() {
+ return name;
+ }
+
+ public void setQName(final QName newName) {
+ this.name = newName;
+ }
+
+ public String getAttributeName() {
+ return attributeName;
+ }
+
+ public void setAttributeName(final String newAttributeName) {
+ this.attributeName = newAttributeName;
+ }
+
+ public String getAttributeValue() {
+ return attributeValue;
+ }
+
+ public void setAttributeValue(final String newAttributeValue) {
+ this.attributeValue = newAttributeValue;
+ }
+
+ public XNode getParentNode() {
+ return parentNode;
+ }
+
+ public void setParentNode(final XNode newParentNode) {
+ this.parentNode = newParentNode;
+ }
+
+ public Map<String, String> getNSMap() {
+ return nsMap;
+ }
+
+ public String getText() {
+ StringBuffer sb = new StringBuffer();
+ sb.append("[");
+ sb.append(name.getLocalPart());
+ sb.append(":");
+ sb.append(getAttributeValue());
+ sb.append("]");
+ return sb.toString();
+ }
+
+ public String getPlainText() {
+ StringBuffer sb = new StringBuffer();
+ Stack<XNode> parentNodes = getParentNodes();
+ while (!parentNodes.empty()) {
+ sb.append(parentNodes.pop().getText());
+ }
+ sb.append(getText());
+ nsMap.put(prefix, name.getNamespaceURI());
+ return sb.toString();
+ }
+
+ public String getXPath() {
+ StringBuffer sb = new StringBuffer();
+ sb.append("/");
+ sb.append(prefix);
+ sb.append(":");
+ sb.append(name.getLocalPart());
+ if (!StringUtils.isEmpty(attributeName) && !StringUtils.isEmpty(attributeValue)) {
+ sb.append("[@");
+ sb.append(attributeName);
+ sb.append("='");
+ sb.append(attributeValue);
+ sb.append("']");
+ }
+ return sb.toString();
+ }
+
+ private Stack<XNode> getParentNodes() {
+ Stack<XNode> parentNodes = new Stack<XNode>();
+
+ XNode pNode = getParentNode();
+ while (pNode != null) {
+ nsMap.put(pNode.getPrefix(),
+ pNode.getQName().getNamespaceURI());
+ parentNodes.push(pNode);
+ pNode = pNode.getParentNode();
+ }
+ return parentNodes;
+ }
+
+ public String toString() {
+ Stack<XNode> parentNodes = getParentNodes();
+ StringBuffer sb = new StringBuffer();
+ while (!parentNodes.empty()) {
+ sb.append(parentNodes.pop().getXPath());
+ }
+ sb.append(getXPath());
+ nsMap.put(prefix, name.getNamespaceURI());
+ return sb.toString();
+ }
+}
Added: incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XOperation.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XOperation.java?view=auto&rev=539994
==============================================================================
--- incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XOperation.java (added)
+++ incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XOperation.java Sun May 20 19:12:43 2007
@@ -0,0 +1,29 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.tools.validator.internal.model;
+
+import org.apache.cxf.tools.common.WSDLConstants;
+
+public final class XOperation extends XWsdl {
+ public XOperation() {
+ super();
+ setQName(WSDLConstants.QNAME_OPERATION);
+ }
+}
Added: incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XOutput.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XOutput.java?view=auto&rev=539994
==============================================================================
--- incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XOutput.java (added)
+++ incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XOutput.java Sun May 20 19:12:43 2007
@@ -0,0 +1,29 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.tools.validator.internal.model;
+
+import org.apache.cxf.tools.common.WSDLConstants;
+
+public final class XOutput extends XWsdl {
+ public XOutput() {
+ super();
+ setQName(WSDLConstants.QNAME_OUTPUT);
+ }
+}
Added: incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XPort.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XPort.java?view=auto&rev=539994
==============================================================================
--- incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XPort.java (added)
+++ incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XPort.java Sun May 20 19:12:43 2007
@@ -0,0 +1,30 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.tools.validator.internal.model;
+
+import org.apache.cxf.tools.common.WSDLConstants;
+
+public final class XPort extends XWsdl {
+
+ public XPort() {
+ super();
+ setQName(WSDLConstants.QNAME_PORT);
+ }
+}
Added: incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XPortType.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XPortType.java?view=auto&rev=539994
==============================================================================
--- incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XPortType.java (added)
+++ incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XPortType.java Sun May 20 19:12:43 2007
@@ -0,0 +1,29 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.tools.validator.internal.model;
+
+import org.apache.cxf.tools.common.WSDLConstants;
+
+public final class XPortType extends XWsdl {
+ public XPortType() {
+ super();
+ setQName(WSDLConstants.QNAME_PORT_TYPE);
+ }
+}
Added: incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XService.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XService.java?view=auto&rev=539994
==============================================================================
--- incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XService.java (added)
+++ incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XService.java Sun May 20 19:12:43 2007
@@ -0,0 +1,30 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.tools.validator.internal.model;
+
+import org.apache.cxf.tools.common.WSDLConstants;
+
+public final class XService extends XWsdl {
+
+ public XService() {
+ super();
+ setQName(WSDLConstants.QNAME_SERVICE);
+ }
+}
Added: incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XWsdl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XWsdl.java?view=auto&rev=539994
==============================================================================
--- incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XWsdl.java (added)
+++ incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XWsdl.java Sun May 20 19:12:43 2007
@@ -0,0 +1,33 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.tools.validator.internal.model;
+
+
+public class XWsdl extends XNode {
+
+ public XWsdl() {
+ setPrefix("wsdl");
+ }
+
+ public void setName(final String newName) {
+ setAttributeName("name");
+ setAttributeValue(newName);
+ }
+}
Modified: incubator/cxf/trunk/tools/validator/src/test/java/org/apache/cxf/tools/validator/WSDLValidationTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/validator/src/test/java/org/apache/cxf/tools/validator/WSDLValidationTest.java?view=diff&rev=539994&r1=539993&r2=539994
==============================================================================
--- incubator/cxf/trunk/tools/validator/src/test/java/org/apache/cxf/tools/validator/WSDLValidationTest.java (original)
+++ incubator/cxf/trunk/tools/validator/src/test/java/org/apache/cxf/tools/validator/WSDLValidationTest.java Sun May 20 19:12:43 2007
@@ -89,10 +89,9 @@
String[] args = new String[] {"-verbose",
getLocation("/validator_wsdl/hello_world_error_reference.wsdl")};
WSDLValidator.main(args);
- assertTrue("Reference error should be discovered: " + getStdErr(),
- getStdErr().indexOf("reference binding is not defined") > -1);
-
-
+ assertTrue(getStdErr().indexOf("[147,3]") != -1);
+ assertTrue(getStdErr().indexOf("Caused by {http://apache.org/hello_world_soap_http}"
+ + "[binding:Greeter_SOAPBinding1] not exist.") != -1);
} catch (Exception e) {
e.printStackTrace();
}
Added: incubator/cxf/trunk/tools/validator/src/test/java/org/apache/cxf/tools/validator/internal/SchemaValidatorTest.java.bak
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/validator/src/test/java/org/apache/cxf/tools/validator/internal/SchemaValidatorTest.java.bak?view=auto&rev=539994
==============================================================================
--- incubator/cxf/trunk/tools/validator/src/test/java/org/apache/cxf/tools/validator/internal/SchemaValidatorTest.java.bak (added)
+++ incubator/cxf/trunk/tools/validator/src/test/java/org/apache/cxf/tools/validator/internal/SchemaValidatorTest.java.bak Sun May 20 19:12:43 2007
@@ -0,0 +1,53 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.tools.validator.internal;
+
+import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.Ignore;
+
+public class SchemaValidatorTest extends TestCase {
+
+ @Ignore
+ public void testWSDLImport1() throws Exception {
+ String wsdlSource = getClass().getResource("resources/a.wsdl").toURI().toString();
+ SchemaValidator validator = new SchemaValidator(null);
+ try {
+ assertFalse(validator.validate(wsdlSource, null));
+ fail("should fail, a.wsdl is not a valid wsdl");
+ } catch (Exception e) {
+ System.err.println(e.getMessage());
+ // ok
+ }
+ }
+
+
+ @Ignore
+ public void testWSDLImport2() throws Exception {
+ String wsdlSource = getClass().getResource("resources/physicalpt.wsdl").toURI().toString();
+ SchemaValidator validator = new SchemaValidator(null);
+ try {
+ assertTrue(validator.validate(wsdlSource, null));
+ } catch (Exception e) {
+ System.err.println(e.getMessage());
+ fail("physicalpt.wsdl is a valid wsdl");
+ }
+ }
+}
Added: incubator/cxf/trunk/tools/validator/src/test/java/org/apache/cxf/tools/validator/internal/Stax2DOMTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/validator/src/test/java/org/apache/cxf/tools/validator/internal/Stax2DOMTest.java?view=auto&rev=539994
==============================================================================
--- incubator/cxf/trunk/tools/validator/src/test/java/org/apache/cxf/tools/validator/internal/Stax2DOMTest.java (added)
+++ incubator/cxf/trunk/tools/validator/src/test/java/org/apache/cxf/tools/validator/internal/Stax2DOMTest.java Sun May 20 19:12:43 2007
@@ -0,0 +1,38 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.tools.validator.internal;
+
+import java.io.File;
+
+import org.w3c.dom.Document;
+
+import junit.framework.TestCase;
+import org.apache.cxf.helpers.XMLUtils;
+
+public class Stax2DOMTest extends TestCase {
+
+ public void testGetDocument() throws Exception {
+ File wsdl = new File(getClass().getResource("/validator_wsdl/jms_test.wsdl").toURI());
+ Document doc = new Stax2DOM().getDocument(wsdl);
+ String content = XMLUtils.toString(doc);
+ assertTrue(content.indexOf("xmlns:ns0=\"http://www.w3.org/2001/XMLSchema\"") != -1);
+ assertTrue(content.indexOf("ns0:x1=\"http://cxf.apache.org/hello_world_jms/types\"") != -1);
+ }
+}
Added: incubator/cxf/trunk/tools/validator/src/test/java/org/apache/cxf/tools/validator/internal/WSDL11ValidatorTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/validator/src/test/java/org/apache/cxf/tools/validator/internal/WSDL11ValidatorTest.java?view=auto&rev=539994
==============================================================================
--- incubator/cxf/trunk/tools/validator/src/test/java/org/apache/cxf/tools/validator/internal/WSDL11ValidatorTest.java (added)
+++ incubator/cxf/trunk/tools/validator/src/test/java/org/apache/cxf/tools/validator/internal/WSDL11ValidatorTest.java Sun May 20 19:12:43 2007
@@ -0,0 +1,43 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.tools.validator.internal;
+
+import junit.framework.TestCase;
+import org.apache.cxf.tools.common.ToolConstants;
+import org.apache.cxf.tools.common.ToolContext;
+import org.junit.Test;
+
+public class WSDL11ValidatorTest extends TestCase {
+ private ToolContext context = new ToolContext();
+
+ @Test
+ public void testWSDLImport() throws Exception {
+ String wsdlSource = getClass().getResource("resources/a.wsdl").toURI().toString();
+ context.put(ToolConstants.CFG_WSDLURL, wsdlSource);
+ WSDL11Validator validator = new WSDL11Validator(null, context);
+ try {
+ assertFalse(validator.isValid());
+ } catch (Exception e) {
+ System.err.println(e.getMessage());
+ assertTrue(e.getMessage().indexOf("Caused by {http://apache.org/hello_world/messages}"
+ + "[portType:GreeterA][operation:sayHi] not exist.") != -1);
+ }
+ }
+}
Added: incubator/cxf/trunk/tools/validator/src/test/java/org/apache/cxf/tools/validator/internal/WSDLRefValidatorTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/validator/src/test/java/org/apache/cxf/tools/validator/internal/WSDLRefValidatorTest.java?view=auto&rev=539994
==============================================================================
--- incubator/cxf/trunk/tools/validator/src/test/java/org/apache/cxf/tools/validator/internal/WSDLRefValidatorTest.java (added)
+++ incubator/cxf/trunk/tools/validator/src/test/java/org/apache/cxf/tools/validator/internal/WSDLRefValidatorTest.java Sun May 20 19:12:43 2007
@@ -0,0 +1,94 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.tools.validator.internal;
+
+import java.io.File;
+import java.util.HashSet;
+import java.util.Set;
+
+import junit.framework.TestCase;
+import org.apache.cxf.common.i18n.Message;
+import org.apache.cxf.tools.validator.internal.model.XNode;
+import org.junit.Test;
+
+public class WSDLRefValidatorTest extends TestCase {
+
+ @Test
+ public void testNoService() throws Exception {
+ String wsdl = getClass().getResource("resources/b.wsdl").toURI().toString();
+ WSDLRefValidator validator = new WSDLRefValidator(wsdl);
+ assertFalse(validator.isValid());
+ ValidationResult results = validator.getValidationResults();
+ assertEquals(1, results.getErrors().size());
+ String t = results.getErrors().pop();
+ assertEquals("WSDL document does not define any services", t);
+ }
+
+ @Test
+ public void testWSDLImport1() throws Exception {
+ String wsdl = getClass().getResource("resources/a.wsdl").toURI().toString();
+ WSDLRefValidator validator = new WSDLRefValidator(wsdl);
+ validator.isValid();
+ ValidationResult results = validator.getValidationResults();
+ assertEquals(2, results.getErrors().size());
+ String t = results.getErrors().pop();
+ String text = "{http://apache.org/hello_world/messages}[portType:GreeterA][operation:sayHi]";
+ Message msg = new Message("FAILED_AT_POINT",
+ WSDLRefValidator.LOG,
+ 8,
+ 2,
+ new File(new java.net.URI(wsdl)).toString(),
+ text);
+ assertEquals(msg.toString(), t);
+ }
+
+
+ @Test
+ public void testWSDLImport2() throws Exception {
+ String wsdl = getClass().getResource("resources/physicalpt.wsdl").toURI().toString();
+ WSDLRefValidator validator = new WSDLRefValidator(wsdl);
+ assertTrue(validator.isValid());
+ String expected = "/wsdl:definitions[@targetNamespace='http://schemas.apache.org/yoko/idl/OptionsPT']"
+ + "/wsdl:portType[@name='foo.bar']";
+
+ Set<String> xpath = new HashSet<String>();
+
+ for (XNode node : validator.vNodes) {
+ xpath.add(node.toString());
+ }
+ assertTrue(xpath.contains(expected));
+ }
+
+ @Test
+ public void testNoTeypRef() throws Exception {
+ String wsdl = getClass().getResource("resources/NoTypeRef.wsdl").toURI().toString();
+ WSDLRefValidator validator = new WSDLRefValidator(wsdl);
+ assertFalse(validator.isValid());
+ assertEquals(3, validator.getValidationResults().getErrors().size());
+
+ String t = validator.getValidationResults().getErrors().pop();
+
+ String expected = "Part <header_info> in Message "
+ + "<{http://apache.org/samples/headers}inHeaderRequest>"
+ + " referenced Type <{http://apache.org/samples/headers}SOAPHeaderInfo> "
+ + "can not be found in the schemas";
+ assertEquals(expected, t);
+ }
+}
Added: incubator/cxf/trunk/tools/validator/src/test/java/org/apache/cxf/tools/validator/internal/model/XNodeTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/validator/src/test/java/org/apache/cxf/tools/validator/internal/model/XNodeTest.java?view=auto&rev=539994
==============================================================================
--- incubator/cxf/trunk/tools/validator/src/test/java/org/apache/cxf/tools/validator/internal/model/XNodeTest.java (added)
+++ incubator/cxf/trunk/tools/validator/src/test/java/org/apache/cxf/tools/validator/internal/model/XNodeTest.java Sun May 20 19:12:43 2007
@@ -0,0 +1,58 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.tools.validator.internal.model;
+
+import junit.framework.TestCase;
+import org.apache.cxf.tools.common.WSDLConstants;
+
+public class XNodeTest extends TestCase {
+ public void testGetXPath() {
+ XNode node = new XNode();
+ node.setQName(WSDLConstants.QNAME_BINDING);
+ node.setPrefix("wsdl");
+ node.setAttributeName("name");
+ node.setAttributeValue("SOAPBinding");
+ assertEquals("/wsdl:binding[@name='SOAPBinding']", node.toString());
+ assertEquals("[binding:SOAPBinding]", node.getPlainText());
+ }
+
+ public void testParentNode() {
+ XDef definition = new XDef();
+ String ns = "{http://apache.org/hello_world/messages}";
+ definition.setTargetNamespace("http://apache.org/hello_world/messages");
+ assertEquals(ns, definition.getPlainText());
+
+ XPortType portType = new XPortType();
+ portType.setName("Greeter");
+ portType.setParentNode(definition);
+
+ String portTypeText = ns + "[portType:Greeter]";
+ assertEquals(portTypeText, portType.getPlainText());
+
+ XOperation op = new XOperation();
+ op.setName("sayHi");
+ op.setParentNode(portType);
+ assertEquals(portTypeText + "[operation:sayHi]", op.getPlainText());
+
+ String expected = "/wsdl:definitions[@targetNamespace='http://apache.org/hello_world/messages']";
+ expected += "/wsdl:portType[@name='Greeter']/wsdl:operation[@name='sayHi']";
+ assertEquals(expected, op.toString());
+ }
+}
Added: incubator/cxf/trunk/tools/validator/src/test/java/org/apache/cxf/tools/validator/internal/resources/NoTypeRef.wsdl
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/validator/src/test/java/org/apache/cxf/tools/validator/internal/resources/NoTypeRef.wsdl?view=auto&rev=539994
==============================================================================
--- incubator/cxf/trunk/tools/validator/src/test/java/org/apache/cxf/tools/validator/internal/resources/NoTypeRef.wsdl (added)
+++ incubator/cxf/trunk/tools/validator/src/test/java/org/apache/cxf/tools/validator/internal/resources/NoTypeRef.wsdl Sun May 20 19:12:43 2007
@@ -0,0 +1,76 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<definitions name="soap_header" targetNamespace="http://apache.org/samples/headers"
+ xmlns="http://schemas.xmlsoap.org/wsdl/"
+ xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
+ xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
+ xmlns:tns="http://apache.org/samples/headers"
+ xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+ <types>
+ <schema targetNamespace="http://apache.org/samples/headers"
+ xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
+
+ <complexType name="SOAPHeaderData">
+ <sequence>
+ <element maxOccurs="1" minOccurs="1" name="originator" type="string"/>
+ <element maxOccurs="1" minOccurs="1" name="message" type="string"/>
+ </sequence>
+ </complexType>
+ </schema>
+ </types>
+
+ <message name="inHeaderRequest">
+ <part element="tns:inHeader" name="me"/>
+ <part element="tns:SOAPHeaderInfo" name="header_info"/>
+ </message>
+ <message name="inHeaderResponse">
+ <part element="tns:inHeaderResponse" name="the_response"/>
+ </message>
+ <portType name="headerTester">
+ <operation name="inHeader">
+ <input message="tns:inHeaderRequest" name="inHeaderRequest"/>
+ <output message="tns:inHeaderResponse" name="inHeaderResponse"/>
+ </operation>
+ </portType>
+
+ <binding name="headerTesterSOAPBinding" type="tns:headerTester">
+ <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
+ <operation name="inHeader">
+ <soap:operation soapAction="" style="document"/>
+ <input name="inHeaderRequest">
+ <soap:body parts="me" use="literal"/>
+ <soap:header message="tns:inHeaderRequest" part="header_info"
+ use="literal"/>
+ </input>
+ <output name="inHeaderResponse">
+ <soap:body use="literal"/>
+ </output>
+ </operation>
+ </binding>
+
+ <service name="HeaderService">
+ <port binding="tns:headerTesterSOAPBinding" name="SoapPort">
+ <soap:address location="http://localhost:9000/headers"/>
+ </port>
+ </service>
+</definitions>