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/15 22:37:06 UTC
(sling-org-apache-sling-resourceresolver) branch SLING-12620 created (now 6ea1638)
This is an automated email from the ASF dual-hosted git repository.
reschke pushed a change to branch SLING-12620
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourceresolver.git
at 6ea1638 SLING-12620: Resource Resolver: needs to handle getParent()==null for vanity path resources gracefully - add test
This branch includes the following new commits:
new 6ea1638 SLING-12620: Resource Resolver: needs to handle getParent()==null for vanity path resources gracefully - add test
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(sling-org-apache-sling-resourceresolver) 01/01: SLING-12620: Resource Resolver: needs to handle getParent()==null for vanity path resources gracefully - add test
Posted by re...@apache.org.
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
commit 6ea16383b66f5a218898774ec5d4b9f43549a13b
Author: Julian Reschke <re...@apache.org>
AuthorDate: Wed Jan 15 23:36:48 2025 +0100
SLING-12620: Resource Resolver: needs to handle getParent()==null for vanity path resources gracefully - add test
---
.../impl/mapping/MapEntriesTest.java | 73 +++++++++++++++++++---
1 file changed, 65 insertions(+), 8 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 75b5e50..16c79cd 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
@@ -276,15 +276,72 @@ public class MapEntriesTest extends AbstractMappingMapEntriesTest {
when(aliasResource.getValueMap()).thenReturn(buildValueMap(ResourceResolverImpl.PROP_ALIAS, alias));
- when(resourceResolver.findResources(anyString(), eq("JCR-SQL2"))).thenAnswer(new Answer<Iterator<Resource>>() {
+ when(resourceResolver.findResources(anyString(), eq("JCR-SQL2"))).thenAnswer((Answer<Iterator<Resource>>) invocation -> {
+ if (invocation.getArguments()[0].toString().contains(ResourceResolverImpl.PROP_ALIAS)) {
+ return Collections.singleton(aliasResource).iterator();
+ } else {
+ return Collections.<Resource> emptySet().iterator();
+ }
+ });
+ }
- @Override
- public Iterator<Resource> answer(InvocationOnMock invocation) throws Throwable {
- if (invocation.getArguments()[0].toString().contains(ResourceResolverImpl.PROP_ALIAS)) {
- return Collections.singleton(aliasResource).iterator();
- } else {
- return Collections.<Resource> emptySet().iterator();
- }
+ @Test
+ public void test_simple_vanity_path() throws IOException {
+ String vanityPath = "/xyz";
+ String containerName = "foo";
+ String childName = "child";
+ prepareMapEntriesForVanityPath(false, false, containerName, childName, vanityPath);
+ mapEntries.doInit();
+ mapEntries.initializeVanityPaths();
+ Map<String, List<String>> vanityMap = mapEntries.getVanityPathMappings();
+ assertNotNull(vanityMap);
+ assertEquals(vanityPath, vanityMap.get("/" + containerName + "/" + childName).get(0));
+ }
+
+ // see SLING-12620
+ @Test(expected = NullPointerException.class)
+ public void test_simple_vanity_path_support_with_null_parent() throws IOException {
+ String vanityPath = "/xyz";
+ String containerName = "foo";
+ String childName = "child";
+ prepareMapEntriesForVanityPath(true, true, containerName, childName, 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));
+ }
+
+ private void prepareMapEntriesForVanityPath(boolean onJcrContent, boolean withNullParent, String containerName, String childName, String vanityPath) {
+
+ final Resource parent = mock(Resource.class);
+
+ when(parent.getParent()).thenReturn(null);
+ when(parent.getPath()).thenReturn("/" + containerName);
+ when(parent.getName()).thenReturn(containerName);
+
+ final Resource vanity = mock(Resource.class);
+
+ when(vanity.getParent()).thenReturn(withNullParent && !onJcrContent ? null : parent);
+ when(vanity.getPath()).thenReturn("/" + containerName + "/" + childName);
+ when(vanity.getName()).thenReturn(childName);
+
+ final Resource content = mock(Resource.class);
+
+ when(content.getParent()).thenReturn(withNullParent && onJcrContent ? null : vanity);
+ when(content.getPath()).thenReturn("/" + containerName + "/" + childName + "/jcr:content");
+ when(content.getName()).thenReturn("jcr:content");
+
+ 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();
+ } else {
+ return Collections.<Resource> emptySet().iterator();
}
});
}