incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1346470 - in /sling/whiteboard/SLING-2396/resourceresolver/src: main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java test/java/org/apache/sling/resourceresolver/impl/ResourceResolverImplTest.java
Date Tue, 05 Jun 2012 17:07:55 GMT
Author: cziegeler
Date: Tue Jun  5 17:07:54 2012
New Revision: 1346470

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

Modified:
    sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
    sling/whiteboard/SLING-2396/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/ResourceResolverImplTest.java

Modified: sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java?rev=1346470&r1=1346469&r2=1346470&view=diff
==============================================================================
--- sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
(original)
+++ sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
Tue Jun  5 17:07:54 2012
@@ -106,8 +106,8 @@ public class ResourceResolverImpl extend
     /**
      * @see org.apache.sling.api.resource.ResourceResolver#clone(Map)
      */
-    public ResourceResolver clone(final Map<String, Object> authenticationInfo) throws
LoginException {
-
+    public ResourceResolver clone(final Map<String, Object> authenticationInfo)
+    throws LoginException {
         // ensure resolver is still live
         checkClosed();
 
@@ -150,8 +150,9 @@ public class ResourceResolverImpl extend
      * cleaned up before it is being collected by the garbage collector because
      * it is not referred to any more.
      */
-    protected void finalize() {
+    protected void finalize() throws Throwable {
         close();
+        super.finalize();
     }
 
     /**
@@ -180,6 +181,7 @@ public class ResourceResolverImpl extend
      * @see org.apache.sling.api.resource.ResourceResolver#getAttribute(String)
      */
     public Object getAttribute(final String name) {
+        checkClosed();
         if (name == null) {
             throw new NullPointerException("name");
         }
@@ -629,7 +631,8 @@ public class ResourceResolverImpl extend
      * @see org.apache.sling.api.resource.ResourceResolver#queryResources(java.lang.String,
      *      java.lang.String)
      */
-    public Iterator<Map<String, Object>> queryResources(final String query, final
String language) throws SlingException {
+    public Iterator<Map<String, Object>> queryResources(final String query, final
String language)
+    throws SlingException {
         checkClosed();
 
         return this.factory.getRootProviderEntry().queryResources(this.context, query, language);
@@ -725,7 +728,7 @@ public class ResourceResolverImpl extend
      *            The (absolute) path
      * @return The request path string {scheme}/{host}.{port}{path}.
      */
-    public static String getMapPath(final String scheme, final String host, int port, final
String path) {
+    private static String getMapPath(final String scheme, final String host, int port, final
String path) {
         if (port < 0) {
             port = ("https".equals(scheme)) ? 443 : 80;
         }
@@ -876,9 +879,9 @@ public class ResourceResolverImpl extend
     }
 
     /**
-     * Creates a JcrNodeResource with the given path if existing
+     * Creates a resource with the given path if existing
      */
-    protected Resource getResourceInternal(final String path) {
+    private Resource getResourceInternal(final String path) {
 
         final Resource resource = this.factory.getRootProviderEntry().getResource(this.context,
this, path);
         if (resource != null) {
@@ -890,11 +893,11 @@ public class ResourceResolverImpl extend
         return null;
     }
 
-    public String getProperty(final Resource res, final String propName) {
+    private String getProperty(final Resource res, final String propName) {
         return getProperty(res, propName, String.class);
     }
 
-    public <Type> Type getProperty(final Resource res, final String propName, final
Class<Type> type) {
+    private <Type> Type getProperty(final Resource res, final String propName, final
Class<Type> type) {
 
         // check the property in the resource itself
         final ValueMap props = res.adaptTo(ValueMap.class);

Modified: sling/whiteboard/SLING-2396/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/ResourceResolverImplTest.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/SLING-2396/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/ResourceResolverImplTest.java?rev=1346470&r1=1346469&r2=1346470&view=diff
==============================================================================
--- sling/whiteboard/SLING-2396/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/ResourceResolverImplTest.java
(original)
+++ sling/whiteboard/SLING-2396/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/ResourceResolverImplTest.java
Tue Jun  5 17:07:54 2012
@@ -45,6 +45,7 @@ import org.apache.sling.api.resource.Non
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.api.resource.ResourceResolverFactory;
+import org.apache.sling.resourceresolver.impl.helper.ResourceResolverContext;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -56,7 +57,114 @@ public class ResourceResolverImplTest {
 
     @Before public void setup() {
         resFac = new ResourceResolverFactoryImpl();
-        resResolver = new ResourceResolverImpl(resFac, null);
+        resResolver = new ResourceResolverImpl(resFac, new ResourceResolverContext(false,
null));
+    }
+
+    @Test public void testClose() throws Exception {
+        final ResourceResolver rr = new ResourceResolverImpl(resFac, new ResourceResolverContext(false,
null));
+        assertTrue(rr.isLive());
+        rr.close();
+        assertFalse(rr.isLive());
+        // close is always allowed to be called
+        rr.close();
+        assertFalse(rr.isLive());
+        // now check all public method - they should all throw!
+        try {
+            rr.adaptTo(Session.class);
+            fail();
+        } catch (final IllegalStateException ise) {
+            // expected
+        }
+        try {
+            rr.clone(null);
+            fail();
+        } catch (final IllegalStateException ise) {
+            // expected
+        }
+        try {
+            rr.findResources("a", "b");
+            fail();
+        } catch (final IllegalStateException ise) {
+            // expected
+        }
+        try {
+            rr.getAttribute("a");
+            fail();
+        } catch (final IllegalStateException ise) {
+            // expected
+        }
+        try {
+            rr.getAttributeNames();
+            fail();
+        } catch (final IllegalStateException ise) {
+            // expected
+        }
+        try {
+            rr.getResource(null);
+            fail();
+        } catch (final IllegalStateException ise) {
+            // expected
+        }
+        try {
+            rr.getResource(null, "/a");
+            fail();
+        } catch (final IllegalStateException ise) {
+            // expected
+        }
+        try {
+            rr.getSearchPath();
+            fail();
+        } catch (final IllegalStateException ise) {
+            // expected
+        }
+        try {
+            rr.getUserID();
+            fail();
+        } catch (final IllegalStateException ise) {
+            // expected
+        }
+        try {
+            rr.listChildren(null);
+            fail();
+        } catch (final IllegalStateException ise) {
+            // expected
+        }
+        try {
+            rr.map("/somepath");
+            fail();
+        } catch (final IllegalStateException ise) {
+            // expected
+        }
+        try {
+            rr.map(null, "/somepath");
+            fail();
+        } catch (final IllegalStateException ise) {
+            // expected
+        }
+        try {
+            rr.queryResources("a", "b");
+            fail();
+        } catch (final IllegalStateException ise) {
+            // expected
+        }
+        try {
+            rr.resolve((HttpServletRequest)null);
+            fail();
+        } catch (final IllegalStateException ise) {
+            // expected
+        }
+        try {
+            rr.resolve("/path");
+            fail();
+        } catch (final IllegalStateException ise) {
+            // expected
+        }
+        try {
+            rr.resolve(null, "/path");
+            fail();
+        } catch (final IllegalStateException ise) {
+            // expected
+        }
     }
 
     @SuppressWarnings("deprecation")



Mime
View raw message