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 2019/05/21 13:51:44 UTC

[sling-org-apache-sling-testing-sling-mock-oak] branch feature/SLING-8428-mixin-linkedfile created (now 8bae3ea)

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

sseifert pushed a change to branch feature/SLING-8428-mixin-linkedfile
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock-oak.git.


      at 8bae3ea  add linkedfile and mixin support

This branch includes the following new commits:

     new 8bae3ea  add linkedfile and mixin support

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-testing-sling-mock-oak] 01/01: add linkedfile and mixin support

Posted by ss...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

sseifert pushed a commit to branch feature/SLING-8428-mixin-linkedfile
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock-oak.git

commit 8bae3eacf3ed4b42b90d846053a7c814be3b1792
Author: Dominique Jäggi <dj...@adobe.com>
AuthorDate: Tue May 21 12:45:05 2019 +0200

    add linkedfile and mixin support
---
 pom.xml                                            |  2 +-
 .../oak/contentimport/ContentLoaderJsonTest.java   | 58 ++++++++++++++++++++++
 2 files changed, 59 insertions(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index 1126712..6f98cd6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -37,7 +37,7 @@
     <properties>
         <oak.version>1.8.9</oak.version>
         <jackrabbit.version>2.16.3</jackrabbit.version>
-        <sling-mock.version>2.3.2</sling-mock.version>
+        <sling-mock.version>2.3.11-SNAPSHOT</sling-mock.version>
     </properties>
 
     <scm>
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/oak/contentimport/ContentLoaderJsonTest.java b/src/test/java/org/apache/sling/testing/mock/sling/oak/contentimport/ContentLoaderJsonTest.java
index fdacb1a..3a00285 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/oak/contentimport/ContentLoaderJsonTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/oak/contentimport/ContentLoaderJsonTest.java
@@ -18,8 +18,17 @@
  */
 package org.apache.sling.testing.mock.sling.oak.contentimport;
 
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.nodetype.NodeType;
+import java.util.ArrayList;
+import java.util.Arrays;
+
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.collections.Predicate;
 import org.apache.jackrabbit.JcrConstants;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceUtil;
@@ -28,6 +37,8 @@ import org.apache.sling.testing.mock.sling.ResourceResolverType;
 import org.apache.sling.testing.mock.sling.loader.AbstractContentLoaderJsonTest;
 import org.junit.Test;
 
+import com.google.common.collect.Lists;
+
 @SuppressWarnings("null")
 public class ContentLoaderJsonTest extends AbstractContentLoaderJsonTest {
 
@@ -45,4 +56,51 @@ public class ContentLoaderJsonTest extends AbstractContentLoaderJsonTest {
         assertNotNull(props.get(JcrConstants.JCR_UUID));
     }
 
+    @Test
+    public void testMixinNodeType() throws Exception {
+        Resource resource = context.resourceResolver().getResource(path + "/sample/en/jcr:content/par/image/ntLinkedFileTargetWithMixin/" + JcrConstants.JCR_CONTENT);
+
+        assertMixinNodeType(resource, "app:TestMixin");
+    }
+
+    @Test
+    public void testReferenceable() throws Exception {
+        Resource resource = context.resourceResolver().getResource(path + "/sample/en/jcr:content/par/image/ntLinkedFileTargetWithMixin/" + JcrConstants.JCR_CONTENT);
+        ValueMap props = ResourceUtil.getValueMap(resource);
+
+        assertMixinNodeType(resource, "mix:referenceable");
+        assertNotNull(props.get(JcrConstants.JCR_UUID));
+    }
+
+    @Test
+    public void testLinkedFile() throws Exception {
+        Resource resource = context.resourceResolver().getResource(path + "/sample/en/jcr:content/par/image/ntLinkedFile");
+        Resource targetResource = context.resourceResolver().getResource(path + "/sample/en/jcr:content/par/image/ntLinkedFileTargetWithMixin/" + JcrConstants.JCR_CONTENT);
+        Node node = resource.adaptTo(Node.class);
+        Node target = node.getProperty(JcrConstants.JCR_CONTENT).getNode();
+
+        assertEquals(targetResource.getPath(), target.getPath());
+        assertEquals(targetResource.getValueMap().get(JcrConstants.JCR_UUID), target.getProperty(JcrConstants.JCR_UUID).getString());
+    }
+
+    private void assertMixinNodeType(final Resource resource, final String mixinNodeType) throws RepositoryException {
+        ArrayList<NodeType> mixinNodeTypes = Lists.newArrayList();
+        Node node = resource.adaptTo(Node.class);
+        if (node != null) {
+            mixinNodeTypes.addAll(Arrays.asList(node.getMixinNodeTypes()));
+        } else {
+            ValueMap props = ResourceUtil.getValueMap(resource);
+            mixinNodeTypes.addAll(Arrays.asList((NodeType[]) props.get(JcrConstants.JCR_MIXINTYPES)));
+        }
+
+        Object hit = CollectionUtils.find(mixinNodeTypes, new Predicate() {
+            @Override
+            public boolean evaluate(Object o) {
+                NodeType nodeType = (NodeType) o;
+                return nodeType.getName().equals(mixinNodeType);
+            }
+        });
+        assertNotNull(hit);
+    }
+
 }