/** * Assert that an InputSource containing XML contains valid XML: * the document must contain a DOCTYPE declaration to be validated * @param xml * @throws SAXException * @throws ConfigurationException if validation could not be turned on * @see Validator */ public static void assertXMLValid(InputSource xml) throws SAXException, ConfigurationException { assertXMLValid(new Validator(xml)); }
/** * Assert that an InputSource containing XML contains valid XML: * the document must contain a DOCTYPE declaration to be validated * @param xml * @throws SAXException * @throws ConfigurationException if validation could not be turned on * @see Validator */ public static void assertXMLValid(InputSource xml) throws SAXException, ConfigurationException { assertXMLValid(new Validator(xml)); }
/** * Assert that a String containing XML contains valid XML: the String must * contain a DOCTYPE declaration to be validated * @param xmlString * @throws SAXException * @throws ConfigurationException if validation could not be turned on * @see Validator */ public static void assertXMLValid(String xmlString) throws SAXException, ConfigurationException { assertXMLValid(new Validator(xmlString)); }
/** * Assert that a String containing XML contains valid XML: the String must * contain a DOCTYPE declaration to be validated * @param xmlString * @throws SAXException * @throws ConfigurationException if validation could not be turned on * @see Validator */ public static void assertXMLValid(String xmlString) throws SAXException, ConfigurationException { assertXMLValid(new Validator(xmlString)); }
/** * Assert that an InputSource containing XML contains valid XML: * the document must contain a DOCTYPE to be validated, but the * validation will use the systemId to obtain the DTD * @param xml * @param systemId * @throws SAXException * @throws ConfigurationException if validation could not be turned on * @see Validator */ public static void assertXMLValid(InputSource xml, String systemId) throws SAXException, ConfigurationException { assertXMLValid(new Validator(xml, systemId)); }
/** * Assert that an InputSource containing XML contains valid XML: * the document must contain a DOCTYPE to be validated, but the * validation will use the systemId to obtain the DTD * @param xml * @param systemId * @throws SAXException * @throws ConfigurationException if validation could not be turned on * @see Validator */ public static void assertXMLValid(InputSource xml, String systemId) throws SAXException, ConfigurationException { assertXMLValid(new Validator(xml, systemId)); }
/** * Assert that a String containing XML contains valid XML: the String must * contain a DOCTYPE to be validated, but the validation will use the * systemId to obtain the DTD * @param xmlString * @param systemId * @throws SAXException * @throws ConfigurationException if validation could not be turned on * @see Validator */ public static void assertXMLValid(String xmlString, String systemId) throws SAXException, ConfigurationException { assertXMLValid(new Validator(xmlString, systemId)); }
/** * Assert that a String containing XML contains valid XML: the String will * be given a DOCTYPE to be validated with the name and systemId specified * regardless of whether it already contains a doctype declaration. * @param xmlString * @param systemId * @param doctype * @throws SAXException * @throws ConfigurationException if validation could not be turned on * @see Validator */ public static void assertXMLValid(String xmlString, String systemId, String doctype) throws SAXException, ConfigurationException { assertXMLValid(new Validator(new StringReader(xmlString), systemId, doctype)); }
/** * Assert that a String containing XML contains valid XML: the String must * contain a DOCTYPE to be validated, but the validation will use the * systemId to obtain the DTD * @param xmlString * @param systemId * @throws SAXException * @throws ConfigurationException if validation could not be turned on * @see Validator */ public static void assertXMLValid(String xmlString, String systemId) throws SAXException, ConfigurationException { assertXMLValid(new Validator(xmlString, systemId)); }
/** * Assert that a String containing XML contains valid XML: the String will * be given a DOCTYPE to be validated with the name and systemId specified * regardless of whether it already contains a doctype declaration. * @param xmlString * @param systemId * @param doctype * @throws SAXException * @throws ConfigurationException if validation could not be turned on * @see Validator */ public static void assertXMLValid(String xmlString, String systemId, String doctype) throws SAXException, ConfigurationException { assertXMLValid(new Validator(new StringReader(xmlString), systemId, doctype)); }
/** * Assert that a piece of XML contains valid XML: the document * will be given a DOCTYPE to be validated with the name and * systemId specified regardless of whether it already contains a * doctype declaration. * @param xml * @param systemId * @param doctype * @throws SAXException * @throws ConfigurationException if validation could not be turned on * @see Validator */ public static void assertXMLValid(InputSource xml, String systemId, String doctype) throws SAXException, ConfigurationException { assertXMLValid(new Validator(xml, systemId, doctype)); }
/** * Assert that a piece of XML contains valid XML: the document * will be given a DOCTYPE to be validated with the name and * systemId specified regardless of whether it already contains a * doctype declaration. * @param xml * @param systemId * @param doctype * @throws SAXException * @throws ConfigurationException if validation could not be turned on * @see Validator */ public static void assertXMLValid(InputSource xml, String systemId, String doctype) throws SAXException, ConfigurationException { assertXMLValid(new Validator(xml, systemId, doctype)); }
/** assert xml is DTD-valid * @param d document to validate * @param doctype the DOCTYPE that the xml should have (i.e. the root element). * @param dtdResource url of dtd file. */ public static void assertDTDValid(Document d,String doctype, URL dtdResource) { try { assertXMLValid(new Validator(d,dtdResource.toString(),doctype)); } catch (SAXException e) { fail("assertDTDValid: parse failure " + e.getMessage()); } catch (ParserConfigurationException e) { fail("assertDTDValid: parser configuration failure " + e.getMessage()); } }
/** * 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(); }
/** assert xml is DTD valid. * @param xmlStream stream of xml to validate * @param doctype the DOCTYPE that the xml should have (ie. the expected root element) * @param dtdResource url to dtd file. */ public static void assertDTDValid(InputStream xmlStream, String doctype, URL dtdResource) { try { assertXMLValid(new Validator(DomHelper.newDocument(xmlStream),dtdResource.toString(),doctype)); } catch (SAXException e) { fail("assertDTDValid: parse failure " + e.getMessage()); } catch (ParserConfigurationException e) { fail("assertDTDValid: parser configuration failure " + e.getMessage()); } catch (IOException e) { fail("assertDTDValid: failed to read from stream " + e.getMessage()); } }
/** * 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"); } }
/** * 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) { // Some web components generate a fragment of xhtml markup that does not // have a single root element, so we add a "body" root element to the // markup fragment and the schema fragment. 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); // validator. return validator; } catch (Exception e) { return null; } }
Validator validator = new Validator(result); validator.useXMLSchema(true); validator.assertIsValid();