Author: bimargulies Date: Sat Dec 20 11:45:40 2008 New Revision: 728334 URL: http://svn.apache.org/viewvc?rev=728334&view=rev Log: Make the NIST tests part of the default maven build. Oddly, in spite of comments to the contrary, they pass.
Added: webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/w3c/ParameterizedW3CTestsTest.java (with props) webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/w3c/SchemaAttrDiff.java (with props) webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/w3c/SchemaCase.java - copied, changed from r728284, webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/w3c/SchemaTest.java webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/w3c/W3CTestCaseCollector.java (with props) Removed: webservices/commons/trunk/modules/XmlSchema/build.xml webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/w3c/SchemaTest.java webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/w3c/TestRoundTripXSD.java webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/w3c/TestW3CSchemaBucket.java webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/w3c/TestW3CSchemaTestSet.java Modified: webservices/commons/trunk/modules/XmlSchema/pom.xml Modified: webservices/commons/trunk/modules/XmlSchema/pom.xml URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/pom.xml?rev=728334&r1=728333&r2=728334&view=diff ============================================================================== --- webservices/commons/trunk/modules/XmlSchema/pom.xml (original) +++ webservices/commons/trunk/modules/XmlSchema/pom.xml Sat Dec 20 11:45:40 2008 @@ -121,28 +121,6 @@ </execution> </executions> </plugin> - <plugin> - <artifactId>maven-antrun-plugin</artifactId> - <version>1.1</version> - <executions> - <execution> - <id>prepareNistTest</id> - <phase>generate-test-resources</phase> - <goals> - <goal>run</goal> - </goals> - <configuration> - <tasks> - <ant inheritRefs="true" antfile="${basedir}/build.xml"> - <property value="${basedir}/target" name="build.dir" /> - <property value="${maven.test.skip}" name="maven.test.skip" /> - <target name="prepareNistTest" /> - </ant> - </tasks> - </configuration> - </execution> - </executions> - </plugin> </plugins> <defaultGoal>install</defaultGoal> <pluginManagement> @@ -225,17 +203,6 @@ <plugin> <artifactId>maven-surefire-plugin</artifactId> <configuration> - <includes> - <include>**/*Test.java</include> - <include>**/Test*.java</include> - <!-- - Fails in about half of the tests - <include>tests/w3c/TestW3CSchemaBucket.java</include> - --> - </includes> - <excludes> - <exclude>tests/w3c/**.java</exclude> - </excludes> </configuration> </plugin> <plugin> @@ -385,42 +352,6 @@ <activation> <activeByDefault>true</activeByDefault> </activation> - <build> - <plugins> - <plugin> - <artifactId>maven-surefire-plugin</artifactId> - <configuration> - <includes> - <include>**/*Test.java</include> - <include>**/Test*.java</include> -<!-- - Fails in about half of the tests - <include>tests/w3c/TestW3CSchemaBucket.java</include> - --> - </includes> - <excludes> - <exclude> - tests/w3c/**.java - </exclude> - </excludes> - <systemProperties> -<!-- - The default xalan TransformerFactory on the ibm jdk is - org.apache.xalan.processor.TransformerFactoryImpl which has a - known issue with implicit namespaces. Set this property to use - the xsltc TransformerFactory (which the sun jdk seems to - default to). - --> -<!-- - <property> <name>javax.xml.transform.TransformerFactory</name> - <value>com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl</value> - </property> - --> - </systemProperties> - </configuration> - </plugin> - </plugins> - </build> </profile> <profile> <id>IBMTest</id> @@ -447,18 +378,6 @@ <plugin> <artifactId>maven-surefire-plugin</artifactId> <configuration> - <includes> - <include>**/*Test.java</include> -<!-- - Fails in about half of the tests - <include>tests/w3c/TestW3CSchemaBucket.java</include> - --> - </includes> - <excludes> - <exclude> - tests/w3c/SchemaTest.java - </exclude> - </excludes> <systemProperties> <!-- The default xalan TransformerFactory on the ibm jdk is Added: webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/w3c/ParameterizedW3CTestsTest.java URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/w3c/ParameterizedW3CTestsTest.java?rev=728334&view=auto ============================================================================== --- webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/w3c/ParameterizedW3CTestsTest.java (added) +++ webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/w3c/ParameterizedW3CTestsTest.java Sat Dec 20 11:45:40 2008 @@ -0,0 +1,118 @@ +/** + * 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 tests.w3c; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileReader; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +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.XMLAssert; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + + +/** + * + */ +...@runwith(Parameterized.class) +public class ParameterizedW3CTestsTest extends XMLAssert { + private SchemaCase currentTest; + + public ParameterizedW3CTestsTest(SchemaCase test) { + currentTest = test; + } + + @Parameters + public static Collection<Object[]> data() throws Exception { + List<SchemaCase> tests = W3CTestCaseCollector.getSchemaTests(); + List<Object[]> results = new ArrayList<Object[]>(); + for (SchemaCase st : tests) { + results.add(new Object[] {st}); + } + return results; + } + + public XmlSchema loadSchema(File f) throws Exception { + XmlSchemaCollection col = new XmlSchemaCollection(); + col.setBaseUri(f.getPath()); + return col.read(new FileReader(f), null); + } + + @Test + public void testRoundTrip() throws Exception { + + XmlSchema schema = null; + DetailedDiff detaileddiffs = null; + + try { + schema = loadSchema(currentTest.getTestCaseFile()); + + // 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); + Diff diff = new Diff(new FileReader(currentTest.getTestCaseFile()), + new InputStreamReader(new ByteArrayInputStream(baos.toByteArray()))); + + detaileddiffs = new DetailedDiff(diff); + detaileddiffs.overrideDifferenceListener(new SchemaAttrDiff()); + boolean result = detaileddiffs.similar(); + if (!result) { + printFailureDetail(schema, detaileddiffs); + } + assertTrue("Serialized out schema not similar to original", result); + } catch (Exception e) { + if (currentTest.isValid()) { + printFailureDetail(schema, detaileddiffs); + } + throw new Exception(currentTest.getTestCaseFile().getPath(), e); + } + } + + private void printFailureDetail(XmlSchema schema, DetailedDiff detaileddiffs) { + System.err.println("Failure detail"); + System.err.println("-----"); + schema.write(System.err); + if (detaileddiffs != null) { + ListIterator li = detaileddiffs.getAllDifferences().listIterator(); + + while (li.hasNext()) { + System.err.println(li.next()); + } + } + } + + +} Propchange: webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/w3c/ParameterizedW3CTestsTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/w3c/ParameterizedW3CTestsTest.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Added: webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/w3c/SchemaAttrDiff.java URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/w3c/SchemaAttrDiff.java?rev=728334&view=auto ============================================================================== --- webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/w3c/SchemaAttrDiff.java (added) +++ webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/w3c/SchemaAttrDiff.java Sat Dec 20 11:45:40 2008 @@ -0,0 +1,59 @@ +/** + * 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 tests.w3c; + +import org.w3c.dom.Element; + +import org.custommonkey.xmlunit.Difference; +import org.custommonkey.xmlunit.DifferenceConstants; +import org.custommonkey.xmlunit.IgnoreTextAndAttributeValuesDifferenceListener; + +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); + } +} \ No newline at end of file Propchange: webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/w3c/SchemaAttrDiff.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/w3c/SchemaAttrDiff.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Copied: webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/w3c/SchemaCase.java (from r728284, webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/w3c/SchemaTest.java) URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/w3c/SchemaCase.java?p2=webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/w3c/SchemaCase.java&p1=webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/w3c/SchemaTest.java&r1=728284&r2=728334&rev=728334&view=diff ============================================================================== --- webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/w3c/SchemaTest.java (original) +++ webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/w3c/SchemaCase.java Sat Dec 20 11:45:40 2008 @@ -18,6 +18,8 @@ */ package tests.w3c; +import java.io.File; + import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; @@ -25,18 +27,20 @@ /** * Class representing a single schema test as described in a .testSet file. */ -public class SchemaTest { +public class SchemaCase { private static final String SCHEMA_DOCUMENT = "schemaDocument"; private static final String EXPECTED = "expected"; private static final String CURRENT = "current"; - String schemaDocumentLink; + private String schemaDocumentLink; private String expectedValidity; private String currentStatus; private String currentDate; + + private File baseFilePathname; - public SchemaTest(Element n) throws Exception { + public SchemaCase(Element n) throws Exception { NodeList nl = n.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node c = nl.item(i); @@ -90,4 +94,27 @@ public String getCurrentStatus() { return currentStatus; } + + + public void setSchemaDocumentLink(String schemaDocumentLink) { + this.schemaDocumentLink = schemaDocumentLink; + } + + + public String getSchemaDocumentLink() { + return schemaDocumentLink; + } + + public File getBaseFilePathname() { + return baseFilePathname; + } + + public void setBaseFilePathname(File baseFilePathname) { + this.baseFilePathname = baseFilePathname; + } + + public File getTestCaseFile() { + return new File(baseFilePathname, schemaDocumentLink); + } + } Added: webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/w3c/W3CTestCaseCollector.java URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/w3c/W3CTestCaseCollector.java?rev=728334&view=auto ============================================================================== --- webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/w3c/W3CTestCaseCollector.java (added) +++ webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/w3c/W3CTestCaseCollector.java Sat Dec 20 11:45:40 2008 @@ -0,0 +1,133 @@ +/** + * 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 tests.w3c; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.URISyntaxException; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; + +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + +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; + +/** + * + */ +public final class W3CTestCaseCollector { + private static final String[] TEST_SUITE_PATHS = + {"w3c/xmlschema2006-11-06/nistMeta/NISTXMLSchemaDatatypes.testSet" + }; + + private W3CTestCaseCollector() { + } + + /** + * Return all the tests to be used in automated testing. + * @return a list of SchemaTest objects. + * @throws ParserConfigurationException + * @throws SAXException + * @throws IOException + * @throws URISyntaxException + */ + public static List<SchemaCase> getSchemaTests() + throws ParserConfigurationException, SAXException, IOException, URISyntaxException { + List<SchemaCase> results = new ArrayList<SchemaCase>(); + for (String path : TEST_SUITE_PATHS) { + results.addAll(getSchemaTests(path)); + } + return results; + } + + /** + * Return a list of tests as specified by some specific XML file. + * @param testSet + * @return + * @throws ParserConfigurationException + * @throws SAXException + * @throws IOException + * @throws URISyntaxException + */ + public static List<SchemaCase> getSchemaTests(String testSet) throws ParserConfigurationException, + SAXException, + IOException, URISyntaxException { + URL setURL = W3CTestCaseCollector.class.getClassLoader().getResource(testSet); + InputStream setXmlStream = setURL.openStream(); + File basePath = new File(setURL.toURI()).getParentFile(); + List<SchemaCase> schemaTests = new ArrayList<SchemaCase>(); + Document doc = getDocument(new InputSource(setXmlStream)); + 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 { + + SchemaCase schemaTest = new SchemaCase(schemaTestElem); + schemaTest.setBaseFilePathname(basePath); + if (schemaTest.getSchemaDocumentLink() != null) { + schemaTests.add(schemaTest); + } + } catch (Exception e) { + // ignore errors? + } + } + } + + 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 ParserConfigurationException, + SAXException, IOException { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setNamespaceAware(true); + dbf.setValidating(false); + + return dbf.newDocumentBuilder().parse(inputSource); + } +} Propchange: webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/w3c/W3CTestCaseCollector.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/w3c/W3CTestCaseCollector.java ------------------------------------------------------------------------------ svn:keywords = Rev Date