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

rombert pushed a commit to annotated tag 
org.apache.sling.testing.sling-mock-oak-1.0.0
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock-oak.git

commit 300fe88196dfbf1509118922c0103fbd7a3da7a7
Author: Stefan Seifert <[email protected]>
AuthorDate: Thu Oct 1 17:43:53 2015 +0000

    SLING-5084 sling-mock-oak: Provide a minimal index configuration for 
Sling-related properties
    
    git-svn-id: 
https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock-oak@1706299
 13f79535-47bb-0310-9956-ffa450edef68
---
 .../sling/oak/OakMockResourceResolverAdapter.java  | 47 +++++++++++++++++++++-
 1 file changed, 46 insertions(+), 1 deletion(-)

diff --git 
a/src/main/java/org/apache/sling/testing/mock/sling/oak/OakMockResourceResolverAdapter.java
 
b/src/main/java/org/apache/sling/testing/mock/sling/oak/OakMockResourceResolverAdapter.java
index 393fdc1..5b4cd73 100644
--- 
a/src/main/java/org/apache/sling/testing/mock/sling/oak/OakMockResourceResolverAdapter.java
+++ 
b/src/main/java/org/apache/sling/testing/mock/sling/oak/OakMockResourceResolverAdapter.java
@@ -18,7 +18,15 @@
  */
 package org.apache.sling.testing.mock.sling.oak;
 
+import static java.util.Collections.singleton;
+import static 
org.apache.jackrabbit.oak.plugins.index.IndexConstants.INDEX_DEFINITIONS_NAME;
+import static 
org.apache.jackrabbit.oak.plugins.index.IndexUtils.createIndexDefinition;
+
+import javax.jcr.Repository;
+
 import org.apache.jackrabbit.oak.jcr.Jcr;
+import org.apache.jackrabbit.oak.spi.lifecycle.RepositoryInitializer;
+import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.sling.api.resource.ResourceResolverFactory;
 import org.apache.sling.jcr.api.SlingRepository;
 import org.apache.sling.testing.mock.sling.spi.ResourceResolverTypeAdapter;
@@ -35,7 +43,44 @@ public class OakMockResourceResolverAdapter implements 
ResourceResolverTypeAdapt
 
     @Override
     public SlingRepository newSlingRepository() {
-        return new RepositoryWrapper(new Jcr().createRepository());
+        Repository repository = new Jcr()
+        .with(new ExtraSlingContent())
+        .createRepository();
+        return new RepositoryWrapper(repository);
+    }
+
+    /**
+     * Adds some default indexes useful for by sling resource-jcr mapping.
+     * This is only a small subset of what is defined by default in the 
org.apache.sling.jcr.oak.server bundle.
+     */
+    private static final class ExtraSlingContent implements 
RepositoryInitializer {
+
+        @Override
+        public void initialize(NodeBuilder root) {
+            if (root.hasChildNode(INDEX_DEFINITIONS_NAME)) {
+                NodeBuilder index = root.child(INDEX_DEFINITIONS_NAME);
+
+                // jcr:
+                property(index, "jcrLanguage", "jcr:language");
+                property(index, "jcrLockOwner", "jcr:lockOwner");
+
+                // sling:
+                property(index, "slingAlias", "sling:alias");
+                property(index, "slingResource", "sling:resource");
+                property(index, "slingResourceType", "sling:resourceType");
+                property(index, "slingVanityPath", "sling:vanityPath");
+            }
+        }
+
+        /**
+         * A convenience method to create a non-unique property index.
+         */
+        private static void property(NodeBuilder index, String indexName, 
String propertyName) {
+            if (!index.hasChildNode(indexName)) {
+                createIndexDefinition(index, indexName, true, false, 
singleton(propertyName), null);
+            }
+        }
+
     }
 
 }

-- 
To stop receiving notification emails like this one, please contact
"[email protected]" <[email protected]>.

Reply via email to