Search in sources :

Example 1 with XmlValidationService

use of com.adaptris.core.transform.XmlValidationService in project interlok by adaptris.

the class BasicSchemaValidationTest method testBasicSchemaValidator_Exception.

@Test(expected = ServiceException.class)
public void testBasicSchemaValidator_Exception() throws Exception {
    String schemaUrl = PROPERTIES.getProperty(KEY_WILL_VALIDATE_SCHEMA);
    BasicXmlSchemaValidator validator = new BasicXmlSchemaValidator().withSchema(schemaUrl).withSchemaCache(new CacheConnection().withCacheInstance(new ExpiringMapCache()));
    XmlValidationService service = new XmlValidationService(validator);
    try {
        LifecycleHelper.initAndStart(service);
        AdaptrisMessage m1 = new DefectiveMessageFactory(WhenToBreak.BOTH).newMessage();
        service.doService(m1);
    } finally {
        LifecycleHelper.stopAndClose(service);
    }
}
Also used : DefectiveMessageFactory(com.adaptris.core.stubs.DefectiveMessageFactory) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ExpiringMapCache(com.adaptris.core.cache.ExpiringMapCache) XmlValidationService(com.adaptris.core.transform.XmlValidationService) CacheConnection(com.adaptris.core.services.cache.CacheConnection) Test(org.junit.Test)

Example 2 with XmlValidationService

use of com.adaptris.core.transform.XmlValidationService in project interlok by adaptris.

the class ExtendedSchemaValidatorTest method testExtendedValidator_Invalid.

@Test
public void testExtendedValidator_Invalid() throws Exception {
    String schemaUrl = PROPERTIES.getProperty(KEY_WILL_NOT_VALIDATE);
    ExtendedXmlSchemaValidator validator = new ExtendedXmlSchemaValidator().withSchemaViolationHandler(new ViolationsAsMetadata()).withSchema(schemaUrl);
    AdaptrisMessage msg = MessageHelper.createMessage(PROPERTIES.getProperty(KEY_INPUT_FILE));
    XmlValidationService service = new XmlValidationService(validator);
    execute(service, msg);
    assertTrue(msg.headersContainsKey(ViolationHandlerImpl.DEFAULT_KEY));
    SchemaViolations v = (SchemaViolations) new XStreamMarshaller().unmarshal(msg.getMetadataValue(ViolationHandlerImpl.DEFAULT_KEY));
    assertEquals(2, v.getViolations().size());
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) XmlValidationService(com.adaptris.core.transform.XmlValidationService) XStreamMarshaller(com.adaptris.core.XStreamMarshaller) Test(org.junit.Test)

Example 3 with XmlValidationService

use of com.adaptris.core.transform.XmlValidationService in project interlok by adaptris.

the class BasicSchemaValidationTest method testBasicSchemaValidator_Invalid.

@Test(expected = ServiceException.class)
public void testBasicSchemaValidator_Invalid() throws Exception {
    String schemaUrl = PROPERTIES.getProperty(KEY_WILL_NOT_VALIDATE);
    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 : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) XmlValidationService(com.adaptris.core.transform.XmlValidationService) Test(org.junit.Test)

Example 4 with XmlValidationService

use of com.adaptris.core.transform.XmlValidationService in project interlok by adaptris.

the class BasicSchemaValidationTest method testBasicSchemaValidator.

@Test
public void testBasicSchemaValidator() throws Exception {
    String schemaUrl = PROPERTIES.getProperty(KEY_WILL_VALIDATE_SCHEMA);
    BasicXmlSchemaValidator validator = new BasicXmlSchemaValidator().withSchema(schemaUrl).withSchemaCache(new CacheConnection().withCacheInstance(new ExpiringMapCache()));
    XmlValidationService service = new XmlValidationService(validator);
    try {
        LifecycleHelper.initAndStart(service);
        AdaptrisMessage m1 = MessageHelper.createMessage(PROPERTIES.getProperty(KEY_INPUT_FILE));
        AdaptrisMessage m2 = MessageHelper.createMessage(PROPERTIES.getProperty(KEY_INPUT_FILE));
        service.doService(m1);
        service.doService(m2);
    } finally {
        LifecycleHelper.stopAndClose(service);
    }
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ExpiringMapCache(com.adaptris.core.cache.ExpiringMapCache) XmlValidationService(com.adaptris.core.transform.XmlValidationService) CacheConnection(com.adaptris.core.services.cache.CacheConnection) Test(org.junit.Test)

Example 5 with XmlValidationService

use of com.adaptris.core.transform.XmlValidationService in project interlok by adaptris.

the class ExtendedSchemaValidatorTest method testExtendedValidator_Valid.

@Test
public void testExtendedValidator_Valid() throws Exception {
    String schemaUrl = PROPERTIES.getProperty(KEY_WILL_VALIDATE_SCHEMA);
    ExtendedXmlSchemaValidator validator = new ExtendedXmlSchemaValidator().withSchemaViolationHandler(new ViolationsAsMetadata()).withSchema(schemaUrl);
    AdaptrisMessage msg = MessageHelper.createMessage(PROPERTIES.getProperty(KEY_INPUT_FILE));
    XmlValidationService service = new XmlValidationService(validator);
    execute(service, msg);
    assertFalse(msg.headersContainsKey(ViolationHandlerImpl.DEFAULT_KEY));
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) XmlValidationService(com.adaptris.core.transform.XmlValidationService) Test(org.junit.Test)

Aggregations

AdaptrisMessage (com.adaptris.core.AdaptrisMessage)5 XmlValidationService (com.adaptris.core.transform.XmlValidationService)5 Test (org.junit.Test)5 ExpiringMapCache (com.adaptris.core.cache.ExpiringMapCache)2 CacheConnection (com.adaptris.core.services.cache.CacheConnection)2 XStreamMarshaller (com.adaptris.core.XStreamMarshaller)1 DefectiveMessageFactory (com.adaptris.core.stubs.DefectiveMessageFactory)1