Author: asanso
Date: Tue Jul 1 15:42:38 2014
New Revision: 1607119
URL: http://svn.apache.org/r1607119
Log:
SLING-3723 - MapEntries->resolveMapsMap holds incorrect information in case of
vanityPath removal
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=1607119&r1=1607118&r2=1607119&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 15:42:38 2014
@@ -321,13 +321,19 @@ public class MapEntries implements Event
if (l != null){
for (String s : l){
List<MapEntry> entries = this.resolveMapsMap.get(s);
- for (Iterator<MapEntry> iterator =entries.iterator();
iterator.hasNext(); ) {
- MapEntry entry = iterator.next();
- String redirect = getMapEntryRedirect(entry);
- if (redirect != null &&
redirect.equals(actualContentPath)) {
- iterator.remove();
+ if (entries!= null) {
+ for (Iterator<MapEntry> iterator =entries.iterator();
iterator.hasNext(); ) {
+ MapEntry entry = iterator.next();
+ String redirect = getMapEntryRedirect(entry);
+ if (redirect != null &&
redirect.equals(actualContentPath)) {
+ iterator.remove();
+ }
}
}
+ entries = this.resolveMapsMap.get(s);
+ if (entries!= null && entries.isEmpty()) {
+ this.resolveMapsMap.remove(s);
+ }
}
}
vanityTargets.remove(actualContentPath);
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=1607119&r1=1607118&r2=1607119&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 15:42:38 2014
@@ -396,4 +396,45 @@ public class MapEntriesTest {
assertNotNull(vanityTargets.get("/vanityPathOnJcrContent"));
}
+ @Test
+ public void test_doUpdateVanity() 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("doUpdateVanity",
String.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");
+
+ assertEquals(2, resolveMapsMap.size());
+
+ assertNotNull(resolveMapsMap.get("/target/justVanityPath"));
+ assertNull(resolveMapsMap.get("/target/justVanityPathUpdated"));
+ assertEquals(1, vanityTargets.get("/justVanityPath").size());
+ assertEquals("/target/justVanityPath",
vanityTargets.get("/justVanityPath").get(0));
+
+
when(justVanityPath.adaptTo(ValueMap.class)).thenReturn(buildValueMap("sling:vanityPath",
"/target/justVanityPathUpdated"));
+ method1.invoke(mapEntries, "/justVanityPath");
+
+ assertNull(resolveMapsMap.get("/target/justVanityPath"));
+ assertNotNull(resolveMapsMap.get("/target/justVanityPathUpdated"));
+ assertEquals(1, vanityTargets.get("/justVanityPath").size());
+ assertEquals("/target/justVanityPathUpdated",
vanityTargets.get("/justVanityPath").get(0));
+ }
}