Search in sources :

Example 11 with ChildResource

use of org.apache.sling.validation.model.ChildResource in project sling by apache.

the class ValidationServiceImplTest method testResourceWithMissingOptionalChildResource.

@Test
public void testResourceWithMissingOptionalChildResource() throws Exception {
    // accept any digits
    propertyBuilder.validator(REGEX_VALIDATOR_ID, 0, RegexValidator.REGEX_PARAM, "\\d");
    ResourceProperty property = propertyBuilder.build("field1");
    ChildResource child = new ChildResourceImpl("child", null, false, Collections.singletonList(property), Collections.<ChildResource>emptyList());
    modelBuilder.childResource(child);
    ValidationModel vm = modelBuilder.build("type", "some source");
    // create a resource (lacking the optional "child" sub resource)
    ResourceResolver rr = context.resourceResolver();
    Resource testResource = ResourceUtil.getOrCreateResource(rr, "/content/validation/1/resource", JcrConstants.NT_UNSTRUCTURED, JcrConstants.NT_UNSTRUCTURED, true);
    ValidationResult vr = validationService.validate(testResource, vm);
    Assert.assertThat(vr.getFailures(), Matchers.hasSize(0));
    Assert.assertTrue(vr.isValid());
}
Also used : ResourceProperty(org.apache.sling.validation.model.ResourceProperty) ValidationModel(org.apache.sling.validation.model.ValidationModel) ChildResourceImpl(org.apache.sling.validation.impl.model.ChildResourceImpl) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) NonExistingResource(org.apache.sling.api.resource.NonExistingResource) Resource(org.apache.sling.api.resource.Resource) ChildResource(org.apache.sling.validation.model.ChildResource) SyntheticResource(org.apache.sling.api.resource.SyntheticResource) ChildResource(org.apache.sling.validation.model.ChildResource) DefaultValidationResult(org.apache.sling.validation.spi.support.DefaultValidationResult) ValidationResult(org.apache.sling.validation.ValidationResult) Test(org.junit.Test)

Aggregations

ChildResource (org.apache.sling.validation.model.ChildResource)11 Resource (org.apache.sling.api.resource.Resource)10 ChildResourceImpl (org.apache.sling.validation.impl.model.ChildResourceImpl)8 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)7 ResourceProperty (org.apache.sling.validation.model.ResourceProperty)7 ValidationModel (org.apache.sling.validation.model.ValidationModel)7 Test (org.junit.Test)7 NonExistingResource (org.apache.sling.api.resource.NonExistingResource)6 SyntheticResource (org.apache.sling.api.resource.SyntheticResource)6 ValidationResult (org.apache.sling.validation.ValidationResult)6 DefaultValidationResult (org.apache.sling.validation.spi.support.DefaultValidationResult)6 HashMap (java.util.HashMap)4 DefaultValidationFailure (org.apache.sling.validation.spi.support.DefaultValidationFailure)4 ModifiableValueMap (org.apache.sling.api.resource.ModifiableValueMap)2 ArrayList (java.util.ArrayList)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Nonnull (javax.annotation.Nonnull)1 Node (javax.jcr.Node)1 ValueMap (org.apache.sling.api.resource.ValueMap)1