You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by hu...@apache.org on 2006/07/12 17:50:02 UTC
svn commit: r421295 - in /webservices/commons/trunk/modules/XmlSchema: ./
test/tests/ test/tests/w3c/
Author: hughesj
Date: Wed Jul 12 08:50:02 2006
New Revision: 421295
URL: http://svn.apache.org/viewvc?rev=421295&view=rev
Log:
WSCOMMONS-58: added test harness to 'round trip test' *all* the valid schemas from the W3C xsts-2002-01-16.tar.gz test bucket. The list of schemas to test is taken from the three .testSet files in the xmlschema2002-01-16 directory of the extracted xsts-2002-01-16.tar.gz.
There is one .testSet file for each of NIST, Microsoft and Sun test schemas. A single junit test is created for each schema tested - so the report is now much more detailed.
I've removed NISTSchemaTest.java - tests.w3c.TestW3CSchemaTestSet will by default run the same set (except it creates and runs a separate junit test case for each schema in the NIST set.
'ant test' and 'maven test:test' remain functionally unchanged:
'ant test' runs the NIST bucket but now uses tests.w3c.TestW3CSchemaTestSet to do that instead of NISTSchemaTest
'maven test:test' doesn't run the NIST bucket (as before) ... we may want to resolve this inconsistency.
To run the full XML schema test suite (>4000 tests now):
cd <XmlSchema project root>
java tests.w3c.TestW3CSchemaBucket
Will follow up with Ant / maven instructions
Added:
webservices/commons/trunk/modules/XmlSchema/test/tests/w3c/
webservices/commons/trunk/modules/XmlSchema/test/tests/w3c/SchemaTest.java
webservices/commons/trunk/modules/XmlSchema/test/tests/w3c/TestRoundTripXSD.java
webservices/commons/trunk/modules/XmlSchema/test/tests/w3c/TestW3CSchemaBucket.java
webservices/commons/trunk/modules/XmlSchema/test/tests/w3c/TestW3CSchemaTestSet.java
Removed:
webservices/commons/trunk/modules/XmlSchema/test/tests/NISTSchemaTest.java
Modified:
webservices/commons/trunk/modules/XmlSchema/NOTICE.txt
webservices/commons/trunk/modules/XmlSchema/build.xml
webservices/commons/trunk/modules/XmlSchema/project.xml
Modified: webservices/commons/trunk/modules/XmlSchema/NOTICE.txt
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/NOTICE.txt?rev=421295&r1=421294&r2=421295&view=diff
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/NOTICE.txt (original)
+++ webservices/commons/trunk/modules/XmlSchema/NOTICE.txt Wed Jul 12 08:50:02 2006
@@ -9,3 +9,5 @@
Please read the different LICENSE files present in the licenses directory of
this distribution.
+
+ Portions Copyright 2006 International Business Machines Corp.
Modified: webservices/commons/trunk/modules/XmlSchema/build.xml
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/build.xml?rev=421295&r1=421294&r2=421295&view=diff
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/build.xml (original)
+++ webservices/commons/trunk/modules/XmlSchema/build.xml Wed Jul 12 08:50:02 2006
@@ -89,7 +89,8 @@
<formatter type="plain"/>
<batchtest todir="${test_reports.dir}">
<fileset dir="${test.dir}">
- <include name="**/*Test*.java"/>
+ <include name="tests/*Test*.java"/>
+ <include name="tests/w3c/TestW3CSchemaBucket.java"/>
</fileset>
</batchtest>
Modified: webservices/commons/trunk/modules/XmlSchema/project.xml
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/project.xml?rev=421295&r1=421294&r2=421295&view=diff
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/project.xml (original)
+++ webservices/commons/trunk/modules/XmlSchema/project.xml Wed Jul 12 08:50:02 2006
@@ -198,12 +198,12 @@
<unitTestSourceDirectory>test</unitTestSourceDirectory>
<unitTest>
- <excludes>
- <exclude>**/NISTSchemaTest.java</exclude>
- </excludes>
<includes>
<include>**/*Test*.java</include>
</includes>
+ <excludes>
+ <exclude>**/w3c/*.java</exclude>
+ </excludes>
<resources>
<resource>
Added: webservices/commons/trunk/modules/XmlSchema/test/tests/w3c/SchemaTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/test/tests/w3c/SchemaTest.java?rev=421295&view=auto
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/test/tests/w3c/SchemaTest.java (added)
+++ webservices/commons/trunk/modules/XmlSchema/test/tests/w3c/SchemaTest.java Wed Jul 12 08:50:02 2006
@@ -0,0 +1,88 @@
+/**
+ * Copyright 2006 Apache Software Foundation
+ *
+ * Licensed 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 tests.w3c;
+
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * Class representing a single schema test as described in a .testSet file.
+ *
+ */
+public class SchemaTest {
+
+ private final static String SCHEMA_DOCUMENT = "schemaDocument";
+
+ private final static String EXPECTED = "expected";
+
+ private final static String CURRENT = "current";
+
+ String schemaDocumentLink = null;
+
+ private String expectedValidity = null;
+
+ String currentStatus = null;
+
+ String currentDate = null;
+
+ public SchemaTest(Element n) throws Exception {
+ NodeList nl = n.getChildNodes();
+ for (int i = 0; i < nl.getLength(); i++) {
+ Node c = nl.item(i);
+ if (!(c instanceof Element))
+ continue;
+ Element elem = (Element) c;
+ String elemName = elem.getNodeName();
+ if (elemName.equals(SCHEMA_DOCUMENT)) {
+ schemaDocumentLink = elem.getAttributeNS(
+ "http://www.w3.org/1999/xlink", "href");
+
+ // Workaround for mistake in the NISTXMLSchema1-0-20020116.testSet file
+ // See http://lists.w3.org/Archives/Public/www-xml-schema-comments/2006JulSep/0000.html
+ if (schemaDocumentLink.equals("./NISTTestsAll/NISTSchema-anyURI-maxLength-1.xsd")) {
+ schemaDocumentLink = "./nisttest/NISTTestsAll/NISTSchema-anyURI-maxLength-1.xsd";
+ }
+ }
+
+ if (elemName.equals(EXPECTED)) {
+ expectedValidity = elem.getAttribute("validity");
+ }
+
+ if (elemName.equals(CURRENT)) {
+ currentStatus = elem.getAttribute("status");
+ currentDate = elem.getAttribute("date");
+ }
+ }
+ }
+
+ public boolean isValid() {
+ return expectedValidity.equals("valid");
+ }
+
+ public String toString() {
+ StringBuffer sb = new StringBuffer("href=");
+ sb.append(schemaDocumentLink);
+ sb.append(" expectedValidity=");
+ sb.append(expectedValidity);
+ sb.append(" currentStatus=");
+ sb.append(currentStatus);
+ sb.append(" currentDate=");
+ sb.append(currentDate);
+
+ return sb.toString();
+ }
+}
\ No newline at end of file
Added: webservices/commons/trunk/modules/XmlSchema/test/tests/w3c/TestRoundTripXSD.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/test/tests/w3c/TestRoundTripXSD.java?rev=421295&view=auto
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/test/tests/w3c/TestRoundTripXSD.java (added)
+++ webservices/commons/trunk/modules/XmlSchema/test/tests/w3c/TestRoundTripXSD.java Wed Jul 12 08:50:02 2006
@@ -0,0 +1,184 @@
+/**
+ * Copyright 2006 Apache Software Foundation
+ *
+ * Licensed 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 tests.w3c;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileReader;
+import java.io.InputStreamReader;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ListIterator;
+
+import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaCollection;
+import org.custommonkey.xmlunit.DetailedDiff;
+import org.custommonkey.xmlunit.Diff;
+import org.custommonkey.xmlunit.Difference;
+import org.custommonkey.xmlunit.DifferenceConstants;
+import org.custommonkey.xmlunit.IgnoreTextAndAttributeValuesDifferenceListener;
+import org.custommonkey.xmlunit.XMLTestCase;
+import org.w3c.dom.Element;
+
+/**
+ * Class to test a single schema by roundtripping it using XMLUnit
+ * cmd line parms: arg0 - valid|invalid arg1 - path to xsd file
+ *
+ */
+public class TestRoundTripXSD extends XMLTestCase {
+
+ private static boolean debug;
+
+ static {
+ String debugString = System.getProperty("debug");
+ debug = (debugString == null) ? false : debugString.equals("true");
+ }
+
+ private File fileToTest = null;
+
+ private boolean valid = false;
+
+ public final static void main(String[] args) {
+ junit.textui.TestRunner.run(new TestRoundTripXSD(new File(args[1]),
+ args[0].equals("valid")));
+ }
+
+
+ public TestRoundTripXSD() {
+ this(new File(System.getProperty("W3CTestLocation")),
+ System.getProperty("W3CTestValidity").equals("valid"));
+
+ }
+
+ public TestRoundTripXSD(File f, boolean valid) {
+ super(basename(f));
+
+ this.fileToTest = f;
+ this.valid = valid;
+ }
+
+ private static String basename(File f) {
+ String path = f.getPath();
+ int i = path.lastIndexOf(System.getProperty("file.separator"));
+ String retval = path.substring(i+1);
+ return retval;
+ }
+
+ protected void runTest() throws Throwable {
+ try {
+ testRoundTrip();
+ }
+ catch (InvocationTargetException e) {
+ e.fillInStackTrace();
+ throw e.getTargetException();
+ }
+ catch (IllegalAccessException e) {
+ e.fillInStackTrace();
+ throw e;
+ }
+ }
+
+
+ public void testRoundTrip() throws Exception {
+ try {
+ if (debug) {
+ System.out.println("fileToTest=" + this.fileToTest);
+ System.out.println("valid=" + this.valid);
+ }
+ XmlSchema schema = loadSchema(fileToTest);
+
+ // TODO: if we get here and the input was meant to be invalid perhaps
+ // should fail. Depends on whether XmlSchema is doing validation. For
+ // now we're ignoring invalid tests.
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ schema.write(baos);
+ if (debug) {
+ schema.write(System.err);
+ }
+
+ Diff diff = new Diff(new FileReader(fileToTest),
+ new InputStreamReader(new ByteArrayInputStream(baos
+ .toByteArray())));
+
+ DetailedDiff detaileddiffs = new DetailedDiff(diff);
+ detaileddiffs.overrideDifferenceListener(new SchemaAttrDiff());
+ boolean result = detaileddiffs.similar();
+ if (!result && debug) {
+ System.err.println(super.getName() + " failure detail");
+ System.err.println("-----");
+ schema.write(System.err);
+ ListIterator li = detaileddiffs.getAllDifferences().listIterator();
+ while (li.hasNext()) {
+ System.err.println(li.next());
+ }
+ }
+ assertTrue("Serialized out schema not similar to original", result);
+ } catch (Exception e) {
+ if (this.valid) {
+ throw new Exception(this.fileToTest.getPath(), e);
+ }
+ }
+
+ }
+
+ public XmlSchema loadSchema(File f) throws Exception {
+ XmlSchemaCollection col = new XmlSchemaCollection();
+ col.setBaseUri(f.getPath());
+ XmlSchema xmlSchema = col.read(new FileReader(f), null);
+ return xmlSchema;
+ }
+
+ static class SchemaAttrDiff extends
+ IgnoreTextAndAttributeValuesDifferenceListener {
+
+ public int differenceFound(Difference difference) {
+
+ if (difference.getId() == DifferenceConstants.ELEMENT_NUM_ATTRIBUTES
+ .getId()) {
+ // control and test have to be elements
+ // check if they are schema elements .. they only
+ // seem to have the added attributeFormDefault and
+ // elementFormDefault attributes
+ // so shldnt have more than 2 attributes difference
+ Element actualEl = (Element) difference.getControlNodeDetail()
+ .getNode();
+
+ if (actualEl.getLocalName().equals("schema")) {
+
+ int expectedAttrs = Integer.parseInt(difference
+ .getControlNodeDetail().getValue());
+ int actualAttrs = Integer.parseInt(difference
+ .getTestNodeDetail().getValue());
+ if (Math.abs(actualAttrs - expectedAttrs) <= 2) {
+ return RETURN_IGNORE_DIFFERENCE_NODES_SIMILAR;
+ }
+ }
+ } else if (difference.getId() == DifferenceConstants.ATTR_NAME_NOT_FOUND_ID) {
+ // sometimes the serializer throws in a few extra attributes...
+ Element actualEl = (Element) difference.getControlNodeDetail()
+ .getNode();
+
+ if (actualEl.getLocalName().equals("schema")) {
+ return RETURN_IGNORE_DIFFERENCE_NODES_SIMILAR;
+ }
+ }
+
+ return super.differenceFound(difference);
+ }
+ }
+
+}
Added: webservices/commons/trunk/modules/XmlSchema/test/tests/w3c/TestW3CSchemaBucket.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/test/tests/w3c/TestW3CSchemaBucket.java?rev=421295&view=auto
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/test/tests/w3c/TestW3CSchemaBucket.java (added)
+++ webservices/commons/trunk/modules/XmlSchema/test/tests/w3c/TestW3CSchemaBucket.java Wed Jul 12 08:50:02 2006
@@ -0,0 +1,86 @@
+/**
+ * Copyright 2006 Apache Software Foundation
+ *
+ * Licensed 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 tests.w3c;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.ListIterator;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Class to represent a bucket of tests described by a set of .testSet files.
+ * All of the tests described in all of the .testSet files present in the top
+ * level of the directory supplied will be round-trip tested.
+ * Note: Subdirs are not traversed because the .testSet files in the top level
+ * of the xmlschema2002-01-16 bucket describe all the tests in the bucket.
+ * cmd line parms: arg0 - location of the directory containing .testSet files
+ * defaults to ./target/xmlschema2002-01-16
+ *
+ */
+public class TestW3CSchemaBucket extends TestSuite {
+
+ private static List allTestSetFiles;
+
+ // If tests run from cmd line without any args, run the full suite
+ private static String testSetsLocation = "./build/xmlschema2002-01-16";
+
+ public TestW3CSchemaBucket(String name) {
+ super(name);
+ }
+
+ public static void main(String[] args) {
+ try {
+ junit.textui.TestRunner.run(TestW3CSchemaBucket.suite());
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+
+ public static Test suite() throws Exception {
+ testSetsLocation = System.getProperty("W3CTestLocation", testSetsLocation);
+ TestSuite suite = new TestSuite("Test for tests");
+ allTestSetFiles = getTestSetFiles(testSetsLocation);
+ ListIterator li = allTestSetFiles.listIterator();
+ while (li.hasNext()) {
+ Object o = li.next();
+ File testSet = null;
+ if (o instanceof File) {
+ testSet = (File) o;
+ }
+ suite.addTest(TestW3CSchemaTestSet.suite(testSet));
+ }
+ return suite;
+ }
+
+ private static List getTestSetFiles(String testSetsLocation) throws Exception {
+ File dir = new File(testSetsLocation);
+ if (!dir.isDirectory()) {
+ throw new Exception ("testSet files location must be a directory");
+ }
+ ArrayList testSetFiles = new ArrayList();
+ File[] files = dir.listFiles();
+ for (int i = 0; i < files.length; i++) {
+ if (files[i].getAbsolutePath().endsWith("testSet")) {
+ testSetFiles.add(files[i]);
+ }
+ }
+ return testSetFiles;
+ }
+}
Added: webservices/commons/trunk/modules/XmlSchema/test/tests/w3c/TestW3CSchemaTestSet.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/test/tests/w3c/TestW3CSchemaTestSet.java?rev=421295&view=auto
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/test/tests/w3c/TestW3CSchemaTestSet.java (added)
+++ webservices/commons/trunk/modules/XmlSchema/test/tests/w3c/TestW3CSchemaTestSet.java Wed Jul 12 08:50:02 2006
@@ -0,0 +1,158 @@
+/**
+ * Copyright 2006 Apache Software Foundation
+ *
+ * Licensed 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 tests.w3c;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.ListIterator;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.xerces.parsers.DOMParser;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+/**
+ * Class to represent a set of schema tests as described by a .testSet file
+ * When executed each of the schemas described in the .testSet file is round-trip
+ * tested.
+ * cmd line parms: arg0 - location of the .testSet file. Defaults to:
+ * ./target/xmlschema2002-01-16/NISTXMLSchema1-0-20020116.testSet
+ *
+ */
+public class TestW3CSchemaTestSet extends TestSuite {
+
+ private List schemaTests = null;
+
+ private File testSetFile = null;
+
+ // If junit called from cmd line without any args, use the NIST test bucket
+ private static String testSetLocation = "./build/xmlschema2002-01-16/NISTXMLSchema1-0-20020116.testSet";
+
+ private TestW3CSchemaTestSet(String name, File testSetFile) {
+ super(name);
+ this.testSetFile = testSetFile;
+ }
+
+ public static void main(String[] args) {
+ try {
+ if (args[0] != null) {
+ testSetLocation = args[0];
+ }
+ junit.textui.TestRunner.run(TestW3CSchemaTestSet.suite(new File(testSetLocation)));
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public static Test suite() throws Exception {
+ testSetLocation = System.getProperty("W3CTestLocation", testSetLocation);
+ return suite(new File(testSetLocation));
+ }
+
+ /**
+ * Returns a suite of TestRoundTripXSD test case instances. One for each of the tests
+ * described in the testSetFile
+ * @param testSetFile the File object of the .testSet file
+ * @return
+ * @throws Exception
+ */
+ public static Test suite(File testSetFile) throws Exception {
+ TestW3CSchemaTestSet suite = new TestW3CSchemaTestSet("Test for tests", testSetFile);
+ String testSetLocation = suite.testSetFile.getPath();
+ suite.schemaTests = getSchemaTests(testSetLocation);
+ ListIterator li = suite.schemaTests.listIterator();
+ while (li.hasNext()) {
+ SchemaTest st = (SchemaTest) li.next();
+ File f = new File(testSetFile.getParent(), st.schemaDocumentLink);
+
+ if (st.currentStatus!=null) {
+ if (!st.currentStatus.equals("accepted")) {
+ System.out.println("Warning: SchemaTest which isn't accepted: " + st);
+ } else if (st.isValid()){
+ // for now only test schemas that are valid
+ suite.addTest(new TestRoundTripXSD(f, true));
+ }
+ }
+ }
+ return suite;
+ }
+
+ /**
+ * Returns a list of SchemaTest objects created from the .testSet xml file passed
+ * in to the testSet parameter
+ * @param testSet the filename of the .testSet file
+ * @return List of SchemaTest objects describing the schema files to test
+ * @throws Exception
+ */
+ private static List getSchemaTests(String testSet) throws Exception {
+ List schemaTests = new ArrayList();
+ Document doc = getDocument(new InputSource(testSet));
+ NodeList testGroups = doc.getElementsByTagName("testGroup");
+ for (int i = 0; i < testGroups.getLength(); i++) {
+ Node testGroup = testGroups.item(i);
+ NodeList testGroupChildren = testGroup.getChildNodes();
+ Element schemaTestElem = null;
+ for (int j = 0; j < testGroupChildren.getLength(); j++) {
+ Node n = testGroupChildren.item(j);
+ if (!(n instanceof Element))
+ continue;
+ schemaTestElem = (Element) n;
+ if (schemaTestElem.getNodeName().equals("schemaTest")) {
+ break;
+ }
+ }
+ if (schemaTestElem != null) {
+ try {
+
+ SchemaTest schemaTest = new SchemaTest((Element) schemaTestElem);
+ if (schemaTest.schemaDocumentLink != null) schemaTests.add(schemaTest);
+ } catch (Exception e) {
+
+ }
+ }
+ }
+
+ return schemaTests;
+ }
+
+ /**
+ * Returns a DOM Document of the file passed in as the inputsource parameter
+ * @param inputSource input to read in as DOM Document
+ * @return DOM Document of the input source
+ * @throws Exception can be IOException or SAXException
+ */
+ private static Document getDocument(InputSource inputSource)
+ throws SAXException, IOException {
+ DOMParser parser = new DOMParser();
+
+ parser.setFeature("http://xml.org/sax/features/namespaces", true);
+
+ Document doc = null;
+
+ parser.parse(inputSource);
+ doc = parser.getDocument();
+
+ return doc;
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: commons-dev-help@ws.apache.org