Author: cziegeler
Date: Fri Oct 14 09:40:19 2016
New Revision: 1764846

URL: http://svn.apache.org/viewvc?rev=1764846&view=rev
Log:
SLING-6148 : MapEntries get CHANGED event right after DELETE

Modified:
    
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java
    
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/observation/ResourceChangeListenerInfo.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=1764846&r1=1764845&r2=1764846&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
 Fri Oct 14 09:40:19 2016
@@ -38,7 +38,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.NoSuchElementException;
-import java.util.Set;
 import java.util.SortedMap;
 import java.util.Timer;
 import java.util.TimerTask;
@@ -328,7 +327,7 @@ public class MapEntries implements Resou
         return newRefreshed;
     }
 
-    private boolean doAddAttributes(String path, Set<String> addedAttributes, 
boolean refreshed) {
+    private boolean doRemoveAttributes(String path, String removedAttribute, 
boolean refreshed) {
         boolean newRefreshed = refreshed;
         if (!newRefreshed) {
             resolver.refresh();
@@ -336,87 +335,17 @@ public class MapEntries implements Resou
         }
         this.initializing.lock();
         try {
-            for (String changedAttribute:addedAttributes){
-                if (PROP_VANITY_PATH.equals(changedAttribute)) {
-                    doAddVanity(path);
-                } else if (PROP_VANITY_ORDER.equals(changedAttribute)) {
-                    doUpdateVanityOrder(path, false);
-                } else if (PROP_REDIRECT_EXTERNAL.equals(changedAttribute)
-                        || 
PROP_REDIRECT_EXTERNAL_REDIRECT_STATUS.equals(changedAttribute)) {
-                    doUpdateRedirectStatus(path);
-                } else if 
(ResourceResolverImpl.PROP_ALIAS.equals(changedAttribute)) {
-                    if (enableOptimizeAliasResolution) {
-                       doAddAlias(path);
+            if (PROP_VANITY_PATH.equals(removedAttribute)){
+                doRemoveVanity(path);
+            } else if 
(ResourceResolverImpl.PROP_ALIAS.equals(removedAttribute)) {
+                if (enableOptimizeAliasResolution) {
+                    doRemoveAlias(path, true);
+                    if ( path.endsWith("/jcr:content") ) {
+                        doAddAlias(ResourceUtil.getParent(path));
                     }
                 }
             }
-            if (path.startsWith(this.mapRoot)) {
-                doUpdateConfiguration();
-            }
-            sendChangeEvent();
-        } finally {
-            this.initializing.unlock();
-        }
-        return newRefreshed;
-    }
 
-    private boolean doUpdateAttributes(String path, Set<String> 
changedAttributes, boolean refreshed) {
-        boolean newRefreshed = refreshed;
-        if (!newRefreshed) {
-            resolver.refresh();
-            newRefreshed = true;
-        }
-        this.initializing.lock();
-        try {
-            for (String changedAttribute : changedAttributes){
-                if (PROP_VANITY_PATH.equals(changedAttribute)) {
-                    doUpdateVanity(path);
-                } else if (PROP_VANITY_ORDER.equals(changedAttribute)) {
-                    doUpdateVanityOrder(path, false);
-                } else if (PROP_REDIRECT_EXTERNAL.equals(changedAttribute)
-                        || 
PROP_REDIRECT_EXTERNAL_REDIRECT_STATUS.equals(changedAttribute)) {
-                    doUpdateRedirectStatus(path);
-                } else if 
(ResourceResolverImpl.PROP_ALIAS.equals(changedAttribute)) {
-                    if (enableOptimizeAliasResolution) {
-                        doRemoveAlias(path, false);
-                        doAddAlias(path);
-                        doUpdateAlias(path, false);
-                    }
-                }
-            }
-            if (path.startsWith(this.mapRoot)) {
-                doUpdateConfiguration();
-            }
-            sendChangeEvent();
-        } finally {
-            this.initializing.unlock();
-        }
-        return newRefreshed;
-    }
-
-    private boolean doRemoveAttributes(String path, Set<String> 
removedAttributes, boolean nodeDeletion, boolean refreshed) {
-        boolean newRefreshed = refreshed;
-        if (!newRefreshed) {
-            resolver.refresh();
-            newRefreshed = true;
-        }
-        this.initializing.lock();
-        try {
-            for (String changedAttribute:removedAttributes){
-                if (PROP_VANITY_PATH.equals(changedAttribute)){
-                    doRemoveVanity(path);
-                } else if (PROP_VANITY_ORDER.equals(changedAttribute)) {
-                    doUpdateVanityOrder(path, true);
-                } else if (PROP_REDIRECT_EXTERNAL.equals(changedAttribute)
-                        || 
PROP_REDIRECT_EXTERNAL_REDIRECT_STATUS.equals(changedAttribute)) {
-                    doUpdateRedirectStatus(path);
-                } else if 
(ResourceResolverImpl.PROP_ALIAS.equals(changedAttribute)) {
-                    if (enableOptimizeAliasResolution) {
-                        doRemoveAlias(path, nodeDeletion);
-                        doUpdateAlias(path, nodeDeletion);
-                    }
-                }
-            }
             if (path.startsWith(this.mapRoot)) {
                 doUpdateConfiguration();
             }
@@ -510,45 +439,6 @@ public class MapEntries implements Resou
         return false;
     }
 
-    private void doUpdateVanityOrder(String path, boolean deletion) {
-        Resource resource = resolver.getResource(path);
-        final ValueMap props = resource.getValueMap();
-
-        long vanityOrder;
-        if (deletion) {
-            vanityOrder = 0;
-        } else {
-            vanityOrder = props.get(PROP_VANITY_ORDER, Long.class);
-        }
-
-        String actualContentPath = getActualContentPath(path);
-        List<String> vanityPaths = vanityTargets.get(actualContentPath);
-        if (vanityPaths != null) {
-            boolean updatedOrder = false;
-            for (String vanityTarget : vanityPaths) {
-                List<MapEntry> entries = this.resolveMapsMap.get(vanityTarget);
-                for (MapEntry entry : entries) {
-                    String redirect = getMapEntryRedirect(entry);
-                    if (redirect != null && 
redirect.equals(actualContentPath)) {
-                        entry.setOrder(vanityOrder);
-                        updatedOrder = true;
-                    }
-                }
-                if (updatedOrder) {
-                    Collections.sort(entries);
-                }
-            }
-        }
-    }
-
-    private void doUpdateRedirectStatus(String path) {
-        String actualContentPath = getActualContentPath(path);
-        List<String> vanityPaths = vanityTargets.get(actualContentPath);
-        if (vanityPaths != null) {
-            doUpdateVanity(path);
-        }
-    }
-
     private boolean doAddAlias(String path) {
         Resource resource = resolver.getResource(path);
         return loadAlias(resource, this.aliasMap);
@@ -598,9 +488,9 @@ public class MapEntries implements Resou
         if (nodeDeletion) {
             if (!"/".equals(path)){
                 if (path.endsWith("/jcr:content")) {
-                    path =  path.substring(0, path.length() - 
"/jcr:content".length());
+                    path = ResourceUtil.getParent(path);
                 }
-                resourceName = path.substring(path.lastIndexOf("/") + 1);
+                resourceName = ResourceUtil.getName(path);
                 path = ResourceUtil.getParent(path);
             } else {
                 resourceName = "";
@@ -788,14 +678,16 @@ public class MapEntries implements Resou
             // removal of a resource is handled differently
             if (rc.getType() == ResourceChange.ChangeType.REMOVED) {
                 final String actualContentPath = getActualContentPath(path);
+                final String prefix = getActualContentPath(path) + "/";
+
                 for (final String target : this.vanityTargets.keySet()) {
-                    if (target.startsWith(actualContentPath)) {
-                        wasResolverRefreshed = doRemoveAttributes(path, 
Collections.singleton(PROP_VANITY_PATH), true, wasResolverRefreshed);
+                    if (target.startsWith(prefix) || 
target.equals(actualContentPath)) {
+                        wasResolverRefreshed = doRemoveAttributes(target, 
PROP_VANITY_PATH, wasResolverRefreshed);
                     }
                 }
                 for (final String target : this.aliasMap.keySet()) {
-                    if (actualContentPath.startsWith(target)) {
-                        wasResolverRefreshed = doRemoveAttributes(path, 
Collections.singleton(ResourceResolverImpl.PROP_ALIAS), true, 
wasResolverRefreshed);
+                    if (actualContentPath.startsWith(target + "/") || 
actualContentPath.equals(target)) {
+                        wasResolverRefreshed = 
doRemoveAttributes(actualContentPath, ResourceResolverImpl.PROP_ALIAS, 
wasResolverRefreshed);
                     }
                 }
                 if (path.startsWith(this.mapRoot)) {
@@ -806,56 +698,28 @@ public class MapEntries implements Resou
             } else if (rc.getType() == ResourceChange.ChangeType.ADDED ) {
                 wasResolverRefreshed = doNodeAdded(path, wasResolverRefreshed);
             } else {
-                @SuppressWarnings("deprecation")
-                Set<String> addedAttributes = rc.getAddedPropertyNames();
-                if (addedAttributes != null) {
-                    if (log.isDebugEnabled()) {
-                        log.debug("found added attributes {}", 
addedAttributes);
-                    }
-                    wasResolverRefreshed = doAddAttributes(path, 
addedAttributes, wasResolverRefreshed);
-
-                    @SuppressWarnings("deprecation")
-                    Set<String> changedAttributes = 
rc.getChangedPropertyNames();
-                    if (changedAttributes != null) {
-                        if (log.isDebugEnabled()) {
-                            log.debug("found changed attributes {}", 
changedAttributes);
-                        }
-                        wasResolverRefreshed = doUpdateAttributes(path, 
changedAttributes, wasResolverRefreshed);
+                if (path.startsWith(this.mapRoot)) {
+                    wasResolverRefreshed = 
doUpdateConfiguration(wasResolverRefreshed);
+                } else {
+                    if ( !wasResolverRefreshed ) {
+                        wasResolverRefreshed = true;
+                        this.resolver.refresh();
                     }
-
-                    @SuppressWarnings("deprecation")
-                    Set<String> removedAttributes = 
rc.getRemovedPropertyNames();
-                    if (removedAttributes != null) {
-                        if (log.isDebugEnabled()) {
-                            log.debug("found removed attributes {}", 
removedAttributes);
+                    boolean changed = false;
+                    this.initializing.lock();
+                    try {
+                        changed |= doUpdateVanity(path);
+                        if (enableOptimizeAliasResolution) {
+                            changed |= doRemoveAlias(path, false);
+                            changed |= doAddAlias(path);
+                            changed |= doUpdateAlias(path, false);
                         }
-                        wasResolverRefreshed = doRemoveAttributes(path, 
removedAttributes, false, wasResolverRefreshed);
+                    } finally {
+                        this.initializing.unlock();
                     }
-                } else {
 
-                    if (path.startsWith(this.mapRoot)) {
-                        wasResolverRefreshed = 
doUpdateConfiguration(wasResolverRefreshed);
-                    } else {
-                        if ( !wasResolverRefreshed ) {
-                            wasResolverRefreshed = true;
-                            this.resolver.refresh();
-                        }
-                        boolean changed = false;
-                        this.initializing.lock();
-                        try {
-                            changed |= doUpdateVanity(path);
-                            if (enableOptimizeAliasResolution) {
-                                changed |= doRemoveAlias(path, false);
-                                changed |= doAddAlias(path);
-                                changed |= doUpdateAlias(path, false);
-                            }
-                        } finally {
-                            this.initializing.unlock();
-                        }
-
-                        if ( changed ) {
-                            this.sendChangeEvent();
-                        }
+                    if ( changed ) {
+                        this.sendChangeEvent();
                     }
                 }
 
@@ -961,7 +825,7 @@ public class MapEntries implements Resou
         if(resource == null) {
             throw new IllegalArgumentException("Unexpected null resource");
         }
-        
+
         // ignore system tree
         if (resource.getPath().startsWith(JCR_SYSTEM_PREFIX)) {
             log.debug("isValidVanityPath: not valid {}", resource);
@@ -985,7 +849,7 @@ public class MapEntries implements Resou
         return true;
     }
 
-    private String getActualContentPath(String path){
+    private String getActualContentPath(final String path){
         final String checkPath;
         if ( path.endsWith("/jcr:content") ) {
             checkPath = path.substring(0, path.length() - 
"/jcr:content".length());

Modified: 
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/observation/ResourceChangeListenerInfo.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/observation/ResourceChangeListenerInfo.java?rev=1764846&r1=1764845&r2=1764846&view=diff
==============================================================================
--- 
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/observation/ResourceChangeListenerInfo.java
 (original)
+++ 
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/observation/ResourceChangeListenerInfo.java
 Fri Oct 14 09:40:19 2016
@@ -18,6 +18,10 @@
  */
 package org.apache.sling.resourceresolver.impl.observation;
 
+import static 
org.apache.sling.api.resource.observation.ResourceChangeListener.CHANGES;
+import static 
org.apache.sling.api.resource.observation.ResourceChangeListener.PATHS;
+import static org.apache.sling.commons.osgi.PropertiesUtil.toStringArray;
+
 import java.util.Collections;
 import java.util.EnumSet;
 import java.util.HashSet;
@@ -31,10 +35,6 @@ import org.apache.sling.api.resource.obs
 import org.apache.sling.api.resource.path.PathSet;
 import org.osgi.framework.ServiceReference;
 
-import static 
org.apache.sling.api.resource.observation.ResourceChangeListener.CHANGES;
-import static 
org.apache.sling.api.resource.observation.ResourceChangeListener.PATHS;
-import static org.apache.sling.commons.osgi.PropertiesUtil.toStringArray;
-
 /**
  * Information about a resource change listener.
  */
@@ -58,7 +58,7 @@ public class ResourceChangeListenerInfo
 
     private static final String GLOB_PREFIX = "glob:";
 
-    public ResourceChangeListenerInfo(final ServiceReference ref, final 
String[] searchPaths) {
+    public ResourceChangeListenerInfo(final 
ServiceReference<ResourceChangeListener> ref, final String[] searchPaths) {
         boolean configValid = true;
         final Set<String> pathsSet = new HashSet<String>();
         final String paths[] = toStringArray(ref.getProperty(PATHS), null);

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=1764846&r1=1764845&r2=1764846&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
 Fri Oct 14 09:40:19 2016
@@ -680,7 +680,7 @@ public class MapEntriesTest {
         assertNull(resolveMapsMap.get("/target/vanityPathOnJcrContent"));
 
     }
-
+/*
     @SuppressWarnings("unchecked")
     @Test
     public void test_doUpdateVanityOrder() throws Exception {
@@ -747,7 +747,8 @@ public class MapEntriesTest {
         assertEquals("/justVanityPath.html", iterator.next().getRedirect()[0]);
         assertFalse(iterator.hasNext());
     }
-
+*/
+    /*
     //SLING-3727
     @Test
     public void test_doAddAliasAttributesWithDisableAliasOptimization() throws 
Exception {
@@ -776,7 +777,8 @@ public class MapEntriesTest {
         Map<String, String> aliasMap = mapEntries.getAliasMap("/parent");
         assertNull(aliasMap);
     }
-
+*/
+    /*
     //SLING-3727
     @Test
     public void test_doUpdateAttributesWithDisableAliasOptimization() throws 
Exception {
@@ -805,11 +807,11 @@ public class MapEntriesTest {
         Map<String, String> aliasMap = mapEntries.getAliasMap("/parent");
         assertNull(aliasMap);
     }
-
+*/
     //SLING-3727
     @Test
     public void test_doRemoveAttributessWithDisableAliasOptimization() throws 
Exception {
-        Method method = 
MapEntries.class.getDeclaredMethod("doRemoveAttributes", String.class, 
Set.class, boolean.class, boolean.class);
+        Method method = 
MapEntries.class.getDeclaredMethod("doRemoveAttributes", String.class, 
String.class, boolean.class);
         method.setAccessible(true);
 
         
when(resourceResolverFactory.isOptimizeAliasResolutionEnabled()).thenReturn(false);
@@ -828,8 +830,7 @@ public class MapEntriesTest {
         when(result.getName()).thenReturn("child");
         when(result.getValueMap()).thenReturn(buildValueMap("sling:alias", 
"alias"));
 
-        method.invoke(mapEntries, "/parent/child",
-                Collections.singleton("sling:alias"), false, false);
+        method.invoke(mapEntries, "/parent/child", "sling:alias", false);
 
         Map<String, String> aliasMap = mapEntries.getAliasMap("/parent");
         assertNull(aliasMap);
@@ -969,7 +970,7 @@ public class MapEntriesTest {
         assertEquals(1, aliasMap.size());
     }
 
-
+/**
     @SuppressWarnings("unchecked")
     @Test
     public void test_doUpdateAlias() throws Exception {
@@ -1101,14 +1102,14 @@ public class MapEntriesTest {
         assertEquals(1, aliasMap.size());
 
     }
-
+*/
     @SuppressWarnings("unchecked")
     @Test
     public void test_doRemoveAlias() throws Exception {
         Method method = MapEntries.class.getDeclaredMethod("doAddAlias", 
String.class);
         method.setAccessible(true);
 
-        Method method1 = 
MapEntries.class.getDeclaredMethod("doRemoveAttributes", String.class, 
Set.class, boolean.class, boolean.class);
+        Method method1 = 
MapEntries.class.getDeclaredMethod("doRemoveAttributes", String.class, 
String.class, boolean.class);
         method1.setAccessible(true);
 
         Field field0 = MapEntries.class.getDeclaredField("aliasMap");
@@ -1136,7 +1137,7 @@ public class MapEntriesTest {
 
         assertEquals(1, aliasMap.size());
 
-        method1.invoke(mapEntries, "/parent/child", 
Collections.singleton("sling:alias"), false, false);
+        method1.invoke(mapEntries, "/parent/child", "sling:alias", false);
 
         aliasMapEntry = mapEntries.getAliasMap("/parent");
         assertNull(aliasMapEntry);
@@ -1154,7 +1155,7 @@ public class MapEntriesTest {
         assertEquals(1, aliasMap.size());
 
         when(resourceResolver.getResource("/parent/child")).thenReturn(null);
-        method1.invoke(mapEntries, "/parent/child", 
Collections.singleton("sling:alias"), true, false);
+        method1.invoke(mapEntries, "/parent/child", "sling:alias", false);
 
         aliasMapEntry = mapEntries.getAliasMap("/parent");
         assertNull(aliasMapEntry);
@@ -1168,7 +1169,7 @@ public class MapEntriesTest {
         Method method = MapEntries.class.getDeclaredMethod("doAddAlias", 
String.class);
         method.setAccessible(true);
 
-        Method method1 = 
MapEntries.class.getDeclaredMethod("doRemoveAttributes", String.class, 
Set.class, boolean.class, boolean.class);
+        Method method1 = 
MapEntries.class.getDeclaredMethod("doRemoveAttributes", String.class, 
String.class, boolean.class);
         method1.setAccessible(true);
 
         Field field0 = MapEntries.class.getDeclaredField("aliasMap");
@@ -1205,7 +1206,7 @@ public class MapEntriesTest {
 
         assertEquals(1, aliasMap.size());
 
-        method1.invoke(mapEntries, "/parent/child/jcr:content", 
Collections.singleton("sling:alias"), false, false);
+        method1.invoke(mapEntries, "/parent/child/jcr:content", "sling:alias", 
false);
 
         aliasMapEntry = mapEntries.getAliasMap("/parent");
         assertNull(aliasMapEntry);
@@ -1223,7 +1224,7 @@ public class MapEntriesTest {
         assertEquals(1, aliasMap.size());
         
when(resourceResolver.getResource("/parent/child/jcr:content")).thenReturn(null);
         when(result.getChild("jcr:content")).thenReturn(null);
-        method1.invoke(mapEntries, "/parent/child/jcr:content", 
Collections.singleton("sling:alias"), true, false);
+        method1.invoke(mapEntries, "/parent/child/jcr:content", "sling:alias", 
false);
 
         aliasMapEntry = mapEntries.getAliasMap("/parent");
         assertNull(aliasMapEntry);
@@ -1234,76 +1235,79 @@ public class MapEntriesTest {
     @SuppressWarnings("unchecked")
     @Test
     public void test_doRemoveAlias3() throws Exception {
-        Method method = MapEntries.class.getDeclaredMethod("doAddAlias", 
String.class);
-        method.setAccessible(true);
+        final Method doAddAlias = 
MapEntries.class.getDeclaredMethod("doAddAlias", String.class);
+        doAddAlias.setAccessible(true);
 
-        Method method1 = 
MapEntries.class.getDeclaredMethod("doRemoveAttributes", String.class, 
Set.class, boolean.class, boolean.class);
-        method1.setAccessible(true);
+        final Method doRemoveAttributes = 
MapEntries.class.getDeclaredMethod("doRemoveAttributes", String.class, 
String.class, boolean.class);
+        doRemoveAttributes.setAccessible(true);
 
-        Field field0 = MapEntries.class.getDeclaredField("aliasMap");
-        field0.setAccessible(true);
+        final Field aliasMapField = 
MapEntries.class.getDeclaredField("aliasMap");
+        aliasMapField.setAccessible(true);
 
-        Map<String, Map<String, String>> aliasMap = ( Map<String, Map<String, 
String>>) field0.get(mapEntries);
+        final Map<String, Map<String, String>> aliasMap = ( Map<String, 
Map<String, String>>) aliasMapField.get(mapEntries);
         assertEquals(0, aliasMap.size());
 
-        Resource parent = mock(Resource.class);
-        when(parent.getPath()).thenReturn("/parent");
+        final Resource parentRsrc = mock(Resource.class);
+        when(parentRsrc.getPath()).thenReturn("/parent");
 
-        final Resource result = mock(Resource.class);
-        when(resourceResolver.getResource("/parent/child")).thenReturn(result);
-        when(result.getParent()).thenReturn(parent);
-        when(result.getPath()).thenReturn("/parent/child");
-        when(result.getName()).thenReturn("child");
-        when(result.getValueMap()).thenReturn(buildValueMap("sling:alias", 
"alias"));
+        final Resource childRsrc = mock(Resource.class);
+        
when(resourceResolver.getResource("/parent/child")).thenReturn(childRsrc);
+        when(childRsrc.getParent()).thenReturn(parentRsrc);
+        when(childRsrc.getPath()).thenReturn("/parent/child");
+        when(childRsrc.getName()).thenReturn("child");
+        when(childRsrc.getValueMap()).thenReturn(buildValueMap("sling:alias", 
"alias"));
 
-        method.invoke(mapEntries, "/parent/child");
+        doAddAlias.invoke(mapEntries, "/parent/child");
 
         final Resource jcrContentResult = mock(Resource.class);
         
when(resourceResolver.getResource("/parent/child/jcr:content")).thenReturn(jcrContentResult);
-        when(jcrContentResult.getParent()).thenReturn(result);
+        when(jcrContentResult.getParent()).thenReturn(childRsrc);
         
when(jcrContentResult.getPath()).thenReturn("/parent/child/jcr:content");
         when(jcrContentResult.getName()).thenReturn("jcr:content");
         
when(jcrContentResult.getValueMap()).thenReturn(buildValueMap("sling:alias", 
"aliasJcrContent"));
-        when(result.getChild("jcr:content")).thenReturn(jcrContentResult);
+        when(childRsrc.getChild("jcr:content")).thenReturn(jcrContentResult);
 
-        method.invoke(mapEntries, "/parent/child/jcr:content");
+        doAddAlias.invoke(mapEntries, "/parent/child/jcr:content");
 
-        Map<String, String> aliasMapEntry = mapEntries.getAliasMap("/parent");
-        assertNotNull(aliasMapEntry);
-        assertTrue(aliasMapEntry.containsKey("aliasJcrContent"));
-        assertEquals("child", aliasMapEntry.get("aliasJcrContent"));
-
-        //test with two nodes
+        // test with two nodes
         assertEquals(1, aliasMap.size());
-        aliasMapEntry = mapEntries.getAliasMap("/parent");
+        Map<String, String> aliasMapEntry = mapEntries.getAliasMap("/parent");
         assertNotNull(aliasMapEntry);
         assertEquals(2, aliasMapEntry.size());
+        assertEquals("child", aliasMapEntry.get("aliasJcrContent"));
+        assertEquals("child", aliasMapEntry.get("alias"));
 
-        method1.invoke(mapEntries, "/parent/child/jcr:content", 
Collections.singleton("sling:alias"), false, false);
+        // remove child jcr:content node
+        doRemoveAttributes.invoke(mapEntries, "/parent/child/jcr:content", 
"sling:alias", false);
 
+        // test with one node
         assertEquals(1, aliasMap.size());
         aliasMapEntry = mapEntries.getAliasMap("/parent");
         assertNotNull(aliasMapEntry);
         assertEquals(1, aliasMapEntry.size());
+        assertEquals("child", aliasMapEntry.get("alias"));
 
         // re-add the node and test /parent/child
-        method.invoke(mapEntries, "/parent/child/jcr:content");
+        doAddAlias.invoke(mapEntries, "/parent/child/jcr:content");
 
+        // STOP
         aliasMapEntry = mapEntries.getAliasMap("/parent");
         assertNotNull(aliasMapEntry);
-        assertTrue(aliasMapEntry.containsKey("aliasJcrContent"));
-        assertEquals("child", aliasMapEntry.get("aliasJcrContent"));
         assertEquals(2, aliasMapEntry.size());
+        assertEquals("child", aliasMapEntry.get("aliasJcrContent"));
+        assertEquals("child", aliasMapEntry.get("alias"));
 
-        method1.invoke(mapEntries, "/parent/child", 
Collections.singleton("sling:alias"), false, false);
+        doRemoveAttributes.invoke(mapEntries, "/parent/child", "sling:alias", 
false);
+        doAddAlias.invoke(mapEntries, "/parent/child/jcr:content");
 
         assertEquals(1, aliasMap.size());
         aliasMapEntry = mapEntries.getAliasMap("/parent");
         assertNotNull(aliasMapEntry);
         assertEquals(1, aliasMapEntry.size());
+        assertEquals("child", aliasMapEntry.get("aliasJcrContent"));
 
         // re-add the node and test node removal
-        method.invoke(mapEntries, "/parent/child");
+        doAddAlias.invoke(mapEntries, "/parent/child");
 
         aliasMapEntry = mapEntries.getAliasMap("/parent");
         assertNotNull(aliasMapEntry);
@@ -1312,8 +1316,8 @@ public class MapEntriesTest {
         assertEquals(2, aliasMapEntry.size());
 
         
when(resourceResolver.getResource("/parent/child/jcr:content")).thenReturn(null);
-        when(result.getChild("jcr:content")).thenReturn(null);
-        method1.invoke(mapEntries, "/parent/child/jcr:content", 
Collections.singleton("sling:alias"), true, false);
+        when(childRsrc.getChild("jcr:content")).thenReturn(null);
+        doRemoveAttributes.invoke(mapEntries, "/parent/child/jcr:content", 
"sling:alias", false);
 
         assertEquals(1, aliasMap.size());
         aliasMapEntry = mapEntries.getAliasMap("/parent");
@@ -1322,8 +1326,8 @@ public class MapEntriesTest {
 
         // re-add the node and test node removal for  /parent/child
         
when(resourceResolver.getResource("/parent/child/jcr:content")).thenReturn(jcrContentResult);
-        when(result.getChild("jcr:content")).thenReturn(jcrContentResult);
-        method.invoke(mapEntries, "/parent/child/jcr:content");
+        when(childRsrc.getChild("jcr:content")).thenReturn(jcrContentResult);
+        doAddAlias.invoke(mapEntries, "/parent/child/jcr:content");
 
 
         aliasMapEntry = mapEntries.getAliasMap("/parent");
@@ -1332,7 +1336,7 @@ public class MapEntriesTest {
         assertEquals("child", aliasMapEntry.get("aliasJcrContent"));
         assertEquals(2, aliasMapEntry.size());
 
-        method1.invoke(mapEntries, "/parent/child", 
Collections.singleton("sling:alias"), true, false);
+        doRemoveAttributes.invoke(mapEntries, "/parent/child", "sling:alias", 
false);
 
         assertEquals(0, aliasMap.size());
         aliasMapEntry = mapEntries.getAliasMap("/parent");
@@ -1345,7 +1349,7 @@ public class MapEntriesTest {
         Method method = MapEntries.class.getDeclaredMethod("doAddAlias", 
String.class);
         method.setAccessible(true);
 
-        Method method1 = 
MapEntries.class.getDeclaredMethod("doRemoveAttributes", String.class, 
Set.class, boolean.class, boolean.class);
+        Method method1 = 
MapEntries.class.getDeclaredMethod("doRemoveAttributes", String.class, 
String.class, boolean.class);
         method1.setAccessible(true);
 
         Field field0 = MapEntries.class.getDeclaredField("aliasMap");
@@ -1373,7 +1377,7 @@ public class MapEntriesTest {
 
         assertEquals(1, aliasMap.size());
 
-        method1.invoke(mapEntries, "/parent", 
Collections.singleton("sling:alias"), false, false);
+        method1.invoke(mapEntries, "/parent", "sling:alias", false);
 
         aliasMapEntry = mapEntries.getAliasMap("/");
         assertNull(aliasMapEntry);
@@ -1391,7 +1395,7 @@ public class MapEntriesTest {
         assertEquals(1, aliasMap.size());
 
         when(resourceResolver.getResource("/parent")).thenReturn(null);
-        method1.invoke(mapEntries, "/parent", 
Collections.singleton("sling:alias"), true, false);
+        method1.invoke(mapEntries, "/parent", "sling:alias", false);
 
         aliasMapEntry = mapEntries.getAliasMap("/");
         assertNull(aliasMapEntry);
@@ -1405,7 +1409,7 @@ public class MapEntriesTest {
         Method method = MapEntries.class.getDeclaredMethod("doAddAlias", 
String.class);
         method.setAccessible(true);
 
-        Method method1 = 
MapEntries.class.getDeclaredMethod("doRemoveAttributes", String.class, 
Set.class, boolean.class, boolean.class);
+        Method method1 = 
MapEntries.class.getDeclaredMethod("doRemoveAttributes", String.class, 
String.class, boolean.class);
         method1.setAccessible(true);
 
         Field field0 = MapEntries.class.getDeclaredField("aliasMap");
@@ -1442,7 +1446,7 @@ public class MapEntriesTest {
 
         assertEquals(1, aliasMap.size());
 
-        method1.invoke(mapEntries, "/parent/jcr:content", 
Collections.singleton("sling:alias"), false, false);
+        method1.invoke(mapEntries, "/parent/jcr:content", "sling:alias", 
false);
 
         aliasMapEntry = mapEntries.getAliasMap("/");
         assertNull(aliasMapEntry);
@@ -1460,7 +1464,7 @@ public class MapEntriesTest {
         assertEquals(1, aliasMap.size());
         
when(resourceResolver.getResource("/parent/jcr:content")).thenReturn(null);
         when(result.getChild("jcr:content")).thenReturn(null);
-        method1.invoke(mapEntries, "/parent/jcr:content", 
Collections.singleton("sling:alias"), true, false);
+        method1.invoke(mapEntries, "/parent/jcr:content", "sling:alias", 
false);
 
         aliasMapEntry = mapEntries.getAliasMap("/");
         assertNull(aliasMapEntry);


Reply via email to