Search in sources :

Example 16 with ValidationStage

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

the class XmlRuleValidatorTest method testContentValidation_XmlMessage_BadXpath.

@Test
public void testContentValidation_XmlMessage_BadXpath() throws Exception {
    XmlRuleValidator validator = new XmlRuleValidator();
    AdaptrisMessage msg = new DefaultMessageFactory().newMessage(XML_FAMILY_TREE);
    ValidationStage vs = new ValidationStage("/path/to/something/that/does/not/exist", XPATH_CHILDREN_OF_HERA, new NotNullContentValidation());
    vs.setFailOnIterateFailure(true);
    validator.addValidationStage(vs);
    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) NotNullContentValidation(com.adaptris.transform.validate.NotNullContentValidation) ValidationStage(com.adaptris.transform.validate.ValidationStage) Test(org.junit.Test)

Example 17 with ValidationStage

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

the class XmlRuleValidatorTest method testNotNullContentValidation_DataNotNull.

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

Example 18 with ValidationStage

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

the class XmlValidationServiceTest method retrieveObjectForSampleConfig.

@Override
protected Object retrieveObjectForSampleConfig() {
    ValidationStage vs = new ValidationStage();
    vs.setIterationXpath("/document/names");
    vs.setElementXpath("fullName");
    vs.addRule(new NotNullContentValidation());
    KeyValuePair disableExternalEntities = new KeyValuePair("http://xml.org/sax/features/external-general-entities", "false");
    KeyValuePair disableDoctypeDecl = new KeyValuePair("http://apache.org/xml/features/disallow-doctype-decl", "true");
    return new XmlValidationService(new XmlBasicValidator(new DocumentBuilderFactoryBuilder().withNamespaceAware(true).withFeatures(new KeyValuePairSet(Arrays.asList(disableExternalEntities, disableDoctypeDecl)))), new BasicXmlSchemaValidator().withSchema("http://host/schema.xsd or %message{metadatKey}"), new XmlRuleValidator(vs));
}
Also used : KeyValuePair(com.adaptris.util.KeyValuePair) BasicXmlSchemaValidator(com.adaptris.core.transform.schema.BasicXmlSchemaValidator) NotNullContentValidation(com.adaptris.transform.validate.NotNullContentValidation) DocumentBuilderFactoryBuilder(com.adaptris.core.util.DocumentBuilderFactoryBuilder) KeyValuePairSet(com.adaptris.util.KeyValuePairSet) ValidationStage(com.adaptris.transform.validate.ValidationStage)

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