sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sseif...@apache.org
Subject svn commit: r1710961 - /sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/ResourceResolverImplTest.java
Date Wed, 28 Oct 2015 08:25:38 GMT
Author: sseifert
Date: Wed Oct 28 08:25:38 2015
New Revision: 1710961

URL: http://svn.apache.org/viewvc?rev=1710961&view=rev
Log:
SLING-5207 add another unit test to test with typical resource type hierarchy

Modified:
    sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/ResourceResolverImplTest.java

Modified: sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/ResourceResolverImplTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/ResourceResolverImplTest.java?rev=1710961&r1=1710960&r2=1710961&view=diff
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/ResourceResolverImplTest.java
(original)
+++ sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/ResourceResolverImplTest.java
Wed Oct 28 08:25:38 2015
@@ -489,11 +489,8 @@ public class ResourceResolverImplTest {
         }
     }
 
-    @Test public void test_getResourceSuperType() throws LoginException {
-        // the resource resolver
-        final List<ResourceResolver> resolvers = new ArrayList<ResourceResolver>();
-        final PathBasedResourceResolverImpl resolver = new PathBasedResourceResolverImpl(resolvers,
resourceProviderTracker);
-        resolvers.add(resolver);
+    @Test public void test_getResourceSuperType() {
+        final PathBasedResourceResolverImpl resolver = getPathBasedResourceResolver();
 
         // the resources to test
         final Resource r = resolver.add(new SyntheticResource(resolver, "/a", "a:b"));
@@ -504,10 +501,8 @@ public class ResourceResolverImplTest {
         assertNull(resolver.getParentResourceType(r2.getResourceType()));
     }
 
-    @Test public void test_isA() throws LoginException {
-        final List<ResourceResolver> resolvers = new ArrayList<ResourceResolver>();
-        final PathBasedResourceResolverImpl resolver = new PathBasedResourceResolverImpl(resolvers,
resourceProviderTracker);
-        resolvers.add(resolver);
+    @Test public void testIsResourceType() {
+        final PathBasedResourceResolverImpl resolver = getPathBasedResourceResolver();
         
         final Resource r = resolver.add(new SyntheticResourceWithSupertype(resolver, "/a",
"a:b", "d:e"));
         resolver.add(new SyntheticResourceWithSupertype(resolver, "/d/e", "x:y", "t:c"));
@@ -519,6 +514,54 @@ public class ResourceResolverImplTest {
         assertFalse(resolver.isResourceType(r, "h:p"));
     }
 
+    @Test public void testIsResourceTypeWithPaths() {
+        final PathBasedResourceResolverImpl resolver = getPathBasedResourceResolver();
+        
+        /**
+         * prepare resource type hierarchy
+         * /types/1
+         *  +- /types/2
+         *    +- /types/3
+         */
+        resolver.add(new SyntheticResourceWithSupertype(resolver, "/types/1", "/types/component",
"/types/2"));
+        resolver.add(new SyntheticResourceWithSupertype(resolver, "/types/2", "/types/component",
"/types/3"));
+        resolver.add(new SyntheticResource(resolver, "/types/3", "/types/component"));
+
+        Resource resourceT1 = resolver.add(new SyntheticResource(resolver, "/resourceT1",
"/types/1"));
+        Resource resourceT2 = resolver.add(new SyntheticResource(resolver, "/resourceT2",
"/types/2"));
+        Resource resourceT3 = resolver.add(new SyntheticResource(resolver, "/resourceT3",
"/types/3"));
+
+        assertTrue(resolver.isResourceType(resourceT1, "/types/1"));
+        assertTrue(resolver.isResourceType(resourceT1, "/types/2"));
+        assertTrue(resolver.isResourceType(resourceT1, "/types/3"));
+        assertFalse(resolver.isResourceType(resourceT1, "/types/component"));
+        assertFalse(resolver.isResourceType(resourceT1, "/types/unknown"));
+
+        assertFalse(resolver.isResourceType(resourceT2, "/types/1"));
+        assertTrue(resolver.isResourceType(resourceT2, "/types/2"));
+        assertTrue(resolver.isResourceType(resourceT2, "/types/3"));
+        assertFalse(resolver.isResourceType(resourceT2, "/types/component"));
+        assertFalse(resolver.isResourceType(resourceT2, "/types/unknown"));
+
+        assertFalse(resolver.isResourceType(resourceT3, "/types/1"));
+        assertFalse(resolver.isResourceType(resourceT3, "/types/2"));
+        assertTrue(resolver.isResourceType(resourceT3, "/types/3"));
+        assertFalse(resolver.isResourceType(resourceT3, "/types/component"));
+        assertFalse(resolver.isResourceType(resourceT3, "/types/unknown"));
+    }
+
+    private PathBasedResourceResolverImpl getPathBasedResourceResolver() {
+        try {
+            final List<ResourceResolver> resolvers = new ArrayList<ResourceResolver>();
+            final PathBasedResourceResolverImpl resolver = new PathBasedResourceResolverImpl(resolvers,
resourceProviderTracker);
+            resolvers.add(resolver);
+            return resolver;
+        }
+        catch (LoginException ex) {
+            throw new RuntimeException(ex);
+        }
+    }
+
     private static class PathBasedResourceResolverImpl extends ResourceResolverImpl {
 
         private final Map<String, Resource> resources = new HashMap<String, Resource>();



Mime
View raw message