Author: cziegeler
Date: Fri Oct 14 14:08:08 2016
New Revision: 1764903

URL: http://svn.apache.org/viewvc?rev=1764903&view=rev
Log:
SLING-6153 : Improve MapEntries implementation

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=1764903&r1=1764902&r2=1764903&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 14:08:08 2016
@@ -260,45 +260,76 @@ public class MapEntries implements
 
     }
 
-    private void doNodeAdded(String path, final AtomicBoolean 
resolverRefreshed) {
+    private boolean addResource(final String path, final AtomicBoolean 
resolverRefreshed) {
         this.refreshResolverIfNecessary(resolverRefreshed);
 
         this.initializing.lock();
         try {
-            Resource resource = resolver.getResource(path);
+            final Resource resource = resolver.getResource(path);
             if (resource != null) {
+                boolean changed = false;
                 final ValueMap props = resource.getValueMap();
                 if (props.containsKey(PROP_VANITY_PATH)) {
-                    doAddVanity(path);
+                    changed |= doAddVanity(resource, props);
                 }
                 if (props.containsKey(ResourceResolverImpl.PROP_ALIAS)) {
-                    doAddAlias(path);
+                    changed |= doAddAlias(resource);
                 }
-                if (path.startsWith(this.factory.getMapRoot())) {
-                    doUpdateConfiguration();
+                return changed;
+            }
+
+            return false;
+        } finally {
+            this.initializing.unlock();
+        }
+    }
+
+    private boolean updateResource(final String path, final AtomicBoolean 
resolverRefreshed) {
+        this.refreshResolverIfNecessary(resolverRefreshed);
+
+        this.initializing.lock();
+        try {
+            final Resource resource = resolver.getResource(path);
+            if (resource != null) {
+                boolean changed = false;
+                final ValueMap props = resource.getValueMap();
+
+                changed |= doRemoveVanity(path);
+                if (props.containsKey(PROP_VANITY_PATH)) {
+                    changed |= doAddVanity(resource, props);
+                }
+
+                if (this.factory.isOptimizeAliasResolutionEnabled()) {
+                    changed |= doRemoveAlias(path, resource, props);
+                    if (props.containsKey(ResourceResolverImpl.PROP_ALIAS)) {
+                        changed |= doAddAlias(resource);
+                    }
                 }
+
+                return changed;
             }
-            sendChangeEvent();
 
+            return false;
         } finally {
             this.initializing.unlock();
         }
     }
 
     /**
-     * Remove all aliases for the vanity path
-     * @param vanityPath The vanity path
-     * @param refreshed Flag if session needs refresh
+     * Remove all aliases for the content path
+     * @param contentPath The content path
      * @param path Optional sub path of the vanity path
-     * @return
+     * @param refreshed Flag if session needs refresh
+     * @return {@code true} if a change happened
      */
-    private boolean doRemoveAllAliases(final String vanityPath, AtomicBoolean 
resolverRefreshed, final String path) {
+    private boolean removeAlias(final String contentPath, final String path, 
final AtomicBoolean resolverRefreshed) {
         // if path is specified we first need to find out if it is
         // a direct child of vanity path but not jcr:content, or a jcr:content 
child of a direct child
         // otherwise we can discard the event
         boolean handle = true;
+        String addParentPath = null;
         if ( path != null ) {
-            final String subPath = path.substring(vanityPath.length() + 1);
+            final String subPath = path.substring(contentPath.length() + 1);
             final int firstSlash = subPath.indexOf('/');
             if ( firstSlash == -1 ) {
                 if ( subPath.equals(JCR_CONTENT) ) {
@@ -308,6 +339,7 @@ public class MapEntries implements
                 if ( subPath.startsWith(JCR_CONTENT_PREFIX) || 
!subPath.endsWith(JCR_CONTENT_SUFFIX) ) {
                     handle = false;
                 }
+                addParentPath = ResourceUtil.getParent(path);
             } else {
                 handle = false;
             }
@@ -316,57 +348,32 @@ public class MapEntries implements
             return false;
         }
 
-        this.initializing.lock();
-        try {
-            if (this.factory.isOptimizeAliasResolutionEnabled()) {
-                final Map<String, String> aliasMapEntry = 
aliasMap.remove(vanityPath);
-                if (aliasMapEntry != null && path != null && 
path.endsWith(JCR_CONTENT_SUFFIX) ) {
+        if (this.factory.isOptimizeAliasResolutionEnabled()) {
+            this.initializing.lock();
+            try {
+                final Map<String, String> aliasMapEntry = 
aliasMap.remove(contentPath);
+                if (aliasMapEntry != null && addParentPath != null ) {
                     this.refreshResolverIfNecessary(resolverRefreshed);
                     // we need to re-add
                     // from a potential parent
-                    doAddAlias(ResourceUtil.getParent(path));
+                    final Resource parent = 
this.resolver.getResource(addParentPath);
+                    if ( parent != null && 
parent.getValueMap().containsKey(ResourceResolverImpl.PROP_ALIAS)) {
+                        doAddAlias(parent);
+                    }
                 }
                 return aliasMapEntry != null;
+            } finally {
+                this.initializing.unlock();
             }
-
-        } finally {
-            this.initializing.unlock();
         }
-        return false;
-    }
 
-    private void doRemoveAttributes(String path, String removedAttribute, 
final AtomicBoolean resolverRefreshed) {
-        this.refreshResolverIfNecessary(resolverRefreshed);
-        this.initializing.lock();
-        try {
-            if (PROP_VANITY_PATH.equals(removedAttribute)){
-                doRemoveVanity(path);
-            } else if 
(ResourceResolverImpl.PROP_ALIAS.equals(removedAttribute)) {
-                if (this.factory.isOptimizeAliasResolutionEnabled()) {
-                    doRemoveAlias(path, true);
-                    if ( path.endsWith("/jcr:content") ) {
-                        // as doRemoveAlias removes all aliases we need to 
re-add
-                        // from a potential parent
-                        doAddAlias(ResourceUtil.getParent(path));
-                    }
-                }
-            }
-
-            if (path.startsWith(this.factory.getMapRoot())) {
-                doUpdateConfiguration();
-            }
-            sendChangeEvent();
-        } finally {
-            this.initializing.unlock();
-        }
+        return false;
     }
 
-    private void doUpdateConfiguration(final AtomicBoolean resolverRefreshed) {
-        this.refreshResolverIfNecessary(resolverRefreshed);
+    private boolean removeVanityPath(final String path) {
         this.initializing.lock();
         try {
-            doUpdateConfiguration();
-            sendChangeEvent();
+            return doRemoveVanity(path);
         } finally {
             this.initializing.unlock();
         }
@@ -391,9 +398,9 @@ public class MapEntries implements
         this.mapMaps = Collections.unmodifiableSet(new 
TreeSet<MapEntry>(newMapMaps.values()));
     }
 
-    private boolean doAddVanity(String path) {
-        log.debug("doAddVanity getting {}", path);
-        Resource resource = resolver.getResource(path);
+    private boolean doAddVanity(final Resource resource, final ValueMap props) 
{
+        log.debug("doAddVanity getting {}", resource.getPath());
+
         boolean needsUpdate = false;
         if (isAllVanityPathEntriesCached() || vanityCounter.longValue() < 
this.factory.getMaxCachedVanityPathEntries()) {
             // fill up the cache and the bloom filter
@@ -409,23 +416,16 @@ public class MapEntries implements
         return false;
     }
 
-    private boolean doUpdateVanity(String path) {
-         boolean changed = doRemoveVanity(path);
-         changed |= doAddVanity(path);
-
-         return changed;
-    }
-
-    private boolean doRemoveVanity(String path) {
-        String actualContentPath = getActualContentPath(path);
-        List <String> l = vanityTargets.remove(actualContentPath);
+    private boolean doRemoveVanity(final String path) {
+        final String actualContentPath = getActualContentPath(path);
+        final List <String> l = vanityTargets.remove(actualContentPath);
         if (l != null){
-            for (String s : l){
-                List<MapEntry> entries = this.resolveMapsMap.get(s);
+            for (final String s : l){
+                final List<MapEntry> entries = this.resolveMapsMap.get(s);
                 if (entries!= null) {
-                    for (Iterator<MapEntry> iterator =entries.iterator(); 
iterator.hasNext(); ) {
-                        MapEntry entry = iterator.next();
-                        String redirect = getMapEntryRedirect(entry);
+                    for (final Iterator<MapEntry> iterator 
=entries.iterator(); iterator.hasNext(); ) {
+                        final MapEntry entry = iterator.next();
+                        final String redirect = getMapEntryRedirect(entry);
                         if (redirect != null && 
redirect.equals(actualContentPath)) {
                             iterator.remove();
                         }
@@ -443,53 +443,14 @@ public class MapEntries implements
         return false;
     }
 
-    private boolean doAddAlias(String path) {
-        Resource resource = resolver.getResource(path);
+    private boolean doAddAlias(final Resource resource) {
         return loadAlias(resource, this.aliasMap);
     }
 
-    private boolean doUpdateAlias(String path, boolean nodeDeletion) {
-        if (nodeDeletion){
-            if (path.endsWith("/jcr:content")) {
-                path =  path.substring(0, path.length() - 
"/jcr:content".length());
-                final Resource resource = resolver.getResource(path);
-                if (resource != null) {
-                    path =  resource.getPath();
-                    final ValueMap props = resource.getValueMap();
-                    if (props.get(ResourceResolverImpl.PROP_ALIAS, 
String[].class) != null) {
-                        doAddAlias(path);
-                        return true;
-                    }
-                }
-            }
-        } else {
-            final Resource resource = resolver.getResource(path);
-            if (resource != null) {
-                if (resource.getName().equals("jcr:content")) {
-                    final Resource parent = resource.getParent();
-                    path =  parent.getPath();
-                    final ValueMap props = parent.getValueMap();
-                    if (props.get(ResourceResolverImpl.PROP_ALIAS, 
String[].class) != null) {
-                        doAddAlias(path);
-                        return true;
-                    }
-                } else if (resource.getChild("jcr:content") != null) {
-                    Resource jcrContent = resource.getChild("jcr:content");
-                    path =  jcrContent.getPath();
-                    final ValueMap props = jcrContent.getValueMap();
-                    if (props.get(ResourceResolverImpl.PROP_ALIAS, 
String[].class) != null) {
-                        doAddAlias(path);
-                        return true;
-                    }
-                }
-            }
-        }
-        return false;
-    }
 
-    private boolean doRemoveAlias(String path, boolean nodeDeletion) {
+    private boolean doRemoveAlias(String path, final Resource resource, final 
ValueMap props) {
         String resourceName = null;
-        if (nodeDeletion) {
+        if (resource == null) {
             if (!"/".equals(path)){
                 if (path.endsWith("/jcr:content")) {
                     path = ResourceUtil.getParent(path);
@@ -500,7 +461,6 @@ public class MapEntries implements
                 resourceName = "";
             }
         } else {
-            final Resource resource = resolver.getResource(path);
             if (resource.getName().equals("jcr:content")) {
                 final Resource containingResource = resource.getParent();
                 if ( containingResource != null ) {
@@ -657,17 +617,35 @@ public class MapEntries implements
         return mapEntries;
     }
 
+    /**
+     * Refresh the resource resolver if not already done
+     * @param resolverRefreshed Boolean flag containing the state if the 
resolver
+     *                          has been refreshed. True in any case when this
+     *                          method returns
+     */
     private void refreshResolverIfNecessary(final AtomicBoolean 
resolverRefreshed) {
         if ( resolverRefreshed.compareAndSet(false, true) ) {
             this.resolver.refresh();
         }
     }
 
+    /**
+     * Checks if the path affects the map configuration. If it does
+     * the configuration is updated.
+     * @param path The changed path (could be add/remove/update)
+     * @param resolverRefreshed Boolean flag handling resolver refresh
+     * @return {@code true} if the configuration has been updated.
+     */
     private boolean handleConfigurationUpdate(final String path, final 
AtomicBoolean resolverRefreshed) {
         if ( this.factory.isMapConfiguration(path) ) {
             refreshResolverIfNecessary(resolverRefreshed);
 
-            doUpdateConfiguration();
+            this.initializing.lock();
+            try {
+                doUpdateConfiguration();
+            } finally {
+                this.initializing.unlock();
+            }
 
             return true;
         }
@@ -685,9 +663,9 @@ public class MapEntries implements
     @Override
     public void onChange(final List<ResourceChange> changes) {
         final AtomicBoolean resolverRefreshed = new AtomicBoolean(false);
-        boolean changed = false;
 
         for(final ResourceChange rc : changes) {
+
             final String path = rc.getPath();
             log.debug("onChange, type={}, path={}", rc.getType(), path);
 
@@ -696,6 +674,7 @@ public class MapEntries implements
                 continue;
             }
 
+            boolean changed = false;
             // removal of a resource is handled differently
             if (rc.getType() == ResourceChange.ChangeType.REMOVED) {
 
@@ -708,50 +687,39 @@ public class MapEntries implements
 
                     for (final String target : this.vanityTargets.keySet()) {
                         if (target.startsWith(actualContentPathPrefix) || 
target.equals(actualContentPath)) {
-                            doRemoveAttributes(target, PROP_VANITY_PATH, 
resolverRefreshed);
+                            changed |= removeVanityPath(target);
                         }
                     }
-                    for (final String target : this.aliasMap.keySet()) {
-                        if (path.startsWith(target + "/") || 
path.equals(target)) {
-                            changed |= doRemoveAllAliases(target, 
resolverRefreshed, null);
-                        } else if ( target.startsWith(actualContentPathPrefix) 
) {
-                            changed |= doRemoveAllAliases(target, 
resolverRefreshed, path);
+                    for (final String contentPath : this.aliasMap.keySet()) {
+                        if (path.startsWith(contentPath + "/") || 
path.equals(contentPath)) {
+                            changed |= removeAlias(contentPath, null, 
resolverRefreshed);
+                        } else if ( 
contentPath.startsWith(actualContentPathPrefix) ) {
+                            changed |= removeAlias(contentPath, path, 
resolverRefreshed);
                         }
                     }
-                    if (path.startsWith(this.factory.getMapRoot())) {
-                        //need to update the configuration
-                        doUpdateConfiguration(resolverRefreshed);
-                    }
                 }
+
             //session.move() is handled differently see also SLING-3713 and
             } else if (rc.getType() == ResourceChange.ChangeType.ADDED ) {
-               doNodeAdded(path, resolverRefreshed);
+
+                if ( handleConfigurationUpdate(path, resolverRefreshed) ) {
+                    changed = true;
+                } else {
+                    changed |= addResource(path, resolverRefreshed);
+                }
+
             } else {
                 if (handleConfigurationUpdate(path, resolverRefreshed)) {
                     changed = true;
                 } else {
-                    this.refreshResolverIfNecessary(resolverRefreshed);
-                    this.initializing.lock();
-                    try {
-                        changed |= doUpdateVanity(path);
-                        if (this.factory.isOptimizeAliasResolutionEnabled()) {
-                            changed |= doRemoveAlias(path, false);
-                            changed |= doAddAlias(path);
-                            changed |= doUpdateAlias(path, false);
-                        }
-                    } finally {
-                        this.initializing.unlock();
-                    }
-
-                    if ( changed ) {
-                        this.sendChangeEvent();
-                    }
+                    changed |= updateResource(path, resolverRefreshed);
                 }
 
             }
-        }
-        if ( changed ) {
-            this.sendChangeEvent();
+
+            if ( changed ) {
+                this.sendChangeEvent();
+            }
         }
     }
 
@@ -887,7 +855,7 @@ public class MapEntries implements
         return checkPath;
     }
 
-    private String getMapEntryRedirect(MapEntry mapEntry) {
+    private String getMapEntryRedirect(final  MapEntry mapEntry) {
         String[] redirect = mapEntry.getRedirect();
         if (redirect.length > 1) {
             log.warn("something went wrong, please restart the bundle");

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=1764903&r1=1764902&r2=1764903&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 14:08:08 2016
@@ -52,6 +52,7 @@ import org.apache.sling.api.resource.Res
 import org.apache.sling.api.resource.ResourceUtil;
 import org.apache.sling.api.resource.ValueMap;
 import org.apache.sling.api.wrappers.ValueMapDecorator;
+import org.apache.sling.resourceresolver.impl.ResourceResolverImpl;
 import 
org.apache.sling.resourceresolver.impl.mapping.MapConfigurationProvider.VanityPathConfig;
 import org.junit.After;
 import org.junit.Before;
@@ -85,7 +86,9 @@ public class MapEntriesTest {
     @Mock
     private EventAdmin eventAdmin;
 
-    @SuppressWarnings("deprecation")
+    private Map<String, Map<String, String>> aliasMap;
+
+    @SuppressWarnings({ "deprecation", "unchecked" })
     @Before
     public void setup() throws Exception {
         MockitoAnnotations.initMocks(this);
@@ -119,6 +122,10 @@ public class MapEntriesTest {
                 Collections.<Resource> emptySet().iterator());
 
         mapEntries = new MapEntries(resourceResolverFactory, bundleContext, 
eventAdmin);
+        final Field aliasMapField = 
MapEntries.class.getDeclaredField("aliasMap");
+        aliasMapField.setAccessible(true);
+
+        this.aliasMap = ( Map<String, Map<String, String>>) 
aliasMapField.get(mapEntries);
     }
 
     @After
@@ -126,6 +133,7 @@ public class MapEntriesTest {
         vanityBloomFilterFile.delete();
     }
 
+
     @Test
     public void test_simple_alias_support() {
         Resource parent = mock(Resource.class);
@@ -382,8 +390,8 @@ public class MapEntriesTest {
         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);
+        final Method addResource = 
MapEntries.class.getDeclaredMethod("addResource", String.class, 
AtomicBoolean.class);
+        addResource.setAccessible(true);
 
         Resource justVanityPath = mock(Resource.class, "justVanityPath");
         
when(resourceResolver.getResource("/justVanityPath")).thenReturn(justVanityPath);
@@ -391,7 +399,7 @@ public class MapEntriesTest {
         when(justVanityPath.getName()).thenReturn("justVanityPath");
         
when(justVanityPath.getValueMap()).thenReturn(buildValueMap("sling:vanityPath", 
"/target/justVanityPath"));
 
-        method.invoke(mapEntries, "/justVanityPath");
+        addResource.invoke(mapEntries, "/justVanityPath", new AtomicBoolean());
 
         entries = mapEntries.getResolveMaps();
         assertEquals(2, entries.size());
@@ -408,7 +416,7 @@ public class MapEntriesTest {
         when(badVanityPath.getName()).thenReturn("badVanityPath");
         
when(badVanityPath.getValueMap()).thenReturn(buildValueMap("sling:vanityPath", 
"/content/mypage/en-us-{132"));
 
-        method.invoke(mapEntries, "/badVanityPath");
+        addResource.invoke(mapEntries, "/badVanityPath", new AtomicBoolean());
 
 
         assertEquals(2, entries.size());
@@ -428,7 +436,7 @@ public class MapEntriesTest {
         
when(vanityPathOnJcrContent.getParent()).thenReturn(vanityPathOnJcrContentParent);
         
when(vanityPathOnJcrContent.getValueMap()).thenReturn(buildValueMap("sling:vanityPath",
 "/target/vanityPathOnJcrContent"));
 
-        method.invoke(mapEntries, "/vanityPathOnJcrContent/jcr:content");
+        addResource.invoke(mapEntries, "/vanityPathOnJcrContent/jcr:content", 
new AtomicBoolean());
 
         entries = mapEntries.getResolveMaps();
         assertEquals(4, entries.size());
@@ -455,8 +463,8 @@ public class MapEntriesTest {
         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);
+        final Method addResource = 
MapEntries.class.getDeclaredMethod("addResource", String.class, 
AtomicBoolean.class);
+        addResource.setAccessible(true);
 
         Resource justVanityPath = mock(Resource.class, "justVanityPath");
         
when(resourceResolver.getResource("/justVanityPath")).thenReturn(justVanityPath);
@@ -464,7 +472,7 @@ public class MapEntriesTest {
         when(justVanityPath.getName()).thenReturn("justVanityPath");
         
when(justVanityPath.getValueMap()).thenReturn(buildValueMap("sling:vanityPath", 
"/target/justVanityPath"));
 
-        method.invoke(mapEntries, "/justVanityPath");
+        addResource.invoke(mapEntries, "/justVanityPath", new AtomicBoolean());
 
         entries = mapEntries.getResolveMaps();
         assertEquals(2, entries.size());
@@ -481,7 +489,7 @@ public class MapEntriesTest {
         when(badVanityPath.getName()).thenReturn("badVanityPath");
         
when(badVanityPath.getValueMap()).thenReturn(buildValueMap("sling:vanityPath", 
"/content/mypage/en-us-{132"));
 
-        method.invoke(mapEntries, "/badVanityPath");
+        addResource.invoke(mapEntries, "/badVanityPath", new AtomicBoolean());
 
 
         assertEquals(2, entries.size());
@@ -501,7 +509,7 @@ public class MapEntriesTest {
         
when(vanityPathOnJcrContent.getParent()).thenReturn(vanityPathOnJcrContentParent);
         
when(vanityPathOnJcrContent.getValueMap()).thenReturn(buildValueMap("sling:vanityPath",
 "/target/vanityPathOnJcrContent"));
 
-        method.invoke(mapEntries, "/vanityPathOnJcrContent/jcr:content");
+        addResource.invoke(mapEntries, "/vanityPathOnJcrContent/jcr:content", 
new AtomicBoolean());
 
         entries = mapEntries.getResolveMaps();
         assertEquals(4, entries.size());
@@ -530,11 +538,11 @@ public class MapEntriesTest {
         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);
+        final Method addResource = 
MapEntries.class.getDeclaredMethod("addResource", String.class, 
AtomicBoolean.class);
+        addResource.setAccessible(true);
 
-        Method method1 = MapEntries.class.getDeclaredMethod("doUpdateVanity", 
String.class);
-        method1.setAccessible(true);
+        final Method updateResource = 
MapEntries.class.getDeclaredMethod("updateResource", String.class, 
AtomicBoolean.class);
+        updateResource.setAccessible(true);
 
         Resource justVanityPath = mock(Resource.class, "justVanityPath");
         
when(resourceResolver.getResource("/justVanityPath")).thenReturn(justVanityPath);
@@ -542,7 +550,7 @@ public class MapEntriesTest {
         when(justVanityPath.getName()).thenReturn("justVanityPath");
         
when(justVanityPath.getValueMap()).thenReturn(buildValueMap("sling:vanityPath", 
"/target/justVanityPath"));
 
-        method.invoke(mapEntries, "/justVanityPath");
+        addResource.invoke(mapEntries, "/justVanityPath", new AtomicBoolean());
 
         assertEquals(2, resolveMapsMap.size());
         assertEquals(1, vanityTargets.size());
@@ -553,7 +561,7 @@ public class MapEntriesTest {
 
         //update vanity path
         
when(justVanityPath.getValueMap()).thenReturn(buildValueMap("sling:vanityPath", 
"/target/justVanityPathUpdated"));
-        method1.invoke(mapEntries, "/justVanityPath");
+        updateResource.invoke(mapEntries, "/justVanityPath", new 
AtomicBoolean());
 
         assertEquals(2, resolveMapsMap.size());
         assertEquals(1, vanityTargets.size());
@@ -574,7 +582,7 @@ public class MapEntriesTest {
         
when(vanityPathOnJcrContent.getParent()).thenReturn(vanityPathOnJcrContentParent);
         
when(vanityPathOnJcrContent.getValueMap()).thenReturn(buildValueMap("sling:vanityPath",
 "/target/vanityPathOnJcrContent"));
 
-        method.invoke(mapEntries, "/vanityPathOnJcrContent/jcr:content");
+        addResource.invoke(mapEntries, "/vanityPathOnJcrContent/jcr:content", 
new AtomicBoolean());
 
         assertEquals(3, resolveMapsMap.size());
         assertEquals(2, vanityTargets.size());
@@ -585,7 +593,7 @@ public class MapEntriesTest {
 
         //update vanity path
         
when(vanityPathOnJcrContent.getValueMap()).thenReturn(buildValueMap("sling:vanityPath",
 "/target/vanityPathOnJcrContentUpdated"));
-        method1.invoke(mapEntries, "/vanityPathOnJcrContent/jcr:content");
+        updateResource.invoke(mapEntries, 
"/vanityPathOnJcrContent/jcr:content", new AtomicBoolean());
 
         assertEquals(3, resolveMapsMap.size());
         assertEquals(2, vanityTargets.size());
@@ -608,8 +616,8 @@ public class MapEntriesTest {
         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);
+        final Method addResource = 
MapEntries.class.getDeclaredMethod("addResource", String.class, 
AtomicBoolean.class);
+        addResource.setAccessible(true);
 
         Method method1 = MapEntries.class.getDeclaredMethod("doRemoveVanity", 
String.class);
         method1.setAccessible(true);
@@ -620,7 +628,7 @@ public class MapEntriesTest {
         when(justVanityPath.getName()).thenReturn("justVanityPath");
         
when(justVanityPath.getValueMap()).thenReturn(buildValueMap("sling:vanityPath", 
"/target/justVanityPath"));
 
-        method.invoke(mapEntries, "/justVanityPath");
+        addResource.invoke(mapEntries, "/justVanityPath", new AtomicBoolean());
 
         Field vanityCounter = 
MapEntries.class.getDeclaredField("vanityCounter");
         vanityCounter.setAccessible(true);
@@ -654,7 +662,7 @@ public class MapEntriesTest {
         
when(vanityPathOnJcrContent.getParent()).thenReturn(vanityPathOnJcrContentParent);
         
when(vanityPathOnJcrContent.getValueMap()).thenReturn(buildValueMap("sling:vanityPath",
 "/target/vanityPathOnJcrContent"));
 
-        method.invoke(mapEntries, "/vanityPathOnJcrContent/jcr:content");
+        addResource.invoke(mapEntries, "/vanityPathOnJcrContent/jcr:content", 
new AtomicBoolean());
 
         assertEquals(2, resolveMapsMap.size());
         assertEquals(1, vanityTargets.size());
@@ -738,7 +746,7 @@ public class MapEntriesTest {
         assertFalse(iterator.hasNext());
     }
 */
-    /*
+
     //SLING-3727
     @Test
     public void test_doAddAliasAttributesWithDisableAliasOptimization() throws 
Exception {
@@ -767,8 +775,8 @@ public class MapEntriesTest {
         Map<String, String> aliasMap = mapEntries.getAliasMap("/parent");
         assertNull(aliasMap);
     }
-*/
-    /*
+
+
     //SLING-3727
     @Test
     public void test_doUpdateAttributesWithDisableAliasOptimization() throws 
Exception {
@@ -797,12 +805,12 @@ 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, 
String.class, AtomicBoolean.class);
-        method.setAccessible(true);
+        final Method removeAlias = 
MapEntries.class.getDeclaredMethod("removeAlias", String.class, String.class, 
AtomicBoolean.class);
+        removeAlias.setAccessible(true);
 
         
when(resourceResolverFactory.isOptimizeAliasResolutionEnabled()).thenReturn(false);
         
when(this.resourceResolverFactory.getMapRoot()).thenReturn(MapEntries.DEFAULT_MAP_ROOT);
@@ -818,22 +826,17 @@ public class MapEntriesTest {
         when(result.getName()).thenReturn("child");
         when(result.getValueMap()).thenReturn(buildValueMap("sling:alias", 
"alias"));
 
-        method.invoke(mapEntries, "/parent/child", "sling:alias", new 
AtomicBoolean());
+        removeAlias.invoke(mapEntries, "/parent", "/parent/child", new 
AtomicBoolean());
 
         Map<String, String> aliasMap = mapEntries.getAliasMap("/parent");
         assertNull(aliasMap);
     }
 
-    @SuppressWarnings("unchecked")
     @Test
     public void test_doAddAlias() throws Exception {
-        Method method = MapEntries.class.getDeclaredMethod("doAddAlias", 
String.class);
-        method.setAccessible(true);
+        final Method addResource = 
MapEntries.class.getDeclaredMethod("addResource", String.class, 
AtomicBoolean.class);
+        addResource.setAccessible(true);
 
-        Field field0 = MapEntries.class.getDeclaredField("aliasMap");
-        field0.setAccessible(true);
-
-        Map<String, Map<String, String>> aliasMap = ( Map<String, Map<String, 
String>>) field0.get(mapEntries);
         assertEquals(0, aliasMap.size());
 
         Resource parent = mock(Resource.class);
@@ -844,9 +847,9 @@ public class MapEntriesTest {
         when(result.getParent()).thenReturn(parent);
         when(result.getPath()).thenReturn("/parent/child");
         when(result.getName()).thenReturn("child");
-        when(result.getValueMap()).thenReturn(buildValueMap("sling:alias", 
"alias"));
+        
when(result.getValueMap()).thenReturn(buildValueMap(ResourceResolverImpl.PROP_ALIAS,
 "alias"));
 
-        method.invoke(mapEntries, "/parent/child");
+        addResource.invoke(mapEntries, "/parent/child", new AtomicBoolean());
 
         Map<String, String> aliasMapEntry = mapEntries.getAliasMap("/parent");
         assertNotNull(aliasMapEntry);
@@ -861,9 +864,9 @@ public class MapEntriesTest {
         when(secondResult.getParent()).thenReturn(parent);
         when(secondResult.getPath()).thenReturn("/parent/child2");
         when(secondResult.getName()).thenReturn("child2");
-        
when(secondResult.getValueMap()).thenReturn(buildValueMap("sling:alias", 
"alias"));
+        
when(secondResult.getValueMap()).thenReturn(buildValueMap(ResourceResolverImpl.PROP_ALIAS,
 "alias"));
 
-        method.invoke(mapEntries, "/parent/child2");
+        addResource.invoke(mapEntries, "/parent/child2", new AtomicBoolean());
 
         aliasMapEntry = mapEntries.getAliasMap("/parent");
         assertNotNull(aliasMapEntry);
@@ -878,9 +881,9 @@ public class MapEntriesTest {
         when(jcrContentResult.getParent()).thenReturn(result);
         
when(jcrContentResult.getPath()).thenReturn("/parent/child/jcr:content");
         when(jcrContentResult.getName()).thenReturn("jcr:content");
-        
when(jcrContentResult.getValueMap()).thenReturn(buildValueMap("sling:alias", 
"aliasJcrContent"));
+        
when(jcrContentResult.getValueMap()).thenReturn(buildValueMap(ResourceResolverImpl.PROP_ALIAS,
 "aliasJcrContent"));
 
-        method.invoke(mapEntries, "/parent/child/jcr:content");
+        addResource.invoke(mapEntries, "/parent/child/jcr:content", new 
AtomicBoolean());
 
         aliasMapEntry = mapEntries.getAliasMap("/parent");
         assertNotNull(aliasMapEntry);
@@ -891,16 +894,11 @@ public class MapEntriesTest {
         assertEquals(1, aliasMap.size());
     }
 
-    @SuppressWarnings("unchecked")
     @Test
     public void test_doAddAlias2() throws Exception {
-        Method method = MapEntries.class.getDeclaredMethod("doAddAlias", 
String.class);
-        method.setAccessible(true);
-
-        Field field0 = MapEntries.class.getDeclaredField("aliasMap");
-        field0.setAccessible(true);
+        final Method addResource = 
MapEntries.class.getDeclaredMethod("addResource", String.class, 
AtomicBoolean.class);
+        addResource.setAccessible(true);
 
-        Map<String, Map<String, String>> aliasMap = ( Map<String, Map<String, 
String>>) field0.get(mapEntries);
         assertEquals(0, aliasMap.size());
 
         Resource parent = mock(Resource.class);
@@ -913,7 +911,7 @@ public class MapEntriesTest {
         when(result.getName()).thenReturn("parent");
         when(result.getValueMap()).thenReturn(buildValueMap("sling:alias", 
"alias"));
 
-        method.invoke(mapEntries, "/parent");
+        addResource.invoke(mapEntries, "/parent", new AtomicBoolean());
 
         Map<String, String> aliasMapEntry = mapEntries.getAliasMap("/");
         assertNotNull(aliasMapEntry);
@@ -930,7 +928,7 @@ public class MapEntriesTest {
         when(secondResult.getName()).thenReturn("parent2");
         
when(secondResult.getValueMap()).thenReturn(buildValueMap("sling:alias", 
"alias"));
 
-        method.invoke(mapEntries, "/parent2");
+        addResource.invoke(mapEntries, "/parent2", new AtomicBoolean());
 
         aliasMapEntry = mapEntries.getAliasMap("/");
         assertNotNull(aliasMapEntry);
@@ -947,7 +945,7 @@ public class MapEntriesTest {
         when(jcrContentResult.getName()).thenReturn("jcr:content");
         
when(jcrContentResult.getValueMap()).thenReturn(buildValueMap("sling:alias", 
"aliasJcrContent"));
 
-        method.invoke(mapEntries, "/parent/jcr:content");
+        addResource.invoke(mapEntries, "/parent/jcr:content", new 
AtomicBoolean());
 
         aliasMapEntry = mapEntries.getAliasMap("/");
         assertNotNull(aliasMapEntry);
@@ -1091,32 +1089,28 @@ public class MapEntriesTest {
 
     }
 */
-    @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, 
String.class, AtomicBoolean.class);
-        method1.setAccessible(true);
+        final Method addResource = 
MapEntries.class.getDeclaredMethod("addResource", String.class, 
AtomicBoolean.class);
+        addResource.setAccessible(true);
 
-        Field field0 = MapEntries.class.getDeclaredField("aliasMap");
-        field0.setAccessible(true);
+        final Method removeAlias = 
MapEntries.class.getDeclaredMethod("removeAlias", String.class, String.class, 
AtomicBoolean.class);
+        removeAlias.setAccessible(true);
 
-        Map<String, Map<String, String>> aliasMap = ( Map<String, Map<String, 
String>>) field0.get(mapEntries);
+        // check that alias map is empty
         assertEquals(0, aliasMap.size());
 
-        Resource parent = mock(Resource.class);
+        final Resource parent = mock(Resource.class);
         when(parent.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 child = mock(Resource.class);
+        when(resourceResolver.getResource("/parent/child")).thenReturn(child);
+        when(child.getParent()).thenReturn(parent);
+        when(child.getPath()).thenReturn("/parent/child");
+        when(child.getName()).thenReturn("child");
+        
when(child.getValueMap()).thenReturn(buildValueMap(ResourceResolverImpl.PROP_ALIAS,
 "alias"));
 
-        method.invoke(mapEntries, "/parent/child");
+        addResource.invoke(mapEntries, "/parent/child", new AtomicBoolean());
 
         Map<String, String> aliasMapEntry = mapEntries.getAliasMap("/parent");
         assertNotNull(aliasMapEntry);
@@ -1125,7 +1119,7 @@ public class MapEntriesTest {
 
         assertEquals(1, aliasMap.size());
 
-        method1.invoke(mapEntries, "/parent/child", "sling:alias", new 
AtomicBoolean());
+        removeAlias.invoke(mapEntries, "/parent", "/parent/child", new 
AtomicBoolean());
 
         aliasMapEntry = mapEntries.getAliasMap("/parent");
         assertNull(aliasMapEntry);
@@ -1133,7 +1127,7 @@ public class MapEntriesTest {
         assertEquals(0, aliasMap.size());
 
         //re-add node and test nodeDeletion true
-        method.invoke(mapEntries, "/parent/child");
+        addResource.invoke(mapEntries, "/parent/child", new AtomicBoolean());
 
         aliasMapEntry = mapEntries.getAliasMap("/parent");
         assertNotNull(aliasMapEntry);
@@ -1143,7 +1137,7 @@ public class MapEntriesTest {
         assertEquals(1, aliasMap.size());
 
         when(resourceResolver.getResource("/parent/child")).thenReturn(null);
-        method1.invoke(mapEntries, "/parent/child", "sling:alias", new 
AtomicBoolean());
+        removeAlias.invoke(mapEntries, "/parent", "/parent/child", new 
AtomicBoolean());
 
         aliasMapEntry = mapEntries.getAliasMap("/parent");
         assertNull(aliasMapEntry);
@@ -1151,19 +1145,14 @@ public class MapEntriesTest {
         assertEquals(0, aliasMap.size());
     }
 
-    @SuppressWarnings("unchecked")
     @Test
     public void test_doRemoveAlias2() throws Exception {
-        Method method = MapEntries.class.getDeclaredMethod("doAddAlias", 
String.class);
-        method.setAccessible(true);
-
-        Method method1 = 
MapEntries.class.getDeclaredMethod("doRemoveAttributes", String.class, 
String.class, AtomicBoolean.class);
-        method1.setAccessible(true);
+        final Method addResource = 
MapEntries.class.getDeclaredMethod("addResource", String.class, 
AtomicBoolean.class);
+        addResource.setAccessible(true);
 
-        Field field0 = MapEntries.class.getDeclaredField("aliasMap");
-        field0.setAccessible(true);
+        final Method removeAlias = 
MapEntries.class.getDeclaredMethod("removeAlias", String.class, String.class, 
AtomicBoolean.class);
+        removeAlias.setAccessible(true);
 
-        Map<String, Map<String, String>> aliasMap = ( Map<String, Map<String, 
String>>) field0.get(mapEntries);
         assertEquals(0, aliasMap.size());
 
         Resource parent = mock(Resource.class);
@@ -1185,7 +1174,7 @@ public class MapEntriesTest {
         
when(jcrContentResult.getValueMap()).thenReturn(buildValueMap("sling:alias", 
"aliasJcrContent"));
         when(result.getChild("jcr:content")).thenReturn(jcrContentResult);
 
-        method.invoke(mapEntries, "/parent/child/jcr:content");
+        addResource.invoke(mapEntries, "/parent/child/jcr:content", new 
AtomicBoolean());
 
         Map<String, String> aliasMapEntry = mapEntries.getAliasMap("/parent");
         assertNotNull(aliasMapEntry);
@@ -1194,7 +1183,7 @@ public class MapEntriesTest {
 
         assertEquals(1, aliasMap.size());
 
-        method1.invoke(mapEntries, "/parent/child/jcr:content", "sling:alias", 
new AtomicBoolean());
+        removeAlias.invoke(mapEntries, "/parent", "/parent/child/jcr:content", 
new AtomicBoolean());
 
         aliasMapEntry = mapEntries.getAliasMap("/parent");
         assertNull(aliasMapEntry);
@@ -1202,7 +1191,7 @@ public class MapEntriesTest {
         assertEquals(0, aliasMap.size());
 
         //re-add node and test nodeDeletion true
-        method.invoke(mapEntries, "/parent/child/jcr:content");
+        addResource.invoke(mapEntries, "/parent/child/jcr:content", new 
AtomicBoolean());
 
         aliasMapEntry = mapEntries.getAliasMap("/parent");
         assertNotNull(aliasMapEntry);
@@ -1212,7 +1201,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", "sling:alias", 
new AtomicBoolean());
+        removeAlias.invoke(mapEntries, "/parent", "/parent/child/jcr:content", 
new AtomicBoolean());
 
         aliasMapEntry = mapEntries.getAliasMap("/parent");
         assertNull(aliasMapEntry);
@@ -1220,19 +1209,14 @@ public class MapEntriesTest {
         assertEquals(0, aliasMap.size());
     }
 
-    @SuppressWarnings("unchecked")
     @Test
     public void test_doRemoveAlias3() throws Exception {
-        final Method doAddAlias = 
MapEntries.class.getDeclaredMethod("doAddAlias", String.class);
-        doAddAlias.setAccessible(true);
+        final Method addResource = 
MapEntries.class.getDeclaredMethod("addResource", String.class, 
AtomicBoolean.class);
+        addResource.setAccessible(true);
 
-        final Method doRemoveAttributes = 
MapEntries.class.getDeclaredMethod("doRemoveAttributes", String.class, 
String.class, AtomicBoolean.class);
-        doRemoveAttributes.setAccessible(true);
-
-        final Field aliasMapField = 
MapEntries.class.getDeclaredField("aliasMap");
-        aliasMapField.setAccessible(true);
+        final Method removeAlias = 
MapEntries.class.getDeclaredMethod("removeAlias", String.class, String.class, 
AtomicBoolean.class);
+        removeAlias.setAccessible(true);
 
-        final Map<String, Map<String, String>> aliasMap = ( Map<String, 
Map<String, String>>) aliasMapField.get(mapEntries);
         assertEquals(0, aliasMap.size());
 
         final Resource parentRsrc = mock(Resource.class);
@@ -1245,7 +1229,7 @@ public class MapEntriesTest {
         when(childRsrc.getName()).thenReturn("child");
         when(childRsrc.getValueMap()).thenReturn(buildValueMap("sling:alias", 
"alias"));
 
-        doAddAlias.invoke(mapEntries, "/parent/child");
+        addResource.invoke(mapEntries, "/parent/child", new AtomicBoolean());
 
         final Resource jcrContentResult = mock(Resource.class);
         
when(resourceResolver.getResource("/parent/child/jcr:content")).thenReturn(jcrContentResult);
@@ -1255,7 +1239,7 @@ public class MapEntriesTest {
         
when(jcrContentResult.getValueMap()).thenReturn(buildValueMap("sling:alias", 
"aliasJcrContent"));
         when(childRsrc.getChild("jcr:content")).thenReturn(jcrContentResult);
 
-        doAddAlias.invoke(mapEntries, "/parent/child/jcr:content");
+        addResource.invoke(mapEntries, "/parent/child/jcr:content", new 
AtomicBoolean());
 
         // test with two nodes
         assertEquals(1, aliasMap.size());
@@ -1266,7 +1250,7 @@ public class MapEntriesTest {
         assertEquals("child", aliasMapEntry.get("alias"));
 
         // remove child jcr:content node
-        doRemoveAttributes.invoke(mapEntries, "/parent/child/jcr:content", 
"sling:alias", new AtomicBoolean());
+        removeAlias.invoke(mapEntries, "/parent", "/parent/child/jcr:content", 
new AtomicBoolean());
 
         // test with one node
         assertEquals(1, aliasMap.size());
@@ -1276,7 +1260,7 @@ public class MapEntriesTest {
         assertEquals("child", aliasMapEntry.get("alias"));
 
         // re-add the node and test /parent/child
-        doAddAlias.invoke(mapEntries, "/parent/child/jcr:content");
+        addResource.invoke(mapEntries, "/parent/child/jcr:content", new 
AtomicBoolean());
 
         // STOP
         aliasMapEntry = mapEntries.getAliasMap("/parent");
@@ -1285,8 +1269,8 @@ public class MapEntriesTest {
         assertEquals("child", aliasMapEntry.get("aliasJcrContent"));
         assertEquals("child", aliasMapEntry.get("alias"));
 
-        doRemoveAttributes.invoke(mapEntries, "/parent/child", "sling:alias", 
new AtomicBoolean());
-        doAddAlias.invoke(mapEntries, "/parent/child/jcr:content");
+        removeAlias.invoke(mapEntries, "/parent", "/parent/child", new 
AtomicBoolean());
+        addResource.invoke(mapEntries, "/parent/child/jcr:content", new 
AtomicBoolean());
 
         assertEquals(1, aliasMap.size());
         aliasMapEntry = mapEntries.getAliasMap("/parent");
@@ -1295,7 +1279,7 @@ public class MapEntriesTest {
         assertEquals("child", aliasMapEntry.get("aliasJcrContent"));
 
         // re-add the node and test node removal
-        doAddAlias.invoke(mapEntries, "/parent/child");
+        addResource.invoke(mapEntries, "/parent/child", new AtomicBoolean());
 
         aliasMapEntry = mapEntries.getAliasMap("/parent");
         assertNotNull(aliasMapEntry);
@@ -1305,7 +1289,7 @@ public class MapEntriesTest {
 
         
when(resourceResolver.getResource("/parent/child/jcr:content")).thenReturn(null);
         when(childRsrc.getChild("jcr:content")).thenReturn(null);
-        doRemoveAttributes.invoke(mapEntries, "/parent/child/jcr:content", 
"sling:alias", new AtomicBoolean());
+        removeAlias.invoke(mapEntries, "/parent", "/parent/child/jcr:content", 
new AtomicBoolean());
 
         assertEquals(1, aliasMap.size());
         aliasMapEntry = mapEntries.getAliasMap("/parent");
@@ -1315,7 +1299,7 @@ public class MapEntriesTest {
         // re-add the node and test node removal for  /parent/child
         
when(resourceResolver.getResource("/parent/child/jcr:content")).thenReturn(jcrContentResult);
         when(childRsrc.getChild("jcr:content")).thenReturn(jcrContentResult);
-        doAddAlias.invoke(mapEntries, "/parent/child/jcr:content");
+        addResource.invoke(mapEntries, "/parent/child/jcr:content", new 
AtomicBoolean());
 
 
         aliasMapEntry = mapEntries.getAliasMap("/parent");
@@ -1324,26 +1308,21 @@ public class MapEntriesTest {
         assertEquals("child", aliasMapEntry.get("aliasJcrContent"));
         assertEquals(2, aliasMapEntry.size());
 
-        doRemoveAttributes.invoke(mapEntries, "/parent/child", "sling:alias", 
new AtomicBoolean());
+        removeAlias.invoke(mapEntries, "/parent", "/parent/child", new 
AtomicBoolean());
 
         assertEquals(0, aliasMap.size());
         aliasMapEntry = mapEntries.getAliasMap("/parent");
         assertNull(aliasMapEntry);
     }
 
-    @SuppressWarnings("unchecked")
     @Test
     public void test_doRemoveAlias4() throws Exception {
-        Method method = MapEntries.class.getDeclaredMethod("doAddAlias", 
String.class);
-        method.setAccessible(true);
+        final Method addResource = 
MapEntries.class.getDeclaredMethod("addResource", String.class, 
AtomicBoolean.class);
+        addResource.setAccessible(true);
 
-        Method method1 = 
MapEntries.class.getDeclaredMethod("doRemoveAttributes", String.class, 
String.class, AtomicBoolean.class);
-        method1.setAccessible(true);
+        final Method removeAlias = 
MapEntries.class.getDeclaredMethod("removeAlias", String.class, String.class, 
AtomicBoolean.class);
+        removeAlias.setAccessible(true);
 
-        Field field0 = MapEntries.class.getDeclaredField("aliasMap");
-        field0.setAccessible(true);
-
-        Map<String, Map<String, String>> aliasMap = ( Map<String, Map<String, 
String>>) field0.get(mapEntries);
         assertEquals(0, aliasMap.size());
 
         Resource parent = mock(Resource.class);
@@ -1356,7 +1335,7 @@ public class MapEntriesTest {
         when(result.getName()).thenReturn("parent");
         when(result.getValueMap()).thenReturn(buildValueMap("sling:alias", 
"alias"));
 
-        method.invoke(mapEntries, "/parent");
+        addResource.invoke(mapEntries, "/parent", new AtomicBoolean());
 
         Map<String, String> aliasMapEntry = mapEntries.getAliasMap("/");
         assertNotNull(aliasMapEntry);
@@ -1365,7 +1344,7 @@ public class MapEntriesTest {
 
         assertEquals(1, aliasMap.size());
 
-        method1.invoke(mapEntries, "/parent", "sling:alias", new 
AtomicBoolean());
+        removeAlias.invoke(mapEntries, "/", "/parent", new AtomicBoolean());
 
         aliasMapEntry = mapEntries.getAliasMap("/");
         assertNull(aliasMapEntry);
@@ -1373,7 +1352,7 @@ public class MapEntriesTest {
         assertEquals(0, aliasMap.size());
 
         //re-add node and test nodeDeletion true
-        method.invoke(mapEntries, "/parent");
+        addResource.invoke(mapEntries, "/parent", new AtomicBoolean());
 
         aliasMapEntry = mapEntries.getAliasMap("/");
         assertNotNull(aliasMapEntry);
@@ -1383,7 +1362,7 @@ public class MapEntriesTest {
         assertEquals(1, aliasMap.size());
 
         when(resourceResolver.getResource("/parent")).thenReturn(null);
-        method1.invoke(mapEntries, "/parent", "sling:alias", new 
AtomicBoolean());
+        removeAlias.invoke(mapEntries, "/", "/parent", new AtomicBoolean());
 
         aliasMapEntry = mapEntries.getAliasMap("/");
         assertNull(aliasMapEntry);
@@ -1391,19 +1370,14 @@ public class MapEntriesTest {
         assertEquals(0, aliasMap.size());
     }
 
-    @SuppressWarnings("unchecked")
     @Test
     public void test_doRemoveAlias5() throws Exception {
-        Method method = MapEntries.class.getDeclaredMethod("doAddAlias", 
String.class);
-        method.setAccessible(true);
+        final Method addResource = 
MapEntries.class.getDeclaredMethod("addResource", String.class, 
AtomicBoolean.class);
+        addResource.setAccessible(true);
 
-        Method method1 = 
MapEntries.class.getDeclaredMethod("doRemoveAttributes", String.class, 
String.class, AtomicBoolean.class);
-        method1.setAccessible(true);
+        final Method removeAlias = 
MapEntries.class.getDeclaredMethod("removeAlias", String.class, String.class, 
AtomicBoolean.class);
+        removeAlias.setAccessible(true);
 
-        Field field0 = MapEntries.class.getDeclaredField("aliasMap");
-        field0.setAccessible(true);
-
-        Map<String, Map<String, String>> aliasMap = ( Map<String, Map<String, 
String>>) field0.get(mapEntries);
         assertEquals(0, aliasMap.size());
 
         Resource parent = mock(Resource.class);
@@ -1425,7 +1399,7 @@ public class MapEntriesTest {
         
when(jcrContentResult.getValueMap()).thenReturn(buildValueMap("sling:alias", 
"aliasJcrContent"));
         when(result.getChild("jcr:content")).thenReturn(jcrContentResult);
 
-        method.invoke(mapEntries, "/parent/jcr:content");
+        addResource.invoke(mapEntries, "/parent/jcr:content", new 
AtomicBoolean());
 
         Map<String, String> aliasMapEntry = mapEntries.getAliasMap("/");
         assertNotNull(aliasMapEntry);
@@ -1434,7 +1408,7 @@ public class MapEntriesTest {
 
         assertEquals(1, aliasMap.size());
 
-        method1.invoke(mapEntries, "/parent/jcr:content", "sling:alias", new 
AtomicBoolean());
+        removeAlias.invoke(mapEntries, "/", "/parent/jcr:content", new 
AtomicBoolean());
 
         aliasMapEntry = mapEntries.getAliasMap("/");
         assertNull(aliasMapEntry);
@@ -1442,7 +1416,7 @@ public class MapEntriesTest {
         assertEquals(0, aliasMap.size());
 
         //re-add node and test nodeDeletion true
-        method.invoke(mapEntries, "/parent/jcr:content");
+        addResource.invoke(mapEntries, "/parent/jcr:content", new 
AtomicBoolean());
 
         aliasMapEntry = mapEntries.getAliasMap("/");
         assertNotNull(aliasMapEntry);
@@ -1452,7 +1426,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", "sling:alias", new 
AtomicBoolean());
+        removeAlias.invoke(mapEntries, "/", "/parent/jcr:content", new 
AtomicBoolean());
 
         aliasMapEntry = mapEntries.getAliasMap("/");
         assertNull(aliasMapEntry);
@@ -1479,10 +1453,10 @@ public class MapEntriesTest {
     @Test
     //SLING-4847
     public void test_doNodeAdded1() throws Exception {
-        Method method = MapEntries.class.getDeclaredMethod("doNodeAdded", 
String.class, AtomicBoolean.class);
-        method.setAccessible(true);
-        final AtomicBoolean refreshed = new AtomicBoolean(true);
-        method.invoke(mapEntries, "/node", refreshed);
+        final Method addResource = 
MapEntries.class.getDeclaredMethod("addResource", String.class, 
AtomicBoolean.class);
+        addResource.setAccessible(true);
+        final AtomicBoolean refreshed = new AtomicBoolean(false);
+        addResource.invoke(mapEntries, "/node", refreshed);
         assertTrue(refreshed.get());
     }
 


Reply via email to