use of org.apache.sling.validation.spi.support.DefaultValidationFailure in project sling by apache.
the class ValidationServiceImplTest method testValueMapWithMissingField.
@Test()
public void testValueMapWithMissingField() throws Exception {
modelBuilder.resourceProperty(propertyBuilder.build("field1"));
modelBuilder.resourceProperty(propertyBuilder.build("field2"));
modelBuilder.resourceProperty(propertyBuilder.build("field3"));
modelBuilder.resourceProperty(propertyBuilder.build("field4"));
ValidationModel vm = modelBuilder.build("sling/validation/test", "some source");
// this should not be detected as missing property
HashMap<String, Object> hashMap = new HashMap<String, Object>();
hashMap.put("field1", new String[] {});
hashMap.put("field2", new String[] { "null" });
hashMap.put("field3", "");
ValidationResult vr = validationService.validate(new ValueMapDecorator(hashMap), vm);
Assert.assertThat(vr.getFailures(), Matchers.<ValidationFailure>contains(new DefaultValidationFailure("", 20, defaultResourceBundle, ValidationServiceImpl.I18N_KEY_MISSING_REQUIRED_PROPERTY_WITH_NAME, "field4")));
}
Aggregations