Search in sources :

Example 6 with BasicXmlSchemaValidator

use of com.adaptris.core.transform.schema.BasicXmlSchemaValidator in project interlok by adaptris.

the class XmlValidationServiceTest method testSchemaValidator_InvalidXmlSchemaInMetadata.

@Test
public void testSchemaValidator_InvalidXmlSchemaInMetadata() throws Exception {
    String schemaUrl = PROPERTIES.getProperty(KEY_INVALID_SCHEMA_URL);
    // if (!ExternalResourcesHelper.isExternalServerAvailable(new URLString(schemaUrl))) {
    // log.debug(schemaUrl + " not available, ignoring testInvalidXmlSchemaInMetadata 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);
    try {
        execute(service, msg);
        fail("Success with an invalid schema");
    } catch (ServiceException e) {
        ;
    }
}
Also used : BasicXmlSchemaValidator(com.adaptris.core.transform.schema.BasicXmlSchemaValidator) ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Example 7 with BasicXmlSchemaValidator

use of com.adaptris.core.transform.schema.BasicXmlSchemaValidator in project interlok by adaptris.

the class XmlValidationServiceTest method testSchemaValidator_InitDefault.

@Test
public void testSchemaValidator_InitDefault() {
    XmlValidationService service = new XmlValidationService(new BasicXmlSchemaValidator());
    try {
        LifecycleHelper.init(service);
        fail();
    } catch (Exception expected) {
    } finally {
        LifecycleHelper.close(service);
    }
}
Also used : BasicXmlSchemaValidator(com.adaptris.core.transform.schema.BasicXmlSchemaValidator) ServiceException(com.adaptris.core.ServiceException) Test(org.junit.Test)

Example 8 with BasicXmlSchemaValidator

use of com.adaptris.core.transform.schema.BasicXmlSchemaValidator in project interlok by adaptris.

the class XmlValidationServiceTest method testValidXmlSchema_Expression.

@Test
public void testValidXmlSchema_Expression() 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().withSchema("%message{schema-key}").withSchemaCache(new CacheConnection(new ExpiringMapCache().withMaxEntries(1)));
    AdaptrisMessage msg = MessageHelper.createMessage(PROPERTIES.getProperty(KEY_INPUT_FILE));
    msg.addMetadata("schema-key", schemaUrl);
    XmlValidationService service = new XmlValidationService(validator);
    try {
        LifecycleHelper.initAndStart(service);
        service.doService(msg);
        // Hits the cache the 2nd time round
        service.doService(msg);
    } finally {
        LifecycleHelper.stopAndClose(service);
    }
}
Also used : BasicXmlSchemaValidator(com.adaptris.core.transform.schema.BasicXmlSchemaValidator) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ExpiringMapCache(com.adaptris.core.cache.ExpiringMapCache) CacheConnection(com.adaptris.core.services.cache.CacheConnection) 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