Search in sources :

Example 11 with ValidationStage

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

the class XmlRuleValidatorTest method testListContentValidation_DataNotInList.

@Test
public void testListContentValidation_DataNotInList() throws Exception {
    XmlRuleValidator validator = new XmlRuleValidator();
    validator.addValidationStage(new ValidationStage(XPATH_ITERATION_CHILDREN_OF_ZEUS, XPATH_CHILDREN_OF_DEMETER, new SimpleListContentValidation(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 exception");
    } catch (ServiceException e) {
        // expected
        ;
    }
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) SimpleListContentValidation(com.adaptris.transform.validate.SimpleListContentValidation) ValidationStage(com.adaptris.transform.validate.ValidationStage) Test(org.junit.Test)

Example 12 with ValidationStage

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

the class XmlRuleValidatorTest method createSample.

static XmlRuleValidator createSample() {
    XmlRuleValidator validator = new XmlRuleValidator();
    ValidationStage stage1 = new ValidationStage(XPATH_ITERATION_CHILDREN_OF_CRONOS, XPATH_CHILDREN_OF_RHEA, new NotNullContentValidation(), new SimpleListContentValidation(CHILDREN_OF_RHEA));
    validator.addValidationStage(stage1);
    ValidationStage stage2 = new ValidationStage(XPATH_ITERATION_CHILDREN_OF_ZEUS, XPATH_CHILDREN_OF_HERA, new NotNullContentValidation(), new SimpleListContentValidation(CHILDREN_OF_HERA));
    validator.addValidationStage(stage2);
    ValidationStage stage3 = new ValidationStage(XPATH_ITERATION_CHILDREN_OF_ZEUS, XPATH_CHILDREN_OF_LETO, new NotNullContentValidation(), new NotInListContentValidation(CHILDREN_OF_HERA));
    validator.addValidationStage(stage3);
    return validator;
}
Also used : NotNullContentValidation(com.adaptris.transform.validate.NotNullContentValidation) SimpleListContentValidation(com.adaptris.transform.validate.SimpleListContentValidation) NotInListContentValidation(com.adaptris.transform.validate.NotInListContentValidation) ValidationStage(com.adaptris.transform.validate.ValidationStage)

Example 13 with ValidationStage

use of com.adaptris.transform.validate.ValidationStage 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 14 with ValidationStage

use of com.adaptris.transform.validate.ValidationStage 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 15 with ValidationStage

use of com.adaptris.transform.validate.ValidationStage 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

ValidationStage (com.adaptris.transform.validate.ValidationStage)18 ServiceException (com.adaptris.core.ServiceException)16 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)15 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)15 Test (org.junit.Test)15 NotNullContentValidation (com.adaptris.transform.validate.NotNullContentValidation)8 SimpleListContentValidation (com.adaptris.transform.validate.SimpleListContentValidation)6 NotInListContentValidation (com.adaptris.transform.validate.NotInListContentValidation)3 RegexpContentValidation (com.adaptris.transform.validate.RegexpContentValidation)3 DocumentBuilderFactoryBuilder (com.adaptris.core.util.DocumentBuilderFactoryBuilder)2 IsNullContentValidation (com.adaptris.transform.validate.IsNullContentValidation)2 CoreException (com.adaptris.core.CoreException)1 BasicXmlSchemaValidator (com.adaptris.core.transform.schema.BasicXmlSchemaValidator)1 XmlHelper.createDocument (com.adaptris.core.util.XmlHelper.createDocument)1 ContentValidation (com.adaptris.transform.validate.ContentValidation)1 KeyValuePair (com.adaptris.util.KeyValuePair)1 KeyValuePairSet (com.adaptris.util.KeyValuePairSet)1 SimpleNamespaceContext (com.adaptris.util.text.xml.SimpleNamespaceContext)1 XPath (com.adaptris.util.text.xml.XPath)1 NamespaceContext (javax.xml.namespace.NamespaceContext)1