incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1346349 - in /sling/whiteboard/SLING-2396/resourceresolver/src: main/java/org/apache/sling/resourceresolver/impl/helper/ main/java/org/apache/sling/resourceresolver/impl/tree/ test/java/org/apache/sling/resourceresolver/impl/helper/
Date Tue, 05 Jun 2012 11:25:12 GMT
Author: cziegeler
Date: Tue Jun  5 11:25:11 2012
New Revision: 1346349

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

Added:
    sling/whiteboard/SLING-2396/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/helper/SortedProviderListTest.java
  (with props)
Modified:
    sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/SortedProviderList.java
    sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/tree/ProviderHandler.java
    sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/tree/ResourceProviderHandler.java
    sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/tree/RootResourceProviderEntry.java
    sling/whiteboard/SLING-2396/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/helper/MapEntryTest.java
    sling/whiteboard/SLING-2396/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/helper/RedirectResourceTest.java
    sling/whiteboard/SLING-2396/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/helper/ResourcePathIteratorTest.java
    sling/whiteboard/SLING-2396/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/helper/ResourceProviderEntryTest.java
    sling/whiteboard/SLING-2396/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/helper/StarResourceTest.java

Modified: sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/SortedProviderList.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/SortedProviderList.java?rev=1346349&r1=1346348&r2=1346349&view=diff
==============================================================================
--- sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/SortedProviderList.java
(original)
+++ sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/SortedProviderList.java
Tue Jun  5 11:25:11 2012
@@ -18,13 +18,15 @@
  */
 package org.apache.sling.resourceresolver.impl.helper;
 
+import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.Iterator;
-import java.util.LinkedList;
 import java.util.List;
 import java.util.NoSuchElementException;
 
 import org.apache.sling.resourceresolver.impl.tree.ResourceProviderFactoryHandler;
+import org.apache.sling.resourceresolver.impl.tree.ResourceProviderHandler;
 
 /**
  * Helper class to get a sorted list of resource providers which implement
@@ -37,7 +39,7 @@ public class SortedProviderList<T> {
     private final Class<T> genericClass;
 
     /** Sorted list of providers and factories. */
-    private Object[] sortedList = new Object[0];
+    private Entry[] sortedList = new Entry[0];
 
     /**
      * We need the class to do the instanceof test for providers
@@ -54,7 +56,7 @@ public class SortedProviderList<T> {
     public Iterator<T> getProviders(final ResourceResolverContext ctx) {
         return new Iterator<T>() {
 
-            private final Object[] list = sortedList;
+            private final Entry[] list = sortedList;
 
             private int index = 0;
 
@@ -63,7 +65,7 @@ public class SortedProviderList<T> {
             private Object seek() {
                 Object result;
                 if ( this.index < list.length ) {
-                    result = list[this.index];
+                    result = list[this.index].object;
                     this.index++;
                     if ( result instanceof ResourceProviderFactoryHandler ) {
                         result = ((ResourceProviderFactoryHandler)result).getResourceProvider(ctx);
@@ -112,28 +114,41 @@ public class SortedProviderList<T> {
     /**
      * Add an object to the list
      */
-    private synchronized void addToList(final Object obj) {
-        final List<Object> list = new LinkedList<Object>();
+    private synchronized void addToList(final Object obj,
+                    final String[] roots,
+                    final Long serviceId) {
+        final List<Entry> list = new ArrayList<Entry>();
         list.addAll(Arrays.asList(this.sortedList));
-        list.add(obj);
-        this.sortedList = list.toArray(new Object[list.size()]);
+        list.add(new Entry(obj, roots, serviceId));
+        Collections.sort(list);
+        this.sortedList = list.toArray(new Entry[list.size()]);
     }
 
     /**
      * Remove an object from the list
      */
     private synchronized void removeFromList(final Object obj) {
-        final List<Object> list = new LinkedList<Object>();
+        final List<Entry> list = new ArrayList<Entry>();
         list.addAll(Arrays.asList(this.sortedList));
-        list.remove(obj);
-        this.sortedList = list.toArray(new Object[list.size()]);
+        final Iterator<Entry> i = list.iterator();
+        while ( i.hasNext() ) {
+            final Entry entry = i.next();
+            if ( entry.object.equals(obj) ) {
+                i.remove();
+                break;
+            }
+        }
+        this.sortedList = list.toArray(new Entry[list.size()]);
     }
 
     /**
-     * Add a resource provider implementing the feature interface.
+     * Add a resource provider
+     * This first checks if it implements the feature interface.
      */
-    public void add(final T provider) {
-        this.addToList(provider);
+    public void add(final ResourceProviderHandler rpHandler) {
+        if ( genericClass.isAssignableFrom(rpHandler.getResourceProvider().getClass())) {
+            this.addToList(rpHandler.getResourceProvider(), rpHandler.getRoots(), rpHandler.getServiceId());
+        }
     }
 
     /**
@@ -142,14 +157,16 @@ public class SortedProviderList<T> {
      * This will be checked on demand.
      */
     public void add(final ResourceProviderFactoryHandler factory) {
-        this.addToList(factory);
+        this.addToList(factory, factory.getRoots(), factory.getServiceId());
     }
 
     /**
-     * Remove a resource provider implementing the feature interface.
+     * Remove a resource provider.
      */
-    public void remove(final T provider) {
-        this.removeFromList(provider);
+    public void remove(final ResourceProviderHandler rpHandler) {
+        if ( genericClass.isAssignableFrom(rpHandler.getResourceProvider().getClass())) {
+            this.removeFromList(rpHandler.getResourceProvider());
+        }
     }
 
     /**
@@ -158,4 +175,34 @@ public class SortedProviderList<T> {
     public void remove(final ResourceProviderFactoryHandler factory) {
         this.removeFromList(factory);
     }
+
+    private static final class Entry implements Comparable<Entry> {
+
+        private final String path;
+        private final Long   id;
+
+        public final Object object;
+
+        public Entry(final Object object, final String[] roots, final Long serviceId) {
+            this.id = serviceId;
+            this.object = object;
+            if ( roots != null ) {
+                this.path = roots[0];
+            } else {
+                this.path = "";
+            }
+        }
+
+        /**
+         * @see java.lang.Comparable#compareTo(java.lang.Object)
+         */
+        public int compareTo(final Entry other) {
+            int result = this.path.compareTo(other.path);
+            if ( result == 0 ) {
+                result = this.id.compareTo(other.id);
+            }
+            return result;
+        }
+
+    }
 }

Modified: sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/tree/ProviderHandler.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/tree/ProviderHandler.java?rev=1346349&r1=1346348&r2=1346349&view=diff
==============================================================================
--- sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/tree/ProviderHandler.java
(original)
+++ sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/tree/ProviderHandler.java
Tue Jun  5 11:25:11 2012
@@ -17,12 +17,16 @@
  */
 package org.apache.sling.resourceresolver.impl.tree;
 
+import java.util.ArrayList;
+import java.util.Collections;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceProvider;
 import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.commons.osgi.PropertiesUtil;
 import org.apache.sling.resourceresolver.impl.helper.ResourceResolverContext;
 import org.osgi.framework.Constants;
 
@@ -39,12 +43,38 @@ public abstract class ProviderHandler im
     /** Unique service id */
     private final Long serviceId;
 
+    /** Configured roots. */
+    private final String[] roots;
+
     /**
-     *
+     * Create a new handler
      */
     public ProviderHandler(final Map<String, Object> properties) {
         this.properties = properties;
         this.serviceId = (Long) properties.get(Constants.SERVICE_ID);
+        // calculate roots
+        final List<String> configuredRoots = new ArrayList<String>();
+        final String[] paths = PropertiesUtil.toStringArray(properties.get(ResourceProvider.ROOTS));
+        if ( paths != null) {
+            for(final String r : paths) {
+                if (r != null) {
+                    String path = r.trim();
+                    // cut off trailing slash
+                    if (path.endsWith("/") && path.length() > 1) {
+                        path = path.substring(0, path.length() - 1);
+                    }
+                    if ( path.length() > 0 && !configuredRoots.contains(path))
{
+                        configuredRoots.add(path);
+                    }
+                }
+            }
+        }
+        if ( configuredRoots.size() == 0 ) {
+            this.roots = null;
+        } else {
+            Collections.sort(configuredRoots);
+            this.roots = configuredRoots.toArray(new String[configuredRoots.size()]);
+        }
     }
 
     /**
@@ -62,6 +92,15 @@ public abstract class ProviderHandler im
     }
 
     /**
+     * Return a sorted array of roots for this provider. If no roots are configured,
+     * this will return <code>null</code>
+     * @return The array of roots or <code>null</code>
+     */
+    public String[] getRoots() {
+        return this.roots;
+    }
+
+    /**
      * @see java.lang.Comparable#compareTo(java.lang.Object)
      */
     public int compareTo(final ProviderHandler other) {

Modified: sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/tree/ResourceProviderHandler.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/tree/ResourceProviderHandler.java?rev=1346349&r1=1346348&r2=1346349&view=diff
==============================================================================
--- sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/tree/ResourceProviderHandler.java
(original)
+++ sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/tree/ResourceProviderHandler.java
Tue Jun  5 11:25:11 2012
@@ -58,6 +58,13 @@ public class ResourceProviderHandler ext
     }
 
     /**
+     * Return the resource provider.
+     */
+    public ResourceProvider getResourceProvider() {
+        return this.resourceProvider;
+    }
+
+    /**
      * {@inheritDoc}
      * @see java.lang.Object#hashCode()
      */

Modified: sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/tree/RootResourceProviderEntry.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/tree/RootResourceProviderEntry.java?rev=1346349&r1=1346348&r2=1346349&view=diff
==============================================================================
--- sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/tree/RootResourceProviderEntry.java
(original)
+++ sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/tree/RootResourceProviderEntry.java
Tue Jun  5 11:25:11 2012
@@ -284,51 +284,43 @@ public class RootResourceProviderEntry e
      * Bind a resource provider.
      */
     public void bindResourceProvider(final ResourceProvider provider, final Map<String,
Object> props) {
-        this.bindWrapper(new ResourceProviderHandler(provider, props));
-        if ( provider instanceof Adaptable ) {
-            this.adaptableProviders.add((Adaptable)provider);
-        }
-        if ( provider instanceof QueriableResourceProvider ) {
-            this.queriableProviders.add((QueriableResourceProvider)provider);
-        }
-        if ( provider instanceof AttributableResourceProvider ) {
-            this.attributableProviders.add((AttributableResourceProvider)provider);
-        }
+        final ResourceProviderHandler handler = new ResourceProviderHandler(provider, props);
+
+        this.bindHandler(handler);
+        this.adaptableProviders.add(handler);
+        this.queriableProviders.add(handler);
+        this.attributableProviders.add(handler);
     }
 
     /**
      * Unbind a resource provider.
      */
     public void unbindResourceProvider(final ResourceProvider provider, final Map<String,
Object> props) {
-        this.unbindWrapper(new ResourceProviderHandler(provider, props));
-        if ( provider instanceof Adaptable ) {
-            this.adaptableProviders.remove((Adaptable)provider);
-        }
-        if ( provider instanceof QueriableResourceProvider ) {
-            this.queriableProviders.remove((QueriableResourceProvider)provider);
-        }
-        if ( provider instanceof AttributableResourceProvider ) {
-            this.attributableProviders.remove((AttributableResourceProvider)provider);
-        }
+        final ResourceProviderHandler handler = new ResourceProviderHandler(provider, props);
+
+        this.unbindHandler(handler);
+        this.adaptableProviders.remove(handler);
+        this.queriableProviders.remove(handler);
+        this.attributableProviders.remove(handler);
     }
 
     /**
      * Bind a resource provider factory.
      */
     public void bindResourceProviderFactory(final ResourceProviderFactory factory, final
Map<String, Object> props) {
-        final ResourceProviderFactoryHandler wrapper = new ResourceProviderFactoryHandler(factory,
props);
+        final ResourceProviderFactoryHandler handler = new ResourceProviderFactoryHandler(factory,
props);
 
-        this.bindWrapper(wrapper);
-        this.adaptableProviders.add(wrapper);
-        this.queriableProviders.add(wrapper);
-        this.attributableProviders.add(wrapper);
+        this.bindHandler(handler);
+        this.adaptableProviders.add(handler);
+        this.queriableProviders.add(handler);
+        this.attributableProviders.add(handler);
 
         final boolean required = PropertiesUtil.toBoolean(props.get(ResourceProviderFactory.PROPERTY_REQUIRED),
false);
         if (required) {
             synchronized (this) {
                 final List<ResourceProviderFactoryHandler> factories = new LinkedList<ResourceProviderFactoryHandler>();
                 factories.addAll(Arrays.asList(this.requiredFactories));
-                factories.add(wrapper);
+                factories.add(handler);
                 this.requiredFactories = factories.toArray(new ResourceProviderFactoryHandler[factories.size()]);
             }
         }
@@ -338,19 +330,19 @@ public class RootResourceProviderEntry e
      * Unbind a resource provider factory
      */
     public void unbindResourceProviderFactory(final ResourceProviderFactory factory, final
Map<String, Object> props) {
-        final ResourceProviderFactoryHandler wrapper = new ResourceProviderFactoryHandler(factory,
props);
+        final ResourceProviderFactoryHandler handler = new ResourceProviderFactoryHandler(factory,
props);
 
-        this.unbindWrapper(new ResourceProviderHandler(null, props));
-        this.adaptableProviders.remove(wrapper);
-        this.queriableProviders.remove(wrapper);
-        this.attributableProviders.remove(wrapper);
+        this.unbindHandler(handler);
+        this.adaptableProviders.remove(handler);
+        this.queriableProviders.remove(handler);
+        this.attributableProviders.remove(handler);
 
         final boolean required = PropertiesUtil.toBoolean(props.get(ResourceProviderFactory.PROPERTY_REQUIRED),
false);
         if (required) {
             synchronized (this) {
                 final List<ResourceProviderFactoryHandler> factories = new LinkedList<ResourceProviderFactoryHandler>();
                 factories.addAll(Arrays.asList(this.requiredFactories));
-                factories.remove(wrapper);
+                factories.remove(handler);
                 this.requiredFactories = factories.toArray(new ResourceProviderFactoryHandler[factories.size()]);
             }
         }
@@ -359,32 +351,26 @@ public class RootResourceProviderEntry e
     /**
      * Bind a resource provider wrapper
      */
-    private void bindWrapper(final ProviderHandler provider) {
+    private void bindHandler(final ProviderHandler provider) {
         // this is just used for debug logging
         final String debugServiceName = getDebugServiceName(provider);
 
         logger.debug("bindResourceProvider: Binding {}", debugServiceName);
 
-        final String[] roots = PropertiesUtil.toStringArray(provider.getProperties().get(ResourceProvider.ROOTS));
+        final String[] roots = provider.getRoots();
         boolean foundRoot = false;
-        if (roots != null && roots.length > 0) {
+        if (roots != null) {
             final EventAdmin localEA = this.eventAdmin;
-            for (String root : roots) {
-                if (root != null && root.length() > 0) {
-                    foundRoot = true;
-                    // cut off trailing slash
-                    if (root.endsWith("/") && root.length() > 1) {
-                        root = root.substring(0, root.length() - 1);
-                    }
-
-                    this.addResourceProvider(root, provider);
-
-                    logger.debug("bindResourceProvider: {}={} ({})", new Object[] { root,
provider, debugServiceName });
-                    if (localEA != null) {
-                        final Dictionary<String, Object> eventProps = new Hashtable<String,
Object>();
-                        eventProps.put(SlingConstants.PROPERTY_PATH, root);
-                        localEA.postEvent(new Event(SlingConstants.TOPIC_RESOURCE_PROVIDER_ADDED,
eventProps));
-                    }
+            for (final String root : roots) {
+                foundRoot = true;
+
+                this.addResourceProvider(root, provider);
+
+                logger.debug("bindResourceProvider: {}={} ({})", new Object[] { root, provider,
debugServiceName });
+                if (localEA != null) {
+                    final Dictionary<String, Object> eventProps = new Hashtable<String,
Object>();
+                    eventProps.put(SlingConstants.PROPERTY_PATH, root);
+                    localEA.postEvent(new Event(SlingConstants.TOPIC_RESOURCE_PROVIDER_ADDED,
eventProps));
                 }
             }
         }
@@ -397,32 +383,26 @@ public class RootResourceProviderEntry e
     /**
      * Unbind a resource provider wrapper
      */
-    private void unbindWrapper(final ProviderHandler provider) {
+    private void unbindHandler(final ProviderHandler provider) {
         // this is just used for debug logging
         final String debugServiceName = getDebugServiceName(provider);
 
         logger.debug("unbindResourceProvider: Unbinding {}", debugServiceName);
 
-        final String[] roots = PropertiesUtil.toStringArray(provider.getProperties().get(ResourceProvider.ROOTS));
-        if (roots != null && roots.length > 0) {
+        final String[] roots = provider.getRoots();
+        if (roots != null) {
 
             final EventAdmin localEA = this.eventAdmin;
 
-            for (String root : roots) {
-                if (root != null && root.length() > 0) {
-                    // cut off trailing slash
-                    if (root.endsWith("/") && root.length() > 1) {
-                        root = root.substring(0, root.length() - 1);
-                    }
-
-                    this.removeResourceProvider(root, provider);
-
-                    logger.debug("unbindResourceProvider: root={} ({})", root, debugServiceName);
-                    if (localEA != null) {
-                        final Dictionary<String, Object> eventProps = new Hashtable<String,
Object>();
-                        eventProps.put(SlingConstants.PROPERTY_PATH, root);
-                        localEA.postEvent(new Event(SlingConstants.TOPIC_RESOURCE_PROVIDER_REMOVED,
eventProps));
-                    }
+            for (final String root : roots) {
+
+                this.removeResourceProvider(root, provider);
+
+                logger.debug("unbindResourceProvider: root={} ({})", root, debugServiceName);
+                if (localEA != null) {
+                    final Dictionary<String, Object> eventProps = new Hashtable<String,
Object>();
+                    eventProps.put(SlingConstants.PROPERTY_PATH, root);
+                    localEA.postEvent(new Event(SlingConstants.TOPIC_RESOURCE_PROVIDER_REMOVED,
eventProps));
                 }
             }
         }

Modified: sling/whiteboard/SLING-2396/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/helper/MapEntryTest.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/SLING-2396/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/helper/MapEntryTest.java?rev=1346349&r1=1346348&r2=1346349&view=diff
==============================================================================
--- sling/whiteboard/SLING-2396/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/helper/MapEntryTest.java
(original)
+++ sling/whiteboard/SLING-2396/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/helper/MapEntryTest.java
Tue Jun  5 11:25:11 2012
@@ -18,23 +18,28 @@
  */
 package org.apache.sling.resourceresolver.impl.helper;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
 import java.lang.reflect.Method;
 import java.net.URI;
 
-import org.apache.sling.resourceresolver.impl.mapping.MapEntry;
-
 import junit.framework.TestCase;
 
-public class MapEntryTest extends TestCase {
+import org.apache.sling.resourceresolver.impl.mapping.MapEntry;
+import org.junit.Test;
+
+public class MapEntryTest {
 
-    public void test_to_url_http_80() {
+    @Test public void test_to_url_http_80() {
         assertEqualUri("http://sling.apache.org", "http/sling.apache.org.80");
         assertEqualUri("http://sling.apache.org/", "http/sling.apache.org.80/");
         assertEqualUri("http://sling.apache.org/site/index.html",
             "http/sling.apache.org.80/site/index.html");
     }
 
-    public void test_to_url_https_443() {
+    @Test public void test_to_url_https_443() {
         assertEqualUri("https://sling.apache.org", "https/sling.apache.org.443");
         assertEqualUri("https://sling.apache.org/",
             "https/sling.apache.org.443/");
@@ -42,7 +47,7 @@ public class MapEntryTest extends TestCa
             "https/sling.apache.org.443/site/index.html");
     }
 
-    public void test_to_url_any_999() {
+    @Test public void test_to_url_any_999() {
         // http with arbitrary port
         assertEqualUri("http://sling.apache.org:123",
             "http/sling.apache.org.123");
@@ -68,7 +73,7 @@ public class MapEntryTest extends TestCa
             "gurk/sling.apache.org.321/site/index.html");
     }
 
-    public void test_to_url_any() {
+    @Test public void test_to_url_any() {
         // http without port
         assertEqualUri("http://sling.apache.org", "http/sling.apache.org");
         assertEqualUri("http://sling.apache.org/", "http/sling.apache.org/");
@@ -88,7 +93,7 @@ public class MapEntryTest extends TestCa
             "gurk/sling.apache.org/site/index.html");
     }
 
-    public void test_fixUriPath() {
+    @Test public void test_fixUriPath() {
         // http without port
         assertEqualUriPath("http/sling.apache.org.80", "http/sling.apache.org");
         assertEqualUriPath("http/sling.apache.org.80/",
@@ -136,7 +141,7 @@ public class MapEntryTest extends TestCa
 
     }
 
-    public void test_isRegExp() {
+    @Test public void test_isRegExp() {
         TestCase.assertFalse(isRegExp("http/www.example.com.8080/bla"));
         TestCase.assertTrue(isRegExp("http/.+\\.www.example.com.8080/bla"));
         TestCase.assertTrue(isRegExp("http/(.+)\\.www.example.com.8080/bla"));

Modified: sling/whiteboard/SLING-2396/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/helper/RedirectResourceTest.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/SLING-2396/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/helper/RedirectResourceTest.java?rev=1346349&r1=1346348&r2=1346349&view=diff
==============================================================================
--- sling/whiteboard/SLING-2396/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/helper/RedirectResourceTest.java
(original)
+++ sling/whiteboard/SLING-2396/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/helper/RedirectResourceTest.java
Tue Jun  5 11:25:11 2012
@@ -18,16 +18,19 @@
  */
 package org.apache.sling.resourceresolver.impl.helper;
 
-import java.util.Map;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 
-import junit.framework.TestCase;
+import java.util.Map;
 
 import org.apache.sling.api.resource.PersistableValueMap;
 import org.apache.sling.api.resource.ValueMap;
+import org.junit.Test;
 
-public class RedirectResourceTest extends TestCase {
+public class RedirectResourceTest {
 
-    public void testRedirectResource() {
+    @Test public void testRedirectResource() {
 
         final String path = "/redir/path";
         final String target = "/redir/target";

Modified: sling/whiteboard/SLING-2396/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/helper/ResourcePathIteratorTest.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/SLING-2396/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/helper/ResourcePathIteratorTest.java?rev=1346349&r1=1346348&r2=1346349&view=diff
==============================================================================
--- sling/whiteboard/SLING-2396/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/helper/ResourcePathIteratorTest.java
(original)
+++ sling/whiteboard/SLING-2396/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/helper/ResourcePathIteratorTest.java
Tue Jun  5 11:25:11 2012
@@ -18,55 +18,60 @@
  */
 package org.apache.sling.resourceresolver.impl.helper;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
 import java.util.Iterator;
 import java.util.NoSuchElementException;
 
-import junit.framework.TestCase;
+import org.junit.Test;
 
-public class ResourcePathIteratorTest extends TestCase {
+public class ResourcePathIteratorTest {
 
-    public void testNull() {
+    @Test public void testNull() {
         ResourcePathIterator rpi = new ResourcePathIterator(null);
         assertFinished(rpi);
     }
 
-    public void testEmpty() {
+    @Test public void testEmpty() {
         ResourcePathIterator rpi = new ResourcePathIterator("");
         assertFinished(rpi);
     }
 
-    public void testRoot() {
+    @Test public void testRoot() {
         ResourcePathIterator rpi = new ResourcePathIterator("/");
         assertNext("/", rpi);
         assertFinished(rpi);
     }
 
-    public void testSlashed() {
+    @Test public void testSlashed() {
         ResourcePathIterator rpi = new ResourcePathIterator("/root/child");
         assertNext("/root/child", rpi);
         assertFinished(rpi);
     }
 
-    public void testSlashedTrailingSlash1() {
+    @Test public void testSlashedTrailingSlash1() {
         ResourcePathIterator rpi = new ResourcePathIterator("/root/child/");
         assertNext("/root/child", rpi);
         assertFinished(rpi);
     }
 
-    public void testSlashedTrailingSlash2() {
+    @Test public void testSlashedTrailingSlash2() {
         ResourcePathIterator rpi = new ResourcePathIterator("/root/child//");
         assertNext("/root/child", rpi);
         assertFinished(rpi);
     }
 
-    public void testDotted() {
+    @Test public void testDotted() {
         ResourcePathIterator rpi = new ResourcePathIterator("/root.child");
         assertNext("/root.child", rpi);
         assertNext("/root", rpi);
         assertFinished(rpi);
     }
 
-    public void testMixed() {
+    @Test public void testMixed() {
         ResourcePathIterator rpi = new ResourcePathIterator(
             "/root/child.print.a4.html/with/suffix");
         assertNext("/root/child.print.a4.html/with/suffix", rpi);
@@ -76,14 +81,14 @@ public class ResourcePathIteratorTest ex
         assertFinished(rpi);
     }
 
-    public void testNoSeparators() {
+    @Test public void testNoSeparators() {
         final Iterator<String> rpi = new ResourcePathIterator(
             "MickeyMouseWasHere");
         assertNext("MickeyMouseWasHere", rpi);
         assertFinished(rpi);
     }
 
-    public void testGetA() {
+    @Test public void testGetA() {
         final Iterator<String> rpi = new ResourcePathIterator(
             "/some/stuff/more.a4.html");
         assertNext("/some/stuff/more.a4.html", rpi);
@@ -92,7 +97,7 @@ public class ResourcePathIteratorTest ex
         assertFinished(rpi);
     }
 
-    public void testGetB() {
+    @Test public void testGetB() {
         final Iterator<String> rpi = new ResourcePathIterator(
             "/some/stuff/more.html");
         assertNext("/some/stuff/more.html", rpi);
@@ -100,7 +105,7 @@ public class ResourcePathIteratorTest ex
         assertFinished(rpi);
     }
 
-    public void testHeadB() {
+    @Test public void testHeadB() {
         final Iterator<String> rpi = new ResourcePathIterator(
             "/some/stuff/more.html");
         assertNext("/some/stuff/more.html", rpi);
@@ -108,13 +113,13 @@ public class ResourcePathIteratorTest ex
         assertFinished(rpi);
     }
 
-    public void testGetC() {
+    @Test public void testGetC() {
         final Iterator<String> it = new ResourcePathIterator("/some/stuff/more");
         assertNext("/some/stuff/more", it);
         assertFinished(it);
     }
 
-    public void testGetD() {
+    @Test public void testGetD() {
         final Iterator<String> it = new ResourcePathIterator(
             "/some/stuff.print/more.html");
         assertNext("/some/stuff.print/more.html", it);
@@ -123,7 +128,7 @@ public class ResourcePathIteratorTest ex
         assertFinished(it);
     }
 
-    public void testRelativePathGet() {
+    @Test public void testRelativePathGet() {
         final Iterator<String> it = new ResourcePathIterator("some/stuff.print");
         assertNext("some/stuff.print", it);
         assertNext("some/stuff", it);

Modified: sling/whiteboard/SLING-2396/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/helper/ResourceProviderEntryTest.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/SLING-2396/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/helper/ResourceProviderEntryTest.java?rev=1346349&r1=1346348&r2=1346349&view=diff
==============================================================================
--- sling/whiteboard/SLING-2396/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/helper/ResourceProviderEntryTest.java
(original)
+++ sling/whiteboard/SLING-2396/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/helper/ResourceProviderEntryTest.java
Tue Jun  5 11:25:11 2012
@@ -18,6 +18,9 @@
  */
 package org.apache.sling.resourceresolver.impl.helper;
 
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
@@ -26,8 +29,6 @@ import java.util.Map;
 
 import javax.servlet.http.HttpServletRequest;
 
-import junit.framework.TestCase;
-
 import org.apache.sling.api.resource.AbstractResource;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceMetadata;
@@ -36,30 +37,24 @@ import org.apache.sling.api.resource.Res
 import org.apache.sling.resourceresolver.impl.tree.ProviderHandler;
 import org.apache.sling.resourceresolver.impl.tree.ResourceProviderEntry;
 import org.apache.sling.resourceresolver.impl.tree.ResourceProviderHandler;
+import org.junit.Before;
+import org.junit.Test;
 import org.osgi.framework.Constants;
 
-public class ResourceProviderEntryTest extends TestCase {
+public class ResourceProviderEntryTest {
 
     private ResourceProvider rootProvider;
 
     private ResourceProviderEntry root;
 
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-
+    @Before public void setUp() throws Exception {
         rootProvider = new TestResourceProvider("/");
         final Map<String, Object> props = new HashMap<String, Object>();
         props.put(Constants.SERVICE_ID, (long)0);
         root = new ResourceProviderEntry("/", new ResourceProviderHandler[]{ new ResourceProviderHandler(rootProvider,
props)});
     }
 
-    @Override
-    protected void tearDown() throws Exception {
-        super.tearDown();
-    }
-
-    public void testRootProvider() {
+    @Test public void testRootProvider() {
         assertNull(root.getResource(null, null, "relpath"));
         assertEquals(root, root.getResource(null, null, "/"));
         assertEquals(root, root.getResource(null, null, "/rootel"));
@@ -69,7 +64,7 @@ public class ResourceProviderEntryTest e
             "/apps/sling/microsling/html.js"));
     }
 
-    public void testAdd1Provider() {
+    @Test public void testAdd1Provider() {
         String firstPath = "/rootel";
         ResourceProvider first = new TestResourceProvider(firstPath);
         final Map<String, Object> firstProps = new HashMap<String, Object>();
@@ -88,7 +83,7 @@ public class ResourceProviderEntryTest e
             "/apps/sling/microsling/html.js"));
     }
 
-    public void testAdd3Providers() {
+    @Test public void testAdd3Providers() {
         String firstPath = "/rootel";
         String thirdPath = "/apps/sling/sample";
         String secondPath = firstPath + "/child";
@@ -120,7 +115,7 @@ public class ResourceProviderEntryTest e
             assertEquals(rootProvider, resource);
     }
 
-    public void testAdd3ProvidersReverse() {
+    @Test public void testAdd3ProvidersReverse() {
         String firstPath = "/rootel";
         String thirdPath = "/apps/sling/sample";
         String secondPath = firstPath + "/child";
@@ -151,7 +146,7 @@ public class ResourceProviderEntryTest e
         assertEquals(rootProvider, resource);
     }
 
-    public void testRemoveProviders() {
+    @Test public void testRemoveProviders() {
         String firstPath = "/rootel";
         String thirdPath = "/apps/sling/sample";
         String secondPath = firstPath + "/child";
@@ -189,7 +184,7 @@ public class ResourceProviderEntryTest e
     }
 
     protected void assertEquals(ResourceProvider resProvider, Resource res) {
-        assertEquals(resProvider, res.getResourceResolver());
+        org.junit.Assert.assertEquals(resProvider, res.getResourceResolver());
     }
 
     protected void assertEquals(ResourceProviderEntry resProviderEntry,

Added: 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=1346349&view=auto
==============================================================================
--- sling/whiteboard/SLING-2396/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/helper/SortedProviderListTest.java
(added)
+++ sling/whiteboard/SLING-2396/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/helper/SortedProviderListTest.java
Tue Jun  5 11:25:11 2012
@@ -0,0 +1,149 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.resourceresolver.impl.helper;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.sling.api.adapter.Adaptable;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceProvider;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.resourceresolver.impl.tree.ResourceProviderHandler;
+import org.junit.Test;
+import org.osgi.framework.Constants;
+
+public class SortedProviderListTest {
+
+    @Test public void addTestRemoveResourceProvider() {
+        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 SortedProviderList<Adaptable> spl = new SortedProviderList<Adaptable>(Adaptable.class);
+        check(spl, null);
+        spl.add(new ResourceProviderHandler(rp1, rp1.getProperties()));
+        check(spl, null);
+        spl.add(new ResourceProviderHandler(rp2, rp2.getProperties()));
+        check(spl, null, rp2);
+        spl.add(new ResourceProviderHandler(rp3, rp3.getProperties()));
+        check(spl, null, rp2, rp3);
+        spl.add(new ResourceProviderHandler(rp4, rp4.getProperties()));
+        check(spl, null, rp2, rp3);
+
+        spl.remove(new ResourceProviderHandler(rp1, rp1.getProperties()));
+        check(spl, null, rp2, rp3);
+        spl.remove(new ResourceProviderHandler(rp1, rp1.getProperties()));
+        check(spl, null, rp2, rp3);
+        spl.remove(new ResourceProviderHandler(rp4, rp4.getProperties()));
+        check(spl, null, rp2, rp3);
+        spl.remove(new ResourceProviderHandler(rp2, rp2.getProperties()));
+        check(spl, null, rp3);
+        spl.remove(new ResourceProviderHandler(rp3, rp3.getProperties()));
+        check(spl, null);
+    }
+
+    @Test public void testSorting() {
+        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 SortedProviderList<Adaptable> spl = new SortedProviderList<Adaptable>(Adaptable.class);
+        check(spl, null);
+        spl.add(new ResourceProviderHandler(rp1, rp1.getProperties()));
+        check(spl, null, rp1);
+        spl.add(new ResourceProviderHandler(rp2, rp2.getProperties()));
+        check(spl, null, rp2, rp1);
+        spl.add(new ResourceProviderHandler(rp3, rp3.getProperties()));
+        check(spl, null, rp2, rp1, rp3);
+        spl.add(new ResourceProviderHandler(rp4, rp4.getProperties()));
+        check(spl, null, rp2, rp1, rp4, rp3);
+        spl.add(new ResourceProviderHandler(rp5, rp5.getProperties()));
+        check(spl, null, rp2, rp1, rp4, rp5, rp3);
+    }
+
+    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);
+        int count = 0;
+        while ( i.hasNext() ) {
+            final Adaptable a = i.next();
+            assertEquals(objects[count], a);
+            count++;
+        }
+        assertEquals(expectedCount, count);
+    }
+
+    private static class ResourceProviderImpl implements ResourceProvider {
+
+        private final String[] roots;
+        private final Long serviceId;
+
+        public ResourceProviderImpl(String[] roots, Long serviceId) {
+            this.roots = roots;
+            this.serviceId = serviceId;
+        }
+
+        public Map<String, Object> getProperties() {
+            final Map<String, Object> props = new HashMap<String, Object>();
+            props.put(Constants.SERVICE_ID, serviceId);
+            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;
+        }
+
+    }
+
+    private static class AdaptableResourceProviderImpl extends ResourceProviderImpl
+    implements Adaptable {
+
+        public AdaptableResourceProviderImpl(String[] roots, Long serviceId) {
+            super(roots, serviceId);
+        }
+
+        public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
+            // TODO Auto-generated method stub
+            return null;
+        }
+
+    }
+}

Propchange: sling/whiteboard/SLING-2396/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/helper/SortedProviderListTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/whiteboard/SLING-2396/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/helper/SortedProviderListTest.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Propchange: sling/whiteboard/SLING-2396/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/helper/SortedProviderListTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: sling/whiteboard/SLING-2396/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/helper/StarResourceTest.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/SLING-2396/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/helper/StarResourceTest.java?rev=1346349&r1=1346348&r2=1346349&view=diff
==============================================================================
--- sling/whiteboard/SLING-2396/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/helper/StarResourceTest.java
(original)
+++ sling/whiteboard/SLING-2396/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/helper/StarResourceTest.java
Tue Jun  5 11:25:11 2012
@@ -18,31 +18,33 @@
  */
 package org.apache.sling.resourceresolver.impl.helper;
 
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
 
 import org.apache.sling.api.resource.ResourceMetadata;
+import org.junit.Test;
 
 /** Test the StarResource */
-public class StarResourceTest extends TestCase {
+public class StarResourceTest {
+
 	private void assertSplit(String requestPath, String path, String pathInfo) {
 		final ResourceMetadata rm = StarResource.getResourceMetadata(requestPath);
 		assertEquals("For requestPath=" + requestPath + ", path matches", path, rm.getResolutionPath());
 		assertEquals("For requestPath=" + requestPath + ", pathInfo matches", pathInfo, rm.getResolutionPathInfo());
 	}
-	
-	public void testSimplePath() {
+
+	@Test public void testSimplePath() {
 		assertSplit("/foo/*.html", "/foo/*", ".html");
 	}
-	
-	public void testNoExtension() {
+
+	@Test public void testNoExtension() {
 		assertSplit("/foo/*", "/foo/*", "");
 	}
-	
-	public void testNoStar() {
+
+	@Test public void testNoStar() {
 		assertSplit("/foo/bar.html", "/foo/bar.html", null);
 	}
-	
-	public void testTwoStars() {
+
+	@Test public void testTwoStars() {
 		assertSplit("/foo/*.html/*.txt", "/foo/*", ".html/*.txt");
 	}
 }



Mime
View raw message