Search in sources :

Example 61 with ServiceException

use of com.adaptris.core.ServiceException in project interlok by adaptris.

the class XmlValidationServiceTest method testSimpleValidator_IsInvalidXml_LessThan.

@Test
public void testSimpleValidator_IsInvalidXml_LessThan() throws Exception {
    XmlBasicValidator validator = new XmlBasicValidator(new DocumentBuilderFactoryBuilder());
    AdaptrisMessage msg = new DefaultMessageFactory().newMessage("<?xml version=\"1.0\"?><Root><</Root>");
    XmlValidationService service = new XmlValidationService(validator);
    try {
        execute(service, msg);
        fail("Success with invalid XML");
    } catch (ServiceException e) {
        ;
    }
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) DocumentBuilderFactoryBuilder(com.adaptris.core.util.DocumentBuilderFactoryBuilder) Test(org.junit.Test)

Example 62 with ServiceException

use of com.adaptris.core.ServiceException 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 63 with ServiceException

use of com.adaptris.core.ServiceException in project interlok by adaptris.

the class XmlValidationServiceTest method testSimpleValidator_IsInvalidXml_AmpersandNoEntity.

@Test
public void testSimpleValidator_IsInvalidXml_AmpersandNoEntity() throws Exception {
    XmlBasicValidator validator = new XmlBasicValidator();
    AdaptrisMessage msg = new DefaultMessageFactory().newMessage("<?xml version=\"1.0\"?><Root>&</Root>");
    XmlValidationService service = new XmlValidationService(validator);
    try {
        execute(service, msg);
        fail("Success with invalid XML");
    } catch (ServiceException e) {
        ;
    }
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Example 64 with ServiceException

use of com.adaptris.core.ServiceException 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 65 with ServiceException

use of com.adaptris.core.ServiceException in project interlok by adaptris.

the class XmlRuleValidatorTest method testNotInListContentValidation_DataInList.

@Test
public void testNotInListContentValidation_DataInList() throws Exception {
    XmlRuleValidator validator = new XmlRuleValidator();
    validator.addValidationStage(new ValidationStage(XPATH_ITERATION_CHILDREN_OF_ZEUS, XPATH_CHILDREN_OF_HERA, new NotInListContentValidation(CHILDREN_OF_HERA)));
    AdaptrisMessage msg = new DefaultMessageFactory().newMessage(XML_FAMILY_TREE);
    XmlValidationService service = new XmlValidationService(validator);
    try {
        ExampleServiceCase.execute(service, msg);
        fail("RuleValidationService success when expecting failure");
    } catch (ServiceException expected) {
    }
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) NotInListContentValidation(com.adaptris.transform.validate.NotInListContentValidation) ValidationStage(com.adaptris.transform.validate.ValidationStage) Test(org.junit.Test)

Aggregations

ServiceException (com.adaptris.core.ServiceException)236 Test (org.junit.Test)172 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)161 CoreException (com.adaptris.core.CoreException)45 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)26 StandaloneProducer (com.adaptris.core.StandaloneProducer)18 MetadataElement (com.adaptris.core.MetadataElement)17 ValidationStage (com.adaptris.transform.validate.ValidationStage)16 Cache (com.adaptris.core.cache.Cache)15 DefectiveMessageFactory (com.adaptris.core.stubs.DefectiveMessageFactory)13 TimeInterval (com.adaptris.util.TimeInterval)13 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)11 Connection (java.sql.Connection)10 File (java.io.File)9 IOException (java.io.IOException)9 OutputStream (java.io.OutputStream)9 SQLException (java.sql.SQLException)9 InputStream (java.io.InputStream)8 Document (org.w3c.dom.Document)8 Channel (com.adaptris.core.Channel)7