Skip to content

Commit

Permalink
validation test refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Apr 2, 2018
1 parent ab56fbf commit 4a1549c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
32 changes: 18 additions & 14 deletions src/test/java/stax2/vstream/BaseStax2ValidationTest.java
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
8 changes: 2 additions & 6 deletions src/test/java/stax2/vwstream/BaseOutputTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down

0 comments on commit 4a1549c

Please sign in to comment.