incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From asa...@apache.org
Subject svn commit: r1606994 - in /sling/trunk/bundles/resourceresolver/src: main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java test/java/org/apache/sling/resourceresolver/impl/mapping/MapEntriesTest.java
Date Tue, 01 Jul 2014 06:50:04 GMT
Author: asanso
Date: Tue Jul  1 06:50:04 2014
New Revision: 1606994

URL: http://svn.apache.org/r1606994
Log:
SLING-3719 - MapEntries->updateTargetPaths  holds incorrect information in case of exception
while creating a MapEntry

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

Modified: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java?rev=1606994&r1=1606993&r2=1606994&view=diff
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java
(original)
+++ sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java
Tue Jul  1 06:50:04 2014
@@ -650,9 +650,9 @@ public class MapEntries implements Event
     /**
      * Add an entry to the resolve map.
      */
-    private void addEntry(final Map<String, List<MapEntry>> entryMap, final String
key, final MapEntry entry) {
+    private boolean addEntry(final Map<String, List<MapEntry>> entryMap, final
String key, final MapEntry entry) {
         if (entry==null){
-            return;
+            return false;
         }
         List<MapEntry> entries = entryMap.get(key);
         if (entries == null) {
@@ -662,6 +662,7 @@ public class MapEntries implements Event
         entries.add(entry);
         // and finally sort list
         Collections.sort(entries);
+        return true;
     }
 
     /**
@@ -825,6 +826,7 @@ public class MapEntries implements Event
 
                 final String checkPath = result[1];
 
+                boolean addedEntry;
                 if (redirectName.indexOf('.') > -1) {
                     // 1. entry with exact match
                     this.addEntry(entryMap, checkPath, getMapEntry(url + "$", status, false,
vanityOrder, redirect));
@@ -833,22 +835,24 @@ public class MapEntries implements Event
                     final String extension = redirectName.substring(idx + 1);
 
                     // 2. entry with extension
-                    this.addEntry(entryMap, checkPath, getMapEntry(url + "\\." + extension,
status, false, vanityOrder, redirect));
+                    addedEntry = this.addEntry(entryMap, checkPath, getMapEntry(url + "\\."
+ extension, status, false, vanityOrder, redirect));
                 } else {
                     // 1. entry with exact match
                     this.addEntry(entryMap, checkPath, getMapEntry(url + "$", status, false,
vanityOrder, redirect + ".html"));
 
                     // 2. entry with match supporting selectors and extension
-                    this.addEntry(entryMap, checkPath, getMapEntry(url + "(\\..*)", status,
false, vanityOrder, redirect + "$1"));
+                    addedEntry = this.addEntry(entryMap, checkPath, getMapEntry(url + "(\\..*)",
status, false, vanityOrder, redirect + "$1"));
+                }
+                if (addedEntry) {
+                    // 3. keep the path to return
+                    this.updateTargetPaths(targetPaths, redirect, checkPath);
                 }
-                // 3. keep the path to return
-                this.updateTargetPaths(targetPaths, redirect, checkPath);
             }
         }
     }
     
     private void updateTargetPaths(final Map<String, List<String>> targetPaths,
final String key, final String entry) {
-        if (entry==null){
+        if (entry == null) {
             return;
         }
         List<String> entries = targetPaths.get(key);
@@ -856,7 +860,7 @@ public class MapEntries implements Event
             entries = new ArrayList<String>();
             targetPaths.put(key, entries);
         }
-        entries.add(entry); 
+        entries.add(entry);
     }
     
     /**

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=1606994&r1=1606993&r2=1606994&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  1 06:50:04 2014
@@ -25,6 +25,7 @@ import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
+import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -161,7 +162,7 @@ public class MapEntriesTest {
     }
 
     @Test
-    public void test_vanity_path_registration() {
+    public void test_vanity_path_registration() throws Exception {
         // specifically making this a weird value because we want to verify that
         // the configuration value is being used
         int DEFAULT_VANITY_STATUS = 333333;
@@ -236,6 +237,12 @@ public class MapEntriesTest {
                 }
             }
         }
+        
+        Field field = MapEntries.class.getDeclaredField("vanityTargets");
+        field.setAccessible(true);
+        Map<String, List<String>> vanityTargets = (Map<String, List<String>>)
field.get(mapEntries);
+        assertEquals(4, vanityTargets.size());        
+        
     }
 
     private ValueMap buildValueMap(Object... string) {



Mime
View raw message