Search in sources :

Example 61 with ValueMapDecorator

use of org.apache.sling.api.wrappers.ValueMapDecorator 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 62 with ValueMapDecorator

use of org.apache.sling.api.wrappers.ValueMapDecorator 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)

Example 63 with ValueMapDecorator

use of org.apache.sling.api.wrappers.ValueMapDecorator in project sling by apache.

the class TenantImpl method loadProperties.

void loadProperties(Resource resource) {
    ValueMap jcrVM = ResourceUtil.getValueMap(resource);
    Map<String, Object> localMap = new HashMap<String, Object>();
    // copy all items to local map
    localMap.putAll(jcrVM);
    // decoarate it as value map
    ValueMapDecorator localVM = new ValueMapDecorator(localMap);
    this.vm = localVM;
}
Also used : HashMap(java.util.HashMap) ValueMap(org.apache.sling.api.resource.ValueMap) ValueMapDecorator(org.apache.sling.api.wrappers.ValueMapDecorator)

Aggregations

ValueMapDecorator (org.apache.sling.api.wrappers.ValueMapDecorator)63 Test (org.junit.Test)45 ValueMap (org.apache.sling.api.resource.ValueMap)44 HashMap (java.util.HashMap)36 Resource (org.apache.sling.api.resource.Resource)36 ValidationModel (org.apache.sling.validation.model.ValidationModel)9 ValidationResult (org.apache.sling.validation.ValidationResult)8 DefaultValidationResult (org.apache.sling.validation.spi.support.DefaultValidationResult)6 ArrayList (java.util.ArrayList)3 RepositoryException (javax.jcr.RepositoryException)3 ModifiableValueMap (org.apache.sling.api.resource.ModifiableValueMap)3 ResourceModelWithRequiredField (org.apache.sling.models.testmodels.classes.ResourceModelWithRequiredField)3 MockResource (org.apache.sling.testing.resourceresolver.MockResource)3 DefaultValidationFailure (org.apache.sling.validation.spi.support.DefaultValidationFailure)3 Calendar (java.util.Calendar)2 Collection (java.util.Collection)2 Date (java.util.Date)2 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 LinkedHashMap (java.util.LinkedHashMap)2