use of com.adaptris.core.transform.schema.BasicXmlSchemaValidator in project interlok by adaptris.
the class XmlValidationServiceTest method testValidXmlSchemaInMetadataOnly.
@Test
public void testValidXmlSchemaInMetadataOnly() throws Exception {
String schemaUrl = PROPERTIES.getProperty(KEY_WILL_VALIDATE_SCHEMA);
// if (!ExternalResourcesHelper.isExternalServerAvailable(new URLString(schemaUrl))) {
// log.debug(schemaUrl + " not available, ignoring testMetadataSchemaKeyIsEmpty test");
// return;
// }
BasicXmlSchemaValidator validator = new BasicXmlSchemaValidator();
validator.setSchema("%message{schema-key}");
AdaptrisMessage msg = MessageHelper.createMessage(PROPERTIES.getProperty(KEY_INPUT_FILE));
msg.addMetadata("schema-key", schemaUrl);
XmlValidationService service = new XmlValidationService(validator);
execute(service, msg);
}
use of com.adaptris.core.transform.schema.BasicXmlSchemaValidator in project interlok by adaptris.
the class XmlValidationServiceTest method testSchemaValidator_InvalidXml.
@Test
public void testSchemaValidator_InvalidXml() throws Exception {
String schemaUrl = PROPERTIES.getProperty(KEY_WILL_VALIDATE_SCHEMA);
// if (!ExternalResourcesHelper.isExternalServerAvailable(new URLString(schemaUrl))) {
// log.debug(schemaUrl + " not available, ignoring testInvalidXml test");
// return;
// }
BasicXmlSchemaValidator validator = new BasicXmlSchemaValidator();
validator.setSchema(schemaUrl);
XmlValidationService service = new XmlValidationService(validator);
AdaptrisMessage msg = new DefaultMessageFactory().newMessage("<?xml version=\"1.0\"?><Root></Root>");
try {
execute(service, msg);
fail("Success on a file that isn't valid XML!");
} catch (ServiceException e) {
;
}
}
use of com.adaptris.core.transform.schema.BasicXmlSchemaValidator in project interlok by adaptris.
the class XmlValidationServiceTest method testSchemaValidator_ValidSchema_MessageFails.
@Test
public void testSchemaValidator_ValidSchema_MessageFails() throws Exception {
String schemaUrl = PROPERTIES.getProperty(KEY_WILL_NOT_VALIDATE);
// if (!ExternalResourcesHelper.isExternalServerAvailable(new URLString(schemaUrl))) {
// log.debug(schemaUrl + " not available, ignoring testValidXmlConfiguredSchemaOnly test");
// return;
// }
BasicXmlSchemaValidator validator = new BasicXmlSchemaValidator().withSchema(schemaUrl);
AdaptrisMessage msg = MessageHelper.createMessage(PROPERTIES.getProperty(KEY_INPUT_FILE));
XmlValidationService service = new XmlValidationService(validator);
try {
execute(service, msg);
fail();
} catch (ServiceException expected) {
}
}
use of com.adaptris.core.transform.schema.BasicXmlSchemaValidator in project interlok by adaptris.
the class XmlValidationServiceTest method retrieveObjectForSampleConfig.
@Override
protected Object retrieveObjectForSampleConfig() {
ValidationStage vs = new ValidationStage();
vs.setIterationXpath("/document/names");
vs.setElementXpath("fullName");
vs.addRule(new NotNullContentValidation());
KeyValuePair disableExternalEntities = new KeyValuePair("http://xml.org/sax/features/external-general-entities", "false");
KeyValuePair disableDoctypeDecl = new KeyValuePair("http://apache.org/xml/features/disallow-doctype-decl", "true");
return new XmlValidationService(new XmlBasicValidator(new DocumentBuilderFactoryBuilder().withNamespaceAware(true).withFeatures(new KeyValuePairSet(Arrays.asList(disableExternalEntities, disableDoctypeDecl)))), new BasicXmlSchemaValidator().withSchema("http://host/schema.xsd or %message{metadatKey}"), new XmlRuleValidator(vs));
}
use of com.adaptris.core.transform.schema.BasicXmlSchemaValidator in project interlok by adaptris.
the class XmlValidationServiceTest method testSchemaValidator_ValidXmlConfiguredSchemaOnly.
@Test
public void testSchemaValidator_ValidXmlConfiguredSchemaOnly() throws Exception {
String schemaUrl = PROPERTIES.getProperty(KEY_WILL_VALIDATE_SCHEMA);
// if (!ExternalResourcesHelper.isExternalServerAvailable(new URLString(schemaUrl))) {
// log.debug(schemaUrl + " not available, ignoring testValidXmlConfiguredSchemaOnly test");
// return;
// }
BasicXmlSchemaValidator validator = new BasicXmlSchemaValidator().withSchema(schemaUrl);
AdaptrisMessage msg = MessageHelper.createMessage(PROPERTIES.getProperty(KEY_INPUT_FILE));
XmlValidationService service = new XmlValidationService(validator);
execute(service, msg);
}
Aggregations