Search in sources :

Example 6 with MockResource

use of org.apache.sling.testing.resourceresolver.MockResource in project sling by apache.

the class MergedResourceTest method testResourceTypeMixed.

@Test
public void testResourceTypeMixed() throws Exception {
    final ValueMap vm1 = new ValueMapDecorator(Collections.singletonMap(ResourceResolver.PROPERTY_RESOURCE_TYPE, (Object) "vma"));
    final MockResource r1 = new MockResource("/a", vm1, null) {

        @Override
        public String getResourceType() {
            return "a";
        }
    };
    final ValueMap vm2 = new ValueMapDecorator(Collections.singletonMap(ResourceResolver.PROPERTY_RESOURCE_TYPE, (Object) "vmb"));
    final MockResource r2 = new MockResource("/b", vm2, null) {

        @Override
        public String getResourceType() {
            return "b";
        }
    };
    final ValueMap vm3 = new ValueMapDecorator(Collections.singletonMap(ResourceResolver.PROPERTY_RESOURCE_TYPE, (Object) "vmc"));
    final MockResource r3 = new MockResource("/c", vm3, null) {

        @Override
        public String getResourceType() {
            return "c";
        }
    };
    final List<Resource> resources = new ArrayList<Resource>();
    resources.add(r1);
    resources.add(r2);
    resources.add(r3);
    final List<ValueMap> valueMaps = new ArrayList<ValueMap>();
    valueMaps.add(vm1);
    valueMaps.add(vm2);
    valueMaps.add(vm3);
    final MergedResource mr1 = new MergedResource(null, "/a", "a", resources, valueMaps);
    assertEquals("c", mr1.getResourceType());
    assertEquals("vmc", mr1.getResourceSuperType());
    final MergedResource mr2 = new MergedResource(null, "/a", "a", resources, Collections.singletonList(vm2));
    assertEquals("c", mr2.getResourceType());
    assertEquals("vmb", mr2.getResourceSuperType());
}
Also used : ValueMap(org.apache.sling.api.resource.ValueMap) MockResource(org.apache.sling.testing.resourceresolver.MockResource) ValueMapDecorator(org.apache.sling.api.wrappers.ValueMapDecorator) ArrayList(java.util.ArrayList) Resource(org.apache.sling.api.resource.Resource) MockResource(org.apache.sling.testing.resourceresolver.MockResource) Test(org.junit.Test)

Example 7 with MockResource

use of org.apache.sling.testing.resourceresolver.MockResource in project sling by apache.

the class MergedResourceTest method testToString.

@Test
public void testToString() throws Exception {
    final ValueMap vm = new ValueMapDecorator(Collections.singletonMap(ResourceResolver.PROPERTY_RESOURCE_TYPE, (Object) "vm"));
    final Resource r = new MockResource("/innerResourcePath", vm, null) {

        @Override
        public String getResourceType() {
            return "innerResource";
        }
    };
    final Resource mr = new MergedResource(null, "/merged", "merged", Collections.singletonList(r), Collections.singletonList(vm));
    assertTrue(mr.toString().contains("/innerResourcePath"));
}
Also used : ValueMap(org.apache.sling.api.resource.ValueMap) MockResource(org.apache.sling.testing.resourceresolver.MockResource) ValueMapDecorator(org.apache.sling.api.wrappers.ValueMapDecorator) Resource(org.apache.sling.api.resource.Resource) MockResource(org.apache.sling.testing.resourceresolver.MockResource) Test(org.junit.Test)

Aggregations

Resource (org.apache.sling.api.resource.Resource)7 MockResource (org.apache.sling.testing.resourceresolver.MockResource)7 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)3 JsonObject (javax.json.JsonObject)3 ValueMap (org.apache.sling.api.resource.ValueMap)3 ValueMapDecorator (org.apache.sling.api.wrappers.ValueMapDecorator)3 HashMap (java.util.HashMap)2 JsonArray (javax.json.JsonArray)1