You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ss...@apache.org on 2020/01/10 12:03:06 UTC

[sling-org-apache-sling-testing-resourceresolver-mock] 02/02: SLING-8985 Ensure Resource.getResourceType never returns null

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

sseifert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-resourceresolver-mock.git

commit 1fec07ed591984ebe0cddf9944f309eb3d8d94ab
Author: sseifert <ss...@pro-vision.de>
AuthorDate: Fri Jan 10 13:02:49 2020 +0100

    SLING-8985 Ensure Resource.getResourceType never returns null
---
 .../org/apache/sling/testing/resourceresolver/MockResource.java    | 7 ++++++-
 .../testing/resourceresolver/SlingCrudResourceResolverTest.java    | 5 +++++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/sling/testing/resourceresolver/MockResource.java b/src/main/java/org/apache/sling/testing/resourceresolver/MockResource.java
index bdb22d6..c434b34 100644
--- a/src/main/java/org/apache/sling/testing/resourceresolver/MockResource.java
+++ b/src/main/java/org/apache/sling/testing/resourceresolver/MockResource.java
@@ -44,7 +44,8 @@ public class MockResource extends AbstractResource {
     static final String JCR_DATA = "jcr:data";
     static final String NT_RESOURCE = "nt:resource";
     static final String NT_FILE = "nt:file";
-    
+    static final String NT_UNSTRUCTURED = "nt:unstructured";
+
     public MockResource(final String path,
             final Map<String, Object> props,
             final ResourceResolver resolver) {
@@ -75,6 +76,10 @@ public class MockResource extends AbstractResource {
             // fallback to jcr:primaryType if not resouce type exists (to mimick JCR resource behavior)
             resourceType = this.props.get(JCR_PRIMARYTYPE, String.class);
         }
+        if (resourceType == null) {
+            // fallback to nt:unstructured if no other resource type can be detected
+            resourceType = NT_UNSTRUCTURED;
+        }
         return resourceType;
     }
 
diff --git a/src/test/java/org/apache/sling/testing/resourceresolver/SlingCrudResourceResolverTest.java b/src/test/java/org/apache/sling/testing/resourceresolver/SlingCrudResourceResolverTest.java
index 0783f1d..f86c43b 100644
--- a/src/test/java/org/apache/sling/testing/resourceresolver/SlingCrudResourceResolverTest.java
+++ b/src/test/java/org/apache/sling/testing/resourceresolver/SlingCrudResourceResolverTest.java
@@ -315,4 +315,9 @@ public class SlingCrudResourceResolverTest {
         assertEquals(testRoot.getPath() + "/node1", resource1.getResourceMetadata().getResolutionPath());
     }
 
+    @Test
+    public void testResourceWithoutResourceType() throws PersistenceException {
+        Resource noResourceType = resourceResolver.create(testRoot, "/noResourceType", ImmutableMap.<String, Object>of());
+        assertNotNull(noResourceType.getResourceType());
+    }
 }