You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by as...@apache.org on 2015/07/21 16:34:28 UTC

svn commit: r1692130 - /sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/mapping/MapEntriesTest.java

Author: asanso
Date: Tue Jul 21 14:34:27 2015
New Revision: 1692130

URL: http://svn.apache.org/r1692130
Log:
SLING-4891 - Improve MapEntries to cache searched vanity paths 

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

Modified: sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/mapping/MapEntriesTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/mapping/MapEntriesTest.java?rev=1692130&r1=1692129&r2=1692130&view=diff
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/mapping/MapEntriesTest.java (original)
+++ sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/mapping/MapEntriesTest.java Tue Jul 21 14:34:27 2015
@@ -1508,6 +1508,28 @@ public class MapEntriesTest {
         vanityCounter.setAccessible(true);  
         AtomicLong counter = (AtomicLong) vanityCounter.get(mapEntries);
         assertEquals(2, counter.longValue());        
+        
+        final Resource justVanityPath2 = mock(Resource.class, "justVanityPath2");
+        when(resourceResolver.getResource("/justVanityPath2")).thenReturn(justVanityPath2);
+        when(justVanityPath2.getPath()).thenReturn("/justVanityPath2");                 
+        when(justVanityPath2.getName()).thenReturn("justVanityPath2");
+        when(justVanityPath2.adaptTo(ValueMap.class)).thenReturn(buildValueMap("sling:vanityPath", "/target/justVanityPath","sling:vanityOrder", 100));
+        
+        when(resourceResolver.findResources(anyString(), eq("sql"))).thenAnswer(new Answer<Iterator<Resource>>() {
+
+            public Iterator<Resource> answer(InvocationOnMock invocation) throws Throwable {
+                if (invocation.getArguments()[0].toString().contains("sling:vanityPath")) {
+                    return Collections.singleton(justVanityPath).iterator();
+                } else {
+                    return Collections.<Resource> emptySet().iterator();
+                }
+            }
+        });
+        
+        method.invoke(mapEntries, "/justVanityPath2");
+  
+        counter = (AtomicLong) vanityCounter.get(mapEntries);
+        assertEquals(4, counter.longValue());  
     }
     
     @Test
@@ -1626,6 +1648,28 @@ public class MapEntriesTest {
         vanityCounter.setAccessible(true);  
         AtomicLong counter = (AtomicLong) vanityCounter.get(mapEntries);
         assertEquals(2, counter.longValue());        
+        
+        final Resource justVanityPath2 = mock(Resource.class, "justVanityPath2");
+        when(resourceResolver.getResource("/justVanityPath2")).thenReturn(justVanityPath2);
+        when(justVanityPath2.getPath()).thenReturn("/justVanityPath2");                 
+        when(justVanityPath2.getName()).thenReturn("justVanityPath2");
+        when(justVanityPath2.adaptTo(ValueMap.class)).thenReturn(buildValueMap("sling:vanityPath", "/target/justVanityPath","sling:vanityOrder", 100));
+        
+        when(resourceResolver.findResources(anyString(), eq("sql"))).thenAnswer(new Answer<Iterator<Resource>>() {
+
+            public Iterator<Resource> answer(InvocationOnMock invocation) throws Throwable {
+                if (invocation.getArguments()[0].toString().contains("sling:vanityPath")) {
+                    return Collections.singleton(justVanityPath).iterator();
+                } else {
+                    return Collections.<Resource> emptySet().iterator();
+                }
+            }
+        });
+        
+        method.invoke(mapEntries, "/justVanityPath2");
+  
+        counter = (AtomicLong) vanityCounter.get(mapEntries);
+        assertEquals(2, counter.longValue());  
     }
     
     @Test