This is an automated email from the ASF dual-hosted git repository. joerghoh pushed a commit to branch revert-11-issue/SLING-10011 in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-resource.git
commit fac5b39211eed2cd31a7d457e8543c8985ebd3cb Author: Jörg Hoh <[email protected]> AuthorDate: Thu Jul 22 14:59:03 2021 +0200 Revert "SLING-10011 - Use javax.jcr.Item.getParent to retrieve parent resource in JcrResourceProvider (#11)" This reverts commit 58da1d05ef62f0f32f85e09336dbd2d6cd5eb05e. --- .../internal/helper/jcr/JcrResourceProvider.java | 4 +-- .../helper/jcr/JcrResourceProviderTest.java | 33 ---------------------- 2 files changed, 2 insertions(+), 35 deletions(-) diff --git a/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java b/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java index c6b29ae..e40afb6 100644 --- a/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java +++ b/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java @@ -358,8 +358,8 @@ public class JcrResourceProvider extends ResourceProvider<JcrProviderState> { if (version == null) { String parentPath = ResourceUtil.getParent(child.getPath()); if (parentPath != null) { - Item parentItem = ((JcrItemResource)child).getItem().getParent(); - + Item parentItem = ctx.getProviderState().getResourceFactory() + .getItemOrNull(parentPath); if (parentItem != null && parentItem.isNode()) { return new JcrNodeResource(ctx.getResourceResolver(), parentPath, null, (Node)parentItem, diff --git a/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProviderTest.java b/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProviderTest.java index 637108a..b7641bc 100644 --- a/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProviderTest.java +++ b/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProviderTest.java @@ -20,15 +20,10 @@ package org.apache.sling.jcr.resource.internal.helper.jcr; import java.security.Principal; -import javax.jcr.Node; import javax.jcr.Repository; -import javax.jcr.RepositoryException; import javax.jcr.Session; -import javax.jcr.nodetype.NodeType; -import org.apache.sling.api.resource.Resource; import org.apache.sling.spi.resource.provider.ResolveContext; -import org.apache.sling.spi.resource.provider.ResourceContext; import org.junit.Assert; import org.mockito.Mockito; import org.osgi.framework.ServiceReference; @@ -62,34 +57,6 @@ public class JcrResourceProviderTest extends SlingRepositoryTestBase { Mockito.when(ctx.getProviderState()).thenReturn(new JcrProviderState(session, null, false)); Assert.assertNotNull(jcrResourceProvider.adaptTo(ctx, Principal.class)); } - - public void testGetParent() throws RepositoryException { - - ResolveContext ctx = Mockito.mock(ResolveContext.class); - ResourceContext rCtx = Mockito.mock(ResourceContext.class); - Mockito.when(ctx.getProviderState()).thenReturn(new JcrProviderState(session, null, false)); - - Node root = session.getRootNode(); - - assertNotNull(root); - - Node nodeA = root.addNode("test-jcr-resource-provider-"+System.nanoTime()).addNode("node-a", NodeType.NT_UNSTRUCTURED); - Node nodeB = nodeA.addNode("node-b", NodeType.NT_UNSTRUCTURED); - Node nodeC = nodeB.addNode("node-c", NodeType.NT_UNSTRUCTURED); - - session.save(); - - Resource resourceC = jcrResourceProvider.getResource(ctx, nodeC.getPath(), rCtx, null); - assertNotNull(resourceC); - - Resource resourceB = jcrResourceProvider.getParent(ctx, resourceC); - assertNotNull(resourceB); - assertEquals(resourceB.getPath(), nodeB.getPath()); - - Resource resourceA = jcrResourceProvider.getParent(ctx, resourceB); - assertNotNull(resourceA); - assertEquals(resourceA.getPath(), nodeA.getPath()); - } }
