use of org.custommonkey.xmlunit.Validator in project jslint4java by happygiraffe.
the class XmlResultFormatterTest method assertValid.
private void assertValid(File output) throws FileNotFoundException, SAXException {
InputSource xml = new InputSource(new FileInputStream(output));
URL dtdUrl = getClass().getClassLoader().getResource(DTD_RESOURCE);
assertThat("resource " + DTD_RESOURCE + " exists", dtdUrl, notNullValue());
// Specify a validator as the documents don't have <!DOCTYPE jslint> in them.
Validator validator = new Validator(xml, dtdUrl.toString(), "jslint");
assertThat(validator.toString(), validator.isValid(), is(true));
}
use of org.custommonkey.xmlunit.Validator in project wcomponents by BorderTech.
the class ValidatorApp method assertSchemaMatch.
/**
* Asserts that the given xhtml matches the schema.
*
* @param xhtml the xhtmlto validate.
*
* @throws SAXException if there is a parsing error
*/
public void assertSchemaMatch(final String xhtml) throws SAXException {
// Load the schema.
Object schema = getClass().getResource("/schema/ui/v1/schema.xsd").toString();
// Validate the xhtml.
Validator validator;
StringReader reader = new StringReader(xhtml);
validator = new Validator(reader);
validator.useXMLSchema(true);
validator.setJAXP12SchemaSource(schema);
validator.assertIsValid();
}
use of org.custommonkey.xmlunit.Validator in project wcomponents by BorderTech.
the class AbstractWebXmlRendererTestCase method setupValidator.
/**
* Creates an XML Unit validator for the given xml.
*
* @param xml the xml to validate
* @return an XML Unit validator that for validating the xml.
*/
public Validator setupValidator(final String xml) {
try {
StringReader reader = new StringReader(xml);
Validator validator = new Validator(reader);
validator.useXMLSchema(true);
validator.setJAXP12SchemaSource(new File(getSchemaPath()));
return validator;
} catch (SAXException ex) {
LOG.error("Unexpected error while testing", ex);
throw new IllegalStateException("Unable to set up validator");
}
}
use of org.custommonkey.xmlunit.Validator in project wcomponents by BorderTech.
the class AbstractWebXmlRendererTestCase method assertSchemaMismatch.
/**
* Asserts that the given xhtml does not match the schema.
*
* @param xhtml the xhtml to validate.
*
* @throws IOException if there is an I/O error
* @throws SAXException if there is a parsing error
*/
public void assertSchemaMismatch(final String xhtml) throws IOException, SAXException {
Validator validator = getSchemaValidator(xhtml);
Assert.assertFalse("xhtml should not validate", validator.isValid());
}
use of org.custommonkey.xmlunit.Validator in project wcomponents by BorderTech.
the class AbstractWebXmlRendererTestCase method getSchemaValidator.
/**
* Obtains an XMLUnit schema validator for validating the output.
*
* @param xhtml the html to validate
* @return the validator to use.
*/
protected Validator getSchemaValidator(final String xhtml) {
try {
// Load the schema.
String schemaPath = getSchemaPath();
Object schema = AbstractWebXmlRendererTestCase.class.getResource(schemaPath).toString();
String wrappedXhtml = wrapXHtml(xhtml);
// Validate the xhtml.
Validator validator;
StringReader reader = new StringReader(wrappedXhtml);
validator = new Validator(reader);
validator.useXMLSchema(true);
validator.setJAXP12SchemaSource(schema);
return validator;
} catch (Exception e) {
return null;
}
}
Aggregations