You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by dk...@apache.org on 2014/09/17 17:32:46 UTC
svn commit: r1625632 [5/9] - in /webservices/xmlschema/trunk: ./
xmlschema-walker/ xmlschema-walker/src/ xmlschema-walker/src/main/
xmlschema-walker/src/main/java/ xmlschema-walker/src/main/java/org/
xmlschema-walker/src/main/java/org/apache/ xmlschema...
Added: webservices/xmlschema/trunk/xmlschema-walker/src/test/java/org/apache/ws/commons/schema/docpath/ExpectedPathNode.java
URL: http://svn.apache.org/viewvc/webservices/xmlschema/trunk/xmlschema-walker/src/test/java/org/apache/ws/commons/schema/docpath/ExpectedPathNode.java?rev=1625632&view=auto
==============================================================================
--- webservices/xmlschema/trunk/xmlschema-walker/src/test/java/org/apache/ws/commons/schema/docpath/ExpectedPathNode.java (added)
+++ webservices/xmlschema/trunk/xmlschema-walker/src/test/java/org/apache/ws/commons/schema/docpath/ExpectedPathNode.java Wed Sep 17 15:32:44 2014
@@ -0,0 +1,47 @@
+/**
+ * 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.ws.commons.schema.docpath;
+
+import static org.junit.Assert.*;
+
+/**
+ * Represents the expected {@link XmlSchemaPathNode} at a particular link in the
+ * chain.
+ */
+class ExpectedPathNode {
+ ExpectedNode expDocNode;
+ XmlSchemaPathNode.Direction expDirection;
+ int expIteration;
+
+ ExpectedPathNode(XmlSchemaPathNode.Direction expectedDirection, ExpectedNode expectedDocNode,
+ int expectedIteration) {
+ expDocNode = expectedDocNode;
+ expDirection = expectedDirection;
+ expIteration = expectedIteration;
+ }
+
+ void validate(int pathIndex, XmlSchemaPathNode actualPathNode) {
+ assertEquals("Path Index: " + pathIndex, expDirection, actualPathNode.getDirection());
+
+ ExpectedNode.validate("Path Index: " + pathIndex, expDocNode, actualPathNode.getDocumentNode(), null);
+
+ assertEquals("Path Index: " + pathIndex, expIteration, actualPathNode.getIteration());
+ }
+}
Propchange: webservices/xmlschema/trunk/xmlschema-walker/src/test/java/org/apache/ws/commons/schema/docpath/ExpectedPathNode.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/xmlschema/trunk/xmlschema-walker/src/test/java/org/apache/ws/commons/schema/docpath/ExpectedStateMachineNode.java
URL: http://svn.apache.org/viewvc/webservices/xmlschema/trunk/xmlschema-walker/src/test/java/org/apache/ws/commons/schema/docpath/ExpectedStateMachineNode.java?rev=1625632&view=auto
==============================================================================
--- webservices/xmlschema/trunk/xmlschema-walker/src/test/java/org/apache/ws/commons/schema/docpath/ExpectedStateMachineNode.java (added)
+++ webservices/xmlschema/trunk/xmlschema-walker/src/test/java/org/apache/ws/commons/schema/docpath/ExpectedStateMachineNode.java Wed Sep 17 15:32:44 2014
@@ -0,0 +1,61 @@
+/**
+ * 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.ws.commons.schema.docpath;
+
+import static org.junit.Assert.*;
+
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+class ExpectedStateMachineNode {
+ XmlSchemaStateMachineNode.Type expNodeType;
+ ExpectedElement expElem;
+ QName expElemQName;
+ List<ExpectedStateMachineNode> expNextStates;
+
+ ExpectedStateMachineNode(XmlSchemaStateMachineNode.Type expNodeType, QName expElemQName,
+ ExpectedElement expElem) {
+ this.expNodeType = expNodeType;
+ this.expElem = expElem;
+ this.expElemQName = expElemQName;
+ this.expNextStates = new java.util.ArrayList<ExpectedStateMachineNode>();
+ }
+
+ void addNextState(ExpectedStateMachineNode expNextState) {
+ expNextStates.add(expNextState);
+ }
+
+ void validate(XmlSchemaStateMachineNode actualNode) {
+ assertEquals("Expected Type: " + expNodeType + "; actual: " + actualNode.getNodeType(), expNodeType,
+ actualNode.getNodeType());
+
+ if (actualNode.getNodeType().equals(XmlSchemaStateMachineNode.Type.ELEMENT)) {
+ assertEquals("Expected QName: " + expElemQName + "; actual: "
+ + actualNode.getElement().getQName(), expElemQName, actualNode.getElement()
+ .getQName());
+
+ expElem.validate(expElemQName.toString(), actualNode.getElementType());
+ }
+
+ assertEquals(expNodeType.name() + " number of children", expNextStates.size(), actualNode
+ .getPossibleNextStates().size());
+ }
+}
Propchange: webservices/xmlschema/trunk/xmlschema-walker/src/test/java/org/apache/ws/commons/schema/docpath/ExpectedStateMachineNode.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/xmlschema/trunk/xmlschema-walker/src/test/java/org/apache/ws/commons/schema/docpath/TestDomBuilderFromSax.java
URL: http://svn.apache.org/viewvc/webservices/xmlschema/trunk/xmlschema-walker/src/test/java/org/apache/ws/commons/schema/docpath/TestDomBuilderFromSax.java?rev=1625632&view=auto
==============================================================================
--- webservices/xmlschema/trunk/xmlschema-walker/src/test/java/org/apache/ws/commons/schema/docpath/TestDomBuilderFromSax.java (added)
+++ webservices/xmlschema/trunk/xmlschema-walker/src/test/java/org/apache/ws/commons/schema/docpath/TestDomBuilderFromSax.java Wed Sep 17 15:32:44 2014
@@ -0,0 +1,101 @@
+/**
+ * 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.ws.commons.schema.docpath;
+
+import java.io.File;
+import java.io.FileReader;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+import javax.xml.transform.stream.StreamSource;
+
+import org.apache.ws.commons.schema.XmlSchemaCollection;
+import org.apache.ws.commons.schema.docpath.DomBuilderFromSax;
+import org.apache.ws.commons.schema.testutils.UtilsForTests;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.w3c.dom.Document;
+
+public class TestDomBuilderFromSax {
+
+ private static final File TEST_SCHEMA = UtilsForTests.buildFile("src", "test", "resources",
+ "test_schema.xsd");
+
+ private static SAXParserFactory spf;
+ private static DocumentBuilderFactory dbf;
+
+ private SAXParser saxParser;
+ private DocumentBuilder domParser;
+
+ @BeforeClass
+ public static void setUpFactories() {
+ dbf = DocumentBuilderFactory.newInstance();
+ dbf.setNamespaceAware(true);
+
+ spf = SAXParserFactory.newInstance();
+ spf.setNamespaceAware(true);
+ }
+
+ @Before
+ public void setUpTest() throws Exception {
+ saxParser = spf.newSAXParser();
+ domParser = dbf.newDocumentBuilder();
+ }
+
+ @Test
+ public void testRoot() throws Exception {
+ runTest(TEST_SCHEMA, UtilsForTests.buildFile("src", "test", "resources", "test1_root.xml"));
+ }
+
+ @Test
+ public void testChildren() throws Exception {
+ runTest(TEST_SCHEMA, UtilsForTests.buildFile("src", "test", "resources", "test2_children.xml"));
+ }
+
+ @Test
+ public void testGrandchildren() throws Exception {
+ runTest(TEST_SCHEMA, UtilsForTests.buildFile("src", "test", "resources", "test3_grandchildren.xml"));
+ }
+
+ private void runTest(File schemaFile, File xmlFile) throws Exception {
+ XmlSchemaCollection xmlSchemas = new XmlSchemaCollection();
+
+ FileReader schemaFileReader = new FileReader(schemaFile);
+
+ StreamSource schemaSource = new StreamSource(schemaFileReader, schemaFile.getName());
+ xmlSchemas.read(schemaSource);
+
+ schemaFileReader.close();
+
+ // Parse the document using a real DOM parser
+ final Document expectedDoc = domParser.parse(xmlFile);
+
+ // Parse the document using a SAX parser
+ DomBuilderFromSax builder = new DomBuilderFromSax(xmlSchemas);
+ saxParser.parse(xmlFile, builder);
+
+ final Document actualDoc = builder.getDocument();
+
+ UtilsForTests.assertEquivalent(expectedDoc, actualDoc);
+ }
+}
Propchange: webservices/xmlschema/trunk/xmlschema-walker/src/test/java/org/apache/ws/commons/schema/docpath/TestDomBuilderFromSax.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/xmlschema/trunk/xmlschema-walker/src/test/java/org/apache/ws/commons/schema/docpath/TestSaxWalkerOverDom.java
URL: http://svn.apache.org/viewvc/webservices/xmlschema/trunk/xmlschema-walker/src/test/java/org/apache/ws/commons/schema/docpath/TestSaxWalkerOverDom.java?rev=1625632&view=auto
==============================================================================
--- webservices/xmlschema/trunk/xmlschema-walker/src/test/java/org/apache/ws/commons/schema/docpath/TestSaxWalkerOverDom.java (added)
+++ webservices/xmlschema/trunk/xmlschema-walker/src/test/java/org/apache/ws/commons/schema/docpath/TestSaxWalkerOverDom.java Wed Sep 17 15:32:44 2014
@@ -0,0 +1,435 @@
+/**
+ * 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.ws.commons.schema.docpath;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
+import org.w3c.dom.Document;
+import org.xml.sax.Attributes;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+import org.apache.ws.commons.schema.docpath.SaxWalkerOverDom;
+import org.apache.ws.commons.schema.testutils.UtilsForTests;
+import org.junit.Test;
+
+/**
+ * Reads the <code>src/test/resources/test_schema.xsd</code> file as an XML
+ * document and confirms the correct events are triggered.
+ */
+public class TestSaxWalkerOverDom {
+
+ private static class AttrInfo {
+
+ static List<AttrInfo> getAttributesOf(Attributes attrs) {
+ ArrayList<AttrInfo> newAttrs = new ArrayList<AttrInfo>();
+
+ for (int a = 0; a < attrs.getLength(); ++a) {
+ newAttrs.add(new AttrInfo(attrs.getURI(a), attrs.getLocalName(a), attrs.getQName(a), attrs
+ .getValue(a)));
+ }
+
+ return newAttrs;
+ }
+
+ AttrInfo(String ns, String ln, String qn, String v) {
+ namespace = new String(ns);
+ localName = new String(ln);
+ qName = new String(qn);
+ value = new String(v);
+ }
+
+ String namespace;
+ String localName;
+ String qName;
+ String value;
+ }
+
+ private static class StackEntry {
+ enum Type {
+ ELEMENT, TEXT
+ }
+
+ StackEntry(String v) {
+ type = Type.TEXT;
+ value = v;
+ namespace = null;
+ localName = null;
+ qName = null;
+ attributes = null;
+ }
+
+ StackEntry(String ns, String ln, String qn, Attributes attrs) {
+ type = Type.ELEMENT;
+ namespace = ns;
+ localName = ln;
+ qName = qn;
+ attributes = AttrInfo.getAttributesOf(attrs);
+ value = null;
+ }
+
+ boolean equals(String v) {
+ return stringsEqual(value, v);
+ }
+
+ boolean equals(String ns, String ln, String qn, Attributes attrs) {
+ if (!stringsEqual(namespace, ns) || !stringsEqual(localName, ln) || !stringsEqual(qName, qn)
+ || (attributes.size() > attrs.getLength())) {
+ throw new IllegalStateException("Expected element [\"" + namespace + "\", \"" + localName
+ + "\", \"" + qName + "\", " + attributes.size()
+ + " attrs] does not match actual of [\"" + ns + "\", \"" + ln
+ + "\", \"" + qn + "\", " + attrs.getLength() + " attrs].");
+ }
+
+ for (int index = 0; index < attributes.size(); ++index) {
+ AttrInfo attribute = attributes.get(index);
+ final String actual = attrs.getValue(attribute.qName);
+
+ if (!attribute.value.equals(actual)) {
+ return false;
+ }
+
+ if (!attrs.getValue(attribute.namespace, attribute.localName).equals(actual)) {
+ System.err.println("Attribute [\"" + attribute.namespace + "\", \"" + attribute.localName
+ + "\"] has a value of \"" + attribute.value
+ + "\" which does not match the actual value of \"" + actual + "\". ");
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder str = new StringBuilder(type.name());
+ str.append(": ");
+
+ if (type.equals(Type.ELEMENT)) {
+ str.append("namespace=\"").append(namespace);
+ str.append("\", localName=\"").append(localName);
+ str.append("\", qName=\"").append(qName);
+ str.append("\", attributes={ ");
+
+ if (attributes != null) {
+ for (int index = 0; index < attributes.size(); ++index) {
+ AttrInfo attribute = attributes.get(index);
+ str.append("[Attr: namespace=\"").append(attribute.namespace);
+ str.append("\", localName=\"").append(attribute.localName);
+ str.append("\", qName=\"").append(attribute.qName);
+ str.append("\", value=\"").append(attribute.value).append("\"] ");
+ }
+ }
+
+ str.append('}');
+
+ } else if (type.equals(Type.TEXT)) {
+ str.append('\"').append(value).append('\"');
+ }
+
+ return str.toString();
+ }
+
+ private static boolean stringsEqual(String lhs, String rhs) {
+ if (((lhs != null) && (rhs != null) && lhs.equals(rhs)) || ((lhs == null) && (rhs == null))) {
+
+ return true;
+
+ } else {
+ throw new IllegalArgumentException("\"" + lhs + "\" does not match \"" + rhs + "\"");
+ }
+ }
+
+ Type type;
+ String namespace;
+ String localName;
+ String qName;
+ String value;
+ List<AttrInfo> attributes;
+ }
+
+ /**
+ * Used to confirm the {@link SaxWalkerOverDom} walker generates the exact
+ * same events as a real {@link SAXParser}.
+ */
+ private static class ContentValidator implements ContentHandler {
+
+ ContentValidator(List<StackEntry> stack, Map<String, List<String>> prefixMappings) {
+
+ this.stack = stack;
+ this.prefixMappings = prefixMappings;
+ }
+
+ @Override
+ public void startDocument() throws SAXException {
+ }
+
+ @Override
+ public void endDocument() throws SAXException {
+ if (!stack.isEmpty()) {
+ throw new SAXException("Reaced the end of the document early; expected " + stack.size()
+ + " more elements.");
+ }
+ }
+
+ @Override
+ public void startElement(String uri, String localName, String qName, Attributes atts)
+ throws SAXException {
+
+ if (stack.isEmpty()) {
+ throw new SAXException("Element " + toString(uri, localName, qName, atts)
+ + " is not expected; stack is empty!");
+ }
+
+ StackEntry entry = stack.remove(0);
+
+ if (entry.type != StackEntry.Type.ELEMENT) {
+ throw new SAXException("Expected text of (" + entry + ") but received element of ("
+ + toString(uri, localName, qName, atts) + ").");
+ }
+
+ if (!entry.equals(uri, localName, qName, atts)) {
+ throw new SAXException("Expected element (" + entry + ") does not match actual ("
+ + toString(uri, localName, qName, atts) + ").");
+ }
+ }
+
+ @Override
+ public void endElement(String uri, String localName, String qName) throws SAXException {
+ }
+
+ @Override
+ public void characters(char[] ch, int start, int length) throws SAXException {
+
+ final String value = toString(ch, start, length);
+
+ if (stack.isEmpty()) {
+ throw new SAXException("Unexpected string \"" + value + "\"; stack is empty!");
+ }
+
+ StackEntry entry = stack.remove(0);
+
+ if (!entry.type.equals(StackEntry.Type.TEXT)) {
+ throw new SAXException("Unexpected string \"" + value + "\"; was expecting element (" + entry
+ + ").");
+ }
+
+ if (!entry.equals(value)) {
+ throw new SAXException("Expected string \"" + entry + "\" but received \"" + value + "\".");
+ }
+ }
+
+ @Override
+ public void startPrefixMapping(String prefix, String uri) throws SAXException {
+
+ if (!prefixMappings.containsKey(prefix)) {
+ throw new SAXException("Prefix \"" + prefix + "\" and URI \"" + uri + "\" are not expected.");
+ }
+
+ /*
+ * This is a quick and dirty test; in reality the
+ * prefix-to-namespace mapping is only valid if it exists inside the
+ * current scope. That said, keeping track of the scope is a much
+ * more difficult problem.
+ */
+ final List<String> namespaces = prefixMappings.get(prefix);
+ boolean found = false;
+ for (String namespace : namespaces) {
+ if (namespace.equals(uri)) {
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ throw new SAXException("Prefix \"" + prefix + "\" does not have a namespace of \"" + uri
+ + "\".");
+ }
+ }
+
+ @Override
+ public void endPrefixMapping(String prefix) throws SAXException {
+ if (!prefixMappings.containsKey(prefix)) {
+ throw new SAXException("Prefix \"" + prefix + "\" is not expected.");
+ }
+ }
+
+ @Override
+ public void setDocumentLocator(Locator locator) {
+ throw new UnsupportedOperationException("This should not be called.");
+ }
+
+ @Override
+ public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {
+ throw new UnsupportedOperationException("This should not be called.");
+ }
+
+ @Override
+ public void processingInstruction(String target, String data) throws SAXException {
+ throw new UnsupportedOperationException("This should not be called.");
+ }
+
+ @Override
+ public void skippedEntity(String name) throws SAXException {
+ throw new UnsupportedOperationException("This should not be called.");
+ }
+
+ private static String toString(String uri, String localName, String qName, Attributes attrs) {
+
+ StringBuilder str = new StringBuilder("namespace=\"");
+ str.append(uri).append("\", localName=\"").append(localName);
+ str.append("\", qName=\"").append(qName).append("\", attributes={ ");
+
+ for (int index = 0; index < attrs.getLength(); ++index) {
+ str.append("[Attr: namespace=\"").append(attrs.getURI(index));
+ str.append("\", localName=\"").append(attrs.getLocalName(index));
+ str.append("\", qName=\"").append(attrs.getQName(index));
+ str.append("\", value=\"").append(attrs.getValue(index));
+ str.append("\"] ");
+ }
+
+ str.append('}');
+
+ return str.toString();
+ }
+
+ private static String toString(char[] ch, int start, int length) {
+ return new String(ch, start, length);
+ }
+
+ private List<StackEntry> stack;
+ private Map<String, List<String>> prefixMappings;
+ }
+
+ /**
+ * This is traversed by a SAX parser to retrieve the expected SAX events.
+ */
+ private static class StackBuilder extends DefaultHandler {
+
+ public StackBuilder() {
+ stack = new ArrayList<StackEntry>();
+ prefixMappings = new HashMap<String, List<String>>();
+ }
+
+ public ArrayList<StackEntry> getStack() {
+ return stack;
+ }
+
+ public Map<String, List<String>> getPrefixMappings() {
+ return prefixMappings;
+ }
+
+ @Override
+ public void startDocument() throws SAXException {
+ stack.clear();
+ }
+
+ @Override
+ public void startElement(String uri, String localName, String qName, Attributes atts)
+ throws SAXException {
+
+ stack.add(new StackEntry(uri, localName, qName, atts));
+ }
+
+ @Override
+ public void characters(char[] ch, int start, int length) throws SAXException {
+
+ stack.add(new StackEntry(new String(ch, start, length)));
+ }
+
+ @Override
+ public void startPrefixMapping(String prefix, String uri) throws SAXException {
+
+ List<String> mappings = prefixMappings.get(prefix);
+ if (mappings == null) {
+ mappings = new ArrayList<String>(1);
+ prefixMappings.put(prefix, mappings);
+ }
+ mappings.add(uri);
+ }
+
+ private final ArrayList<StackEntry> stack;
+ private final Map<String, List<String>> prefixMappings;
+ }
+
+ @Test
+ public void testRoot() throws Exception {
+ final File xmlFile = UtilsForTests.buildFile("src", "test", "resources", "test1_root.xml");
+ runTest(xmlFile);
+ }
+
+ @Test
+ public void testChildren() throws Exception {
+ final File xmlFile = UtilsForTests.buildFile("src", "test", "resources", "test2_children.xml");
+
+ runTest(xmlFile);
+ }
+
+ @Test
+ public void testGrandchildren() throws Exception {
+ final File xmlFile = UtilsForTests.buildFile("src", "test", "resources", "test3_grandchildren.xml");
+
+ runTest(xmlFile);
+ }
+
+ private static void runTest(File xmlFile) throws Exception {
+ StackBuilder stackBuilder = new StackBuilder();
+
+ // Parse the document using a real SAX parser
+ SAXParserFactory spf = SAXParserFactory.newInstance();
+ spf.setNamespaceAware(true);
+ SAXParser saxParser = spf.newSAXParser();
+ saxParser.parse(xmlFile, stackBuilder);
+
+ // Parse the document using a DOM parser
+ final DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
+ dbFactory.setNamespaceAware(true);
+ final DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
+ final Document doc = dBuilder.parse(xmlFile);
+
+ /*
+ * Walk the DOM, firing off SAX events, and confirm they match the real
+ * SAX events.
+ */
+ final List<StackEntry> stack = stackBuilder.getStack();
+ final int stackSize = stack.size();
+
+ final SaxWalkerOverDom walker = new SaxWalkerOverDom(new ContentValidator(stack,
+ stackBuilder
+ .getPrefixMappings()));
+
+ try {
+ walker.walk(doc);
+ } catch (Exception e) {
+ throw new RuntimeException("Traversed through element " + (stackSize - stack.size())
+ + " before failing.", e);
+ }
+ }
+}
Propchange: webservices/xmlschema/trunk/xmlschema-walker/src/test/java/org/apache/ws/commons/schema/docpath/TestSaxWalkerOverDom.java
------------------------------------------------------------------------------
svn:eol-style = native