incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1346358 - /sling/whiteboard/SLING-2396/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/helper/SortedProviderListTest.java
Date Tue, 05 Jun 2012 11:43:59 GMT
Author: cziegeler
Date: Tue Jun  5 11:43:58 2012
New Revision: 1346358

URL: http://svn.apache.org/viewvc?rev=1346358&view=rev
Log:
SLING-2396 : Add new resource provider interfaces (WiP)

Modified:
    sling/whiteboard/SLING-2396/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/helper/SortedProviderListTest.java

Modified: sling/whiteboard/SLING-2396/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/helper/SortedProviderListTest.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/SLING-2396/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/helper/SortedProviderListTest.java?rev=1346358&r1=1346357&r2=1346358&view=diff
==============================================================================
--- sling/whiteboard/SLING-2396/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/helper/SortedProviderListTest.java
(original)
+++ sling/whiteboard/SLING-2396/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/helper/SortedProviderListTest.java
Tue Jun  5 11:43:58 2012
@@ -27,16 +27,19 @@ import java.util.Map;
 import javax.servlet.http.HttpServletRequest;
 
 import org.apache.sling.api.adapter.Adaptable;
+import org.apache.sling.api.resource.LoginException;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceProvider;
+import org.apache.sling.api.resource.ResourceProviderFactory;
 import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.resourceresolver.impl.tree.ResourceProviderFactoryHandler;
 import org.apache.sling.resourceresolver.impl.tree.ResourceProviderHandler;
 import org.junit.Test;
 import org.osgi.framework.Constants;
 
 public class SortedProviderListTest {
 
-    @Test public void addTestRemoveResourceProvider() {
+    @Test public void testAddRemoveResourceProvider() {
         final ResourceProviderImpl rp1 = new ResourceProviderImpl(null, 1L);
         final AdaptableResourceProviderImpl rp2 = new AdaptableResourceProviderImpl(null,
2L);
         final AdaptableResourceProviderImpl rp3 = new AdaptableResourceProviderImpl(new String[]
{"/hello"}, 3L);
@@ -65,7 +68,7 @@ public class SortedProviderListTest {
         check(spl, null);
     }
 
-    @Test public void testSorting() {
+    @Test public void testSortingRP() {
         final AdaptableResourceProviderImpl rp1 = new AdaptableResourceProviderImpl(new String[]
{"/d", "/a", "x"}, 1L);
         final AdaptableResourceProviderImpl rp2 = new AdaptableResourceProviderImpl(null,
2L);
         final AdaptableResourceProviderImpl rp3 = new AdaptableResourceProviderImpl(new String[]
{"/b"}, 3L);
@@ -86,11 +89,68 @@ public class SortedProviderListTest {
         check(spl, null, rp2, rp1, rp4, rp5, rp3);
     }
 
+    @Test public void testAddRemoveResourceProviderFactory() {
+        final ResourceProviderImpl rp1 = new ResourceProviderImpl(null, 1L);
+        final AdaptableResourceProviderImpl rp2 = new AdaptableResourceProviderImpl(null,
2L);
+        final AdaptableResourceProviderImpl rp3 = new AdaptableResourceProviderImpl(new String[]
{"/hello"}, 3L);
+        final ResourceProviderImpl rp4 = new ResourceProviderImpl(new String[] {"/you"},
4L);
+
+        final ResourceResolverContext ctx = new ResourceResolverContext(false, null);
+
+        final SortedProviderList<Adaptable> spl = new SortedProviderList<Adaptable>(Adaptable.class);
+        check(spl, ctx);
+        spl.add(new ResourceProviderFactoryHandler(new ResourceProviderFactoryImpl(rp1),
rp1.getProperties()));
+        check(spl, ctx);
+        spl.add(new ResourceProviderFactoryHandler(new ResourceProviderFactoryImpl(rp2),
rp2.getProperties()));
+        check(spl, ctx, rp2);
+        spl.add(new ResourceProviderFactoryHandler(new ResourceProviderFactoryImpl(rp3),
rp3.getProperties()));
+        check(spl, ctx, rp2, rp3);
+        spl.add(new ResourceProviderFactoryHandler(new ResourceProviderFactoryImpl(rp4),
rp4.getProperties()));
+        check(spl, ctx, rp2, rp3);
+
+        spl.remove(new ResourceProviderFactoryHandler(new ResourceProviderFactoryImpl(rp1),
rp1.getProperties()));
+        check(spl, ctx, rp2, rp3);
+        spl.remove(new ResourceProviderFactoryHandler(new ResourceProviderFactoryImpl(rp1),
rp1.getProperties()));
+        check(spl, ctx, rp2, rp3);
+        spl.remove(new ResourceProviderFactoryHandler(new ResourceProviderFactoryImpl(rp4),
rp4.getProperties()));
+        check(spl, ctx, rp2, rp3);
+        spl.remove(new ResourceProviderFactoryHandler(new ResourceProviderFactoryImpl(rp2),
rp2.getProperties()));
+        check(spl, ctx, rp3);
+        spl.remove(new ResourceProviderFactoryHandler(new ResourceProviderFactoryImpl(rp3),
rp3.getProperties()));
+        check(spl, ctx);
+    }
+
+    @Test public void testSortingRF() {
+        final AdaptableResourceProviderImpl rp1 = new AdaptableResourceProviderImpl(new String[]
{"/d", "/a", "x"}, 1L);
+        final AdaptableResourceProviderImpl rp2 = new AdaptableResourceProviderImpl(null,
2L);
+        final AdaptableResourceProviderImpl rp3 = new AdaptableResourceProviderImpl(new String[]
{"/b"}, 3L);
+        final AdaptableResourceProviderImpl rp4 = new AdaptableResourceProviderImpl(new String[]
{"/a/a"}, 4L);
+        final AdaptableResourceProviderImpl rp5 = new AdaptableResourceProviderImpl(new String[]
{"/all/or/nothing"}, 5L);
+
+        final ResourceResolverContext ctx = new ResourceResolverContext(false, null);
+
+        final SortedProviderList<Adaptable> spl = new SortedProviderList<Adaptable>(Adaptable.class);
+        check(spl, ctx);
+        spl.add(new ResourceProviderFactoryHandler(new ResourceProviderFactoryImpl(rp1),
rp1.getProperties()));
+        check(spl, ctx, rp1);
+        spl.add(new ResourceProviderFactoryHandler(new ResourceProviderFactoryImpl(rp2),
rp2.getProperties()));
+        check(spl, ctx, rp2, rp1);
+        spl.add(new ResourceProviderFactoryHandler(new ResourceProviderFactoryImpl(rp3),
rp3.getProperties()));
+        check(spl, ctx, rp2, rp1, rp3);
+        spl.add(new ResourceProviderFactoryHandler(new ResourceProviderFactoryImpl(rp4),
rp4.getProperties()));
+        check(spl, ctx, rp2, rp1, rp4, rp3);
+        spl.add(new ResourceProviderFactoryHandler(new ResourceProviderFactoryImpl(rp5),
rp5.getProperties()));
+        check(spl, ctx, rp2, rp1, rp4, rp5, rp3);
+    }
+
+    /**
+     * Helper method checking the order of the sorted array.
+     */
     private void check(final SortedProviderList<Adaptable> spl,
                     final ResourceResolverContext ctx,
                     final Adaptable... objects) {
         final int expectedCount = objects == null ? 0 : objects.length;
-        final Iterator<Adaptable> i = spl.getProviders(null);
+        final Iterator<Adaptable> i = spl.getProviders(ctx);
         int count = 0;
         while ( i.hasNext() ) {
             final Adaptable a = i.next();
@@ -116,21 +176,26 @@ public class SortedProviderListTest {
             props.put(ResourceProvider.ROOTS, roots);
             return props;
         }
+
         public Resource getResource(ResourceResolver resourceResolver, HttpServletRequest
request, String path) {
-            // TODO Auto-generated method stub
             return null;
         }
 
         public Resource getResource(ResourceResolver resourceResolver, String path) {
-            // TODO Auto-generated method stub
             return null;
         }
 
         public Iterator<Resource> listChildren(Resource parent) {
-            // TODO Auto-generated method stub
             return null;
         }
 
+        @Override
+        public boolean equals(Object obj) {
+            if ( obj instanceof ResourceProviderImpl ) {
+                return this.serviceId.equals(((ResourceProviderImpl)obj).serviceId);
+            }
+            return false;
+        }
     }
 
     private static class AdaptableResourceProviderImpl extends ResourceProviderImpl
@@ -141,9 +206,32 @@ public class SortedProviderListTest {
         }
 
         public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
-            // TODO Auto-generated method stub
             return null;
         }
+    }
+
+    private static class ResourceProviderFactoryImpl implements ResourceProviderFactory {
+
+        private final ResourceProviderImpl resourceProviderImpl;
 
+        public ResourceProviderFactoryImpl(ResourceProviderImpl rpi) {
+            this.resourceProviderImpl = rpi;
+        }
+
+        public ResourceProvider getResourceProvider(Map<String, Object> authenticationInfo)
throws LoginException {
+            return this.resourceProviderImpl;
+        }
+
+        public ResourceProvider getAdministrativeResourceProvider(Map<String, Object>
authenticationInfo) throws LoginException {
+            return this.resourceProviderImpl;
+        }
+
+        @Override
+        public boolean equals(Object obj) {
+            if ( obj instanceof ResourceProviderFactoryImpl ) {
+                return this.resourceProviderImpl.equals(((ResourceProviderFactoryImpl)obj).resourceProviderImpl);
+            }
+            return false;
+        }
     }
 }



Mime
View raw message