Search in sources :

Example 1 with ValidationResult

use of org.milyn.validation.ValidationResult in project tutorials by eugenp.

the class OrderValidator method validate.

public ValidationResult validate(String path) throws IOException, SAXException {
    Smooks smooks = new Smooks(OrderValidator.class.getResourceAsStream("/smooks/smooks-validation.xml"));
    try {
        StringResult xmlResult = new StringResult();
        JavaResult javaResult = new JavaResult();
        ValidationResult validationResult = new ValidationResult();
        smooks.filterSource(new StreamSource(OrderValidator.class.getResourceAsStream(path)), xmlResult, javaResult, validationResult);
        return validationResult;
    } finally {
        smooks.close();
    }
}
Also used : Smooks(org.milyn.Smooks) StreamSource(javax.xml.transform.stream.StreamSource) StringResult(org.milyn.payload.StringResult) ValidationResult(org.milyn.validation.ValidationResult) JavaResult(org.milyn.payload.JavaResult)

Example 2 with ValidationResult

use of org.milyn.validation.ValidationResult in project tutorials by eugenp.

the class SmooksIntegrationTest method givenIncorrectOrderXML_whenValidate_thenExpectValidationErrors.

@Test
public void givenIncorrectOrderXML_whenValidate_thenExpectValidationErrors() throws Exception {
    OrderValidator orderValidator = new OrderValidator();
    ValidationResult validationResult = orderValidator.validate("/smooks/order.xml");
    assertThat(validationResult.getErrors(), hasSize(1));
    // 1234567 didn't match ^[0-9\\-\\+]{9,15}$
    assertThat(validationResult.getErrors().get(0).getFailRuleResult().getRuleName(), is("supplierPhone"));
}
Also used : ValidationResult(org.milyn.validation.ValidationResult) Test(org.junit.Test)

Aggregations

ValidationResult (org.milyn.validation.ValidationResult)2 StreamSource (javax.xml.transform.stream.StreamSource)1 Test (org.junit.Test)1 Smooks (org.milyn.Smooks)1 JavaResult (org.milyn.payload.JavaResult)1 StringResult (org.milyn.payload.StringResult)1