Search in sources :

Example 11 with DefaultValidationFailure

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")));
}
Also used : ValidationModel(org.apache.sling.validation.model.ValidationModel) HashMap(java.util.HashMap) ValueMapDecorator(org.apache.sling.api.wrappers.ValueMapDecorator) DefaultValidationFailure(org.apache.sling.validation.spi.support.DefaultValidationFailure) DefaultValidationResult(org.apache.sling.validation.spi.support.DefaultValidationResult) ValidationResult(org.apache.sling.validation.ValidationResult) Test(org.junit.Test)

Aggregations

ValidationResult (org.apache.sling.validation.ValidationResult)11 ValidationModel (org.apache.sling.validation.model.ValidationModel)11 DefaultValidationFailure (org.apache.sling.validation.spi.support.DefaultValidationFailure)11 DefaultValidationResult (org.apache.sling.validation.spi.support.DefaultValidationResult)11 Test (org.junit.Test)11 HashMap (java.util.HashMap)7 NonExistingResource (org.apache.sling.api.resource.NonExistingResource)7 Resource (org.apache.sling.api.resource.Resource)7 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)7 SyntheticResource (org.apache.sling.api.resource.SyntheticResource)7 ChildResource (org.apache.sling.validation.model.ChildResource)7 ValueMapDecorator (org.apache.sling.api.wrappers.ValueMapDecorator)4 ChildResourceImpl (org.apache.sling.validation.impl.model.ChildResourceImpl)4 ResourceProperty (org.apache.sling.validation.model.ResourceProperty)4 ModifiableValueMap (org.apache.sling.api.resource.ModifiableValueMap)3 Predicate (java.util.function.Predicate)1 CheckForNull (javax.annotation.CheckForNull)1 ResourcePropertyBuilder (org.apache.sling.validation.impl.model.ResourcePropertyBuilder)1 ValidationModelBuilder (org.apache.sling.validation.impl.model.ValidationModelBuilder)1 ValidationModelRetriever (org.apache.sling.validation.model.spi.ValidationModelRetriever)1