Search in sources :

Example 1 with BasicXmlSchemaValidator

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);
}
Also used : BasicXmlSchemaValidator(com.adaptris.core.transform.schema.BasicXmlSchemaValidator) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Example 2 with BasicXmlSchemaValidator

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) {
        ;
    }
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) BasicXmlSchemaValidator(com.adaptris.core.transform.schema.BasicXmlSchemaValidator) ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Example 3 with BasicXmlSchemaValidator

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) {
    }
}
Also used : BasicXmlSchemaValidator(com.adaptris.core.transform.schema.BasicXmlSchemaValidator) ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Example 4 with BasicXmlSchemaValidator

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));
}
Also used : KeyValuePair(com.adaptris.util.KeyValuePair) BasicXmlSchemaValidator(com.adaptris.core.transform.schema.BasicXmlSchemaValidator) NotNullContentValidation(com.adaptris.transform.validate.NotNullContentValidation) DocumentBuilderFactoryBuilder(com.adaptris.core.util.DocumentBuilderFactoryBuilder) KeyValuePairSet(com.adaptris.util.KeyValuePairSet) ValidationStage(com.adaptris.transform.validate.ValidationStage)

Example 5 with BasicXmlSchemaValidator

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);
}
Also used : BasicXmlSchemaValidator(com.adaptris.core.transform.schema.BasicXmlSchemaValidator) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Aggregations

BasicXmlSchemaValidator (com.adaptris.core.transform.schema.BasicXmlSchemaValidator)8 Test (org.junit.Test)7 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)6 ServiceException (com.adaptris.core.ServiceException)4 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)1 ExpiringMapCache (com.adaptris.core.cache.ExpiringMapCache)1 CacheConnection (com.adaptris.core.services.cache.CacheConnection)1 DocumentBuilderFactoryBuilder (com.adaptris.core.util.DocumentBuilderFactoryBuilder)1 NotNullContentValidation (com.adaptris.transform.validate.NotNullContentValidation)1 ValidationStage (com.adaptris.transform.validate.ValidationStage)1 KeyValuePair (com.adaptris.util.KeyValuePair)1 KeyValuePairSet (com.adaptris.util.KeyValuePairSet)1