sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sseif...@apache.org
Subject svn commit: r1651632 - in /sling/trunk/testing/mocks: sling-mock-jackrabbit/src/test/java/org/apache/sling/testing/mock/sling/jackrabbit/contentimport/ sling-mock-jackrabbit/src/test/resources/ sling-mock-jackrabbit/src/test/resources/SLING-INF/ sling-...
Date Wed, 14 Jan 2015 12:06:26 GMT
Author: sseifert
Date: Wed Jan 14 12:06:25 2015
New Revision: 1651632

URL: http://svn.apache.org/r1651632
Log:
SLING-4267 support importing nt:resource noded in jackrabbit with empty binary data
enable content loader unit tests in sling-mock-jackrabbit

Added:
    sling/trunk/testing/mocks/sling-mock-jackrabbit/src/test/resources/
    sling/trunk/testing/mocks/sling-mock-jackrabbit/src/test/resources/SLING-INF/
    sling/trunk/testing/mocks/sling-mock-jackrabbit/src/test/resources/SLING-INF/nodetypes/
    sling/trunk/testing/mocks/sling-mock-jackrabbit/src/test/resources/SLING-INF/nodetypes/app.cnd
  (with props)
Modified:
    sling/trunk/testing/mocks/sling-mock-jackrabbit/src/test/java/org/apache/sling/testing/mock/sling/jackrabbit/contentimport/ContentLoaderJsonDamTest.java
    sling/trunk/testing/mocks/sling-mock-jackrabbit/src/test/java/org/apache/sling/testing/mock/sling/jackrabbit/contentimport/ContentLoaderJsonTest.java
    sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/loader/ContentLoader.java
    sling/trunk/testing/mocks/sling-mock/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderJsonDamTest.java

Modified: sling/trunk/testing/mocks/sling-mock-jackrabbit/src/test/java/org/apache/sling/testing/mock/sling/jackrabbit/contentimport/ContentLoaderJsonDamTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/mocks/sling-mock-jackrabbit/src/test/java/org/apache/sling/testing/mock/sling/jackrabbit/contentimport/ContentLoaderJsonDamTest.java?rev=1651632&r1=1651631&r2=1651632&view=diff
==============================================================================
--- sling/trunk/testing/mocks/sling-mock-jackrabbit/src/test/java/org/apache/sling/testing/mock/sling/jackrabbit/contentimport/ContentLoaderJsonDamTest.java
(original)
+++ sling/trunk/testing/mocks/sling-mock-jackrabbit/src/test/java/org/apache/sling/testing/mock/sling/jackrabbit/contentimport/ContentLoaderJsonDamTest.java
Wed Jan 14 12:06:25 2015
@@ -28,10 +28,7 @@ import org.apache.sling.commons.testing.
 import org.apache.sling.testing.mock.sling.MockSling;
 import org.apache.sling.testing.mock.sling.ResourceResolverType;
 import org.apache.sling.testing.mock.sling.loader.AbstractContentLoaderJsonDamTest;
-import org.junit.Ignore;
 
-//TEST IS DISABLED currently, it does not work with jackrabbit repository yet
-@Ignore
 public class ContentLoaderJsonDamTest extends AbstractContentLoaderJsonDamTest {
 
     @Override
@@ -43,9 +40,12 @@ public class ContentLoaderJsonDamTest ex
     protected ResourceResolver newResourceResolver() {
         ResourceResolver resolver = MockSling.newResourceResolver(getResourceResolverType());
 
-        // register sling node types
+        // register sling and app node types
         try {
-            RepositoryUtil.registerSlingNodeTypes(resolver.adaptTo(Session.class));
+            Session session = resolver.adaptTo(Session.class);
+            RepositoryUtil.registerSlingNodeTypes(session);
+            RepositoryUtil.registerNodeType(session,
+                    ContentLoaderJsonTest.class.getResourceAsStream("/SLING-INF/nodetypes/app.cnd"));
         } catch (IOException ex) {
             throw new RuntimeException("Unable to register sling node types.", ex);
         } catch (RepositoryException ex) {

Modified: sling/trunk/testing/mocks/sling-mock-jackrabbit/src/test/java/org/apache/sling/testing/mock/sling/jackrabbit/contentimport/ContentLoaderJsonTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/mocks/sling-mock-jackrabbit/src/test/java/org/apache/sling/testing/mock/sling/jackrabbit/contentimport/ContentLoaderJsonTest.java?rev=1651632&r1=1651631&r2=1651632&view=diff
==============================================================================
--- sling/trunk/testing/mocks/sling-mock-jackrabbit/src/test/java/org/apache/sling/testing/mock/sling/jackrabbit/contentimport/ContentLoaderJsonTest.java
(original)
+++ sling/trunk/testing/mocks/sling-mock-jackrabbit/src/test/java/org/apache/sling/testing/mock/sling/jackrabbit/contentimport/ContentLoaderJsonTest.java
Wed Jan 14 12:06:25 2015
@@ -28,10 +28,7 @@ import org.apache.sling.commons.testing.
 import org.apache.sling.testing.mock.sling.MockSling;
 import org.apache.sling.testing.mock.sling.ResourceResolverType;
 import org.apache.sling.testing.mock.sling.loader.AbstractContentLoaderJsonTest;
-import org.junit.Ignore;
 
-// TEST IS DISABLED currently, it does not work with jackrabbit repository yet
-@Ignore
 public class ContentLoaderJsonTest extends AbstractContentLoaderJsonTest {
 
     @Override
@@ -43,9 +40,12 @@ public class ContentLoaderJsonTest exten
     protected ResourceResolver newResourceResolver() {
         ResourceResolver resolver = MockSling.newResourceResolver(getResourceResolverType());
 
-        // register sling node types
+        // register sling and app node types
         try {
-            RepositoryUtil.registerSlingNodeTypes(resolver.adaptTo(Session.class));
+            Session session = resolver.adaptTo(Session.class);
+            RepositoryUtil.registerSlingNodeTypes(session);
+            RepositoryUtil.registerNodeType(session,
+                    ContentLoaderJsonTest.class.getResourceAsStream("/SLING-INF/nodetypes/app.cnd"));
         } catch (IOException ex) {
             throw new RuntimeException("Unable to register sling node types.", ex);
         } catch (RepositoryException ex) {

Added: sling/trunk/testing/mocks/sling-mock-jackrabbit/src/test/resources/SLING-INF/nodetypes/app.cnd
URL: http://svn.apache.org/viewvc/sling/trunk/testing/mocks/sling-mock-jackrabbit/src/test/resources/SLING-INF/nodetypes/app.cnd?rev=1651632&view=auto
==============================================================================
--- sling/trunk/testing/mocks/sling-mock-jackrabbit/src/test/resources/SLING-INF/nodetypes/app.cnd
(added)
+++ sling/trunk/testing/mocks/sling-mock-jackrabbit/src/test/resources/SLING-INF/nodetypes/app.cnd
Wed Jan 14 12:06:25 2015
@@ -0,0 +1,8 @@
+<app='http://example.com/jcr/app/1.0'>
+<dam='http://example.com/jcr/dam/1.0'>
+
+[app:Page] > nt:unstructured
+[app:PageContent] > nt:unstructured
+
+[dam:Asset] > nt:unstructured
+[dam:AssetContent] > nt:unstructured

Propchange: sling/trunk/testing/mocks/sling-mock-jackrabbit/src/test/resources/SLING-INF/nodetypes/app.cnd
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/testing/mocks/sling-mock-jackrabbit/src/test/resources/SLING-INF/nodetypes/app.cnd
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Wed Jan 14 12:06:25 2015
@@ -0,0 +1 @@
+LastChangedDate LastChangedRevision LastChangedBy HeadURL Id Author

Propchange: sling/trunk/testing/mocks/sling-mock-jackrabbit/src/test/resources/SLING-INF/nodetypes/app.cnd
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/loader/ContentLoader.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/loader/ContentLoader.java?rev=1651632&r1=1651631&r2=1651632&view=diff
==============================================================================
--- sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/loader/ContentLoader.java
(original)
+++ sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/loader/ContentLoader.java
Wed Jan 14 12:06:25 2015
@@ -18,6 +18,7 @@
  */
 package org.apache.sling.testing.mock.sling.loader;
 
+import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.text.DateFormat;
@@ -55,6 +56,7 @@ public final class ContentLoader {
     private static final String REFERENCE = "jcr:reference:";
     private static final String PATH = "jcr:path:";
     private static final String CONTENTTYPE_OCTET_STREAM = "application/octet-stream";
+    private static final String JCR_DATA_PLACEHOLDER = ":jcr:data";
 
     private static final Set<String> IGNORED_NAMES = ImmutableSet.of(
             JcrConstants.JCR_PRIMARYTYPE,
@@ -67,7 +69,6 @@ public final class ContentLoader {
             JcrConstants.JCR_VERSIONHISTORY,
             "jcr:checkedOut",
             "jcr:isCheckedOut",
-            ":jcr:data",
             "rep:policy");
 
     private final ResourceResolver resourceResolver;
@@ -204,7 +205,11 @@ public final class ContentLoader {
         JSONArray names = jsonObject.names();
         for (int i = 0; names != null && i < names.length(); i++) {
             final String name = names.getString(i);
-            if (!IGNORED_NAMES.contains(name)) {
+            if (StringUtils.equals(name, JCR_DATA_PLACEHOLDER)) {
+                // we cannot import binary data here - but to avoid complaints by JCR we
create it with empty binary data
+                this.setProperty(props, JcrConstants.JCR_DATA, new ByteArrayInputStream(new
byte[0]));
+            }
+            else if (!IGNORED_NAMES.contains(name)) {
                 Object obj = jsonObject.get(name);
                 if (!(obj instanceof JSONObject)) {
                     this.setProperty(props, name, obj);

Modified: sling/trunk/testing/mocks/sling-mock/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderJsonDamTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/mocks/sling-mock/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderJsonDamTest.java?rev=1651632&r1=1651631&r2=1651632&view=diff
==============================================================================
--- sling/trunk/testing/mocks/sling-mock/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderJsonDamTest.java
(original)
+++ sling/trunk/testing/mocks/sling-mock/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderJsonDamTest.java
Wed Jan 14 12:06:25 2015
@@ -21,6 +21,8 @@ package org.apache.sling.testing.mock.sl
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
 
+import java.io.IOException;
+
 import javax.jcr.NamespaceRegistry;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
@@ -68,7 +70,7 @@ public abstract class AbstractContentLoa
     }
 
     @Test
-    public void testDamAssetMetadata() {
+    public void testDamAssetMetadata() throws IOException {
         Resource assetMetadata = this.resourceResolver
                 .getResource("/content/dam/sample/portraits/scott_reynolds.jpg/jcr:content/metadata");
         ValueMap props = ResourceUtil.getValueMap(assetMetadata);
@@ -80,6 +82,15 @@ public abstract class AbstractContentLoa
 
         assertArrayEquals(new String[] { "stockphotography:business/business_people", "properties:style/color",
                 "properties:orientation/landscape" }, props.get("app:tags", String[].class));
+
+        /*
+         TODO: this is not working yet in the different resource resolver types - goal: validate
binary is present, but empty.
+        Resource binaryMetadata = this.resourceResolver
+                .getResource("/content/dam/sample/portraits/scott_reynolds.jpg/jcr:content/renditions/original/jcr:content");
+        ValueMap binaryProps = ResourceUtil.getValueMap(binaryMetadata);
+        InputStream is = binaryProps.get(JcrConstants.JCR_DATA, InputStream.class);
+        assertNotNull(is);
+        */
     }
 
 }



Mime
View raw message