add linkedfile and mixin support
diff --git a/core/pom.xml b/core/pom.xml
index 69e14a3..6163a5a 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -247,6 +247,12 @@
<artifactId>org.apache.sling.testing.logging-mock</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>javax.annotation</groupId>
+ <artifactId>javax.annotation-api</artifactId>
+ <version>1.3.2</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
diff --git a/core/src/main/java/org/apache/sling/testing/mock/sling/loader/ContentLoader.java b/core/src/main/java/org/apache/sling/testing/mock/sling/loader/ContentLoader.java
index ca4ed9f..ef117ad 100644
--- a/core/src/main/java/org/apache/sling/testing/mock/sling/loader/ContentLoader.java
+++ b/core/src/main/java/org/apache/sling/testing/mock/sling/loader/ContentLoader.java
@@ -69,7 +69,6 @@
// set of resource or property names that is used when JCR_OAK resource resolver type (= a real repo impl) is used
private static final Set<String> OAK_IGNORED_NAMES = ImmutableSet.<String>builder()
- .addAll(MOCK_IGNORED_NAMES)
.add(JcrConstants.JCR_UUID)
.add(JcrConstants.JCR_CREATED)
.build();
diff --git a/core/src/main/java/org/apache/sling/testing/mock/sling/loader/LoaderContentHandler.java b/core/src/main/java/org/apache/sling/testing/mock/sling/loader/LoaderContentHandler.java
index 93beb2d..3b44805 100644
--- a/core/src/main/java/org/apache/sling/testing/mock/sling/loader/LoaderContentHandler.java
+++ b/core/src/main/java/org/apache/sling/testing/mock/sling/loader/LoaderContentHandler.java
@@ -18,6 +18,7 @@
*/
package org.apache.sling.testing.mock.sling.loader;
+import javax.jcr.Node;
import java.io.ByteArrayInputStream;
import java.util.HashMap;
import java.util.Map;
@@ -36,7 +37,8 @@
final class LoaderContentHandler implements ContentHandler {
private static final String JCR_DATA_PLACEHOLDER = ":jcr:data";
-
+ private static final String JCR_REFERENCE_PLACEHOLDER = ":jcr:content";
+
private final @NotNull String rootPath;
private final @NotNull ResourceResolver resourceResolver;
@@ -74,6 +76,7 @@
// collect all properties first
boolean hasJcrData = false;
+ String referencedNodePath = null;
Map<String, Object> props = new HashMap<String, Object>();
if (content != null) {
for (Map.Entry<String,Object> entry : content.entrySet()) {
@@ -81,6 +84,9 @@
if (StringUtils.equals(name, JCR_DATA_PLACEHOLDER)) {
hasJcrData = true;
}
+ else if (StringUtils.equals(name, JCR_REFERENCE_PLACEHOLDER)) {
+ referencedNodePath = (String) entry.getValue();
+ }
else {
props.put(name, entry.getValue());
}
@@ -89,12 +95,18 @@
// 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
- if (valueMap != null) {
+
+ ModifiableValueMap valueMap = resource.adaptTo(ModifiableValueMap.class);
+ if (valueMap != null) {
+ if (hasJcrData) {
+ // 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]));
+ } else if (StringUtils.isNotBlank(referencedNodePath)) {
+ // target reference has to be specified relative to linking node, as tests may apply a dynamic root directory
+ Resource referencedNodeResource = resourceResolver.getResource(resource.getPath() + "/" + referencedNodePath);
+ if (referencedNodeResource != null) {
+ valueMap.put(JcrConstants.JCR_CONTENT, referencedNodeResource.adaptTo(Node.class));
+ }
}
}
diff --git a/core/src/test/resources/SLING-INF/nodetypes/app.cnd b/core/src/test/resources/SLING-INF/nodetypes/app.cnd
index 105d39f..121343b 100644
--- a/core/src/test/resources/SLING-INF/nodetypes/app.cnd
+++ b/core/src/test/resources/SLING-INF/nodetypes/app.cnd
@@ -24,3 +24,6 @@
[dam:Asset] > nt:unstructured
[dam:AssetContent] > nt:unstructured
+
+[app:TestMixin] mixin
+ - testMixinProp (string) copy
diff --git a/core/src/test/resources/json-import-samples/content.json b/core/src/test/resources/json-import-samples/content.json
index 31860dc..a2d4358 100644
--- a/core/src/test/resources/json-import-samples/content.json
+++ b/core/src/test/resources/json-import-samples/content.json
@@ -42,12 +42,25 @@
"jcr:created": "Thu Aug 07 2014 16:32:59 GMT+0200",
"jcr:content": {
"jcr:primaryType": "nt:resource",
+ "jcr:mixinTypes": ["mix:referenceable"],
"jcr:lastModifiedBy": "anonymous",
"jcr:mimeType": "image/jpeg",
"jcr:lastModified": "Thu Aug 07 2014 16:32:59 GMT+0200",
":jcr:data": 24377,
"jcr:uuid": "eda76d00-b2cd-4b59-878f-c33f71ceaddc"
}
+ },
+ "ntLinkedFileTargetWithMixin": {
+ "jcr:primaryType": "nt:file",
+ "jcr:content": {
+ "jcr:primaryType": "nt:resource",
+ "jcr:mixinTypes": ["mix:referenceable"],
+ ":jcr:data": 24377
+ }
+ },
+ "ntLinkedFile": {
+ "jcr:primaryType": "nt:linkedFile",
+ ":jcr:content": "../ntLinkedFileTargetWithMixin/jcr:content"
}
},
"title_1": {