XmlRuleValidator extends MessageValidatorImpl { public void addValidationStage(ValidationStage vs) { validationStages.add(vs); } XmlRuleValidator();  XmlRuleValidator(ValidationStage... stages); @Override void validate(AdaptrisMessage msg); void addValidationStage(ValidationStage vs); List<ValidationStage> getValidationStages(); void setValidationStages(List<ValidationStage> l); KeyValuePairSet getNamespaceContext(); void setNamespaceContext(KeyValuePairSet set); DocumentBuilderFactoryBuilder getXmlDocumentFactoryConfig(); void setXmlDocumentFactoryConfig(DocumentBuilderFactoryBuilder xml);  }
@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) { } }
@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); } }
@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); } }
@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) { } }
@Test public void testNotInListContentValidation_DataNotInList() throws Exception { XmlRuleValidator validator = new XmlRuleValidator(); validator.addValidationStage(new ValidationStage(XPATH_ITERATION_CHILDREN_OF_ZEUS, XPATH_CHILDREN_OF_HERA, new NotInListContentValidation(CHILDREN_OF_RHEA))); AdaptrisMessage msg = new DefaultMessageFactory().newMessage(XML_FAMILY_TREE); XmlValidationService service = new XmlValidationService(validator); try { ExampleServiceCase.execute(service, msg); } catch (ServiceException expected) { fail("RuleValidationService failure when expecting success"); } }
@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) { ; } }
@Test public void testIsNullContentValidation_DataNotNull() throws Exception { XmlRuleValidator validator = new XmlRuleValidator(); validator.addValidationStage(new ValidationStage(XPATH_ITERATION_CHILDREN_OF_ZEUS, XPATH_CHILD_NAME, new IsNullContentValidation())); AdaptrisMessage msg = new DefaultMessageFactory().newMessage(XML_FAMILY_TREE); XmlValidationService service = new XmlValidationService(validator); try { ExampleServiceCase.execute(service, msg); fail("RuleValidationService sucess when expecting failure"); } catch (ServiceException e) { } }
@Test public void testIsNullContentValidation_DataIsNull() throws Exception { XmlRuleValidator validator = new XmlRuleValidator(); ValidationStage vs = new ValidationStage(XPATH_ITERATION_CHILDREN_OF_HADES, XPATH_CHILD_NAME, new IsNullContentValidation()); validator.addValidationStage(vs); 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"); } }
@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"); } }
@Test public void testNotNullContentValidation_DataIsNull() throws Exception { XmlRuleValidator validator = new XmlRuleValidator(); ValidationStage vs = new ValidationStage(XPATH_ITERATION_CHILDREN_OF_HADES, XPATH_CHILD_NAME, new NotNullContentValidation()); validator.addValidationStage(vs); 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) { ; } }
@Test public void testMultipleContentValidation() throws Exception { XmlRuleValidator validator = new XmlRuleValidator(); ValidationStage vs = new ValidationStage(XPATH_ITERATION_CHILDREN_OF_ZEUS, XPATH_CHILDREN_OF_HERA, new SimpleListContentValidation(CHILDREN_OF_HERA), new NotNullContentValidation()); validator.addValidationStage(vs); ValidationStage vs2 = new ValidationStage(XPATH_ITERATION_CHILDREN_OF_CRONOS, XPATH_CHILDREN_OF_RHEA, new SimpleListContentValidation( CHILDREN_OF_RHEA), new NotNullContentValidation()); validator.addValidationStage(vs2); 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"); } }
@Test public void testRegexpContentValidation_ComplexRegexp() throws Exception { XmlRuleValidator validator = new XmlRuleValidator(); validator.addValidationStage(new ValidationStage(" "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) { assertTrue(expected.getMessage().startsWith("NodeList entry ")); } finally { ExampleServiceCase.stop(service); } }