From 4a1549c87051a8dd4fc6c11ba657054f738ff24a Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Sun, 1 Apr 2018 17:34:29 -0700 Subject: [PATCH] validation test refactoring --- .../vstream/BaseStax2ValidationTest.java | 32 +++++++++++-------- .../java/stax2/vwstream/BaseOutputTest.java | 8 ++--- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/test/java/stax2/vstream/BaseStax2ValidationTest.java b/src/test/java/stax2/vstream/BaseStax2ValidationTest.java index f52fadbc..e40a84f1 100644 --- a/src/test/java/stax2/vstream/BaseStax2ValidationTest.java +++ b/src/test/java/stax2/vstream/BaseStax2ValidationTest.java @@ -1,48 +1,52 @@ package stax2.vstream; import java.io.StringReader; -import java.net.URL; import javax.xml.stream.XMLStreamException; import org.codehaus.stax2.XMLStreamReader2; import org.codehaus.stax2.validation.*; +import com.ctc.wstx.dtd.DTDSchemaFactory; +import com.ctc.wstx.msv.RelaxNGSchemaFactory; +import com.ctc.wstx.msv.W3CSchemaFactory; + import stax2.BaseStax2Test; public abstract class BaseStax2ValidationTest extends BaseStax2Test { - protected XMLValidationSchema parseSchema(String contents, String schemaType) - throws XMLStreamException - { - XMLValidationSchemaFactory schF = XMLValidationSchemaFactory.newInstance(schemaType); - return schF.createSchema(new StringReader(contents)); + protected XMLValidationSchemaFactory newW3CSchemaValidatorFactory() { + return new W3CSchemaFactory(); } - protected XMLValidationSchema parseSchema(URL ref, String schemaType) - throws XMLStreamException - { - XMLValidationSchemaFactory schF = XMLValidationSchemaFactory.newInstance(schemaType); - return schF.createSchema(ref); + protected XMLValidationSchemaFactory newRelaxNGValidatorFactory() { + return new RelaxNGSchemaFactory(); + } + + protected XMLValidationSchemaFactory newDTDValidatorFactory() { + return new DTDSchemaFactory(); } protected XMLValidationSchema parseRngSchema(String contents) throws XMLStreamException { - return parseSchema(contents, XMLValidationSchema.SCHEMA_ID_RELAXNG); + return newRelaxNGValidatorFactory() + .createSchema(new StringReader(contents)); } protected XMLValidationSchema parseDTDSchema(String contents) throws XMLStreamException { - return parseSchema(contents, XMLValidationSchema.SCHEMA_ID_DTD); + return newDTDValidatorFactory() + .createSchema(new StringReader(contents)); } protected XMLValidationSchema parseW3CSchema(String contents) throws XMLStreamException { - return parseSchema(contents, XMLValidationSchema.SCHEMA_ID_W3C_SCHEMA); + return newW3CSchemaValidatorFactory() + .createSchema(new StringReader(contents)); } protected void verifyFailure(String xml, XMLValidationSchema schema, String failMsg, diff --git a/src/test/java/stax2/vwstream/BaseOutputTest.java b/src/test/java/stax2/vwstream/BaseOutputTest.java index 021b9c38..a56439af 100644 --- a/src/test/java/stax2/vwstream/BaseOutputTest.java +++ b/src/test/java/stax2/vwstream/BaseOutputTest.java @@ -20,9 +20,7 @@ public XMLStreamWriter2 getDTDValidatingWriter(Writer w, String dtdSrc, outf.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, new Boolean(repairing)); XMLStreamWriter2 strw = (XMLStreamWriter2)outf.createXMLStreamWriter(w); - XMLValidationSchemaFactory vd = XMLValidationSchemaFactory.newInstance(XMLValidationSchema.SCHEMA_ID_DTD); - - XMLValidationSchema schema = vd.createSchema(new StringReader(dtdSrc)); + XMLValidationSchema schema = parseDTDSchema(dtdSrc); strw.validateAgainst(schema); strw.writeStartDocument(); @@ -38,9 +36,7 @@ public XMLStreamWriter2 getSchemaValidatingWriter(Writer w, String schemaSrc, outf.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, new Boolean(repairing)); XMLStreamWriter2 strw = (XMLStreamWriter2)outf.createXMLStreamWriter(w); - XMLValidationSchemaFactory vd = XMLValidationSchemaFactory.newInstance(XMLValidationSchema.SCHEMA_ID_W3C_SCHEMA); - - XMLValidationSchema schema = vd.createSchema(new StringReader(schemaSrc)); + XMLValidationSchema schema = parseW3CSchema(schemaSrc); strw.validateAgainst(schema); strw.writeStartDocument();