Search in sources :

Example 1 with ResourcePropertyNameMatcher

use of org.apache.sling.validation.impl.util.ResourcePropertyNameMatcher in project sling by apache.

the class ValidationModelRetrieverImplTest method testGetModelWithResourceInheritance.

@Test
public void testGetModelWithResourceInheritance() {
    // in case no super type is known, just return model
    applicablePathPerResourceType.put("test/type", "/content/site1");
    ValidationModel model = validationModelRetriever.getValidationModel("test/type", "/content/site1", true);
    Assert.assertNotNull(model);
    Assert.assertThat(model.getResourceProperties(), Matchers.contains(new ResourcePropertyNameMatcher("test/type")));
    // in case there is one super type make sure the merged model is returned!
    Mockito.when(resourceResolver.getParentResourceType("test/type")).thenReturn("test/supertype");
    applicablePathPerResourceType.put("test/supertype", "/content/site1");
    model = validationModelRetriever.getValidationModel("test/type", "/content/site1", true);
    Assert.assertNotNull(model);
    Assert.assertThat(model.getResourceProperties(), Matchers.<ResourceProperty>containsInAnyOrder(Arrays.asList(new ResourcePropertyNameMatcher("test/type"), new ResourcePropertyNameMatcher("test/supertype"))));
}
Also used : ValidationModel(org.apache.sling.validation.model.ValidationModel) ResourcePropertyNameMatcher(org.apache.sling.validation.impl.util.ResourcePropertyNameMatcher) Test(org.junit.Test)

Example 2 with ResourcePropertyNameMatcher

use of org.apache.sling.validation.impl.util.ResourcePropertyNameMatcher in project sling by apache.

the class ValidationModelRetrieverImplTest method testGetModelWithResourceInheritanceAndNoSuitableBaseModelFound.

@Test
public void testGetModelWithResourceInheritanceAndNoSuitableBaseModelFound() {
    // no model found for base type and no resource super type set
    ValidationModel model = validationModelRetriever.getValidationModel("test/type", "/content/site1", true);
    Assert.assertNull("Found model although no model has been specified", model);
    // set super super type
    Mockito.when(resourceResolver.getParentResourceType("test/type")).thenReturn("test/supertype");
    // no model found at all (neither base nor super type)
    model = validationModelRetriever.getValidationModel("test/type", "/content/site1", true);
    Assert.assertNull("Found model although no model has been specified (neither in base nor in super type)", model);
    // only supertype has model being set
    applicablePathPerResourceType.put("test/supertype", "/content/site1");
    model = validationModelRetriever.getValidationModel("test/type", "/content/site1", true);
    Assert.assertNotNull(model);
    Assert.assertThat(model.getResourceProperties(), Matchers.contains(new ResourcePropertyNameMatcher("test/supertype")));
}
Also used : ValidationModel(org.apache.sling.validation.model.ValidationModel) ResourcePropertyNameMatcher(org.apache.sling.validation.impl.util.ResourcePropertyNameMatcher) Test(org.junit.Test)

Example 3 with ResourcePropertyNameMatcher

use of org.apache.sling.validation.impl.util.ResourcePropertyNameMatcher in project sling by apache.

the class ValidationModelRetrieverImplTest method testGetModelWithResourceInheritanceAndNoModelForSuperTypeFound.

@Test
public void testGetModelWithResourceInheritanceAndNoModelForSuperTypeFound() {
    applicablePathPerResourceType.put("test/type", "/content/site1");
    Mockito.when(resourceResolver.getParentResourceType("test/type")).thenReturn("test/supertype");
    Mockito.when(resourceResolver.getParentResourceType("test/supertype")).thenReturn("test/supersupertype");
    // only model found for base type
    ValidationModel model = validationModelRetriever.getValidationModel("test/type", "/content/site1", true);
    Assert.assertNotNull(model);
    Assert.assertThat(model.getResourceProperties(), Matchers.contains(new ResourcePropertyNameMatcher("test/type")));
}
Also used : ValidationModel(org.apache.sling.validation.model.ValidationModel) ResourcePropertyNameMatcher(org.apache.sling.validation.impl.util.ResourcePropertyNameMatcher) Test(org.junit.Test)

Aggregations

ResourcePropertyNameMatcher (org.apache.sling.validation.impl.util.ResourcePropertyNameMatcher)3 ValidationModel (org.apache.sling.validation.model.ValidationModel)3 Test (org.junit.Test)3