sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From asa...@apache.org
Subject svn commit: r1607304 - /sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/mapping/MapEntriesTest.java
Date Wed, 02 Jul 2014 09:52:19 GMT
Author: asanso
Date: Wed Jul  2 09:52:19 2014
New Revision: 1607304

URL: http://svn.apache.org/r1607304
Log:
SLING-3712 - Increase code coverage for MapEntries

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=1607304&r1=1607303&r2=1607304&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
Wed Jul  2 09:52:19 2014
@@ -79,6 +79,7 @@ public class MapEntriesTest {
         configs.add(new VanityPathConfig("/foo/", false));
         configs.add(new VanityPathConfig("/baa/", false));
         configs.add(new VanityPathConfig("/justVanityPath", false));
+        configs.add(new VanityPathConfig("/justVanityPath2", false));
         configs.add(new VanityPathConfig("/badVanityPath", false));
         configs.add(new VanityPathConfig("/redirectingVanityPath", false));
         configs.add(new VanityPathConfig("/redirectingVanityPath301", false));
@@ -542,4 +543,70 @@ public class MapEntriesTest {
         
     }
     
+    @Test
+    public void test_doUpdateVanityOrder() throws Exception {
+        Field field0 = MapEntries.class.getDeclaredField("resolveMapsMap");
+        field0.setAccessible(true);   
+        Map<String, List<MapEntry>> resolveMapsMap = (Map<String, List<MapEntry>>)
field0.get(mapEntries);
+        assertEquals(1, resolveMapsMap.size());
+        
+        Field field = MapEntries.class.getDeclaredField("vanityTargets");
+        field.setAccessible(true);
+        Map<String, List<String>> vanityTargets = (Map<String, List<String>>)
field.get(mapEntries);
+        assertEquals(0, vanityTargets.size());
+        
+        Method method = MapEntries.class.getDeclaredMethod("doAddVanity", String.class);
+        method.setAccessible(true);
+        
+        Method method1 = MapEntries.class.getDeclaredMethod("doUpdateVanityOrder", String.class,
boolean.class);
+        method1.setAccessible(true);
+        
+        Resource justVanityPath = mock(Resource.class, "justVanityPath");
+        when(resourceResolver.getResource("/justVanityPath")).thenReturn(justVanityPath);
+        when(justVanityPath.getPath()).thenReturn("/justVanityPath");                 
+        when(justVanityPath.getName()).thenReturn("justVanityPath");
+        when(justVanityPath.adaptTo(ValueMap.class)).thenReturn(buildValueMap("sling:vanityPath",
"/target/justVanityPath"));
+        
+        method.invoke(mapEntries, "/justVanityPath");
+        
+        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));
+        
+        method.invoke(mapEntries, "/justVanityPath2");
+              
+        assertEquals(2, resolveMapsMap.size());
+        assertEquals(2, vanityTargets.size());    
+        assertNotNull(resolveMapsMap.get("/target/justVanityPath"));
+        
+        Iterator <MapEntry> iterator = resolveMapsMap.get("/target/justVanityPath").iterator();
+        assertEquals("/justVanityPath2$1", iterator.next().getRedirect()[0]);
+        assertEquals("/justVanityPath$1", iterator.next().getRedirect()[0]);
+        assertEquals("/justVanityPath2.html", iterator.next().getRedirect()[0]);
+        assertEquals("/justVanityPath.html", iterator.next().getRedirect()[0]);    
+        assertFalse(iterator.hasNext());
+        
+        when(justVanityPath.adaptTo(ValueMap.class)).thenReturn(buildValueMap("sling:vanityPath",
"/target/justVanityPath","sling:vanityOrder", 1000));
+        method1.invoke(mapEntries, "/justVanityPath",false);
+        
+        iterator = resolveMapsMap.get("/target/justVanityPath").iterator();
+        assertEquals("/justVanityPath$1", iterator.next().getRedirect()[0]);
+        assertEquals("/justVanityPath2$1", iterator.next().getRedirect()[0]);
+        assertEquals("/justVanityPath.html", iterator.next().getRedirect()[0]);
+        assertEquals("/justVanityPath2.html", iterator.next().getRedirect()[0]);    
+        assertFalse(iterator.hasNext());
+        
+        when(justVanityPath.adaptTo(ValueMap.class)).thenReturn(buildValueMap("sling:vanityPath",
"/target/justVanityPath"));
+        method1.invoke(mapEntries, "/justVanityPath",true);
+        
+        iterator = resolveMapsMap.get("/target/justVanityPath").iterator();
+        assertEquals("/justVanityPath2$1", iterator.next().getRedirect()[0]);
+        assertEquals("/justVanityPath$1", iterator.next().getRedirect()[0]);
+        assertEquals("/justVanityPath2.html", iterator.next().getRedirect()[0]);
+        assertEquals("/justVanityPath.html", iterator.next().getRedirect()[0]);    
+        assertFalse(iterator.hasNext());
+    }
+    
 }



Mime
View raw message