sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From romb...@apache.org
Subject [sling-org-apache-sling-testing-sling-mock] 16/27: SLING-5064 sling-mock: Register JCR node types for OSGi bundles in class path
Date Tue, 07 Nov 2017 10:28:48 GMT
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.git

commit 9484e6db5c181eb96e245e175b2043f12cde3d84
Author: Stefan Seifert <sseifert@apache.org>
AuthorDate: Sat Sep 26 15:30:02 2015 +0000

    SLING-5064 sling-mock: Register JCR node types for OSGi bundles in class path
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock-oak@1705475
13f79535-47bb-0310-9956-ffa450edef68
---
 .../sling/oak/OakMockResourceResolverAdapter.java  | 30 ++++++++++++++++++++--
 1 file changed, 28 insertions(+), 2 deletions(-)

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 895608b..a017407 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,10 +18,14 @@
  */
 package org.apache.sling.testing.mock.sling.oak;
 
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
 import org.apache.jackrabbit.oak.jcr.Jcr;
 import org.apache.sling.api.resource.ResourceResolverFactory;
 import org.apache.sling.commons.testing.jcr.RepositoryUtil;
 import org.apache.sling.jcr.api.SlingRepository;
+import org.apache.sling.testing.mock.sling.context.NodeTypeDefinitionScanner;
 import org.apache.sling.testing.mock.sling.spi.ResourceResolverTypeAdapter;
 
 /**
@@ -36,8 +40,30 @@ public class OakMockResourceResolverAdapter implements ResourceResolverTypeAdapt
 
     @Override
     public SlingRepository newSlingRepository() {
-        
-        return new RepositoryUtil.RepositoryWrapper(new Jcr().createRepository());
+        SlingRepository slingRepository = new RepositoryUtil.RepositoryWrapper(new Jcr().createRepository());
+        registerJcrNodeTypes(slingRepository);
+        return slingRepository;
+    }
+
+    /**
+     * Registers all JCR node types found in classpath.
+     * @param slingRepository Sling repository
+     */
+    @SuppressWarnings("deprecation")
+    private static void registerJcrNodeTypes(SlingRepository slingRepository) {
+      Session session = null;
+      try {
+          session =  slingRepository.loginAdministrative(null);
+          NodeTypeDefinitionScanner.get().register(session);
+      }
+      catch (RepositoryException ex) {
+          throw new RuntimeException("Error registering JCR nodetypes: " + ex.getMessage(),
ex);
+      }
+      finally {
+          if (session != null) {
+              session.logout();
+          }
+      }
     }
 
 }

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <commits@sling.apache.org>.

Mime
View raw message