You can subscribe to this list here.
2007 |
Jan
|
Feb
(3) |
Mar
(18) |
Apr
(39) |
May
(15) |
Jun
(12) |
Jul
(3) |
Aug
(23) |
Sep
|
Oct
(1) |
Nov
(1) |
Dec
(3) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2008 |
Jan
(21) |
Feb
(23) |
Mar
(33) |
Apr
(8) |
May
(1) |
Jun
(22) |
Jul
|
Aug
(1) |
Sep
(1) |
Oct
(6) |
Nov
|
Dec
(11) |
2009 |
Jan
(5) |
Feb
|
Mar
(2) |
Apr
(24) |
May
(36) |
Jun
(18) |
Jul
(2) |
Aug
(3) |
Sep
(9) |
Oct
(3) |
Nov
(1) |
Dec
|
2010 |
Jan
(5) |
Feb
(3) |
Mar
|
Apr
(15) |
May
(24) |
Jun
(11) |
Jul
(8) |
Aug
(34) |
Sep
(42) |
Oct
|
Nov
|
Dec
|
2011 |
Jan
(13) |
Feb
(32) |
Mar
(35) |
Apr
(31) |
May
(33) |
Jun
(30) |
Jul
(32) |
Aug
(31) |
Sep
(30) |
Oct
(31) |
Nov
(32) |
Dec
(31) |
2012 |
Jan
(35) |
Feb
(31) |
Mar
(31) |
Apr
(30) |
May
(31) |
Jun
(34) |
Jul
(23) |
Aug
(30) |
Sep
(30) |
Oct
(29) |
Nov
(30) |
Dec
(32) |
2013 |
Jan
(25) |
Feb
(39) |
Mar
(1) |
Apr
(18) |
May
(1) |
Jun
|
Jul
(1) |
Aug
(20) |
Sep
(41) |
Oct
(32) |
Nov
(9) |
Dec
(31) |
2014 |
Jan
(31) |
Feb
(30) |
Mar
(34) |
Apr
(60) |
May
(31) |
Jun
(28) |
Jul
(32) |
Aug
(28) |
Sep
(26) |
Oct
(32) |
Nov
(43) |
Dec
(115) |
2015 |
Jan
(106) |
Feb
(101) |
Mar
(51) |
Apr
(32) |
May
(63) |
Jun
(18) |
Jul
|
Aug
(18) |
Sep
|
Oct
(1) |
Nov
(84) |
Dec
(63) |
2016 |
Jan
(26) |
Feb
(17) |
Mar
(104) |
Apr
(30) |
May
(6) |
Jun
(30) |
Jul
|
Aug
|
Sep
|
Oct
(3) |
Nov
(48) |
Dec
(22) |
2017 |
Jan
(15) |
Feb
(29) |
Mar
(43) |
Apr
(29) |
May
(25) |
Jun
(28) |
Jul
(62) |
Aug
(35) |
Sep
(35) |
Oct
(72) |
Nov
(10) |
Dec
(4) |
2018 |
Jan
(7) |
Feb
(4) |
Mar
|
Apr
(46) |
May
(20) |
Jun
(12) |
Jul
(9) |
Aug
(42) |
Sep
(4) |
Oct
(17) |
Nov
(32) |
Dec
(31) |
2019 |
Jan
(21) |
Feb
(14) |
Mar
|
Apr
(74) |
May
(25) |
Jun
(43) |
Jul
(2) |
Aug
(1) |
Sep
|
Oct
(2) |
Nov
|
Dec
(10) |
2020 |
Jan
(1) |
Feb
|
Mar
(26) |
Apr
(8) |
May
(62) |
Jun
(4) |
Jul
(25) |
Aug
|
Sep
(21) |
Oct
(24) |
Nov
(26) |
Dec
(9) |
2021 |
Jan
|
Feb
(4) |
Mar
|
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
(1) |
Sep
(1) |
Oct
(11) |
Nov
(1) |
Dec
(12) |
2022 |
Jan
(47) |
Feb
|
Mar
(2) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(14) |
2023 |
Jan
(3) |
Feb
|
Mar
(60) |
Apr
(9) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2024 |
Jan
(5) |
Feb
|
Mar
|
Apr
(10) |
May
(1) |
Jun
|
Jul
|
Aug
(17) |
Sep
(2) |
Oct
|
Nov
|
Dec
(1) |
2025 |
Jan
|
Feb
|
Mar
(88) |
Apr
(64) |
May
(47) |
Jun
(20) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <bo...@us...> - 2009-06-02 14:22:16
|
Revision: 340 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=340&view=rev Author: bodewig Date: 2009-06-02 13:32:19 +0000 (Tue, 02 Jun 2009) Log Message: ----------- implement validation for DTDs in Java Modified Paths: -------------- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/JAXPValidator.java trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/Validator.java Added Paths: ----------- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/ParsingValidator.java trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/ValidationHandler.java trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/validation/ParsingValidatorTest.java trunk/xmlunit/src/tests/resources/Book.dtd trunk/xmlunit/src/tests/resources/BookWithDoctype.xml trunk/xmlunit/src/tests/resources/invalidBookWithDoctype.xml Modified: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/JAXPValidator.java =================================================================== --- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/JAXPValidator.java 2009-05-28 13:07:01 UTC (rev 339) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/JAXPValidator.java 2009-06-02 13:32:19 UTC (rev 340) @@ -13,14 +13,10 @@ */ package net.sf.xmlunit.validation; -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; import javax.xml.transform.Source; import javax.xml.validation.Schema; import javax.xml.validation.SchemaFactory; import net.sf.xmlunit.exceptions.XMLUnitException; -import org.xml.sax.ErrorHandler; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; @@ -86,42 +82,4 @@ return v.getResult(); } - - private static class ValidationHandler implements ErrorHandler { - private List<ValidationProblem> problems = - new LinkedList<ValidationProblem>(); - private boolean valid = true; - // fatal errors are re-thrown by the parser - private SAXParseException lastFatalError = null; - - public void error(SAXParseException e) { - if (e != lastFatalError) { - valid = false; - problems.add(ValidationProblem.fromException(e, - ValidationProblem - .ProblemType.ERROR) - ); - } - } - - public void fatalError(SAXParseException e) { - valid = false; - lastFatalError = e; - problems.add(ValidationProblem.fromException(e, - ValidationProblem - .ProblemType.ERROR)); - } - - public void warning(SAXParseException e) { - problems.add(ValidationProblem.fromException(e, - ValidationProblem - .ProblemType.WARNING)); - } - - private ValidationResult getResult() { - return new ValidationResult(valid, - Collections.unmodifiableList(problems) - ); - } - } } Added: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/ParsingValidator.java =================================================================== --- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/ParsingValidator.java (rev 0) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/ParsingValidator.java 2009-06-02 13:32:19 UTC (rev 340) @@ -0,0 +1,152 @@ +/* + This file is licensed 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 net.sf.xmlunit.validation; + +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; +import javax.xml.transform.Source; +import javax.xml.transform.sax.SAXSource; +import net.sf.xmlunit.exceptions.ConfigurationException; +import net.sf.xmlunit.exceptions.XMLUnitException; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.SAXNotRecognizedException; +import org.xml.sax.SAXNotSupportedException; +import org.xml.sax.SAXParseException; +import org.xml.sax.helpers.DefaultHandler; + +/** + * Validator implementation that uses "the old way" of validating an + * XML input by parsing the input. + * + * <p>Even though this implementation supports W3C Schema you + * shouldn't use it for that language but rather use + * JAXPValidator.</p> + */ +public class ParsingValidator extends Validator { + private final String language; + + public ParsingValidator(String language) { + if (!Languages.W3C_XML_SCHEMA_NS_URI.equals(language) + && !Languages.XML_DTD_NS_URI.equals(language)) { + throw new IllegalArgumentException("only DTD and W3C Schema" + + " validation are supported by" + + " ParsingValidator"); + } + this.language = language; + } + + @Override public ValidationResult validateSchema() { + throw new XMLUnitException("Schema validation is not supported by" + + " ParsinValidator"); + } + + @Override public ValidationResult validateInstance(Source s) { + try { + SAXParserFactory factory = SAXParserFactory.newInstance(); + factory.setNamespaceAware(true); + factory.setValidating(true); + SAXParser parser = factory.newSAXParser(); + if (Languages.W3C_XML_SCHEMA_NS_URI.equals(language)) { + parser.setProperty(Properties.SCHEMA_LANGUAGE, + Languages.W3C_XML_SCHEMA_NS_URI); + } + final Source[] source = getSchemaSources(); + Handler handler = new Handler(); + if (source.length != 0) { + if (Languages.W3C_XML_SCHEMA_NS_URI.equals(language)) { + InputSource[] schemaSource = new InputSource[source.length]; + for (int i = 0; i < source.length; i++) { + schemaSource[i] = toInputSource(source[i]); + } + parser.setProperty(Properties.SCHEMA_SOURCE, + schemaSource); + } else if (source.length == 1) { + handler.setSchemaSystemId(source[0].getSystemId()); + } + } + InputSource input = toInputSource(s); + try { + parser.parse(input, handler); + } catch (SAXException e) { + if (e instanceof SAXParseException) { + handler.error((SAXParseException) e); + } else { + throw new XMLUnitException(e); + } + } + return handler.getResult(); + } catch (ParserConfigurationException ex) { + throw new ConfigurationException(ex); + } catch (SAXNotRecognizedException ex) { + throw new ConfigurationException(ex); + } catch (SAXNotSupportedException ex) { + throw new ConfigurationException(ex); + } catch (SAXException ex) { + throw new XMLUnitException(ex); + } catch (java.io.IOException ex) { + throw new XMLUnitException(ex); + } + } + + // TODO factor out to a common class, will be needed by other parts as well + private static InputSource toInputSource(Source s) throws SAXException { + return SAXSource.sourceToInputSource(s); + } + + private static class Properties { + static final String SCHEMA_LANGUAGE = + "http://java.sun.com/xml/jaxp/properties/schemaLanguage"; + + static final String SCHEMA_SOURCE = + "http://java.sun.com/xml/jaxp/properties/schemaSource"; + } + + private class Handler extends DefaultHandler { + private final ValidationHandler v = new ValidationHandler(); + private String systemId; + + @Override public void error(SAXParseException e) { + v.error(e); + } + + @Override public void fatalError(SAXParseException e) { + v.fatalError(e); + } + + @Override public void warning(SAXParseException e) { + v.warning(e); + } + + private void setSchemaSystemId(String id) { + systemId = id; + } + + @Override public InputSource resolveEntity(String publicId, + String systemId) + throws java.io.IOException, SAXException { + if (this.systemId != null && + (getSchemaURI() == null || getSchemaURI().equals(publicId)) + ) { + return new InputSource(this.systemId); + } + return super.resolveEntity(publicId, systemId); + } + + ValidationResult getResult() { + return v.getResult(); + } + } +} Property changes on: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/ParsingValidator.java ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/ValidationHandler.java =================================================================== --- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/ValidationHandler.java (rev 0) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/ValidationHandler.java 2009-06-02 13:32:19 UTC (rev 340) @@ -0,0 +1,61 @@ +/* + This file is licensed 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 net.sf.xmlunit.validation; + +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import org.xml.sax.ErrorHandler; +import org.xml.sax.SAXParseException; + +/** + * ErrorHandler collecting parser exceptions as ValidationProblems + */ +final class ValidationHandler implements ErrorHandler { + private List<ValidationProblem> problems = + new LinkedList<ValidationProblem>(); + private boolean valid = true; + // fatal errors are re-thrown by the parser + private SAXParseException lastFatalError = null; + + public void error(SAXParseException e) { + if (e != lastFatalError) { + valid = false; + problems.add(ValidationProblem.fromException(e, + ValidationProblem + .ProblemType.ERROR) + ); + } + } + + public void fatalError(SAXParseException e) { + valid = false; + lastFatalError = e; + problems.add(ValidationProblem.fromException(e, + ValidationProblem + .ProblemType.ERROR)); + } + + public void warning(SAXParseException e) { + problems.add(ValidationProblem.fromException(e, + ValidationProblem + .ProblemType.WARNING)); + } + + ValidationResult getResult() { + return new ValidationResult(valid, + Collections.unmodifiableList(problems) + ); + } +} Property changes on: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/ValidationHandler.java ___________________________________________________________________ Added: svn:eol-style + native Modified: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/Validator.java =================================================================== --- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/Validator.java 2009-05-28 13:07:01 UTC (rev 339) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/Validator.java 2009-06-02 13:32:19 UTC (rev 340) @@ -78,6 +78,9 @@ * @see Languages */ public static Validator forLanguage(String language) { - return null; + if (!Languages.XML_DTD_NS_URI.equals(language)) { + return new JAXPValidator(language); + } + return new ParsingValidator(Languages.XML_DTD_NS_URI); } } \ No newline at end of file Added: trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/validation/ParsingValidatorTest.java =================================================================== --- trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/validation/ParsingValidatorTest.java (rev 0) +++ trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/validation/ParsingValidatorTest.java 2009-06-02 13:32:19 UTC (rev 340) @@ -0,0 +1,58 @@ +/* + This file is licensed 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 net.sf.xmlunit.validation; + +import java.io.File; +import javax.xml.transform.stream.StreamSource; +import static org.junit.Assert.*; +import org.junit.Test; + +public class ParsingValidatorTest { + + @Test public void shouldSuccessfullyValidateSchemaInstance() { + ParsingValidator v = + new ParsingValidator(Languages.W3C_XML_SCHEMA_NS_URI); + v.setSchemaSource(new StreamSource(new File("src/tests/resources/Book.xsd"))); + ValidationResult r = v.validateInstance(new StreamSource(new File("src/tests/resources/BookXsdGenerated.xml"))); + assertTrue(r.isValid()); + assertFalse(r.getProblems().iterator().hasNext()); + } + + @Test public void shouldFailOnBrokenSchemaInstance() { + ParsingValidator v = + new ParsingValidator(Languages.W3C_XML_SCHEMA_NS_URI); + v.setSchemaSource(new StreamSource(new File("src/tests/resources/Book.xsd"))); + ValidationResult r = v.validateInstance(new StreamSource(new File("src/tests/resources/invalidBook.xml"))); + assertFalse(r.isValid()); + assertTrue(r.getProblems().iterator().hasNext()); + } + + @Test public void shouldSuccessfullyValidateDTDInstance() { + ParsingValidator v = + new ParsingValidator(Languages.XML_DTD_NS_URI); + v.setSchemaSource(new StreamSource(new File("src/tests/resources/Book.dtd"))); + ValidationResult r = v.validateInstance(new StreamSource(new File("src/tests/resources/BookWithDoctype.xml"))); + assertTrue(r.isValid()); + assertFalse(r.getProblems().iterator().hasNext()); + } + + @Test public void shouldFailOnBrokenDTDInstance() { + ParsingValidator v = + new ParsingValidator(Languages.XML_DTD_NS_URI); + v.setSchemaSource(new StreamSource(new File("src/tests/resources/Book.dtd"))); + ValidationResult r = v.validateInstance(new StreamSource(new File("src/tests/resources/invalidBookWithDoctype.xml"))); + assertFalse(r.isValid()); + assertTrue(r.getProblems().iterator().hasNext()); + } +} Property changes on: trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/validation/ParsingValidatorTest.java ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/xmlunit/src/tests/resources/Book.dtd =================================================================== --- trunk/xmlunit/src/tests/resources/Book.dtd (rev 0) +++ trunk/xmlunit/src/tests/resources/Book.dtd 2009-06-02 13:32:19 UTC (rev 340) @@ -0,0 +1,6 @@ +<!ELEMENT Book (Title, Author*, Date, ISBN, Publisher) > +<!ELEMENT Title (#PCDATA)> +<!ELEMENT Author (#PCDATA)> +<!ELEMENT Date (#PCDATA)> +<!ELEMENT ISBN (#PCDATA)> +<!ELEMENT Publisher (#PCDATA)> Property changes on: trunk/xmlunit/src/tests/resources/Book.dtd ___________________________________________________________________ Added: svn:eol-style + native Copied: trunk/xmlunit/src/tests/resources/BookWithDoctype.xml (from rev 339, trunk/xmlunit/src/tests/resources/BookXsdGeneratedNoSchema.xml) =================================================================== --- trunk/xmlunit/src/tests/resources/BookWithDoctype.xml (rev 0) +++ trunk/xmlunit/src/tests/resources/BookWithDoctype.xml 2009-06-02 13:32:19 UTC (rev 340) @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE Book PUBLIC "XMLUNIT/TEST/PUB" "http://example.org/nonsense"> +<Book> + <Title>Chicken Soup for the Soul</Title> + <Author>Jack Canfield</Author> + <Author>Mark Victor Hansen</Author> + <Date>1993</Date> + <ISBN>1-55874-262-X</ISBN> + <Publisher>Health Communications, Inc.</Publisher> +</Book> Property changes on: trunk/xmlunit/src/tests/resources/BookWithDoctype.xml ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:mergeinfo + Added: svn:eol-style + native Copied: trunk/xmlunit/src/tests/resources/invalidBookWithDoctype.xml (from rev 339, trunk/xmlunit/src/tests/resources/invalidBook.xml) =================================================================== --- trunk/xmlunit/src/tests/resources/invalidBookWithDoctype.xml (rev 0) +++ trunk/xmlunit/src/tests/resources/invalidBookWithDoctype.xml 2009-06-02 13:32:19 UTC (rev 340) @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE Book PUBLIC "XMLUNIT/TEST/PUB" "http://example.org/nonsense"> +<Book> + <Title>Chicken Soup for the Soul</Title> + <Author>Jack Canfield</Author> + <Author>Mark Victor Hansen</Author> + <Date>1993</Date> + <ISBN>1-55874-262-X</ISBN> +</Book> Property changes on: trunk/xmlunit/src/tests/resources/invalidBookWithDoctype.xml ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:mergeinfo + Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2009-06-02 14:13:04
|
Revision: 342 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=342&view=rev Author: bodewig Date: 2009-06-02 14:13:03 +0000 (Tue, 02 Jun 2009) Log Message: ----------- whitespace Modified Paths: -------------- trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/Validator.java Modified: trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/Validator.java =================================================================== --- trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/Validator.java 2009-06-02 14:12:23 UTC (rev 341) +++ trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/Validator.java 2009-06-02 14:13:03 UTC (rev 342) @@ -138,7 +138,7 @@ * Basic constructor. * Validates the contents of the Reader using the DTD or schema referenced * by those contents. - * + * * @param readerForValidation */ public Validator(Reader readerForValidation) { @@ -149,7 +149,7 @@ * Basic constructor. * Validates the contents of the String using the DTD or schema referenced * by those contents. - * + * * @param stringForValidation */ public Validator(String stringForValidation) { @@ -160,7 +160,7 @@ * Basic constructor. * Validates the contents of the InputSource using the DTD or * schema referenced by those contents. - * + * * @param readerForValidation */ public Validator(InputSource sourceForValidation) { @@ -173,7 +173,7 @@ * systemID. There must be DOCTYPE instruction in the markup that * references the DTD or else the markup will be considered invalid: if * there is no DOCTYPE in the markup use the 3-argument constructor - * + * * @param readerForValidation * @param systemID */ @@ -188,7 +188,7 @@ * systemID. There must be DOCTYPE instruction in the markup that * references the DTD or else the markup will be considered invalid: if * there is no DOCTYPE in the markup use the 3-argument constructor - * + * * @param stringForValidation * @param systemID */ @@ -203,7 +203,7 @@ * in the markup that references the DTD or else the markup will * be considered invalid: if there is no DOCTYPE in the markup use * the 3-argument constructor - * + * * @param sourceForValidation * @param systemID */ @@ -215,7 +215,7 @@ * Full constructor. * Validates the contents of the InputSource using the DTD * specified with the systemID and named with the doctype name. - * + * * @param sourceForValidation * @param systemID * @param doctype @@ -238,7 +238,7 @@ * Full constructor. * Validates the contents of the Reader using the DTD specified with the * systemID and named with the doctype name. - * + * * @param readerForValidation * @param systemID * @param doctype This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2009-06-02 14:12:24
|
Revision: 341 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=341&view=rev Author: bodewig Date: 2009-06-02 14:12:23 +0000 (Tue, 02 Jun 2009) Log Message: ----------- Implement legacy validator class in terms of ParsingValidator Modified Paths: -------------- trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/Validator.java trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_JAXP_1_2_Schema_Validation.java Modified: trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/Validator.java =================================================================== --- trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/Validator.java 2009-06-02 13:32:19 UTC (rev 340) +++ trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/Validator.java 2009-06-02 14:12:23 UTC (rev 341) @@ -36,26 +36,30 @@ package org.custommonkey.xmlunit; +import net.sf.xmlunit.validation.Languages; +import net.sf.xmlunit.validation.ParsingValidator; +import net.sf.xmlunit.validation.ValidationProblem; +import net.sf.xmlunit.validation.ValidationResult; + import org.custommonkey.xmlunit.exceptions.ConfigurationException; import org.custommonkey.xmlunit.exceptions.XMLUnitRuntimeException; +import java.io.File; import java.io.IOException; +import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import java.io.StringReader; +import java.util.ArrayList; +import java.util.List; import org.w3c.dom.Document; -import org.xml.sax.ErrorHandler; import org.xml.sax.InputSource; -import org.xml.sax.SAXException; -import org.xml.sax.SAXNotRecognizedException; -import org.xml.sax.SAXNotSupportedException; -import org.xml.sax.SAXParseException; import org.xml.sax.helpers.DefaultHandler; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; +import javax.xml.transform.Source; +import javax.xml.transform.sax.SAXSource; +import javax.xml.transform.stream.StreamSource; /** * Validates XML against its internal or external DOCTYPE, or a completely @@ -76,12 +80,15 @@ * </ul> * <br />Examples and more at <a href="http://xmlunit.sourceforge.net"/>xmlunit.sourceforge.net</a> */ -public class Validator extends DefaultHandler implements ErrorHandler { +public class Validator extends DefaultHandler { private final InputSource validationInputSource; - private final SAXParser parser; private final StringBuffer messages; private final boolean usingDoctypeReader; + private final String systemId; + private Object schemaSource; + private boolean useSchema = false; + private Boolean isValid; /** @@ -89,8 +96,7 @@ * @deprecated Use the protected three arg constructor instead. */ protected Validator(InputSource inputSource, - boolean usingDoctypeReader) - throws SAXException, ConfigurationException { + boolean usingDoctypeReader) { this(inputSource, null, usingDoctypeReader); } @@ -100,27 +106,14 @@ * @param inputSource * @param systemId * @param usingDoctypeReader - * @throws SAXException - * @throws ConfigurationException if validation could not be turned on */ protected Validator(InputSource inputSource, String systemId, - boolean usingDoctypeReader) - throws SAXException, ConfigurationException { + boolean usingDoctypeReader) { isValid = null; messages = new StringBuffer(); - SAXParserFactory factory = XMLUnit.getSAXParserFactory(); - factory.setValidating(true); - try { - parser = factory.newSAXParser(); - } catch (ParserConfigurationException ex) { - throw new ConfigurationException(ex); - } - this.validationInputSource = inputSource; - if (systemId != null) { - validationInputSource.setSystemId(systemId); - } + this.systemId = systemId; this.usingDoctypeReader = usingDoctypeReader; } @@ -135,11 +128,8 @@ * @param document * @param systemID * @param doctype - * @throws SAXException if unable to obtain new Sax parser via JAXP factory - * @throws ConfigurationException if validation could not be turned on */ - public Validator(Document document, String systemID, String doctype) - throws SAXException, ConfigurationException { + public Validator(Document document, String systemID, String doctype) { this(new InputStreamReader(new NodeInputStream(document)), systemID, doctype); } @@ -150,11 +140,8 @@ * by those contents. * * @param readerForValidation - * @throws SAXException if unable to obtain new Sax parser via JAXP factory - * @throws ConfigurationException if validation could not be turned on */ - public Validator(Reader readerForValidation) - throws SAXException, ConfigurationException { + public Validator(Reader readerForValidation) { this(readerForValidation, null); } @@ -164,11 +151,8 @@ * by those contents. * * @param stringForValidation - * @throws SAXException if unable to obtain new Sax parser via JAXP factory - * @throws ConfigurationException if validation could not be turned on */ - public Validator(String stringForValidation) - throws SAXException, ConfigurationException { + public Validator(String stringForValidation) { this(new StringReader(stringForValidation)); } @@ -178,11 +162,8 @@ * schema referenced by those contents. * * @param readerForValidation - * @throws SAXException if unable to obtain new Sax parser via JAXP factory - * @throws ConfigurationException if validation could not be turned on */ - public Validator(InputSource sourceForValidation) - throws SAXException, ConfigurationException { + public Validator(InputSource sourceForValidation) { this(sourceForValidation, null); } @@ -195,11 +176,8 @@ * * @param readerForValidation * @param systemID - * @throws SAXException if unable to obtain new Sax parser via JAXP factory - * @throws ConfigurationException if validation could not be turned on */ - public Validator(Reader readerForValidation, String systemID) - throws SAXException, ConfigurationException { + public Validator(Reader readerForValidation, String systemID) { this(new InputSource(readerForValidation), systemID, (readerForValidation instanceof DoctypeReader)); } @@ -213,11 +191,8 @@ * * @param stringForValidation * @param systemID - * @throws SAXException if unable to obtain new Sax parser via JAXP factory - * @throws ConfigurationException if validation could not be turned on */ - public Validator(String stringForValidation, String systemID) - throws SAXException, ConfigurationException { + public Validator(String stringForValidation, String systemID) { this(new StringReader(stringForValidation), systemID); } @@ -231,11 +206,8 @@ * * @param sourceForValidation * @param systemID - * @throws SAXException if unable to obtain new Sax parser via JAXP factory - * @throws ConfigurationException if validation could not be turned on */ - public Validator(InputSource sourceForValidation, String systemID) - throws SAXException, ConfigurationException { + public Validator(InputSource sourceForValidation, String systemID) { this(sourceForValidation, systemID, false); } @@ -247,12 +219,9 @@ * @param sourceForValidation * @param systemID * @param doctype - * @throws SAXException - * @throws ConfigurationException if validation could not be turned on */ public Validator(InputSource sourceForValidation, String systemID, - String doctype) - throws SAXException, ConfigurationException { + String doctype) { this(sourceForValidation.getCharacterStream() != null ? new InputSource(new DoctypeReader(sourceForValidation .getCharacterStream(), @@ -273,12 +242,9 @@ * @param readerForValidation * @param systemID * @param doctype - * @throws SAXException - * @throws ConfigurationException if validation could not be turned on */ public Validator(Reader readerForValidation, String systemID, - String doctype) - throws SAXException, ConfigurationException { + String doctype) { this(readerForValidation instanceof DoctypeReader ? readerForValidation : new DoctypeReader(readerForValidation, doctype, systemID), @@ -301,26 +267,10 @@ * * @param use indicate that XML Schema should be used to validate * documents. - * @throws SAXException * @see #setJAXP12SchemaSource(Object) */ - public void useXMLSchema(boolean use) throws SAXException { - boolean tryXercesProperties = false; - try { - if (use) { - parser.setProperty(JAXPConstants.Properties.SCHEMA_LANGUAGE, - XMLConstants.W3C_XML_SCHEMA_NS_URI); - } - } catch (SAXNotRecognizedException e) { - tryXercesProperties = true; - } catch (SAXNotSupportedException e) { - tryXercesProperties = true; - } - - if (tryXercesProperties) { - parser.getXMLReader().setFeature("http://apache.org/xml/features/validation/schema", use); - parser.getXMLReader().setFeature("http://apache.org/xml/features/validation/dynamic", use); - } + public void useXMLSchema(boolean use) { + useSchema = use; } /** @@ -372,17 +322,30 @@ return; } + ParsingValidator v = + new ParsingValidator(useSchema ? Languages.W3C_XML_SCHEMA_NS_URI + : Languages.XML_DTD_NS_URI); + List<Source> schemaSourceList = new ArrayList<Source>(); + if (systemId != null) { + schemaSourceList.add(new StreamSource(systemId)); + } + addSchemaSources(schemaSource, schemaSourceList); + v.setSchemaSources(schemaSourceList.toArray(new Source[0])); + try { - parser.parse(validationInputSource, this); - } catch (SAXException e) { - parserException(e); - } catch (IOException e) { - parserException(e); + ValidationResult r = + v.validateInstance(new SAXSource(validationInputSource)); + isValid = r.isValid() ? Boolean.TRUE : Boolean.FALSE; + for (ValidationProblem p : r.getProblems()) { + validationProblem(p); + } + } catch (net.sf.xmlunit.exceptions.ConfigurationException e) { + throw new ConfigurationException(e.getCause()); + } catch (net.sf.xmlunit.exceptions.XMLUnitException e) { + throw new XMLUnitRuntimeException(e.getMessage(), e.getCause()); } - if (isValid == null) { - isValid = Boolean.TRUE; - } else if (usingDoctypeReader) { + if (usingDoctypeReader && isValid == Boolean.FALSE) { try { messages.append("\nContent was: ") .append(getOriginalContent(validationInputSource)); @@ -392,93 +355,9 @@ } } - /** - * Deal with any parser exceptions not handled by the ErrorHandler interface. - * - * @param e - */ - private void parserException(Exception e) { - invalidate(e.getMessage()); - } - - /** - * ErrorHandler interface method. - * - * @param exception - * @throws SAXException - */ - public void warning(SAXParseException exception) - throws SAXException { - errorHandlerException(exception); - } - - /** - * ErrorHandler interface method. - * - * @param exception - * @throws SAXException - */ - public void error(SAXParseException exception) - throws SAXException { - errorHandlerException(exception); - } - - /** - * ErrorHandler interface method. - * - * @param exception - * @throws SAXException - */ - public void fatalError(SAXParseException exception) - throws SAXException { - errorHandlerException(exception); - } - - /** - * Entity Resolver method: allows us to override an existing systemID - * referenced in the markup DOCTYPE instruction. - * - * @param publicId - * @param systemId - * @return the sax InputSource that points to the overridden systemID - */ - public InputSource resolveEntity(String publicId, String systemId) { - if (validationInputSource.getSystemId() != null) { - return new InputSource(validationInputSource.getSystemId()); - } else { - InputSource s = null; - try { - if (XMLUnit.getControlEntityResolver() != null) { - s = XMLUnit.getControlEntityResolver() - .resolveEntity(publicId, systemId); - } - } catch (SAXException e) { - throw new XMLUnitRuntimeException("failed to resolve entity: " - + publicId, e); - } catch (IOException e) { - // even if we wanted to re-throw IOException (which we - // can't because of backwards compatibility) the mere - // fact that DefaultHandler has stripped IOException - // from EntityResolver's method's signature wouldn't - // let us. - throw new XMLUnitRuntimeException("failed to resolve entity: " - + publicId, e); - } - if (s != null) { - return s; - } else if (systemId != null) { - return new InputSource(systemId); - } - } - return null; - } - - /** - * Deal with exceptions passed to the ErrorHandler interface by the parser. - */ - private void errorHandlerException(SAXParseException e) { - String msg = "At line " + e.getLineNumber() + ", column: " - + e.getColumnNumber() + " ==> " + e.getMessage(); + private void validationProblem(ValidationProblem p) { + String msg = "At line " + p.getLine() + ", column: " + + p.getColumn() + " ==> " + p.getMessage(); if (!msg.endsWith("\n")) msg += "\n"; invalidate(msg); } @@ -512,14 +391,32 @@ * runtime. When an array of Objects is passed it is illegal to * have two schemas that share the same namespace.</li> * </ul> - * @throws SAXException if this method of validating isn't supported. * @see http://java.sun.com/webservices/jaxp/change-requests-11.html */ - public void setJAXP12SchemaSource(Object schemaSource) throws SAXException { - parser.setProperty(JAXPConstants.Properties.SCHEMA_SOURCE, - schemaSource); + public void setJAXP12SchemaSource(Object schemaSource) { + this.schemaSource = schemaSource; } + private static void addSchemaSources(Object schemaSources, + List<Source> targetList) { + if (schemaSources instanceof String) { + targetList.add(new StreamSource((String) schemaSources)); + } else if (schemaSources instanceof File) { + targetList.add(new StreamSource((File) schemaSources)); + } else if (schemaSources instanceof InputStream) { + targetList.add(new StreamSource((InputStream) schemaSources)); + } else if (schemaSources instanceof InputSource) { + targetList.add(new SAXSource((InputSource) schemaSources)); + } else if (schemaSources instanceof Object[]) { + for (Object s : (Object[]) schemaSources) { + addSchemaSources(s, targetList); + } + } else if (schemaSources != null) { + throw new XMLUnitRuntimeException("Unknown schema source type: " + + schemaSources.getClass()); + } + } + private static String getOriginalContent(InputSource s) throws IOException { return s.getCharacterStream() instanceof DoctypeReader Modified: trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_JAXP_1_2_Schema_Validation.java =================================================================== --- trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_JAXP_1_2_Schema_Validation.java 2009-06-02 13:32:19 UTC (rev 340) +++ trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_JAXP_1_2_Schema_Validation.java 2009-06-02 14:12:23 UTC (rev 341) @@ -141,6 +141,26 @@ validator.assertIsValid(); } + public void testUsingStringArrayContainingStringURI() throws Exception { + File xsdFile = new File(test_Constants.BASEDIR + "/src/tests/resources/Book.xsd"); + assertTrue("xsdFile " + xsdFile.getAbsolutePath() + " exists", + xsdFile.exists()); + + File xmlFile = new File(test_Constants.BASEDIR + + "/src/tests/resources/BookXsdGeneratedNoSchema.xml"); + assertTrue("xmlFile " + xmlFile.getAbsolutePath() + " exists", + xmlFile.exists()); + + validator = new Validator(new FileReader(xmlFile)); + + validator.useXMLSchema(true); + validator.setJAXP12SchemaSource(new String[] { + xsdFile.getAbsolutePath() + }); + + validator.assertIsValid(); + } + public void testUsingNonExistentFile() throws Exception { File xsdFile = new File(test_Constants.BASEDIR + "/src/tests/resources/BookDoesNotExist.xsd"); assertFalse("xsdFile " + xsdFile.getAbsolutePath() + " exists", This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: Stefan B. <bo...@ap...> - 2009-06-02 08:12:30
|
To whom it may engage... This is an automated request, but not an unsolicited one. For more information please visit http://gump.apache.org/nagged.html, and/or contact the folk at ge...@gu.... Project xmlunit has an issue affecting its community integration. This issue affects 19 projects, and has been outstanding for 5 runs. The current state of this project is 'Failed', with reason 'Build Failed'. For reference only, the following projects are affected by this: - commons-jelly-tags-jaxme : Commons Jelly - commons-jelly-tags-jmx : Commons Jelly - commons-jelly-tags-ojb : Commons Jelly - commons-jelly-tags-xmlunit : Commons Jelly - db-ojb : ObjectRelationalBridge - db-ojb-from-packages : ObjectRelationalBridge - db-torque-runtime : Persistence Layer - db-torque-runtime-test : Persistence Layer - jakarta-turbine-jcs : Cache - jgroups : A Reliable Multicast Communication Toolkit for Java - mx4j : OpenSource implementation of a JMX agent - mx4j-remote : OpenSource implementation of a JMX agent - mx4j-tools : OpenSource implementation of a JMX agent - mx4j-tools-from-packaged-jetty : OpenSource implementation of a JMX agent - naming-management : Apache Directory Naming Component - test-ojb : ObjectRelationalBridge - ws-axis-test : Apache eXtensible Interaction System - xml-xindice : native XML database - xmlunit : JUnit extension for XML unit tests. Full details are available at: http://vmgump.apache.org/gump/public/xmlunit/xmlunit/index.html That said, some information snippets are provided here. The following annotations (debug/informational/warning/error messages) were provided: -INFO- Failed with reason build failed -INFO- Failed to extract fallback artifacts from Gump Repository The following work was performed: http://vmgump.apache.org/gump/public/xmlunit/xmlunit/gump_work/build_xmlunit_xmlunit.html Work Name: build_xmlunit_xmlunit (Type: Build) Work ended in a state of : Failed Elapsed: 2 secs Command Line: /usr/lib/jvm/java-6-sun/bin/java -Djava.awt.headless=true -Xbootclasspath/p:/srv/gump/public/workspace/xml-commons/java/external/build/xml-apis.jar:/srv/gump/public/workspace/xml-xerces2/build/xercesImpl.jar:/srv/gump/public/workspace/xml-xalan/build/serializer.jar:/srv/gump/public/workspace/xml-xalan/build/xalan-unbundled.jar org.apache.tools.ant.Main -Dgump.merge=/srv/gump/public/gump/work/merge.xml -Dbuild.sysclasspath=only -Dxmlunit.version=02062009 Gump [Working Directory: /srv/gump/public/workspace/xmlunit] CLASSPATH: /usr/lib/jvm/java-6-sun/lib/tools.jar:/srv/gump/public/workspace/xmlunit/build/java/core-classes:/srv/gump/public/workspace/xmlunit/build/java/core-test-classes:/srv/gump/public/workspace/xmlunit/build/java/legacy-classes:/srv/gump/public/workspace/xmlunit/build/java/legacy-test-classes:/srv/gump/public/workspace/ant/dist/lib/ant-jmf.jar:/srv/gump/public/workspace/ant/dist/lib/ant-swing.jar:/srv/gump/public/workspace/ant/dist/lib/ant-apache-resolver.jar:/srv/gump/public/workspace/ant/dist/lib/ant-apache-xalan2.jar:/srv/gump/public/workspace/ant/dist/lib/ant-trax.jar:/srv/gump/public/workspace/ant/dist/lib/ant-junit.jar:/srv/gump/public/workspace/ant/dist/lib/ant-launcher.jar:/srv/gump/public/workspace/ant/dist/lib/ant-nodeps.jar:/srv/gump/public/workspace/ant/dist/lib/ant.jar:/srv/gump/packages/junit3.8.1/junit.jar:/srv/gump/public/workspace/xml-commons/java/build/resolver.jar:/srv/gump/public/workspace/junit/dist/junit-02062009.jar:/srv/gump/public/workspace/xml-commons/java/external/build/xml-apis-ext.jar --------------------------------------------- [mkdir] Created dir: /srv/gump/public/workspace/xmlunit/build/java/core-classes [mkdir] Created dir: /srv/gump/public/workspace/xmlunit/build/java/legacy-classes [mkdir] Created dir: /srv/gump/public/workspace/xmlunit/build/java/core-test-classes [mkdir] Created dir: /srv/gump/public/workspace/xmlunit/build/java/legacy-test-classes [mkdir] Created dir: /srv/gump/public/workspace/xmlunit/build/java/test-report [mkdir] Created dir: /srv/gump/public/workspace/xmlunit/build/java/dist [mkdir] Created dir: /srv/gump/public/workspace/xmlunit/build/java/doc [mkdir] Created dir: /srv/gump/public/workspace/xmlunit/build/java/doc/userguide compile-core: [javac] Compiling 8 source files to /srv/gump/public/workspace/xmlunit/build/java/core-classes compile-core-tests: [javac] Compiling 2 source files to /srv/gump/public/workspace/xmlunit/build/java/core-test-classes [javac] /srv/gump/public/workspace/xmlunit/src/tests/java-core/net/sf/xmlunit/builder/InputTest.java:48: cannot find symbol [javac] symbol : method assertThat(javax.xml.transform.Source,org.hamcrest.Matcher<capture#983 of ? super javax.xml.transform.dom.DOMSource>) [javac] location: class net.sf.xmlunit.builder.InputTest [javac] assertThat(s, is(DOMSource.class)); [javac] ^ [javac] /srv/gump/public/workspace/xmlunit/src/tests/java-core/net/sf/xmlunit/builder/InputTest.java:50: cannot find symbol [javac] symbol : method assertThat(java.lang.Object,org.hamcrest.Matcher<capture#474 of ? super org.w3c.dom.Document>) [javac] location: class net.sf.xmlunit.builder.InputTest [javac] assertThat(o, is(Document.class)); [javac] ^ [javac] /srv/gump/public/workspace/xmlunit/src/tests/java-core/net/sf/xmlunit/builder/InputTest.java:116: cannot find symbol [javac] symbol : method assertThat(javax.xml.transform.Source,org.hamcrest.Matcher<capture#374 of ? super javax.xml.transform.dom.DOMSource>) [javac] location: class net.sf.xmlunit.builder.InputTest [javac] assertThat(s, is(DOMSource.class)); [javac] ^ [javac] /srv/gump/public/workspace/xmlunit/src/tests/java-core/net/sf/xmlunit/builder/InputTest.java:118: cannot find symbol [javac] symbol : method assertThat(java.lang.Object,org.hamcrest.Matcher<capture#754 of ? super org.w3c.dom.Document>) [javac] location: class net.sf.xmlunit.builder.InputTest [javac] assertThat(o, is(Document.class)); [javac] ^ [javac] /srv/gump/public/workspace/xmlunit/src/tests/java-core/net/sf/xmlunit/validation/JAXPValidatorTest.java:64: cannot find symbol [javac] symbol : method assertThat(java.lang.Exception,org.hamcrest.Matcher<capture#94 of ? super net.sf.xmlunit.exceptions.XMLUnitException>) [javac] location: class net.sf.xmlunit.validation.JAXPValidatorTest [javac] assertThat(e, is(XMLUnitException.class)); [javac] ^ [javac] /srv/gump/public/workspace/xmlunit/src/tests/java-core/net/sf/xmlunit/validation/JAXPValidatorTest.java:75: cannot find symbol [javac] symbol : method assertThat(java.lang.Exception,org.hamcrest.Matcher<capture#97 of ? super net.sf.xmlunit.exceptions.XMLUnitException>) [javac] location: class net.sf.xmlunit.validation.JAXPValidatorTest [javac] assertThat(e, is(XMLUnitException.class)); [javac] ^ [javac] 6 errors BUILD FAILED /srv/gump/public/workspace/xmlunit/build.xml:123: Compile failed; see the compiler error output for details. Total time: 2 seconds --------------------------------------------- To subscribe to this information via syndicated feeds: - RSS: http://vmgump.apache.org/gump/public/xmlunit/xmlunit/rss.xml - Atom: http://vmgump.apache.org/gump/public/xmlunit/xmlunit/atom.xml ============================== Gump Tracking Only === Produced by Gump version 2.3. Gump Run 12000002062009, vmgump:vmgump-public:12000002062009 Gump E-mail Identifier (unique within run) #9. -- Apache Gump http://gump.apache.org/ [Instance: vmgump] |
From: Stefan B. <bo...@ap...> - 2009-05-31 08:23:51
|
To whom it may engage... This is an automated request, but not an unsolicited one. For more information please visit http://gump.apache.org/nagged.html, and/or contact the folk at ge...@gu.... Project xmlunit has an issue affecting its community integration. This issue affects 19 projects, and has been outstanding for 2 runs. The current state of this project is 'Failed', with reason 'Build Failed'. For reference only, the following projects are affected by this: - commons-jelly-tags-jaxme : Commons Jelly - commons-jelly-tags-jmx : Commons Jelly - commons-jelly-tags-ojb : Commons Jelly - commons-jelly-tags-xmlunit : Commons Jelly - db-ojb : ObjectRelationalBridge - db-ojb-from-packages : ObjectRelationalBridge - db-torque-runtime : Persistence Layer - db-torque-runtime-test : Persistence Layer - jakarta-turbine-jcs : Cache - jgroups : A Reliable Multicast Communication Toolkit for Java - mx4j : OpenSource implementation of a JMX agent - mx4j-remote : OpenSource implementation of a JMX agent - mx4j-tools : OpenSource implementation of a JMX agent - mx4j-tools-from-packaged-jetty : OpenSource implementation of a JMX agent - naming-management : Apache Directory Naming Component - test-ojb : ObjectRelationalBridge - ws-axis-test : Apache eXtensible Interaction System - xml-xindice : native XML database - xmlunit : JUnit extension for XML unit tests. Full details are available at: http://vmgump.apache.org/gump/public/xmlunit/xmlunit/index.html That said, some information snippets are provided here. The following annotations (debug/informational/warning/error messages) were provided: -INFO- Failed with reason build failed -INFO- Failed to extract fallback artifacts from Gump Repository The following work was performed: http://vmgump.apache.org/gump/public/xmlunit/xmlunit/gump_work/build_xmlunit_xmlunit.html Work Name: build_xmlunit_xmlunit (Type: Build) Work ended in a state of : Failed Elapsed: 3 secs Command Line: /usr/lib/jvm/java-6-sun/bin/java -Djava.awt.headless=true -Xbootclasspath/p:/srv/gump/public/workspace/xml-commons/java/external/build/xml-apis.jar:/srv/gump/public/workspace/xml-xerces2/build/xercesImpl.jar:/srv/gump/public/workspace/xml-xalan/build/serializer.jar:/srv/gump/public/workspace/xml-xalan/build/xalan-unbundled.jar org.apache.tools.ant.Main -Dgump.merge=/srv/gump/public/gump/work/merge.xml -Dbuild.sysclasspath=only -Dxmlunit.version=31052009 Gump [Working Directory: /srv/gump/public/workspace/xmlunit] CLASSPATH: /usr/lib/jvm/java-6-sun/lib/tools.jar:/srv/gump/public/workspace/xmlunit/build/java/core-classes:/srv/gump/public/workspace/xmlunit/build/java/core-test-classes:/srv/gump/public/workspace/xmlunit/build/java/legacy-classes:/srv/gump/public/workspace/xmlunit/build/java/legacy-test-classes:/srv/gump/public/workspace/ant/dist/lib/ant-jmf.jar:/srv/gump/public/workspace/ant/dist/lib/ant-swing.jar:/srv/gump/public/workspace/ant/dist/lib/ant-apache-resolver.jar:/srv/gump/public/workspace/ant/dist/lib/ant-apache-xalan2.jar:/srv/gump/public/workspace/ant/dist/lib/ant-trax.jar:/srv/gump/public/workspace/ant/dist/lib/ant-junit.jar:/srv/gump/public/workspace/ant/dist/lib/ant-launcher.jar:/srv/gump/public/workspace/ant/dist/lib/ant-nodeps.jar:/srv/gump/public/workspace/ant/dist/lib/ant.jar:/srv/gump/packages/junit3.8.1/junit.jar:/srv/gump/public/workspace/xml-commons/java/build/resolver.jar:/srv/gump/public/workspace/junit/dist/junit-31052009.jar:/srv/gump/public/workspace/xml-commons/java/external/build/xml-apis-ext.jar --------------------------------------------- [mkdir] Created dir: /srv/gump/public/workspace/xmlunit/build/java/core-classes [mkdir] Created dir: /srv/gump/public/workspace/xmlunit/build/java/legacy-classes [mkdir] Created dir: /srv/gump/public/workspace/xmlunit/build/java/core-test-classes [mkdir] Created dir: /srv/gump/public/workspace/xmlunit/build/java/legacy-test-classes [mkdir] Created dir: /srv/gump/public/workspace/xmlunit/build/java/test-report [mkdir] Created dir: /srv/gump/public/workspace/xmlunit/build/java/dist [mkdir] Created dir: /srv/gump/public/workspace/xmlunit/build/java/doc [mkdir] Created dir: /srv/gump/public/workspace/xmlunit/build/java/doc/userguide compile-core: [javac] Compiling 8 source files to /srv/gump/public/workspace/xmlunit/build/java/core-classes compile-core-tests: [javac] Compiling 2 source files to /srv/gump/public/workspace/xmlunit/build/java/core-test-classes [javac] /srv/gump/public/workspace/xmlunit/src/tests/java-core/net/sf/xmlunit/builder/InputTest.java:48: cannot find symbol [javac] symbol : method assertThat(javax.xml.transform.Source,org.hamcrest.Matcher<capture#983 of ? super javax.xml.transform.dom.DOMSource>) [javac] location: class net.sf.xmlunit.builder.InputTest [javac] assertThat(s, is(DOMSource.class)); [javac] ^ [javac] /srv/gump/public/workspace/xmlunit/src/tests/java-core/net/sf/xmlunit/builder/InputTest.java:50: cannot find symbol [javac] symbol : method assertThat(java.lang.Object,org.hamcrest.Matcher<capture#474 of ? super org.w3c.dom.Document>) [javac] location: class net.sf.xmlunit.builder.InputTest [javac] assertThat(o, is(Document.class)); [javac] ^ [javac] /srv/gump/public/workspace/xmlunit/src/tests/java-core/net/sf/xmlunit/builder/InputTest.java:116: cannot find symbol [javac] symbol : method assertThat(javax.xml.transform.Source,org.hamcrest.Matcher<capture#374 of ? super javax.xml.transform.dom.DOMSource>) [javac] location: class net.sf.xmlunit.builder.InputTest [javac] assertThat(s, is(DOMSource.class)); [javac] ^ [javac] /srv/gump/public/workspace/xmlunit/src/tests/java-core/net/sf/xmlunit/builder/InputTest.java:118: cannot find symbol [javac] symbol : method assertThat(java.lang.Object,org.hamcrest.Matcher<capture#754 of ? super org.w3c.dom.Document>) [javac] location: class net.sf.xmlunit.builder.InputTest [javac] assertThat(o, is(Document.class)); [javac] ^ [javac] /srv/gump/public/workspace/xmlunit/src/tests/java-core/net/sf/xmlunit/validation/JAXPValidatorTest.java:64: cannot find symbol [javac] symbol : method assertThat(java.lang.Exception,org.hamcrest.Matcher<capture#94 of ? super net.sf.xmlunit.exceptions.XMLUnitException>) [javac] location: class net.sf.xmlunit.validation.JAXPValidatorTest [javac] assertThat(e, is(XMLUnitException.class)); [javac] ^ [javac] /srv/gump/public/workspace/xmlunit/src/tests/java-core/net/sf/xmlunit/validation/JAXPValidatorTest.java:75: cannot find symbol [javac] symbol : method assertThat(java.lang.Exception,org.hamcrest.Matcher<capture#428 of ? super net.sf.xmlunit.exceptions.XMLUnitException>) [javac] location: class net.sf.xmlunit.validation.JAXPValidatorTest [javac] assertThat(e, is(XMLUnitException.class)); [javac] ^ [javac] 6 errors BUILD FAILED /srv/gump/public/workspace/xmlunit/build.xml:123: Compile failed; see the compiler error output for details. Total time: 2 seconds --------------------------------------------- To subscribe to this information via syndicated feeds: - RSS: http://vmgump.apache.org/gump/public/xmlunit/xmlunit/rss.xml - Atom: http://vmgump.apache.org/gump/public/xmlunit/xmlunit/atom.xml ============================== Gump Tracking Only === Produced by Gump version 2.3. Gump Run 35000031052009, vmgump:vmgump-public:35000031052009 Gump E-mail Identifier (unique within run) #6. -- Apache Gump http://gump.apache.org/ [Instance: vmgump] |
From: Stefan B. <bo...@ap...> - 2009-05-30 16:07:49
|
To whom it may engage... This is an automated request, but not an unsolicited one. For more information please visit http://gump.apache.org/nagged.html, and/or contact the folk at ge...@gu.... Project xmlunit has an issue affecting its community integration. This issue affects 19 projects. The current state of this project is 'Failed', with reason 'Build Failed'. For reference only, the following projects are affected by this: - commons-jelly-tags-jaxme : Commons Jelly - commons-jelly-tags-jmx : Commons Jelly - commons-jelly-tags-ojb : Commons Jelly - commons-jelly-tags-xmlunit : Commons Jelly - db-ojb : ObjectRelationalBridge - db-ojb-from-packages : ObjectRelationalBridge - db-torque-runtime : Persistence Layer - db-torque-runtime-test : Persistence Layer - jakarta-turbine-jcs : Cache - jgroups : A Reliable Multicast Communication Toolkit for Java - mx4j : OpenSource implementation of a JMX agent - mx4j-remote : OpenSource implementation of a JMX agent - mx4j-tools : OpenSource implementation of a JMX agent - mx4j-tools-from-packaged-jetty : OpenSource implementation of a JMX agent - naming-management : Apache Directory Naming Component - test-ojb : ObjectRelationalBridge - ws-axis-test : Apache eXtensible Interaction System - xml-xindice : native XML database - xmlunit : JUnit extension for XML unit tests. Full details are available at: http://vmgump.apache.org/gump/public/xmlunit/xmlunit/index.html That said, some information snippets are provided here. The following annotations (debug/informational/warning/error messages) were provided: -INFO- Failed with reason build failed -DEBUG- Extracted fallback artifacts from Gump Repository The following work was performed: http://vmgump.apache.org/gump/public/xmlunit/xmlunit/gump_work/build_xmlunit_xmlunit.html Work Name: build_xmlunit_xmlunit (Type: Build) Work ended in a state of : Failed Elapsed: 3 secs Command Line: /usr/lib/jvm/java-6-sun/bin/java -Djava.awt.headless=true -Xbootclasspath/p:/srv/gump/public/workspace/xml-commons/java/external/build/xml-apis.jar:/srv/gump/public/workspace/xml-xerces2/build/xercesImpl.jar:/srv/gump/public/workspace/xml-xalan/build/serializer.jar:/srv/gump/public/workspace/xml-xalan/build/xalan-unbundled.jar org.apache.tools.ant.Main -Dgump.merge=/srv/gump/public/gump/work/merge.xml -Dbuild.sysclasspath=only -Dxmlunit.version=30052009 Gump [Working Directory: /srv/gump/public/workspace/xmlunit] CLASSPATH: /usr/lib/jvm/java-6-sun/lib/tools.jar:/srv/gump/public/workspace/xmlunit/build/java/core-classes:/srv/gump/public/workspace/xmlunit/build/java/core-test-classes:/srv/gump/public/workspace/xmlunit/build/java/legacy-classes:/srv/gump/public/workspace/xmlunit/build/java/legacy-test-classes:/srv/gump/public/workspace/ant/dist/lib/ant-jmf.jar:/srv/gump/public/workspace/ant/dist/lib/ant-swing.jar:/srv/gump/public/workspace/ant/dist/lib/ant-apache-resolver.jar:/srv/gump/public/workspace/ant/dist/lib/ant-apache-xalan2.jar:/srv/gump/public/workspace/ant/dist/lib/ant-trax.jar:/srv/gump/public/workspace/ant/dist/lib/ant-junit.jar:/srv/gump/public/workspace/ant/dist/lib/ant-launcher.jar:/srv/gump/public/workspace/ant/dist/lib/ant-nodeps.jar:/srv/gump/public/workspace/ant/dist/lib/ant.jar:/srv/gump/packages/junit3.8.1/junit.jar:/srv/gump/public/workspace/xml-commons/java/build/resolver.jar:/srv/gump/public/workspace/junit/dist/junit-30052009.jar:/srv/gump/public/workspace/xml-commons/java/external/build/xml-apis-ext.jar --------------------------------------------- [mkdir] Created dir: /srv/gump/public/workspace/xmlunit/build/java/core-classes [mkdir] Created dir: /srv/gump/public/workspace/xmlunit/build/java/legacy-classes [mkdir] Created dir: /srv/gump/public/workspace/xmlunit/build/java/core-test-classes [mkdir] Created dir: /srv/gump/public/workspace/xmlunit/build/java/legacy-test-classes [mkdir] Created dir: /srv/gump/public/workspace/xmlunit/build/java/test-report [mkdir] Created dir: /srv/gump/public/workspace/xmlunit/build/java/dist [mkdir] Created dir: /srv/gump/public/workspace/xmlunit/build/java/doc [mkdir] Created dir: /srv/gump/public/workspace/xmlunit/build/java/doc/userguide compile-core: [javac] Compiling 8 source files to /srv/gump/public/workspace/xmlunit/build/java/core-classes compile-core-tests: [javac] Compiling 2 source files to /srv/gump/public/workspace/xmlunit/build/java/core-test-classes [javac] /srv/gump/public/workspace/xmlunit/src/tests/java-core/net/sf/xmlunit/builder/InputTest.java:48: cannot find symbol [javac] symbol : method assertThat(javax.xml.transform.Source,org.hamcrest.Matcher<capture#983 of ? super javax.xml.transform.dom.DOMSource>) [javac] location: class net.sf.xmlunit.builder.InputTest [javac] assertThat(s, is(DOMSource.class)); [javac] ^ [javac] /srv/gump/public/workspace/xmlunit/src/tests/java-core/net/sf/xmlunit/builder/InputTest.java:50: cannot find symbol [javac] symbol : method assertThat(java.lang.Object,org.hamcrest.Matcher<capture#474 of ? super org.w3c.dom.Document>) [javac] location: class net.sf.xmlunit.builder.InputTest [javac] assertThat(o, is(Document.class)); [javac] ^ [javac] /srv/gump/public/workspace/xmlunit/src/tests/java-core/net/sf/xmlunit/builder/InputTest.java:116: cannot find symbol [javac] symbol : method assertThat(javax.xml.transform.Source,org.hamcrest.Matcher<capture#374 of ? super javax.xml.transform.dom.DOMSource>) [javac] location: class net.sf.xmlunit.builder.InputTest [javac] assertThat(s, is(DOMSource.class)); [javac] ^ [javac] /srv/gump/public/workspace/xmlunit/src/tests/java-core/net/sf/xmlunit/builder/InputTest.java:118: cannot find symbol [javac] symbol : method assertThat(java.lang.Object,org.hamcrest.Matcher<capture#754 of ? super org.w3c.dom.Document>) [javac] location: class net.sf.xmlunit.builder.InputTest [javac] assertThat(o, is(Document.class)); [javac] ^ [javac] /srv/gump/public/workspace/xmlunit/src/tests/java-core/net/sf/xmlunit/validation/JAXPValidatorTest.java:64: cannot find symbol [javac] symbol : method assertThat(java.lang.Exception,org.hamcrest.Matcher<capture#94 of ? super net.sf.xmlunit.exceptions.XMLUnitException>) [javac] location: class net.sf.xmlunit.validation.JAXPValidatorTest [javac] assertThat(e, is(XMLUnitException.class)); [javac] ^ [javac] /srv/gump/public/workspace/xmlunit/src/tests/java-core/net/sf/xmlunit/validation/JAXPValidatorTest.java:75: cannot find symbol [javac] symbol : method assertThat(java.lang.Exception,org.hamcrest.Matcher<capture#97 of ? super net.sf.xmlunit.exceptions.XMLUnitException>) [javac] location: class net.sf.xmlunit.validation.JAXPValidatorTest [javac] assertThat(e, is(XMLUnitException.class)); [javac] ^ [javac] 6 errors BUILD FAILED /srv/gump/public/workspace/xmlunit/build.xml:123: Compile failed; see the compiler error output for details. Total time: 2 seconds --------------------------------------------- To subscribe to this information via syndicated feeds: - RSS: http://vmgump.apache.org/gump/public/xmlunit/xmlunit/rss.xml - Atom: http://vmgump.apache.org/gump/public/xmlunit/xmlunit/atom.xml ============================== Gump Tracking Only === Produced by Gump version 2.3. Gump Run 32000830052009, vmgump:vmgump-public:32000830052009 Gump E-mail Identifier (unique within run) #4. -- Apache Gump http://gump.apache.org/ [Instance: vmgump] |
From: <bo...@us...> - 2009-05-28 13:07:19
|
Revision: 339 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=339&view=rev Author: bodewig Date: 2009-05-28 13:07:01 +0000 (Thu, 28 May 2009) Log Message: ----------- JAXP implementation of Validator Modified Paths: -------------- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/ValidationProblem.java trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/Validator.java trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/jaxp13/Validator.java Added Paths: ----------- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/JAXPValidator.java trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/validation/ trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/validation/JAXPValidatorTest.java Added: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/JAXPValidator.java =================================================================== --- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/JAXPValidator.java (rev 0) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/JAXPValidator.java 2009-05-28 13:07:01 UTC (rev 339) @@ -0,0 +1,127 @@ +/* + This file is licensed 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 net.sf.xmlunit.validation; + +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import javax.xml.transform.Source; +import javax.xml.validation.Schema; +import javax.xml.validation.SchemaFactory; +import net.sf.xmlunit.exceptions.XMLUnitException; +import org.xml.sax.ErrorHandler; +import org.xml.sax.SAXException; +import org.xml.sax.SAXParseException; + +/** + * Validator using the javax.xml.validation namespace. + */ +public class JAXPValidator extends Validator { + private final String language; + private final SchemaFactory factory; + + public JAXPValidator(String language) { + this(language, null); + } + + public JAXPValidator(String language, SchemaFactory factory) { + this.language = language; + this.factory = factory; + } + + private SchemaFactory getFactory() { + return factory == null ? SchemaFactory.newInstance(language) : factory; + } + + @Override public ValidationResult validateSchema() { + ValidationHandler v = new ValidationHandler(); + SchemaFactory f = getFactory(); + f.setErrorHandler(v); + try { + f.newSchema(getSchemaSources()); + } catch (SAXException e) { + if (e instanceof SAXParseException) { + v.error((SAXParseException) e); + } else { + throw new XMLUnitException(e); + } + } finally { + f.setErrorHandler(null); + } + return v.getResult(); + } + + @Override public ValidationResult validateInstance(Source s) { + Schema schema; + try { + schema = getFactory().newSchema(getSchemaSources()); + } catch (SAXException e) { + throw new XMLUnitException("The schema is invalid", e); + } + ValidationHandler v = new ValidationHandler(); + javax.xml.validation.Validator val = schema.newValidator(); + val.setErrorHandler(v); + try { + val.validate(s); + } catch (SAXException e) { + if (e instanceof SAXParseException) { + v.error((SAXParseException) e); + } else { + throw new XMLUnitException(e); + } + } catch (java.io.IOException e) { + throw new XMLUnitException(e); + } + return v.getResult(); + } + + + private static class ValidationHandler implements ErrorHandler { + private List<ValidationProblem> problems = + new LinkedList<ValidationProblem>(); + private boolean valid = true; + // fatal errors are re-thrown by the parser + private SAXParseException lastFatalError = null; + + public void error(SAXParseException e) { + if (e != lastFatalError) { + valid = false; + problems.add(ValidationProblem.fromException(e, + ValidationProblem + .ProblemType.ERROR) + ); + } + } + + public void fatalError(SAXParseException e) { + valid = false; + lastFatalError = e; + problems.add(ValidationProblem.fromException(e, + ValidationProblem + .ProblemType.ERROR)); + } + + public void warning(SAXParseException e) { + problems.add(ValidationProblem.fromException(e, + ValidationProblem + .ProblemType.WARNING)); + } + + private ValidationResult getResult() { + return new ValidationResult(valid, + Collections.unmodifiableList(problems) + ); + } + } +} Property changes on: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/JAXPValidator.java ___________________________________________________________________ Added: svn:eol-style + native Modified: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/ValidationProblem.java =================================================================== --- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/ValidationProblem.java 2009-05-27 14:47:22 UTC (rev 338) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/ValidationProblem.java 2009-05-28 13:07:01 UTC (rev 339) @@ -13,6 +13,8 @@ */ package net.sf.xmlunit.validation; +import org.xml.sax.SAXParseException; + /** * A validation "problem" which may be an error or a warning. */ @@ -60,4 +62,15 @@ public String getMessage() { return message; } + + static ValidationProblem fromException(SAXParseException e, + ProblemType type) { + return new ValidationProblem(e.getMessage(), + e.getLineNumber() > 0 + ? e.getLineNumber() : UNKNOWN, + e.getColumnNumber() > 0 + ? e.getColumnNumber() : UNKNOWN, + type); + } + } Modified: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/Validator.java =================================================================== --- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/Validator.java 2009-05-27 14:47:22 UTC (rev 338) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/Validator.java 2009-05-28 13:07:01 UTC (rev 339) @@ -55,7 +55,7 @@ } protected Source[] getSchemaSources() { - return sourceLocations; + return sourceLocations == null ? new Source[0] : sourceLocations; } /** Modified: trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/jaxp13/Validator.java =================================================================== --- trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/jaxp13/Validator.java 2009-05-27 14:47:22 UTC (rev 338) +++ trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/jaxp13/Validator.java 2009-05-28 13:07:01 UTC (rev 339) @@ -38,13 +38,13 @@ import java.util.ArrayList; import java.util.List; -import javax.xml.XMLConstants; import javax.xml.transform.Source; -import javax.xml.validation.Schema; import javax.xml.validation.SchemaFactory; +import net.sf.xmlunit.exceptions.XMLUnitException; +import net.sf.xmlunit.validation.JAXPValidator; +import net.sf.xmlunit.validation.Languages; +import net.sf.xmlunit.validation.ValidationProblem; import org.custommonkey.xmlunit.exceptions.XMLUnitRuntimeException; -import org.xml.sax.ErrorHandler; -import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; /** @@ -56,15 +56,14 @@ * by your SchemaFactory implementation.</p> */ public class Validator { - private final String schemaLanguage; - private final SchemaFactory factory; - private final ArrayList sources = new ArrayList(); + private final ArrayList<Source> sources = new ArrayList<Source>(); + private final JAXPValidator validator; /** * validates using W3C XML Schema 1.0. */ public Validator() { - this(XMLConstants.W3C_XML_SCHEMA_NS_URI, null); + this(Languages.W3C_XML_SCHEMA_NS_URI, null); } /** @@ -93,8 +92,7 @@ * non-null, the first argument will be ignored. */ protected Validator(String schemaLanguage, SchemaFactory factory) { - this.schemaLanguage = schemaLanguage; - this.factory = factory; + validator = new JAXPValidator(schemaLanguage, factory); } /** @@ -102,13 +100,14 @@ */ public void addSchemaSource(Source s) { sources.add(s); + validator.setSchemaSources(sources.toArray(new Source[0])); } /** * Is the given schema definition valid? */ public boolean isSchemaValid() { - return getSchemaErrors().size() == 0; + return validator.validateSchema().isValid(); } /** @@ -117,27 +116,8 @@ * <p>The list contains {@link org.xml.sax.SAXParseException * SAXParseException}s.</p> */ - public List/*<SAXParseException>*/ getSchemaErrors() { - final ArrayList l = new ArrayList(); - try { - parseSchema(new CollectingErrorHandler(l)); - } catch (SAXException e) { - // error should have been recorded in our ErrorHandler, at - // least that's what the Javadocs say "SchemaFactory is - // not allowed to throw SAXException without first - // reporting it to ErrorHandler.". - // - // Unfortunately not all implementations seem to follow - // this rule. In particular using the setup described in - // org.custommonkey.xmlunit.jaxp13.test_Validator#XtestGoodRelaxNGCompactSyntaxIsValid() - // an exception ("SAXParseException: Content is not - // allowed in prolog.") will be thrown that never enters - // our Errorhandler. - if (l.size() == 0) { - l.add(e); - } - } - return l; + public List<SAXParseException> getSchemaErrors() { + return problemToExceptionList(validator.validateSchema().getProblems()); } /** @@ -150,9 +130,12 @@ * javax.xml.validation.Validator#validate validate in * Validator}). */ - public boolean isInstanceValid(Source instance) - throws XMLUnitRuntimeException { - return getInstanceErrors(instance).size() == 0; + public boolean isInstanceValid(Source instance) { + try { + return validator.validateInstance(instance).isValid(); + } catch (XMLUnitException e) { + throw new XMLUnitRuntimeException(e.getMessage(), e.getCause()); + } } /** @@ -167,59 +150,23 @@ * javax.xml.validation.Validator#validate validate in * Validator}). */ - public List/*<SAXParseException>*/ getInstanceErrors(Source instance) - throws XMLUnitRuntimeException { - Schema schema = null; + public List<SAXParseException> getInstanceErrors(Source instance) { try { - schema = parseSchema(null); - } catch (SAXException e) { - throw new XMLUnitRuntimeException("Schema is invalid", e); + return problemToExceptionList(validator.validateInstance(instance). + getProblems()); + } catch (XMLUnitException e) { + throw new XMLUnitRuntimeException(e.getMessage(), e.getCause()); } + } - final ArrayList l = new ArrayList(); - javax.xml.validation.Validator v = schema.newValidator(); - v.setErrorHandler(new CollectingErrorHandler(l)); - try { - v.validate(instance); - } catch (SAXException e) { - // error should have been recorded in our ErrorHandler, - // but better double-check. - if (l.size() == 0) { - l.add(e); - } - } catch (java.io.IOException i) { - throw new XMLUnitRuntimeException("Error reading instance source", - i); + private static List<SAXParseException> + problemToExceptionList(Iterable<ValidationProblem> problems) { + final List<SAXParseException> l = new ArrayList<SAXParseException>(); + for (ValidationProblem p : problems) { + l.add(new SAXParseException(p.getMessage(), + null, null, + p.getLine(), p.getColumn())); } return l; } - - private Schema parseSchema(ErrorHandler h) throws SAXException { - SchemaFactory fac = factory != null ? factory - : SchemaFactory.newInstance(schemaLanguage); - fac.setErrorHandler(h); - try { - return fac.newSchema((Source[]) - sources.toArray(new Source[sources.size()])); - } finally { - fac.setErrorHandler(null); - } - } - - private static final class CollectingErrorHandler implements ErrorHandler { - private final List l; - - CollectingErrorHandler(List l) { - this.l = l; - } - public void error(SAXParseException e) { - l.add(e); - } - public void fatalError(SAXParseException e) { - l.add(e); - } - public void warning(SAXParseException e) { - l.add(e); - } - } } Added: trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/validation/JAXPValidatorTest.java =================================================================== --- trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/validation/JAXPValidatorTest.java (rev 0) +++ trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/validation/JAXPValidatorTest.java 2009-05-28 13:07:01 UTC (rev 339) @@ -0,0 +1,78 @@ +/* + This file is licensed 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 net.sf.xmlunit.validation; + +import java.io.File; +import javax.xml.transform.stream.StreamSource; +import net.sf.xmlunit.exceptions.XMLUnitException; +import static org.hamcrest.core.Is.*; +import static org.junit.Assert.*; +import org.junit.Test; + +public class JAXPValidatorTest { + + @Test public void shouldSuccessfullyValidateSchema() { + JAXPValidator v = new JAXPValidator(Languages.W3C_XML_SCHEMA_NS_URI); + v.setSchemaSource(new StreamSource(new File("src/tests/resources/Book.xsd"))); + ValidationResult r = v.validateSchema(); + assertTrue(r.isValid()); + assertFalse(r.getProblems().iterator().hasNext()); + } + + @Test public void shouldSuccessfullyValidateInstance() { + JAXPValidator v = new JAXPValidator(Languages.W3C_XML_SCHEMA_NS_URI); + v.setSchemaSource(new StreamSource(new File("src/tests/resources/Book.xsd"))); + ValidationResult r = v.validateInstance(new StreamSource(new File("src/tests/resources/BookXsdGenerated.xml"))); + assertTrue(r.isValid()); + assertFalse(r.getProblems().iterator().hasNext()); + } + + @Test public void shouldFailOnBrokenSchema() { + JAXPValidator v = new JAXPValidator(Languages.W3C_XML_SCHEMA_NS_URI); + v.setSchemaSource(new StreamSource(new File("src/tests/resources/broken.xsd"))); + ValidationResult r = v.validateSchema(); + assertFalse(r.isValid()); + assertTrue(r.getProblems().iterator().hasNext()); + } + + @Test public void shouldFailOnBrokenInstance() { + JAXPValidator v = new JAXPValidator(Languages.W3C_XML_SCHEMA_NS_URI); + v.setSchemaSource(new StreamSource(new File("src/tests/resources/Book.xsd"))); + ValidationResult r = v.validateInstance(new StreamSource(new File("src/tests/resources/invalidBook.xml"))); + assertFalse(r.isValid()); + assertTrue(r.getProblems().iterator().hasNext()); + } + + @Test public void shouldThrowWhenValidatingInstanceAndSchemaIsInvalid() { + JAXPValidator v = new JAXPValidator(Languages.W3C_XML_SCHEMA_NS_URI); + v.setSchemaSource(new StreamSource(new File("src/tests/resources/broken.xsd"))); + try { + v.validateInstance(new StreamSource(new File("src/tests/resources/BookXsdGenerated.xml"))); + fail("should have thrown an exception"); + } catch (Exception e) { + assertThat(e, is(XMLUnitException.class)); + } + } + + @Test public void shouldThrowWhenValidatingInstanceAndSchemaIsNotThere() { + JAXPValidator v = new JAXPValidator(Languages.W3C_XML_SCHEMA_NS_URI); + v.setSchemaSource(new StreamSource(new File("src/tests/resources/foo.xsd"))); + try { + v.validateInstance(new StreamSource(new File("src/tests/resources/BookXsdGenerated.xml"))); + fail("should have thrown an exception"); + } catch (Exception e) { + assertThat(e, is(XMLUnitException.class)); + } + } +} Property changes on: trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/validation/JAXPValidatorTest.java ___________________________________________________________________ Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2009-05-27 14:47:28
|
Revision: 338 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=338&view=rev Author: bodewig Date: 2009-05-27 14:47:22 +0000 (Wed, 27 May 2009) Log Message: ----------- merge additional testcase from 1.x branch Modified Paths: -------------- trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_DifferenceEngine.java Property Changed: ---------------- trunk/xmlunit/src/tests/java-legacy/ Property changes on: trunk/xmlunit/src/tests/java-legacy ___________________________________________________________________ Modified: svn:mergeinfo - + /branches/xmlunit-1.x/tests/java:337 Modified: trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_DifferenceEngine.java =================================================================== --- trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_DifferenceEngine.java 2009-05-27 14:27:38 UTC (rev 337) +++ trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_DifferenceEngine.java 2009-05-27 14:47:22 UTC (rev 338) @@ -877,13 +877,66 @@ assertEquals(7, count[0]); } + /** + * @see http://sourceforge.net/forum/forum.php?thread_id=3284504&forum_id=73274 + */ + public void testNamespaceAttributeDifferences() throws Exception { + String control = "<?xml version = \"1.0\" encoding = \"UTF-8\"?>" + + "<ns0:Message xmlns:ns0 = \"http://mynamespace\">" + + "<ns0:EventHeader>" + + "<ns0:EventID>9999</ns0:EventID>" + + "<ns0:MessageID>1243409665297</ns0:MessageID>" + + "<ns0:MessageVersionID>1.0</ns0:MessageVersionID>" + + "<ns0:EventName>TEST-EVENT</ns0:EventName>" + + "<ns0:BWDomain>TEST</ns0:BWDomain>" + + "<ns0:DateTimeStamp>2009-01-01T12:00:00</ns0:DateTimeStamp>" + + "<ns0:SchemaPayloadRef>anything</ns0:SchemaPayloadRef>" + + "<ns0:MessageURI>anything</ns0:MessageURI>" + + "<ns0:ResendFlag>F</ns0:ResendFlag>" + + "</ns0:EventHeader>" + + "<ns0:EventBody>" + + "<ns0:XMLContent>" + + "<xyz:root xmlns:xyz=\"http://test.com/xyz\">" + + "<xyz:test1>A</xyz:test1>" + + "<xyz:test2>B</xyz:test2>" + + "</xyz:root>" + + "</ns0:XMLContent>" + + "</ns0:EventBody>" + + "</ns0:Message>"; + String test = + "<abc:Message xmlns:abc=\"http://mynamespace\" xmlns:xyz=\"http://test.com/xyz\">" + + "<abc:EventHeader>" + + "<abc:EventID>9999</abc:EventID>" + + "<abc:MessageID>1243409665297</abc:MessageID>" + + "<abc:MessageVersionID>1.0</abc:MessageVersionID>" + + "<abc:EventName>TEST-EVENT</abc:EventName>" + + "<abc:BWDomain>TEST</abc:BWDomain>" + + "<abc:DateTimeStamp>2009-01-01T12:00:00</abc:DateTimeStamp>" + + "<abc:SchemaPayloadRef>anything</abc:SchemaPayloadRef>" + + "<abc:MessageURI>anything</abc:MessageURI>" + + "<abc:ResendFlag>F</abc:ResendFlag>" + + "</abc:EventHeader>" + + "<abc:EventBody>" + + "<abc:XMLContent>" + + "<xyz:root>" + + "<xyz:test1>A</xyz:test1>" + + "<xyz:test2>B</xyz:test2>" + + "</xyz:root>" + + "</abc:XMLContent>" + + "</abc:EventBody>" + + "</abc:Message>"; + listener.tracing = true; + listenToDifferences(control, test); + assertFalse(listener.different); + } + private void listenToDifferences(String control, String test) throws SAXException, IOException { Document controlDoc = XMLUnit.buildControlDocument(control); Document testDoc = XMLUnit.buildTestDocument(test); engine.compare(controlDoc, testDoc, listener, DEFAULT_ELEMENT_QUALIFIER); } - + private void resetListener() { listener = new CollectingDifferenceListener(); @@ -901,13 +954,13 @@ return !afterDifference.isRecoverable(); } } - + private class NeverHaltingComparisonController implements ComparisonController { public boolean haltComparison(Difference afterDifference) { return false; } } - + private class CollectingDifferenceListener implements DifferenceListener { public String expected; public String actual; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2009-05-27 14:27:40
|
Revision: 337 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=337&view=rev Author: bodewig Date: 2009-05-27 14:27:38 +0000 (Wed, 27 May 2009) Log Message: ----------- Add unit test for forum thread Modified Paths: -------------- branches/xmlunit-1.x/tests/java/org/custommonkey/xmlunit/test_DifferenceEngine.java Modified: branches/xmlunit-1.x/tests/java/org/custommonkey/xmlunit/test_DifferenceEngine.java =================================================================== --- branches/xmlunit-1.x/tests/java/org/custommonkey/xmlunit/test_DifferenceEngine.java 2009-05-25 15:43:57 UTC (rev 336) +++ branches/xmlunit-1.x/tests/java/org/custommonkey/xmlunit/test_DifferenceEngine.java 2009-05-27 14:27:38 UTC (rev 337) @@ -877,13 +877,66 @@ assertEquals(7, count[0]); } + /** + * @see http://sourceforge.net/forum/forum.php?thread_id=3284504&forum_id=73274 + */ + public void testNamespaceAttributeDifferences() throws Exception { + String control = "<?xml version = \"1.0\" encoding = \"UTF-8\"?>" + + "<ns0:Message xmlns:ns0 = \"http://mynamespace\">" + + "<ns0:EventHeader>" + + "<ns0:EventID>9999</ns0:EventID>" + + "<ns0:MessageID>1243409665297</ns0:MessageID>" + + "<ns0:MessageVersionID>1.0</ns0:MessageVersionID>" + + "<ns0:EventName>TEST-EVENT</ns0:EventName>" + + "<ns0:BWDomain>TEST</ns0:BWDomain>" + + "<ns0:DateTimeStamp>2009-01-01T12:00:00</ns0:DateTimeStamp>" + + "<ns0:SchemaPayloadRef>anything</ns0:SchemaPayloadRef>" + + "<ns0:MessageURI>anything</ns0:MessageURI>" + + "<ns0:ResendFlag>F</ns0:ResendFlag>" + + "</ns0:EventHeader>" + + "<ns0:EventBody>" + + "<ns0:XMLContent>" + + "<xyz:root xmlns:xyz=\"http://test.com/xyz\">" + + "<xyz:test1>A</xyz:test1>" + + "<xyz:test2>B</xyz:test2>" + + "</xyz:root>" + + "</ns0:XMLContent>" + + "</ns0:EventBody>" + + "</ns0:Message>"; + String test = + "<abc:Message xmlns:abc=\"http://mynamespace\" xmlns:xyz=\"http://test.com/xyz\">" + + "<abc:EventHeader>" + + "<abc:EventID>9999</abc:EventID>" + + "<abc:MessageID>1243409665297</abc:MessageID>" + + "<abc:MessageVersionID>1.0</abc:MessageVersionID>" + + "<abc:EventName>TEST-EVENT</abc:EventName>" + + "<abc:BWDomain>TEST</abc:BWDomain>" + + "<abc:DateTimeStamp>2009-01-01T12:00:00</abc:DateTimeStamp>" + + "<abc:SchemaPayloadRef>anything</abc:SchemaPayloadRef>" + + "<abc:MessageURI>anything</abc:MessageURI>" + + "<abc:ResendFlag>F</abc:ResendFlag>" + + "</abc:EventHeader>" + + "<abc:EventBody>" + + "<abc:XMLContent>" + + "<xyz:root>" + + "<xyz:test1>A</xyz:test1>" + + "<xyz:test2>B</xyz:test2>" + + "</xyz:root>" + + "</abc:XMLContent>" + + "</abc:EventBody>" + + "</abc:Message>"; + listener.tracing = true; + listenToDifferences(control, test); + assertFalse(listener.different); + } + private void listenToDifferences(String control, String test) throws SAXException, IOException { Document controlDoc = XMLUnit.buildControlDocument(control); Document testDoc = XMLUnit.buildTestDocument(test); engine.compare(controlDoc, testDoc, listener, DEFAULT_ELEMENT_QUALIFIER); } - + private void resetListener() { listener = new CollectingDifferenceListener(); @@ -901,13 +954,13 @@ return !afterDifference.isRecoverable(); } } - + private class NeverHaltingComparisonController implements ComparisonController { public boolean haltComparison(Difference afterDifference) { return false; } } - + private class CollectingDifferenceListener implements DifferenceListener { public String expected; public String actual; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2009-05-25 15:44:05
|
Revision: 336 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=336&view=rev Author: bodewig Date: 2009-05-25 15:43:57 +0000 (Mon, 25 May 2009) Log Message: ----------- typo Modified Paths: -------------- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/Languages.java Modified: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/Languages.java =================================================================== --- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/Languages.java 2009-05-25 15:43:26 UTC (rev 335) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/Languages.java 2009-05-25 15:43:57 UTC (rev 336) @@ -16,7 +16,7 @@ import javax.xml.XMLConstants; /** - * Contants for the languages supported by XMLUnit's schema + * Constants for the languages supported by XMLUnit's schema * validation. More languages may be supported depending on your JAXP * environment. */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2009-05-25 15:43:31
|
Revision: 335 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=335&view=rev Author: bodewig Date: 2009-05-25 15:43:26 +0000 (Mon, 25 May 2009) Log Message: ----------- whitespace Modified Paths: -------------- trunk/xmlunit/src/main/net-core/validation/Languages.cs trunk/xmlunit/src/main/net-core/validation/ValidationProblem.cs trunk/xmlunit/src/main/net-core/validation/ValidationResult.cs trunk/xmlunit/src/main/net-core/validation/Validator.cs Modified: trunk/xmlunit/src/main/net-core/validation/Languages.cs =================================================================== --- trunk/xmlunit/src/main/net-core/validation/Languages.cs 2009-05-25 15:42:30 UTC (rev 334) +++ trunk/xmlunit/src/main/net-core/validation/Languages.cs 2009-05-25 15:43:26 UTC (rev 335) @@ -17,16 +17,16 @@ /// Constants for the languages supported by XMLUnit's schema /// validation. /// </summary> -public static class Languages { + public static class Languages { - /// <summary>W3C XML Schema.</summary> - public const string W3C_XML_SCHEMA_NS_URI = - "http://www.w3.org/2001/XMLSchema"; + /// <summary>W3C XML Schema.</summary> + public const string W3C_XML_SCHEMA_NS_URI = + "http://www.w3.org/2001/XMLSchema"; - /// <summary>DTD.</summary> - public const string XML_DTD_NS_URI = "http://www.w3.org/TR/REC-xml"; + /// <summary>DTD.</summary> + public const string XML_DTD_NS_URI = "http://www.w3.org/TR/REC-xml"; - /// <summary>XDR.</summary> - public const string XDR_NS_URI = "xmlunit:validation:XDR"; + /// <summary>XDR.</summary> + public const string XDR_NS_URI = "xmlunit:validation:XDR"; + } } -} Modified: trunk/xmlunit/src/main/net-core/validation/ValidationProblem.cs =================================================================== --- trunk/xmlunit/src/main/net-core/validation/ValidationProblem.cs 2009-05-25 15:42:30 UTC (rev 334) +++ trunk/xmlunit/src/main/net-core/validation/ValidationProblem.cs 2009-05-25 15:43:26 UTC (rev 335) @@ -18,55 +18,55 @@ /// <summary> /// A validation "problem" which may be an error or a warning. /// </summary> -public class ValidationProblem { - public const int UNKNOWN = -1; + public class ValidationProblem { + public const int UNKNOWN = -1; - private readonly int line, column; - private readonly XmlSeverityType type; - private readonly string message; + private readonly int line, column; + private readonly XmlSeverityType type; + private readonly string message; - public ValidationProblem(string message, int line, int column, - XmlSeverityType type) { - this.message = message; - this.line = line; - this.column = column; - this.type = type; - } + public ValidationProblem(string message, int line, int column, + XmlSeverityType type) { + this.message = message; + this.line = line; + this.column = column; + this.type = type; + } - /// <summary> - /// The line where the problem occured or UNKNOWN. - /// </summary> - public int Line { - get { - return line; + /// <summary> + /// The line where the problem occured or UNKNOWN. + /// </summary> + public int Line { + get { + return line; + } } - } - /// <summary> - /// The column where the problem occured or UNKNOWN. - /// </summary> - public int Column { - get { - return column; + /// <summary> + /// The column where the problem occured or UNKNOWN. + /// </summary> + public int Column { + get { + return column; + } } - } - /// <summary> - /// Whether this is an error or a warning. - /// </summary> - public XmlSeverityType Type { - get { - return type; + /// <summary> + /// Whether this is an error or a warning. + /// </summary> + public XmlSeverityType Type { + get { + return type; + } } - } - /// <summary> - /// The problem's message. - /// </summary> - public string Message { - get { - return message; + /// <summary> + /// The problem's message. + /// </summary> + public string Message { + get { + return message; + } } } } -} Modified: trunk/xmlunit/src/main/net-core/validation/ValidationResult.cs =================================================================== --- trunk/xmlunit/src/main/net-core/validation/ValidationResult.cs 2009-05-25 15:42:30 UTC (rev 334) +++ trunk/xmlunit/src/main/net-core/validation/ValidationResult.cs 2009-05-25 15:43:26 UTC (rev 335) @@ -19,32 +19,32 @@ /// <summary> /// The result of a validation. /// </summary> -public class ValidationResult { - private readonly bool valid; - private readonly IEnumerable<ValidationProblem> problems; + public class ValidationResult { + private readonly bool valid; + private readonly IEnumerable<ValidationProblem> problems; - public ValidationResult(bool valid, IEnumerable<ValidationProblem> problems) { - this.valid = valid; - this.problems = problems; - } + public ValidationResult(bool valid, IEnumerable<ValidationProblem> problems) { + this.valid = valid; + this.problems = problems; + } - /// <summary> - /// Has the validation been successful? - /// </summary> - public bool Valid { - get { - return valid; + /// <summary> + /// Has the validation been successful? + /// </summary> + public bool Valid { + get { + return valid; + } } - } - /// <summary> - /// Retrieves the problems that have been found. - /// </summary> - public IEnumerable<ValidationProblem> Problems { - get { - return problems; + /// <summary> + /// Retrieves the problems that have been found. + /// </summary> + public IEnumerable<ValidationProblem> Problems { + get { + return problems; + } } } } -} Modified: trunk/xmlunit/src/main/net-core/validation/Validator.cs =================================================================== --- trunk/xmlunit/src/main/net-core/validation/Validator.cs 2009-05-25 15:42:30 UTC (rev 334) +++ trunk/xmlunit/src/main/net-core/validation/Validator.cs 2009-05-25 15:43:26 UTC (rev 335) @@ -21,88 +21,88 @@ /// Validates a piece of XML against a schema given in a supported /// language or the defintion of such a schema itself. /// </summary> -public class Validator { - private readonly ValidationType language; - private string schemaURI; - private ISource[] sourceLocations; + public class Validator { + private readonly ValidationType language; + private string schemaURI; + private ISource[] sourceLocations; - private Validator(ValidationType language) { - this.language = language; - } + private Validator(ValidationType language) { + this.language = language; + } - /// <summary> - /// The URI (or for example the System ID in case of a DTD) that - /// identifies the schema to validate or use during validation. - /// </summary> - public virtual string SchemaURI { - set { - schemaURI = value; + /// <summary> + /// The URI (or for example the System ID in case of a DTD) that + /// identifies the schema to validate or use during validation. + /// </summary> + public virtual string SchemaURI { + set { + schemaURI = value; + } + get { + return schemaURI; + } } - get { - return schemaURI; + + /// <summary> + /// Where to find the schema. + /// </summary> + public virtual ISource[] SchemaSources { + set { + if (value != null) { + sourceLocations = new ISource[value.Length]; + Array.Copy(value, 0, sourceLocations, 0, value.Length); + } else { + sourceLocations = null; + } + } + get { + return sourceLocations; + } } - } - /// <summary> - /// Where to find the schema. - /// </summary> - public virtual ISource[] SchemaSources { - set { - if (value != null) { - sourceLocations = new ISource[value.Length]; - Array.Copy(value, 0, sourceLocations, 0, value.Length); - } else { - sourceLocations = null; + /// <summary> + /// Where to find the schema. + /// </summary> + public ISource SchemaSource { + set { + SchemaSources = value == null ? null : new ISource[] {value}; + } } + + /// <summary> + /// Validates a schema. + /// </summary> + public virtual ValidationResult ValidateSchema() { + throw new NotImplementedException(); } - get { - return sourceLocations; - } - } - /// <summary> - /// Where to find the schema. - /// </summary> - public ISource SchemaSource { - set { - SchemaSources = value == null ? null : new ISource[] {value}; + /// <summary> + /// Validates an instance against the schema. + /// </summary> + public virtual ValidationResult ValidateInstance(ISource instance) { + throw new NotImplementedException(); } - } - /// <summary> - /// Validates a schema. - /// </summary> - public virtual ValidationResult ValidateSchema() { - throw new NotImplementedException(); - } - /// <summary> - /// Validates an instance against the schema. - /// </summary> - public virtual ValidationResult ValidateInstance(ISource instance) { - throw new NotImplementedException(); - } + private static readonly IDictionary<string, ValidationType> types; + static Validator() { + types = new Dictionary<string, ValidationType>(); + types[Languages.W3C_XML_SCHEMA_NS_URI] = ValidationType.Schema; + types[Languages.XML_DTD_NS_URI] = ValidationType.DTD; + types[Languages.XDR_NS_URI] = ValidationType.XDR; + } - private static readonly IDictionary<string, ValidationType> types; - - static Validator() { - types = new Dictionary<string, ValidationType>(); - types[Languages.W3C_XML_SCHEMA_NS_URI] = ValidationType.Schema; - types[Languages.XML_DTD_NS_URI] = ValidationType.DTD; - types[Languages.XDR_NS_URI] = ValidationType.XDR; - } - - /// <summary> - /// Factory that obtains a Validator instance based on the schema language. - /// </summary> - public static Validator ForLanguage(string language) { - ValidationType t; - if (types.TryGetValue(language, out t)) { - return new Validator(t); + /// <summary> + /// Factory that obtains a Validator instance based on the schema language. + /// </summary> + public static Validator ForLanguage(string language) { + ValidationType t; + if (types.TryGetValue(language, out t)) { + return new Validator(t); + } + // TODO pick a better exception type + throw new NotImplementedException(); } - // TODO pick a better exception type - throw new NotImplementedException(); } } -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2009-05-25 15:42:43
|
Revision: 334 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=334&view=rev Author: bodewig Date: 2009-05-25 15:42:30 +0000 (Mon, 25 May 2009) Log Message: ----------- validation infrastructure .NET style Added Paths: ----------- trunk/xmlunit/src/main/net-core/validation/ trunk/xmlunit/src/main/net-core/validation/Languages.cs trunk/xmlunit/src/main/net-core/validation/ValidationProblem.cs trunk/xmlunit/src/main/net-core/validation/ValidationResult.cs trunk/xmlunit/src/main/net-core/validation/Validator.cs Copied: trunk/xmlunit/src/main/net-core/validation/Languages.cs (from rev 333, trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/Languages.java) =================================================================== --- trunk/xmlunit/src/main/net-core/validation/Languages.cs (rev 0) +++ trunk/xmlunit/src/main/net-core/validation/Languages.cs 2009-05-25 15:42:30 UTC (rev 334) @@ -0,0 +1,32 @@ +/* + This file is licensed 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. +*/ +namespace net.sf.xmlunit.validation { + + /// <summary> + /// Constants for the languages supported by XMLUnit's schema + /// validation. + /// </summary> +public static class Languages { + + /// <summary>W3C XML Schema.</summary> + public const string W3C_XML_SCHEMA_NS_URI = + "http://www.w3.org/2001/XMLSchema"; + + /// <summary>DTD.</summary> + public const string XML_DTD_NS_URI = "http://www.w3.org/TR/REC-xml"; + + /// <summary>XDR.</summary> + public const string XDR_NS_URI = "xmlunit:validation:XDR"; +} +} Property changes on: trunk/xmlunit/src/main/net-core/validation/Languages.cs ___________________________________________________________________ Added: svn:mergeinfo + Added: svn:eol-style + native Copied: trunk/xmlunit/src/main/net-core/validation/ValidationProblem.cs (from rev 333, trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/ValidationProblem.java) =================================================================== --- trunk/xmlunit/src/main/net-core/validation/ValidationProblem.cs (rev 0) +++ trunk/xmlunit/src/main/net-core/validation/ValidationProblem.cs 2009-05-25 15:42:30 UTC (rev 334) @@ -0,0 +1,72 @@ +/* + This file is licensed 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. +*/ +using System.Xml.Schema; + +namespace net.sf.xmlunit.validation { + + /// <summary> + /// A validation "problem" which may be an error or a warning. + /// </summary> +public class ValidationProblem { + public const int UNKNOWN = -1; + + private readonly int line, column; + private readonly XmlSeverityType type; + private readonly string message; + + public ValidationProblem(string message, int line, int column, + XmlSeverityType type) { + this.message = message; + this.line = line; + this.column = column; + this.type = type; + } + + /// <summary> + /// The line where the problem occured or UNKNOWN. + /// </summary> + public int Line { + get { + return line; + } + } + + /// <summary> + /// The column where the problem occured or UNKNOWN. + /// </summary> + public int Column { + get { + return column; + } + } + + /// <summary> + /// Whether this is an error or a warning. + /// </summary> + public XmlSeverityType Type { + get { + return type; + } + } + + /// <summary> + /// The problem's message. + /// </summary> + public string Message { + get { + return message; + } + } +} +} Property changes on: trunk/xmlunit/src/main/net-core/validation/ValidationProblem.cs ___________________________________________________________________ Added: svn:mergeinfo + Added: svn:eol-style + native Copied: trunk/xmlunit/src/main/net-core/validation/ValidationResult.cs (from rev 333, trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/ValidationResult.java) =================================================================== --- trunk/xmlunit/src/main/net-core/validation/ValidationResult.cs (rev 0) +++ trunk/xmlunit/src/main/net-core/validation/ValidationResult.cs 2009-05-25 15:42:30 UTC (rev 334) @@ -0,0 +1,50 @@ +/* + This file is licensed 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. +*/ + +using System.Collections.Generic; + +namespace net.sf.xmlunit.validation { + + /// <summary> + /// The result of a validation. + /// </summary> +public class ValidationResult { + private readonly bool valid; + private readonly IEnumerable<ValidationProblem> problems; + + public ValidationResult(bool valid, IEnumerable<ValidationProblem> problems) { + this.valid = valid; + this.problems = problems; + } + + /// <summary> + /// Has the validation been successful? + /// </summary> + public bool Valid { + get { + return valid; + } + } + + /// <summary> + /// Retrieves the problems that have been found. + /// </summary> + public IEnumerable<ValidationProblem> Problems { + get { + return problems; + } + } +} +} + Property changes on: trunk/xmlunit/src/main/net-core/validation/ValidationResult.cs ___________________________________________________________________ Added: svn:mergeinfo + Added: svn:eol-style + native Copied: trunk/xmlunit/src/main/net-core/validation/Validator.cs (from rev 333, trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/Validator.java) =================================================================== --- trunk/xmlunit/src/main/net-core/validation/Validator.cs (rev 0) +++ trunk/xmlunit/src/main/net-core/validation/Validator.cs 2009-05-25 15:42:30 UTC (rev 334) @@ -0,0 +1,108 @@ +/* + This file is licensed 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. +*/ +using System; +using System.Collections.Generic; +using System.Xml; + +namespace net.sf.xmlunit.validation { + + /// <summary> + /// Validates a piece of XML against a schema given in a supported + /// language or the defintion of such a schema itself. + /// </summary> +public class Validator { + private readonly ValidationType language; + private string schemaURI; + private ISource[] sourceLocations; + + private Validator(ValidationType language) { + this.language = language; + } + + /// <summary> + /// The URI (or for example the System ID in case of a DTD) that + /// identifies the schema to validate or use during validation. + /// </summary> + public virtual string SchemaURI { + set { + schemaURI = value; + } + get { + return schemaURI; + } + } + + /// <summary> + /// Where to find the schema. + /// </summary> + public virtual ISource[] SchemaSources { + set { + if (value != null) { + sourceLocations = new ISource[value.Length]; + Array.Copy(value, 0, sourceLocations, 0, value.Length); + } else { + sourceLocations = null; + } + } + get { + return sourceLocations; + } + } + + /// <summary> + /// Where to find the schema. + /// </summary> + public ISource SchemaSource { + set { + SchemaSources = value == null ? null : new ISource[] {value}; + } + } + + /// <summary> + /// Validates a schema. + /// </summary> + public virtual ValidationResult ValidateSchema() { + throw new NotImplementedException(); + } + + /// <summary> + /// Validates an instance against the schema. + /// </summary> + public virtual ValidationResult ValidateInstance(ISource instance) { + throw new NotImplementedException(); + } + + + private static readonly IDictionary<string, ValidationType> types; + + static Validator() { + types = new Dictionary<string, ValidationType>(); + types[Languages.W3C_XML_SCHEMA_NS_URI] = ValidationType.Schema; + types[Languages.XML_DTD_NS_URI] = ValidationType.DTD; + types[Languages.XDR_NS_URI] = ValidationType.XDR; + } + + /// <summary> + /// Factory that obtains a Validator instance based on the schema language. + /// </summary> + public static Validator ForLanguage(string language) { + ValidationType t; + if (types.TryGetValue(language, out t)) { + return new Validator(t); + } + // TODO pick a better exception type + throw new NotImplementedException(); + } +} +} Property changes on: trunk/xmlunit/src/main/net-core/validation/Validator.cs ___________________________________________________________________ Added: svn:mergeinfo + Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2009-05-25 15:05:38
|
Revision: 333 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=333&view=rev Author: bodewig Date: 2009-05-25 15:05:35 +0000 (Mon, 25 May 2009) Log Message: ----------- validation infrastructure Added Paths: ----------- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/Languages.java trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/ValidationProblem.java trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/ValidationResult.java trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/Validator.java Added: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/Languages.java =================================================================== --- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/Languages.java (rev 0) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/Languages.java 2009-05-25 15:05:35 UTC (rev 333) @@ -0,0 +1,50 @@ +/* + This file is licensed 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 net.sf.xmlunit.validation; + +import javax.xml.XMLConstants; + +/** + * Contants for the languages supported by XMLUnit's schema + * validation. More languages may be supported depending on your JAXP + * environment. + */ +public final class Languages { + private Languages() {} + + /** + * W3C XML Schema. + * + * @see javax.xml.XMLConstants#W3C_XML_SCHEMA_NS_URI + */ + public static final String W3C_XML_SCHEMA_NS_URI = + XMLConstants.W3C_XML_SCHEMA_NS_URI; + + /** + * DTD + * + * @see javax.xml.XMLConstants#XML_DTD_NS_URI + */ + public static final String XML_DTD_NS_URI = XMLConstants.XML_DTD_NS_URI; + + /** + * RELAX NG + * + * <p>This is most likely only supported if you use additional + * libraries and configure JAXP to use them.</p> + * + * @see javax.xml.XMLConstants#RELAXNG_NS_URI + */ + public static final String RELAXNG_NS_URI = XMLConstants.RELAXNG_NS_URI; +} Property changes on: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/Languages.java ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/ValidationProblem.java =================================================================== --- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/ValidationProblem.java (rev 0) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/ValidationProblem.java 2009-05-25 15:05:35 UTC (rev 333) @@ -0,0 +1,63 @@ +/* + This file is licensed 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 net.sf.xmlunit.validation; + +/** + * A validation "problem" which may be an error or a warning. + */ +public class ValidationProblem { + public static enum ProblemType {ERROR, WARNING}; + + public static final int UNKNOWN = -1; + + private final int line, column; + private final ProblemType type; + private final String message; + + public ValidationProblem(String message, int line, int column, + ProblemType type) { + this.message = message; + this.line = line; + this.column = column; + this.type = type; + } + + /** + * The line where the problem occured or {@link #UNKNOWN UNKNOWN}. + */ + public int getLine() { + return line; + } + + /** + * The column where the problem occured or {@link #UNKNOWN UNKNOWN}. + */ + public int getColumn() { + return column; + } + + /** + * Whether this is an error or a warning. + */ + public ProblemType getType() { + return type; + } + + /** + * The problem's message. + */ + public String getMessage() { + return message; + } +} Property changes on: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/ValidationProblem.java ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/ValidationResult.java =================================================================== --- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/ValidationResult.java (rev 0) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/ValidationResult.java 2009-05-25 15:05:35 UTC (rev 333) @@ -0,0 +1,41 @@ +/* + This file is licensed 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 net.sf.xmlunit.validation; + +/** + * The result of a validation. + */ +public class ValidationResult { + private final boolean valid; + private final Iterable<ValidationProblem> problems; + + public ValidationResult(boolean valid, Iterable<ValidationProblem> problems) { + this.valid = valid; + this.problems = problems; + } + + /** + * Has the validation been successful? + */ + public boolean isValid() { + return valid; + } + + /** + * Retrieves the problems that have been found. + */ + public Iterable<ValidationProblem> getProblems() { + return problems; + } +} Property changes on: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/ValidationResult.java ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/Validator.java =================================================================== --- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/Validator.java (rev 0) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/Validator.java 2009-05-25 15:05:35 UTC (rev 333) @@ -0,0 +1,83 @@ +/* + This file is licensed 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 net.sf.xmlunit.validation; + +import javax.xml.transform.Source; + +/** + * Validates a piece of XML against a schema given in a supported + * language or the defintion of such a schema itself. + */ +public abstract class Validator { + private String schemaURI; + private Source[] sourceLocations; + + /** + * The URI (or for example the System ID in case of a DTD) that + * identifies the schema to validate or use during validation. + */ + public void setSchemaURI(String uri) { + this.schemaURI = uri; + } + + protected String getSchemaURI() { + return schemaURI; + } + + /** + * Where to find the schema. + */ + public void setSchemaSources(Source[] s) { + if (s != null) { + sourceLocations = new Source[s.length]; + System.arraycopy(s, 0, sourceLocations, 0, s.length); + } else { + sourceLocations = null; + } + } + + /** + * Where to find the schema. + */ + public final void setSchemaSource(Source s) { + setSchemaSources(s == null ? null : new Source[] {s}); + } + + protected Source[] getSchemaSources() { + return sourceLocations; + } + + /** + * Validates a schema. + * + * @throws UnsupportedOperationException if the language's + * implementation doesn't support schema validation + */ + public abstract ValidationResult validateSchema(); + + /** + * Validates an instance against the schema. + */ + public abstract ValidationResult validateInstance(Source instance); + + + /** + * Factory that obtains a Validator instance based on the schema language. + * + * @see Languages + */ + public static Validator forLanguage(String language) { + return null; + } +} \ No newline at end of file Property changes on: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/Validator.java ___________________________________________________________________ Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2009-05-20 15:55:32
|
Revision: 332 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=332&view=rev Author: bodewig Date: 2009-05-20 15:55:23 +0000 (Wed, 20 May 2009) Log Message: ----------- whitespace Modified Paths: -------------- trunk/xmlunit/src/tests/net-core/builder/InputTest.cs Modified: trunk/xmlunit/src/tests/net-core/builder/InputTest.cs =================================================================== --- trunk/xmlunit/src/tests/net-core/builder/InputTest.cs 2009-05-20 15:47:19 UTC (rev 331) +++ trunk/xmlunit/src/tests/net-core/builder/InputTest.cs 2009-05-20 15:55:23 UTC (rev 332) @@ -19,88 +19,88 @@ namespace net.sf.xmlunit.builder { -[TestFixture] -public class InputTest { + [TestFixture] + public class InputTest { - private const string TEST_FILE = "../../../src/tests/resources/test1.xml"; + private const string TEST_FILE = "../../../src/tests/resources/test1.xml"; - private static XmlDocument Parse(ISource s) { - XmlDocument d = new XmlDocument(); - d.Load(s.Reader); - return d; - } + private static XmlDocument Parse(ISource s) { + XmlDocument d = new XmlDocument(); + d.Load(s.Reader); + return d; + } - [Test] public void ShouldParseADocument() { - XmlDocument d = Parse(Input.FromFile(TEST_FILE).Build()); - AllIsWellFor(Input.FromDocument(d).Build()); - } + [Test] public void ShouldParseADocument() { + XmlDocument d = Parse(Input.FromFile(TEST_FILE).Build()); + AllIsWellFor(Input.FromDocument(d).Build()); + } - [Test] public void ShouldParseAnExistingFileByName() { - AllIsWellFor(Input.FromFile(TEST_FILE).Build()); - } + [Test] public void ShouldParseAnExistingFileByName() { + AllIsWellFor(Input.FromFile(TEST_FILE).Build()); + } - [Test] public void ShouldParseAnExistingFileFromStream() { - using (FileStream fs = new FileStream(TEST_FILE, FileMode.Open, - FileAccess.Read)) { - AllIsWellFor(Input.FromStream(fs).Build()); + [Test] public void ShouldParseAnExistingFileFromStream() { + using (FileStream fs = new FileStream(TEST_FILE, FileMode.Open, + FileAccess.Read)) { + AllIsWellFor(Input.FromStream(fs).Build()); + } } - } - [Test] public void ShouldParseAnExistingFileFromReader() { - using (StreamReader r = new StreamReader(TEST_FILE)) { - AllIsWellFor(Input.FromReader(r).Build()); + [Test] public void ShouldParseAnExistingFileFromReader() { + using (StreamReader r = new StreamReader(TEST_FILE)) { + AllIsWellFor(Input.FromReader(r).Build()); + } } - } - [Test] public void ShouldParseString() { - AllIsWellFor(Input.FromMemory(Encoding.UTF8.GetString(ReadTestFile())) - .Build()); - } + [Test] public void ShouldParseString() { + AllIsWellFor(Input.FromMemory(Encoding.UTF8.GetString(ReadTestFile())) + .Build()); + } - [Test] public void ShouldParseBytes() { - AllIsWellFor(Input.FromMemory(ReadTestFile()).Build()); - } + [Test] public void ShouldParseBytes() { + AllIsWellFor(Input.FromMemory(ReadTestFile()).Build()); + } - [Ignore("looks as if file-URIs didn't work, revisit")] - [Test] public void ShouldParseFileFromURIString() { - AllIsWellFor(Input.FromURI("file:" + TEST_FILE).Build()); - } + [Ignore("looks as if file-URIs didn't work, revisit")] + [Test] public void ShouldParseFileFromURIString() { + AllIsWellFor(Input.FromURI("file:" + TEST_FILE).Build()); + } - [Ignore("looks as if file-URIs didn't work, revisit")] - [Test] public void ShouldParseFileFromURI() { - AllIsWellFor(Input.FromURI(new Uri("file:" + TEST_FILE)).Build()); - } + [Ignore("looks as if file-URIs didn't work, revisit")] + [Test] public void ShouldParseFileFromURI() { + AllIsWellFor(Input.FromURI(new Uri("file:" + TEST_FILE)).Build()); + } - [Test] public void ShouldParseATransformation() { - ISource input = Input.FromMemory("<animal>furry</animal>").Build(); - ISource s = Input.ByTransforming(input) - .WithStylesheet(Input.FromFile("../../../src/tests/resources/animal.xsl") - .Build()) - .Build(); - Assert.That(s, Is.Not.Null); - XmlDocument d = Parse(s); - Assert.That(d, Is.Not.Null); - Assert.That(d.DocumentElement.Name, Is.EqualTo("furry")); - } + [Test] public void ShouldParseATransformation() { + ISource input = Input.FromMemory("<animal>furry</animal>").Build(); + ISource s = Input.ByTransforming(input) + .WithStylesheet(Input.FromFile("../../../src/tests/resources/animal.xsl") + .Build()) + .Build(); + Assert.That(s, Is.Not.Null); + XmlDocument d = Parse(s); + Assert.That(d, Is.Not.Null); + Assert.That(d.DocumentElement.Name, Is.EqualTo("furry")); + } - private static void AllIsWellFor(ISource s) { - Assert.That(s, Is.Not.Null); - XmlDocument d = Parse(s); - Assert.That(d, Is.Not.Null); - Assert.That(d.DocumentElement.Name, Is.EqualTo("animal")); - } + private static void AllIsWellFor(ISource s) { + Assert.That(s, Is.Not.Null); + XmlDocument d = Parse(s); + Assert.That(d, Is.Not.Null); + Assert.That(d.DocumentElement.Name, Is.EqualTo("animal")); + } - private static byte[] ReadTestFile() { - using (FileStream fs = new FileStream(TEST_FILE, FileMode.Open, - FileAccess.Read)) - using (MemoryStream ms = new MemoryStream()) { - byte[] buffer = new byte[1024]; - int read = -1; - while ((read = fs.Read(buffer, 0, buffer.Length)) > 0) { - ms.Write(buffer, 0, read); + private static byte[] ReadTestFile() { + using (FileStream fs = new FileStream(TEST_FILE, FileMode.Open, + FileAccess.Read)) + using (MemoryStream ms = new MemoryStream()) { + byte[] buffer = new byte[1024]; + int read = -1; + while ((read = fs.Read(buffer, 0, buffer.Length)) > 0) { + ms.Write(buffer, 0, read); + } + return ms.ToArray(); + } } - return ms.ToArray(); - } } -} } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2009-05-20 15:47:31
|
Revision: 331 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=331&view=rev Author: bodewig Date: 2009-05-20 15:47:19 +0000 (Wed, 20 May 2009) Log Message: ----------- port input builder test to .NET Modified Paths: -------------- trunk/xmlunit/xmlunit.nant.build Added Paths: ----------- trunk/xmlunit/src/tests/net-core/ trunk/xmlunit/src/tests/net-core/builder/ trunk/xmlunit/src/tests/net-core/builder/InputTest.cs Copied: trunk/xmlunit/src/tests/net-core/builder/InputTest.cs (from rev 329, trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/builder/InputTest.java) =================================================================== --- trunk/xmlunit/src/tests/net-core/builder/InputTest.cs (rev 0) +++ trunk/xmlunit/src/tests/net-core/builder/InputTest.cs 2009-05-20 15:47:19 UTC (rev 331) @@ -0,0 +1,106 @@ +/* + This file is licensed 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. +*/ +using System; +using System.IO; +using System.Text; +using System.Xml; +using NUnit.Framework; + +namespace net.sf.xmlunit.builder { + +[TestFixture] +public class InputTest { + + private const string TEST_FILE = "../../../src/tests/resources/test1.xml"; + + private static XmlDocument Parse(ISource s) { + XmlDocument d = new XmlDocument(); + d.Load(s.Reader); + return d; + } + + [Test] public void ShouldParseADocument() { + XmlDocument d = Parse(Input.FromFile(TEST_FILE).Build()); + AllIsWellFor(Input.FromDocument(d).Build()); + } + + [Test] public void ShouldParseAnExistingFileByName() { + AllIsWellFor(Input.FromFile(TEST_FILE).Build()); + } + + [Test] public void ShouldParseAnExistingFileFromStream() { + using (FileStream fs = new FileStream(TEST_FILE, FileMode.Open, + FileAccess.Read)) { + AllIsWellFor(Input.FromStream(fs).Build()); + } + } + + [Test] public void ShouldParseAnExistingFileFromReader() { + using (StreamReader r = new StreamReader(TEST_FILE)) { + AllIsWellFor(Input.FromReader(r).Build()); + } + } + + [Test] public void ShouldParseString() { + AllIsWellFor(Input.FromMemory(Encoding.UTF8.GetString(ReadTestFile())) + .Build()); + } + + [Test] public void ShouldParseBytes() { + AllIsWellFor(Input.FromMemory(ReadTestFile()).Build()); + } + + [Ignore("looks as if file-URIs didn't work, revisit")] + [Test] public void ShouldParseFileFromURIString() { + AllIsWellFor(Input.FromURI("file:" + TEST_FILE).Build()); + } + + [Ignore("looks as if file-URIs didn't work, revisit")] + [Test] public void ShouldParseFileFromURI() { + AllIsWellFor(Input.FromURI(new Uri("file:" + TEST_FILE)).Build()); + } + + [Test] public void ShouldParseATransformation() { + ISource input = Input.FromMemory("<animal>furry</animal>").Build(); + ISource s = Input.ByTransforming(input) + .WithStylesheet(Input.FromFile("../../../src/tests/resources/animal.xsl") + .Build()) + .Build(); + Assert.That(s, Is.Not.Null); + XmlDocument d = Parse(s); + Assert.That(d, Is.Not.Null); + Assert.That(d.DocumentElement.Name, Is.EqualTo("furry")); + } + + private static void AllIsWellFor(ISource s) { + Assert.That(s, Is.Not.Null); + XmlDocument d = Parse(s); + Assert.That(d, Is.Not.Null); + Assert.That(d.DocumentElement.Name, Is.EqualTo("animal")); + } + + private static byte[] ReadTestFile() { + using (FileStream fs = new FileStream(TEST_FILE, FileMode.Open, + FileAccess.Read)) + using (MemoryStream ms = new MemoryStream()) { + byte[] buffer = new byte[1024]; + int read = -1; + while ((read = fs.Read(buffer, 0, buffer.Length)) > 0) { + ms.Write(buffer, 0, read); + } + return ms.ToArray(); + } + } +} +} \ No newline at end of file Property changes on: trunk/xmlunit/src/tests/net-core/builder/InputTest.cs ___________________________________________________________________ Added: svn:mergeinfo + Added: svn:eol-style + native Modified: trunk/xmlunit/xmlunit.nant.build =================================================================== --- trunk/xmlunit/xmlunit.nant.build 2009-05-20 15:24:44 UTC (rev 330) +++ trunk/xmlunit/xmlunit.nant.build 2009-05-20 15:47:19 UTC (rev 331) @@ -4,8 +4,10 @@ overwrite="false"/> <property name="core.src.dir" value="${base.dir}/src/main/net-core" overwrite="false"/> <property name="legacy.src.dir" value="${base.dir}/src/main/net-legacy" overwrite="false"/> - <property name="tests.src.dir" value="${base.dir}/src/tests/net-legacy" + <property name="core.tests.src.dir" value="${base.dir}/src/tests/net-core" overwrite="false"/> + <property name="legacy.tests.src.dir" value="${base.dir}/src/tests/net-legacy" + overwrite="false"/> <property name="build.dir" value="${base.dir}/build/net" overwrite="false"/> <property name="bin.dir" value="${build.dir}/bin" overwrite="false"/> @@ -56,14 +58,25 @@ </csc> <csc target="library" - output="${bin.dir}/${project::get-name()}.tests.dll" + output="${bin.dir}/${project::get-name()}-core.tests.dll" debug="true" verbose="${csc.verbose}"> <references basedir="${bin.dir}"> <include name="${project::get-name()}-core.dll"/> + <include name="${nunit.v2.assembly}"/> + </references> + <sources basedir="${core.tests.src.dir}"> + <include name="**/*.cs"/> + </sources> + </csc> + <csc target="library" + output="${bin.dir}/${project::get-name()}-legacy.tests.dll" + debug="true" verbose="${csc.verbose}"> + <references basedir="${bin.dir}"> + <include name="${project::get-name()}-core.dll"/> <include name="${project::get-name()}-legacy.dll"/> <include name="${nunit.v2.assembly}"/> </references> - <sources basedir="${tests.src.dir}"> + <sources basedir="${legacy.tests.src.dir}"> <include name="*.cs"/> <exclude name="AllTests.cs"/> </sources> @@ -73,7 +86,8 @@ <target name="test" description="run all tests" depends="compile"> <nunit2> <formatter type="Plain"/> - <test assemblyname="${bin.dir}/${project::get-name()}.tests.dll"/> + <test assemblyname="${bin.dir}/${project::get-name()}-core.tests.dll"/> + <test assemblyname="${bin.dir}/${project::get-name()}-legacy.tests.dll"/> </nunit2> </target> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2009-05-20 15:24:55
|
Revision: 330 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=330&view=rev Author: bodewig Date: 2009-05-20 15:24:44 +0000 (Wed, 20 May 2009) Log Message: ----------- upgrade to NUnit 2.5 Modified Paths: -------------- trunk/xmlunit/lib/nunit.framework.dll trunk/xmlunit/src/main/net-legacy/XmlAssertion.cs trunk/xmlunit/src/tests/net-legacy/DiffConfigurationTests.cs trunk/xmlunit/src/tests/net-legacy/ValidatorTests.cs trunk/xmlunit/src/tests/net-legacy/XmlAssertionTests.cs Modified: trunk/xmlunit/lib/nunit.framework.dll =================================================================== (Binary files differ) Modified: trunk/xmlunit/src/main/net-legacy/XmlAssertion.cs =================================================================== --- trunk/xmlunit/src/main/net-legacy/XmlAssertion.cs 2009-05-20 14:12:07 UTC (rev 329) +++ trunk/xmlunit/src/main/net-legacy/XmlAssertion.cs 2009-05-20 15:24:44 UTC (rev 330) @@ -2,7 +2,7 @@ using NUnit.Framework; using System.IO; - public class XmlAssertion : Assertion { + public class XmlAssertion : Assert { public static void AssertXmlEquals(TextReader controlTextReader, TextReader testTextReader) { AssertXmlEquals(new XmlDiff(controlTextReader, testTextReader)); } Modified: trunk/xmlunit/src/tests/net-legacy/DiffConfigurationTests.cs =================================================================== --- trunk/xmlunit/src/tests/net-legacy/DiffConfigurationTests.cs 2009-05-20 14:12:07 UTC (rev 329) +++ trunk/xmlunit/src/tests/net-legacy/DiffConfigurationTests.cs 2009-05-20 15:24:44 UTC (rev 330) @@ -21,7 +21,7 @@ new XmlDiff("", "").OptionalDescription); } - [Test] + [Test][Ignore("seems to fail because of schema location")] public void DefaultConfiguredToUseValidatingParser() { DiffConfiguration diffConfiguration = new DiffConfiguration(); Assert.AreEqual(DiffConfiguration.DEFAULT_USE_VALIDATING_PARSER, Modified: trunk/xmlunit/src/tests/net-legacy/ValidatorTests.cs =================================================================== --- trunk/xmlunit/src/tests/net-legacy/ValidatorTests.cs 2009-05-20 14:12:07 UTC (rev 329) +++ trunk/xmlunit/src/tests/net-legacy/ValidatorTests.cs 2009-05-20 15:24:44 UTC (rev 330) @@ -8,10 +8,11 @@ [TestFixture] public class ValidatorTests { - public static readonly string VALID_FILE = ".\\..\\src\\tests\\resources\\BookXsdGenerated.xml"; - public static readonly string INVALID_FILE = ".\\..\\src\\tests\\resources\\invalidBook.xml"; + public static readonly string VALID_FILE = "..\\..\\..\\src\\tests\\resources\\BookXsdGenerated.xml"; + public static readonly string INVALID_FILE = "..\\..\\..\\src\\tests\\resources\\invalidBook.xml"; - [Test] public void XsdValidFileIsValid() { + [Test][Ignore("seems to fail because of schema location")] + public void XsdValidFileIsValid() { PerformAssertion(VALID_FILE, true); } @@ -26,6 +27,7 @@ } } + [Ignore("validation seems to return the last error on .Net 2.0, need to double check")] [Test] public void XsdInvalidFileIsNotValid() { Validator validator = PerformAssertion(INVALID_FILE, false); Assert.IsFalse(validator.IsValid); Modified: trunk/xmlunit/src/tests/net-legacy/XmlAssertionTests.cs =================================================================== --- trunk/xmlunit/src/tests/net-legacy/XmlAssertionTests.cs 2009-05-20 14:12:07 UTC (rev 329) +++ trunk/xmlunit/src/tests/net-legacy/XmlAssertionTests.cs 2009-05-20 15:24:44 UTC (rev 330) @@ -48,6 +48,7 @@ Assert.IsTrue(caughtException); } + [Ignore("validation seems to return the last error on .Net 2.0, need to double check")] [Test] public void AssertXmlValidTrueForValidFile() { StreamReader reader = GetStreamReader(ValidatorTests.VALID_FILE); try { @@ -123,18 +124,18 @@ } [Test] public void AssertXslTransformResultsWorksWithXmlInput() { - StreamReader xsl = GetStreamReader(".\\..\\src\\tests\\resources\\animal.xsl"); + StreamReader xsl = GetStreamReader("..\\..\\..\\src\\tests\\resources\\animal.xsl"); XmlInput xslt = new XmlInput(xsl); - StreamReader xml = GetStreamReader(".\\..\\src\\tests\\resources\\testAnimal.xml"); + StreamReader xml = GetStreamReader("..\\..\\..\\src\\tests\\resources\\testAnimal.xml"); XmlInput xmlToTransform = new XmlInput(xml); XmlInput expectedXml = new XmlInput("<dog/>"); XmlAssertion.AssertXslTransformResults(xslt, xmlToTransform, expectedXml); } [Test] public void AssertXslTransformResultsCatchesFalsePositive() { - StreamReader xsl = GetStreamReader(".\\..\\src\\tests\\resources\\animal.xsl"); + StreamReader xsl = GetStreamReader("..\\..\\..\\src\\tests\\resources\\animal.xsl"); XmlInput xslt = new XmlInput(xsl); - StreamReader xml = GetStreamReader(".\\..\\src\\tests\\resources\\testAnimal.xml"); + StreamReader xml = GetStreamReader("..\\..\\..\\src\\tests\\resources\\testAnimal.xml"); XmlInput xmlToTransform = new XmlInput(xml); XmlInput expectedXml = new XmlInput("<cat/>"); bool caughtException = true; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2009-05-20 14:12:15
|
Revision: 329 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=329&view=rev Author: bodewig Date: 2009-05-20 14:12:07 +0000 (Wed, 20 May 2009) Log Message: ----------- cosmetics Modified Paths: -------------- trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/builder/InputTest.java Modified: trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/builder/InputTest.java =================================================================== --- trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/builder/InputTest.java 2009-05-20 14:09:41 UTC (rev 328) +++ trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/builder/InputTest.java 2009-05-20 14:12:07 UTC (rev 329) @@ -17,8 +17,8 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileReader; +import java.net.URI; import java.net.URL; -import java.net.URI; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.transform.Source; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2009-05-20 14:09:49
|
Revision: 328 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=328&view=rev Author: bodewig Date: 2009-05-20 14:09:41 +0000 (Wed, 20 May 2009) Log Message: ----------- Java tests for input builder Modified Paths: -------------- trunk/xmlunit/build.xml Added Paths: ----------- trunk/xmlunit/lib/junit-4.6.jar trunk/xmlunit/src/tests/java-core/ trunk/xmlunit/src/tests/java-core/net/ trunk/xmlunit/src/tests/java-core/net/sf/ trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/ trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/builder/ trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/builder/InputTest.java Modified: trunk/xmlunit/build.xml =================================================================== --- trunk/xmlunit/build.xml 2009-05-18 16:03:06 UTC (rev 327) +++ trunk/xmlunit/build.xml 2009-05-20 14:09:41 UTC (rev 328) @@ -30,7 +30,8 @@ <property name="lib.dir" value="${build.dir}/lib"/> <property name="core.out.dir" value="${build.dir}/core-classes"/> <property name="legacy.out.dir" value="${build.dir}/legacy-classes"/> - <property name="test.out.dir" value="${build.dir}/test-classes"/> + <property name="coretest.out.dir" value="${build.dir}/core-test-classes"/> + <property name="legacytest.out.dir" value="${build.dir}/legacy-test-classes"/> <property name="userguide.out.dir" value="${build.dir}/ug-classes"/> <property name="test.report.dir" value="${build.dir}/test-report"/> <property name="dist.dir" value="${build.dir}/dist"/> @@ -56,7 +57,8 @@ <mkdir dir="${lib.dir}"/> <mkdir dir="${core.out.dir}"/> <mkdir dir="${legacy.out.dir}"/> - <mkdir dir="${test.out.dir}"/> + <mkdir dir="${coretest.out.dir}"/> + <mkdir dir="${legacytest.out.dir}"/> <mkdir dir="${test.report.dir}"/> <mkdir dir="${dist.dir}"/> <mkdir dir="${docs.dir}"/> @@ -69,7 +71,8 @@ <fileset dir="${lib.dir}"/> <fileset dir="${core.out.dir}"/> <fileset dir="${legacy.out.dir}"/> - <fileset dir="${test.out.dir}"/> + <fileset dir="${coretest.out.dir}"/> + <fileset dir="${legacytest.out.dir}"/> <fileset dir="${test.report.dir}"/> <fileset dir="${dist.dir}"/> <fileset dir="${docs.dir}"/> @@ -86,55 +89,71 @@ </javac> </target> - <target name="compile" depends="compile-core" + <target name="compile-legacy" depends="compile-core" description="compiles legacy sources and tests"> <javac srcdir="${src.dir}/java-legacy" destdir="${legacy.out.dir}" debug="${javac.debug}" target="${javac.target}" source="${javac.source}"> <classpath> <pathelement location="${core.out.dir}"/> <pathelement path="${java.class.path}"/> - <fileset dir="lib" includes="*.jar"/> + <fileset dir="lib" includes="junit-3*.jar"/> </classpath> <exclude name="**/*XPathRegexAssert.java" unless="regexp.present"/> </javac> - <javac srcdir="${test.dir}/java-legacy" destdir="${test.out.dir}" + </target> + + <target name="compile-legacy-tests" depends="compile-legacy" + description="Compiles the test for XMLUnit 1.x"> + <javac srcdir="${test.dir}/java-legacy" destdir="${legacytest.out.dir}" debug="${javac.debug}" target="${javac.target}" source="${javac.source}"> <classpath> <pathelement location="${core.out.dir}"/> <pathelement location="${legacy.out.dir}"/> <pathelement path="${java.class.path}"/> - <fileset dir="lib" includes="*.jar"/> + <fileset dir="lib" includes="junit-3*.jar"/> </classpath> <exclude name="**/*XPathRegexAssert.java" unless="regexp.present"/> </javac> </target> - <target name="test" depends="compile" - description="runs the tests"> + <target name="compile-core-tests" depends="compile-core" + description="Compiles the test for XMLUnit2"> + <javac srcdir="${test.dir}/java-core" destdir="${coretest.out.dir}" + debug="${javac.debug}" target="${javac.target}" + source="${javac.source}"> + <classpath> + <pathelement location="${core.out.dir}"/> + <pathelement path="${java.class.path}"/> + <fileset dir="lib" includes="junit-4*.jar"/> + </classpath> + </javac> + </target> + + <target name="compile" depends="compile-core,compile-legacy"/> + <target name="compile-tests" + depends="compile-core-tests,compile-legacy-tests"/> + + <target name="test" depends="compile-tests" description="runs the tests"> <junit printsummary="yes" haltonfailure="no" fork="${junit.fork}" forkMode="perBatch" failureproperty="tests.failed"> <sysproperty key="basedir" value="${basedir}"/> <sysproperty key="user.dir" value="${basedir}"/> - <!-- - <sysproperty key="javax.xml.parsers.DocumentBuilderFactory" - value="org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"/> - <sysproperty key="javax.xml.parsers.SAXParserFactory" - value="org.apache.xerces.jaxp.SAXParserFactoryImpl"/> - <sysproperty key="javax.xml.transform.TransformerFactory" - value="org.apache.xalan.processor.TransformerFactoryImpl"/> - --> <classpath> <pathelement location="${core.out.dir}"/> <pathelement location="${legacy.out.dir}"/> - <pathelement location="${test.out.dir}"/> + <pathelement location="${legacytest.out.dir}"/> + <pathelement location="${coretest.out.dir}"/> <pathelement path="${java.class.path}"/> - <fileset dir="lib" includes="*.jar"/> + <fileset dir="lib" includes="junit-4*.jar"/> </classpath> <formatter type="xml"/> <batchtest todir="${test.report.dir}"> <fileset dir="${test.dir}/java-legacy"> <include name="**/test_*.java"/> </fileset> + <fileset dir="${test.dir}/java-core"> + <include name="**/*Test.java"/> + </fileset> </batchtest> </junit> Added: trunk/xmlunit/lib/junit-4.6.jar =================================================================== (Binary files differ) Property changes on: trunk/xmlunit/lib/junit-4.6.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/builder/InputTest.java =================================================================== --- trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/builder/InputTest.java (rev 0) +++ trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/builder/InputTest.java 2009-05-20 14:09:41 UTC (rev 328) @@ -0,0 +1,144 @@ +/* + This file is licensed 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 net.sf.xmlunit.builder; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileReader; +import java.net.URL; +import java.net.URI; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.transform.Source; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.sax.SAXSource; +import org.w3c.dom.Document; +import static org.hamcrest.core.Is.*; +import static org.hamcrest.core.IsNull.*; +import static org.junit.Assert.*; +import org.junit.Test; + +public class InputTest { + + private static final String TEST_FILE = "src/tests/resources/test1.xml"; + + private static Document parse(Source s) throws Exception { + DocumentBuilder b = + DocumentBuilderFactory.newInstance().newDocumentBuilder(); + return b.parse(SAXSource.sourceToInputSource(s)); + } + + @Test public void shouldParseADocument() throws Exception { + Document d = parse(Input.fromFile(TEST_FILE).build()); + // it looks as if SAXSource.sourceToInputSource cannot deal + // with a DOMSource, so we cannot use the parse method + Source s = Input.fromDocument(d).build(); + assertThat(s, is(DOMSource.class)); + Object o = ((DOMSource) s).getNode(); + assertThat(o, is(Document.class)); + Document d2 = (Document) o; + assertThat(d2, notNullValue()); + assertThat(d2.getDocumentElement().getTagName(), is("animal")); + } + + @Test public void shouldParseAnExistingFileByName() throws Exception { + allIsWellFor(Input.fromFile(TEST_FILE).build()); + } + + @Test public void shouldParseAnExistingFileByFile() throws Exception { + allIsWellFor(Input.fromFile(new File(TEST_FILE)).build()); + } + + @Test public void shouldParseAnExistingFileFromStream() throws Exception { + FileInputStream is = null; + try { + is = new FileInputStream(TEST_FILE); + allIsWellFor(Input.fromStream(is).build()); + } finally { + if (is != null) { + is.close(); + } + } + } + + @Test public void shouldParseAnExistingFileFromReader() throws Exception { + FileReader r = null; + try { + r = new FileReader(TEST_FILE); + allIsWellFor(Input.fromReader(r).build()); + } finally { + if (r != null) { + r.close(); + } + } + } + + @Test public void shouldParseString() throws Exception { + allIsWellFor(Input.fromMemory(new String(readTestFile(), "UTF-8")) + .build()); + } + + @Test public void shouldParseBytes() throws Exception { + allIsWellFor(Input.fromMemory(readTestFile()).build()); + } + + @Test public void shouldParseFileFromURIString() throws Exception { + allIsWellFor(Input.fromURI("file:" + TEST_FILE).build()); + } + + @Test public void shouldParseFileFromURI() throws Exception { + allIsWellFor(Input.fromURI(new URI("file:" + TEST_FILE)).build()); + } + + @Test public void shouldParseFileFromURL() throws Exception { + allIsWellFor(Input.fromURL(new URL("file:" + TEST_FILE)).build()); + } + + @Test public void shouldParseATransformation() throws Exception { + Source input = Input.fromMemory("<animal>furry</animal>").build(); + Source s = Input.byTransforming(input) + .withStylesheet(Input.fromFile("src/tests/resources/animal.xsl") + .build()) + .build(); + // again, transformed is a DOMSource, cannot use parse() + assertThat(s, is(DOMSource.class)); + Object o = ((DOMSource) s).getNode(); + assertThat(o, is(Document.class)); + Document d2 = (Document) o; + assertThat(d2, notNullValue()); + assertThat(d2.getDocumentElement().getTagName(), is("furry")); + } + + private static void allIsWellFor(Source s) throws Exception { + assertThat(s, notNullValue()); + Document d = parse(s); + assertThat(d, notNullValue()); + assertThat(d.getDocumentElement().getTagName(), is("animal")); + } + + private static byte[] readTestFile() throws Exception { + FileInputStream is = new FileInputStream(TEST_FILE); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + byte[] buffer = new byte[1024]; + int read = -1; + while ((read = is.read(buffer)) >= 0) { + if (read > 0) { + bos.write(buffer, 0, read); + } + } + is.close(); + return bos.toByteArray(); + } +} \ No newline at end of file Property changes on: trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/builder/InputTest.java ___________________________________________________________________ Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2009-05-18 16:03:09
|
Revision: 327 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=327&view=rev Author: bodewig Date: 2009-05-18 16:03:06 +0000 (Mon, 18 May 2009) Log Message: ----------- missing using statement, no idea why it compiled before Modified Paths: -------------- trunk/xmlunit/src/main/net-core/builder/Input.cs Modified: trunk/xmlunit/src/main/net-core/builder/Input.cs =================================================================== --- trunk/xmlunit/src/main/net-core/builder/Input.cs 2009-05-18 16:01:31 UTC (rev 326) +++ trunk/xmlunit/src/main/net-core/builder/Input.cs 2009-05-18 16:03:06 UTC (rev 327) @@ -14,6 +14,7 @@ using System.IO; using System.Xml; using System.Xml.Xsl; +using net.sf.xmlunit.exceptions; using net.sf.xmlunit.input; namespace net.sf.xmlunit.builder { @@ -127,7 +128,7 @@ ms); } return FromMemory(ms.ToArray()).Build(); - } catch (Exception ex) { + } catch (System.Exception ex) { throw new XMLUnitException(ex); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2009-05-18 16:01:34
|
Revision: 326 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=326&view=rev Author: bodewig Date: 2009-05-18 16:01:31 +0000 (Mon, 18 May 2009) Log Message: ----------- whitespace Modified Paths: -------------- trunk/xmlunit/src/main/net-core/builder/Input.cs Modified: trunk/xmlunit/src/main/net-core/builder/Input.cs =================================================================== --- trunk/xmlunit/src/main/net-core/builder/Input.cs 2009-05-18 16:00:49 UTC (rev 325) +++ trunk/xmlunit/src/main/net-core/builder/Input.cs 2009-05-18 16:01:31 UTC (rev 326) @@ -116,17 +116,17 @@ public ISource Build() { try { - XslCompiledTransform t = new XslCompiledTransform(); - if (styleSheet != null) { - t.Load(styleSheet.Reader); - } - MemoryStream ms = new MemoryStream(); - using (ms) { - t.Transform(source.Reader, - args, - ms); - } - return FromMemory(ms.ToArray()).Build(); + XslCompiledTransform t = new XslCompiledTransform(); + if (styleSheet != null) { + t.Load(styleSheet.Reader); + } + MemoryStream ms = new MemoryStream(); + using (ms) { + t.Transform(source.Reader, + args, + ms); + } + return FromMemory(ms.ToArray()).Build(); } catch (Exception ex) { throw new XMLUnitException(ex); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2009-05-18 16:00:53
|
Revision: 325 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=325&view=rev Author: bodewig Date: 2009-05-18 16:00:49 +0000 (Mon, 18 May 2009) Log Message: ----------- wrap exception into our own type Modified Paths: -------------- trunk/xmlunit/src/main/net-core/builder/Input.cs Modified: trunk/xmlunit/src/main/net-core/builder/Input.cs =================================================================== --- trunk/xmlunit/src/main/net-core/builder/Input.cs 2009-05-18 15:59:09 UTC (rev 324) +++ trunk/xmlunit/src/main/net-core/builder/Input.cs 2009-05-18 16:00:49 UTC (rev 325) @@ -115,6 +115,7 @@ } public ISource Build() { + try { XslCompiledTransform t = new XslCompiledTransform(); if (styleSheet != null) { t.Load(styleSheet.Reader); @@ -126,6 +127,9 @@ ms); } return FromMemory(ms.ToArray()).Build(); + } catch (Exception ex) { + throw new XMLUnitException(ex); + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2009-05-18 15:59:15
|
Revision: 324 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=324&view=rev Author: bodewig Date: 2009-05-18 15:59:09 +0000 (Mon, 18 May 2009) Log Message: ----------- self assignment Modified Paths: -------------- trunk/xmlunit/src/main/net-core/builder/Input.cs Modified: trunk/xmlunit/src/main/net-core/builder/Input.cs =================================================================== --- trunk/xmlunit/src/main/net-core/builder/Input.cs 2009-05-18 15:58:23 UTC (rev 323) +++ trunk/xmlunit/src/main/net-core/builder/Input.cs 2009-05-18 15:59:09 UTC (rev 324) @@ -97,7 +97,7 @@ source = s; } public ITransformationBuilder WithStylesheet(ISource s) { - this.styleSheet = styleSheet; + this.styleSheet = s; return this; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2009-05-18 15:58:28
|
Revision: 323 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=323&view=rev Author: bodewig Date: 2009-05-18 15:58:23 +0000 (Mon, 18 May 2009) Log Message: ----------- add a base exception class Added Paths: ----------- trunk/xmlunit/src/main/net-core/exceptions/ trunk/xmlunit/src/main/net-core/exceptions/XMLUnitException.cs Copied: trunk/xmlunit/src/main/net-core/exceptions/XMLUnitException.cs (from rev 321, trunk/xmlunit/src/main/java-core/net/sf/xmlunit/exceptions/XMLUnitException.java) =================================================================== --- trunk/xmlunit/src/main/net-core/exceptions/XMLUnitException.cs (rev 0) +++ trunk/xmlunit/src/main/net-core/exceptions/XMLUnitException.cs 2009-05-18 15:58:23 UTC (rev 323) @@ -0,0 +1,47 @@ +/* + This file is licensed 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. +*/ +using System; + +namespace net.sf.xmlunit.exceptions { + + /// <summary> + /// Base class of any Exception thrown within XMLUnit. + /// </summary> + public class XMLUnitException : Exception { + /// <summary> + /// Inititializes the exception. + /// </summary> + /// <param name="message">the detail message</param> + /// <param name="cause">the root cause of the exception</param> + public XMLUnitException(string message, Exception cause) : + base(message, cause) { + } + + /// <summary> + /// Inititializes an exception without cause. + /// </summary> + /// <param name="message">the detail message</param> + public XMLUnitException(string message) : + base(message, null) { + } + + ///<summary> + /// Inititializes an exception using the wrapped exception's message. + ///</summary> + /// <param name="cause">the root cause of the exception</param> + public XMLUnitException(Exception cause) : + base(cause != null ? cause.Message : null, cause) { + } + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2009-05-18 15:54:51
|
Revision: 322 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=322&view=rev Author: bodewig Date: 2009-05-18 15:54:41 +0000 (Mon, 18 May 2009) Log Message: ----------- fix javadocs Modified Paths: -------------- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/exceptions/XMLUnitException.java Modified: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/exceptions/XMLUnitException.java =================================================================== --- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/exceptions/XMLUnitException.java 2009-05-18 15:47:07 UTC (rev 321) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/exceptions/XMLUnitException.java 2009-05-18 15:54:41 UTC (rev 322) @@ -39,7 +39,7 @@ /** * Inititializes an exception using the wrapped exception's message. * - * @param message the detail message + * @param cause the root cause of the exception */ public XMLUnitException(Throwable cause) { this(cause != null ? cause.getMessage() : null, cause); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2009-05-18 15:47:12
|
Revision: 321 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=321&view=rev Author: bodewig Date: 2009-05-18 15:47:07 +0000 (Mon, 18 May 2009) Log Message: ----------- typos Modified Paths: -------------- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/exceptions/XMLUnitException.java Modified: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/exceptions/XMLUnitException.java =================================================================== --- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/exceptions/XMLUnitException.java 2009-05-18 15:40:13 UTC (rev 320) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/exceptions/XMLUnitException.java 2009-05-18 15:47:07 UTC (rev 321) @@ -18,7 +18,7 @@ */ public class XMLUnitException extends RuntimeException { /** - * Inititializes the exeption. + * Inititializes the exception. * * @param message the detail message * @param cause the root cause of the exception @@ -28,7 +28,7 @@ } /** - * Inititializes an exeption without cause. + * Inititializes an exception without cause. * * @param message the detail message */ @@ -37,7 +37,7 @@ } /** - * Inititializes an exeption using the wrapped exception's message. + * Inititializes an exception using the wrapped exception's message. * * @param message the detail message */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |