incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r935479 - in /sling/trunk/bundles/api/src: main/java/org/apache/sling/api/resource/ResourceUtil.java test/java/org/apache/sling/api/resource/ResourceUtilTest.java
Date Mon, 19 Apr 2010 09:01:08 GMT
Author: bdelacretaz
Date: Mon Apr 19 09:01:08 2010
New Revision: 935479

URL: http://svn.apache.org/viewvc?rev=935479&view=rev
Log:
SLING-1492 - ResourceUtil.isSyntheticResource should take ResourceWrapper into account

Modified:
    sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceUtil.java
    sling/trunk/bundles/api/src/test/java/org/apache/sling/api/resource/ResourceUtilTest.java

Modified: sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceUtil.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceUtil.java?rev=935479&r1=935478&r2=935479&view=diff
==============================================================================
--- sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceUtil.java
(original)
+++ sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceUtil.java
Mon Apr 19 09:01:08 2010
@@ -212,7 +212,12 @@ public class ResourceUtil {
      *         <code>org.apache.sling.resource.SyntheticResource</code> class.
      */
     public static boolean isSyntheticResource(Resource res) {
-        return res instanceof SyntheticResource;
+        if(res instanceof SyntheticResource) {
+        	return true;
+        } else if(res instanceof ResourceWrapper) {
+        	return ((ResourceWrapper)res).getResource() instanceof SyntheticResource;
+        }
+        return false;
     }
 
     /**

Modified: sling/trunk/bundles/api/src/test/java/org/apache/sling/api/resource/ResourceUtilTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/api/src/test/java/org/apache/sling/api/resource/ResourceUtilTest.java?rev=935479&r1=935478&r2=935479&view=diff
==============================================================================
--- sling/trunk/bundles/api/src/test/java/org/apache/sling/api/resource/ResourceUtilTest.java
(original)
+++ sling/trunk/bundles/api/src/test/java/org/apache/sling/api/resource/ResourceUtilTest.java
Mon Apr 19 09:01:08 2010
@@ -377,4 +377,35 @@ public class ResourceUtilTest {
         }
         return count;
     }
+    
+    @Test public void testIsStarResource() {
+		final Resource nonStar = context.mock(Resource.class);
+		final String starPath = "/foo/*";
+		final Resource star = context.mock(Resource.class);
+		final String nonStarPath = "/foo/*";
+        this.context.checking(new Expectations() {{
+        	allowing(star).getPath(); will(returnValue(starPath));
+        	allowing(nonStar).getPath(); will(returnValue(nonStarPath));
+        }});
+        
+		assertTrue("expecting star==true for path" + starPath, 
+				ResourceUtil.isStarResource(star));
+		assertTrue("expecting star==false for path" + starPath, 
+				ResourceUtil.isStarResource(nonStar));
+    }
+    @Test public void testIsSyntheticResource() {
+		final Resource synth = new SyntheticResource(null, "foo", "bar");
+		final Resource star = context.mock(Resource.class);
+        this.context.checking(new Expectations() {{
+        	allowing(star).getPath(); will(returnValue("/foo/*"));
+        }});
+        final Resource wrapped = new ResourceWrapper(synth);
+        
+		assertTrue("expecting synthetic==true for SyntheticResource", 
+				ResourceUtil.isSyntheticResource(synth));
+		assertFalse("expecting synthetic==false for star resource", 
+				ResourceUtil.isSyntheticResource(star));
+		assertTrue("expecting synthetic==true for wrapped Resource", 
+				ResourceUtil.isSyntheticResource(wrapped));
+    }
 }



Mime
View raw message