Search in sources :

Example 1 with RegexpContentValidation

use of com.adaptris.transform.validate.RegexpContentValidation in project interlok by adaptris.

the class XmlRuleValidatorTest method testRegexpContentValidation_ComplexRegexp.

@Test
public void testRegexpContentValidation_ComplexRegexp() throws Exception {
    XmlRuleValidator validator = new XmlRuleValidator();
    validator.addValidationStage(new ValidationStage("//PartnerIdentifier[@Type='GLN']", "text()", new RegexpContentValidation("^[0-9]{13}$")));
    AdaptrisMessage msg = new DefaultMessageFactory().newMessage(REGEXP_XML);
    XmlValidationService service = new XmlValidationService(validator);
    try {
        ExampleServiceCase.execute(service, msg);
        fail("RuleValidationService success when expecting failure");
    } catch (ServiceException expected) {
        // Should be a good msg, not some kind of IllegalArgumentException / no group index.
        assertTrue(expected.getMessage().startsWith("NodeList entry "));
    } finally {
        ExampleServiceCase.stop(service);
    }
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ValidationStage(com.adaptris.transform.validate.ValidationStage) RegexpContentValidation(com.adaptris.transform.validate.RegexpContentValidation) Test(org.junit.Test)

Example 2 with RegexpContentValidation

use of com.adaptris.transform.validate.RegexpContentValidation in project interlok by adaptris.

the class XmlRuleValidatorTest method testRegexpContentValidation_DataDoesNotMatch.

@Test
public void testRegexpContentValidation_DataDoesNotMatch() throws Exception {
    XmlRuleValidator validator = new XmlRuleValidator();
    validator.addValidationStage(new ValidationStage(XPATH_ITERATION_CHILDREN_OF_ZEUS, XPATH_CHILDREN_OF_HERA, new RegexpContentValidation("[0-9]+")));
    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) {
    } finally {
        ExampleServiceCase.stop(service);
    }
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ValidationStage(com.adaptris.transform.validate.ValidationStage) RegexpContentValidation(com.adaptris.transform.validate.RegexpContentValidation) Test(org.junit.Test)

Example 3 with RegexpContentValidation

use of com.adaptris.transform.validate.RegexpContentValidation in project interlok by adaptris.

the class XmlRuleValidatorTest method testRegexpContentValidation_DataMatches.

@Test
public void testRegexpContentValidation_DataMatches() throws Exception {
    XmlRuleValidator validator = new XmlRuleValidator();
    validator.addValidationStage(new ValidationStage(XPATH_ITERATION_CHILDREN_OF_ZEUS, XPATH_CHILDREN_OF_HERA, new RegexpContentValidation("[a-zA-Z]+")));
    AdaptrisMessage msg = new DefaultMessageFactory().newMessage(XML_FAMILY_TREE);
    XmlValidationService service = new XmlValidationService(validator);
    try {
        ExampleServiceCase.start(service);
        service.doService(new DefaultMessageFactory().newMessage(XML_FAMILY_TREE));
        service.doService(new DefaultMessageFactory().newMessage(XML_FAMILY_TREE));
    } catch (ServiceException e) {
        fail("RuleValidationService failure when expecting success");
    } finally {
        ExampleServiceCase.stop(service);
    }
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ValidationStage(com.adaptris.transform.validate.ValidationStage) RegexpContentValidation(com.adaptris.transform.validate.RegexpContentValidation) Test(org.junit.Test)

Aggregations

AdaptrisMessage (com.adaptris.core.AdaptrisMessage)3 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)3 ServiceException (com.adaptris.core.ServiceException)3 RegexpContentValidation (com.adaptris.transform.validate.RegexpContentValidation)3 ValidationStage (com.adaptris.transform.validate.ValidationStage)3 Test (org.junit.Test)3