sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sseif...@apache.org
Subject svn commit: r1651848 - in /sling/trunk/testing/mocks/sling-mock/src: main/java/org/apache/sling/testing/mock/sling/loader/ContentLoader.java test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderJsonDamTest.java
Date Wed, 14 Jan 2015 21:59:15 GMT
Author: sseifert
Date: Wed Jan 14 21:59:15 2015
New Revision: 1651848

URL: http://svn.apache.org/r1651848
Log:
SLING-4267 support importing nt:resource nodes in jackrabbit with empty binary data

Modified:
    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/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=1651848&r1=1651847&r2=1651848&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 21:59:15 2015
@@ -33,6 +33,7 @@ import java.util.Set;
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.jackrabbit.JcrConstants;
+import org.apache.sling.api.resource.ModifiableValueMap;
 import org.apache.sling.api.resource.PersistenceException;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceResolver;
@@ -201,13 +202,13 @@ public final class ContentLoader {
             throws IOException, JSONException {
 
         // collect all properties first
+        boolean hasJcrData = false;
         Map<String, Object> props = new HashMap<String, Object>();
         JSONArray names = jsonObject.names();
         for (int i = 0; names != null && i < names.length(); i++) {
             final String name = names.getString(i);
             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]));
+                hasJcrData = true;
             }
             else if (!IGNORED_NAMES.contains(name)) {
                 Object obj = jsonObject.get(name);
@@ -230,6 +231,12 @@ public final class ContentLoader {
 
         // create resource
         Resource resource = resourceResolver.create(parentResource, childName, props);
+        
+        if (hasJcrData) {
+            ModifiableValueMap valueMap = resource.adaptTo(ModifiableValueMap.class);
+            // we cannot import binary data here - but to avoid complaints by JCR we create
it with empty binary data
+            valueMap.put(JcrConstants.JCR_DATA, new ByteArrayInputStream(new byte[0]));
+        }
 
         // add child resources
         for (int i = 0; names != null && i < names.length(); i++) {

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=1651848&r1=1651847&r2=1651848&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 21:59:15 2015
@@ -20,13 +20,17 @@ package org.apache.sling.testing.mock.sl
 
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
 
 import java.io.IOException;
+import java.io.InputStream;
 
 import javax.jcr.NamespaceRegistry;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 
+import org.apache.commons.io.IOUtils;
+import org.apache.jackrabbit.JcrConstants;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.api.resource.ResourceUtil;
@@ -83,14 +87,14 @@ 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.
+        // validate that a binary data node 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);
-        */
+        byte[] binaryData = IOUtils.toByteArray(is);
+        assertEquals(0, binaryData.length);
     }
 
 }



Mime
View raw message