You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by re...@apache.org on 2025/01/16 13:13:10 UTC

(sling-org-apache-sling-resourceresolver) branch SLING-12620 updated: SLING-12620: Resource Resolver: needs to handle getParent()==null for vanity path resources gracefully - add test - extend tests to check whether init proceeds after problem resource

This is an automated email from the ASF dual-hosted git repository.

reschke pushed a commit to branch SLING-12620
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourceresolver.git


The following commit(s) were added to refs/heads/SLING-12620 by this push:
     new 0a9341f  SLING-12620: Resource Resolver: needs to handle getParent()==null for vanity path resources gracefully - add test - extend tests to check whether init proceeds after problem resource
0a9341f is described below

commit 0a9341f2b0d18b50ac58bf2620c38b92df43b3b4
Author: Julian Reschke <re...@apache.org>
AuthorDate: Thu Jan 16 14:12:59 2025 +0100

    SLING-12620: Resource Resolver: needs to handle getParent()==null for vanity path resources gracefully - add test - extend tests to check whether init proceeds after problem resource
---
 .../impl/mapping/MapEntriesTest.java               | 26 +++++++++++++++++-----
 1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/src/test/java/org/apache/sling/resourceresolver/impl/mapping/MapEntriesTest.java b/src/test/java/org/apache/sling/resourceresolver/impl/mapping/MapEntriesTest.java
index 16c79cd..cafe04f 100644
--- a/src/test/java/org/apache/sling/resourceresolver/impl/mapping/MapEntriesTest.java
+++ b/src/test/java/org/apache/sling/resourceresolver/impl/mapping/MapEntriesTest.java
@@ -290,12 +290,14 @@ public class MapEntriesTest extends AbstractMappingMapEntriesTest {
         String vanityPath = "/xyz";
         String containerName = "foo";
         String childName = "child";
-        prepareMapEntriesForVanityPath(false, false, containerName, childName, vanityPath);
+        prepareMapEntriesForVanityPath(false, false, containerName,
+                childName, "onemore", vanityPath);
         mapEntries.doInit();
         mapEntries.initializeVanityPaths();
         Map<String, List<String>> vanityMap = mapEntries.getVanityPathMappings();
         assertNotNull(vanityMap);
         assertEquals(vanityPath, vanityMap.get("/" + containerName + "/" + childName).get(0));
+        assertEquals(2, vanityMap.size());
     }
 
     // see SLING-12620
@@ -304,16 +306,22 @@ public class MapEntriesTest extends AbstractMappingMapEntriesTest {
         String vanityPath = "/xyz";
         String containerName = "foo";
         String childName = "child";
-        prepareMapEntriesForVanityPath(true, true, containerName, childName, vanityPath);
+        prepareMapEntriesForVanityPath(true, true, containerName,
+                childName, "one-more", vanityPath);
         mapEntries.doInit();
         mapEntries.initializeVanityPaths();
         Map<String, List<String>> vanityMap = mapEntries.getVanityPathMappings();
         assertNotNull(vanityMap);
         assertNull(vanityMap.get("/" + containerName + "/" + childName).get(0));
         assertNull(vanityMap.get("/" + containerName + "/" + childName + "/jcr:content").get(0));
+        assertEquals(1, vanityMap.size());
     }
 
-    private void prepareMapEntriesForVanityPath(boolean onJcrContent, boolean withNullParent, String containerName, String childName, String vanityPath) {
+    // create a 'custom' node (two flags), followed by a hardwired one (this is used to check that vanity path
+    // processing does not abort after the first error
+    private void prepareMapEntriesForVanityPath(boolean onJcrContent, boolean withNullParent,
+                                                String containerName, String childName,
+                                                String additionalChildName, String vanityPath) {
 
         final Resource parent = mock(Resource.class);
 
@@ -333,15 +341,23 @@ public class MapEntriesTest extends AbstractMappingMapEntriesTest {
         when(content.getPath()).thenReturn("/" + containerName + "/" + childName + "/jcr:content");
         when(content.getName()).thenReturn("jcr:content");
 
+        final Resource oneMore = mock(Resource.class);
+
+        when(oneMore.getParent()).thenReturn(parent);
+        when(oneMore.getPath()).thenReturn("/" + containerName + "/" + additionalChildName);
+        when(oneMore.getName()).thenReturn(additionalChildName);
+
+        when(oneMore.getValueMap()).thenReturn(buildValueMap(MapEntries.PROP_VANITY_PATH, vanityPath + "/onemore"));
+
         final Resource vanityPropHolder = onJcrContent ? content : vanity;
 
         when(vanityPropHolder.getValueMap()).thenReturn(buildValueMap(MapEntries.PROP_VANITY_PATH, vanityPath));
 
         when(resourceResolver.findResources(anyString(), eq("JCR-SQL2"))).thenAnswer((Answer<Iterator<Resource>>) invocation -> {
             if (invocation.getArguments()[0].toString().contains(MapEntries.PROP_VANITY_PATH)) {
-                return Collections.singleton(vanityPropHolder).iterator();
+                return List.of(vanityPropHolder, oneMore).iterator();
             } else {
-                return Collections.<Resource> emptySet().iterator();
+                return Collections.emptyIterator();
             }
         });
     }