sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sseif...@apache.org
Subject svn commit: r1705787 - in /sling/trunk/testing/mocks: sling-mock-jackrabbit/src/main/java/org/apache/sling/testing/mock/sling/jackrabbit/ sling-mock-jackrabbit/src/test/java/org/apache/sling/testing/mock/sling/jackrabbit/contentimport/ sling-mock-jackr...
Date Mon, 28 Sep 2015 22:16:39 GMT
Author: sseifert
Date: Mon Sep 28 22:16:38 2015
New Revision: 1705787

URL: http://svn.apache.org/viewvc?rev=1705787&view=rev
Log:
SLING-5064 manual registration of node types no longer required; register namespaces and node types centrally depending on NodeTypeMode

Added:
    sling/trunk/testing/mocks/sling-mock-oak/src/main/java/org/apache/sling/testing/mock/sling/oak/RepositoryWrapper.java   (with props)
    sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/NodeTypeDefinitionScanner.java
      - copied, changed from r1705759, sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/context/NodeTypeDefinitionScanner.java
    sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/NodeTypeMode.java   (with props)
    sling/trunk/testing/mocks/sling-mock/src/test/java/org/apache/sling/testing/mock/sling/NodeTypeDefinitionScannerTest.java
      - copied, changed from r1705759, sling/trunk/testing/mocks/sling-mock/src/test/java/org/apache/sling/testing/mock/sling/context/NodeTypeDefinitionScannerTest.java
    sling/trunk/testing/mocks/sling-mock/src/test/resources/SLING-INF/
    sling/trunk/testing/mocks/sling-mock/src/test/resources/SLING-INF/nodetypes/
    sling/trunk/testing/mocks/sling-mock/src/test/resources/SLING-INF/nodetypes/app.cnd   (with props)
Removed:
    sling/trunk/testing/mocks/sling-mock-jackrabbit/src/test/resources/
    sling/trunk/testing/mocks/sling-mock-oak/src/test/resources/
    sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/context/NodeTypeDefinitionScanner.java
    sling/trunk/testing/mocks/sling-mock/src/test/java/org/apache/sling/testing/mock/sling/context/NodeTypeDefinitionScannerTest.java
Modified:
    sling/trunk/testing/mocks/sling-mock-jackrabbit/src/main/java/org/apache/sling/testing/mock/sling/jackrabbit/JackrabbitMockResourceResolverAdapter.java
    sling/trunk/testing/mocks/sling-mock-jackrabbit/src/test/java/org/apache/sling/testing/mock/sling/jackrabbit/contentimport/ContentLoaderBinaryTest.java
    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-jackrabbit/src/test/java/org/apache/sling/testing/mock/sling/jackrabbit/resource/JcrNamespaceTest.java
    sling/trunk/testing/mocks/sling-mock-jackrabbit/src/test/java/org/apache/sling/testing/mock/sling/jackrabbit/resource/MultipleResourceResolverTest.java
    sling/trunk/testing/mocks/sling-mock-oak/pom.xml
    sling/trunk/testing/mocks/sling-mock-oak/src/main/java/org/apache/sling/testing/mock/sling/oak/OakMockResourceResolverAdapter.java
    sling/trunk/testing/mocks/sling-mock-oak/src/test/java/org/apache/sling/testing/mock/sling/oak/contentimport/ContentLoaderBinaryTest.java
    sling/trunk/testing/mocks/sling-mock-oak/src/test/java/org/apache/sling/testing/mock/sling/oak/contentimport/ContentLoaderJsonDamTest.java
    sling/trunk/testing/mocks/sling-mock-oak/src/test/java/org/apache/sling/testing/mock/sling/oak/contentimport/ContentLoaderJsonTest.java
    sling/trunk/testing/mocks/sling-mock-oak/src/test/java/org/apache/sling/testing/mock/sling/oak/resource/JcrNamespaceTest.java
    sling/trunk/testing/mocks/sling-mock-oak/src/test/java/org/apache/sling/testing/mock/sling/oak/resource/MultipleResourceResolverTest.java
    sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/MockJcrResourceResolverAdapter.java
    sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/MockSling.java
    sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/ResourceResolverType.java
    sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/package-info.java
    sling/trunk/testing/mocks/sling-mock/src/test/java/org/apache/sling/testing/mock/sling/jcrmock/resource/MultipleResourceResolverTest.java
    sling/trunk/testing/mocks/sling-mock/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderJsonDamTest.java
    sling/trunk/testing/mocks/sling-mock/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderJsonTest.java
    sling/trunk/testing/mocks/sling-mock/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractJcrNamespaceTest.java
    sling/trunk/testing/mocks/sling-mock/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractMultipleResourceResolverTest.java

Modified: sling/trunk/testing/mocks/sling-mock-jackrabbit/src/main/java/org/apache/sling/testing/mock/sling/jackrabbit/JackrabbitMockResourceResolverAdapter.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/mocks/sling-mock-jackrabbit/src/main/java/org/apache/sling/testing/mock/sling/jackrabbit/JackrabbitMockResourceResolverAdapter.java?rev=1705787&r1=1705786&r2=1705787&view=diff
==============================================================================
--- sling/trunk/testing/mocks/sling-mock-jackrabbit/src/main/java/org/apache/sling/testing/mock/sling/jackrabbit/JackrabbitMockResourceResolverAdapter.java (original)
+++ sling/trunk/testing/mocks/sling-mock-jackrabbit/src/main/java/org/apache/sling/testing/mock/sling/jackrabbit/JackrabbitMockResourceResolverAdapter.java Mon Sep 28 22:16:38 2015
@@ -19,12 +19,10 @@
 package org.apache.sling.testing.mock.sling.jackrabbit;
 
 import javax.jcr.RepositoryException;
-import javax.jcr.Session;
 
 import org.apache.sling.api.resource.ResourceResolverFactory;
 import org.apache.sling.commons.testing.jcr.RepositoryProvider;
 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;
 
 /**
@@ -40,33 +38,11 @@ public class JackrabbitMockResourceResol
     @Override
     public SlingRepository newSlingRepository() {
         try {
-            SlingRepository slingRepository =  RepositoryProvider.instance().getRepository();
-            registerJcrNodeTypes(slingRepository);
-            return slingRepository;
-        } catch (RepositoryException ex) {
+            return RepositoryProvider.instance().getRepository();
+        }
+        catch (RepositoryException ex) {
             throw new RuntimeException("Unable to get jackrabbit SlingRepository instance.", ex);
         }
     }
 
-    /**
-     * 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();
-          }
-      }
-    }
-    
 }

Modified: sling/trunk/testing/mocks/sling-mock-jackrabbit/src/test/java/org/apache/sling/testing/mock/sling/jackrabbit/contentimport/ContentLoaderBinaryTest.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/ContentLoaderBinaryTest.java?rev=1705787&r1=1705786&r2=1705787&view=diff
==============================================================================
--- sling/trunk/testing/mocks/sling-mock-jackrabbit/src/test/java/org/apache/sling/testing/mock/sling/jackrabbit/contentimport/ContentLoaderBinaryTest.java (original)
+++ sling/trunk/testing/mocks/sling-mock-jackrabbit/src/test/java/org/apache/sling/testing/mock/sling/jackrabbit/contentimport/ContentLoaderBinaryTest.java Mon Sep 28 22:16:38 2015
@@ -18,14 +18,6 @@
  */
 package org.apache.sling.testing.mock.sling.jackrabbit.contentimport;
 
-import java.io.IOException;
-
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-
-import org.apache.sling.api.resource.ResourceResolver;
-import org.apache.sling.commons.testing.jcr.RepositoryUtil;
-import org.apache.sling.testing.mock.sling.MockSling;
 import org.apache.sling.testing.mock.sling.ResourceResolverType;
 import org.apache.sling.testing.mock.sling.loader.AbstractContentLoaderBinaryTest;
 
@@ -36,20 +28,4 @@ public class ContentLoaderBinaryTest ext
         return ResourceResolverType.JCR_JACKRABBIT;
     }
 
-    @Override
-    protected ResourceResolver newResourceResolver() {
-        ResourceResolver resolver = MockSling.newResourceResolver(getResourceResolverType());
-
-        // register sling node types
-        try {
-            RepositoryUtil.registerSlingNodeTypes(resolver.adaptTo(Session.class));
-        } catch (IOException ex) {
-            throw new RuntimeException("Unable to register sling node types.", ex);
-        } catch (RepositoryException ex) {
-            throw new RuntimeException("Unable to register sling node types.", ex);
-        }
-
-        return resolver;
-    }
-
 }

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=1705787&r1=1705786&r2=1705787&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 Mon Sep 28 22:16:38 2015
@@ -18,14 +18,6 @@
  */
 package org.apache.sling.testing.mock.sling.jackrabbit.contentimport;
 
-import java.io.IOException;
-
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-
-import org.apache.sling.api.resource.ResourceResolver;
-import org.apache.sling.commons.testing.jcr.RepositoryUtil;
-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;
 
@@ -36,23 +28,4 @@ public class ContentLoaderJsonDamTest ex
         return ResourceResolverType.JCR_JACKRABBIT;
     }
 
-    @Override
-    protected ResourceResolver newResourceResolver() {
-        ResourceResolver resolver = MockSling.newResourceResolver(getResourceResolverType());
-
-        // register sling and app node types
-        try {
-            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) {
-            throw new RuntimeException("Unable to register sling node types.", ex);
-        }
-
-        return resolver;
-    }
-
 }

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=1705787&r1=1705786&r2=1705787&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 Mon Sep 28 22:16:38 2015
@@ -18,14 +18,6 @@
  */
 package org.apache.sling.testing.mock.sling.jackrabbit.contentimport;
 
-import java.io.IOException;
-
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-
-import org.apache.sling.api.resource.ResourceResolver;
-import org.apache.sling.commons.testing.jcr.RepositoryUtil;
-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;
 
@@ -36,23 +28,4 @@ public class ContentLoaderJsonTest exten
         return ResourceResolverType.JCR_JACKRABBIT;
     }
 
-    @Override
-    protected ResourceResolver newResourceResolver() {
-        ResourceResolver resolver = MockSling.newResourceResolver(getResourceResolverType());
-
-        // register sling and app node types
-        try {
-            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) {
-            throw new RuntimeException("Unable to register sling node types.", ex);
-        }
-
-        return resolver;
-    }
-
 }

Modified: sling/trunk/testing/mocks/sling-mock-jackrabbit/src/test/java/org/apache/sling/testing/mock/sling/jackrabbit/resource/JcrNamespaceTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/mocks/sling-mock-jackrabbit/src/test/java/org/apache/sling/testing/mock/sling/jackrabbit/resource/JcrNamespaceTest.java?rev=1705787&r1=1705786&r2=1705787&view=diff
==============================================================================
--- sling/trunk/testing/mocks/sling-mock-jackrabbit/src/test/java/org/apache/sling/testing/mock/sling/jackrabbit/resource/JcrNamespaceTest.java (original)
+++ sling/trunk/testing/mocks/sling-mock-jackrabbit/src/test/java/org/apache/sling/testing/mock/sling/jackrabbit/resource/JcrNamespaceTest.java Mon Sep 28 22:16:38 2015
@@ -20,10 +20,7 @@ package org.apache.sling.testing.mock.sl
 
 import org.apache.sling.testing.mock.sling.ResourceResolverType;
 import org.apache.sling.testing.mock.sling.resource.AbstractJcrNamespaceTest;
-import org.junit.Ignore;
 
-//TEST IS DISABLED currently, it does not work with jackrabbit repository yet
-@Ignore
 public class JcrNamespaceTest extends AbstractJcrNamespaceTest {
 
     @Override

Modified: sling/trunk/testing/mocks/sling-mock-jackrabbit/src/test/java/org/apache/sling/testing/mock/sling/jackrabbit/resource/MultipleResourceResolverTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/mocks/sling-mock-jackrabbit/src/test/java/org/apache/sling/testing/mock/sling/jackrabbit/resource/MultipleResourceResolverTest.java?rev=1705787&r1=1705786&r2=1705787&view=diff
==============================================================================
--- sling/trunk/testing/mocks/sling-mock-jackrabbit/src/test/java/org/apache/sling/testing/mock/sling/jackrabbit/resource/MultipleResourceResolverTest.java (original)
+++ sling/trunk/testing/mocks/sling-mock-jackrabbit/src/test/java/org/apache/sling/testing/mock/sling/jackrabbit/resource/MultipleResourceResolverTest.java Mon Sep 28 22:16:38 2015
@@ -18,22 +18,9 @@
  */
 package org.apache.sling.testing.mock.sling.jackrabbit.resource;
 
-import java.io.IOException;
-
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-
-import org.apache.sling.api.resource.LoginException;
-import org.apache.sling.api.resource.ResourceResolver;
-import org.apache.sling.api.resource.ResourceResolverFactory;
-import org.apache.sling.commons.testing.jcr.RepositoryUtil;
-import org.apache.sling.testing.mock.sling.MockSling;
 import org.apache.sling.testing.mock.sling.ResourceResolverType;
 import org.apache.sling.testing.mock.sling.resource.AbstractMultipleResourceResolverTest;
-import org.junit.Ignore;
 
-//TEST IS DISABLED currently, it does not work with jackrabbit repository yet
-@Ignore
 public class MultipleResourceResolverTest extends AbstractMultipleResourceResolverTest {
 
     @Override
@@ -41,23 +28,4 @@ public class MultipleResourceResolverTes
         return ResourceResolverType.JCR_JACKRABBIT;
     }
 
-    @Override
-    protected ResourceResolverFactory newResourceResolerFactory() {
-        ResourceResolverFactory factory = MockSling.newResourceResolverFactory(getResourceResolverType());
-
-        // register sling node types
-        try {
-            ResourceResolver resolver = factory.getResourceResolver(null);
-            RepositoryUtil.registerSlingNodeTypes(resolver.adaptTo(Session.class));
-        } catch (LoginException ex) {
-            throw new RuntimeException("Unable to register sling node types.", ex);
-        } catch (IOException ex) {
-            throw new RuntimeException("Unable to register sling node types.", ex);
-        } catch (RepositoryException ex) {
-            throw new RuntimeException("Unable to register sling node types.", ex);
-        }
-
-        return factory;
-    }
-
 }

Modified: sling/trunk/testing/mocks/sling-mock-oak/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/testing/mocks/sling-mock-oak/pom.xml?rev=1705787&r1=1705786&r2=1705787&view=diff
==============================================================================
--- sling/trunk/testing/mocks/sling-mock-oak/pom.xml (original)
+++ sling/trunk/testing/mocks/sling-mock-oak/pom.xml Mon Sep 28 22:16:38 2015
@@ -62,18 +62,6 @@
             <scope>test</scope>
         </dependency>
 
-        <dependency>
-            <groupId>org.apache.sling</groupId>
-            <artifactId>org.apache.sling.commons.testing</artifactId>
-            <version>2.0.16</version>
-            <exclusions>
-                <exclusion>
-                    <groupId>org.jmock</groupId>
-                    <artifactId>jmock-junit4</artifactId>
-                </exclusion>
-            </exclusions>
-        </dependency>
-        
         <!-- Depend on oak-jcr, which pulls in all needed Oak artifacts -->
         <dependency>
             <groupId>org.apache.jackrabbit</groupId>

Modified: sling/trunk/testing/mocks/sling-mock-oak/src/main/java/org/apache/sling/testing/mock/sling/oak/OakMockResourceResolverAdapter.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/mocks/sling-mock-oak/src/main/java/org/apache/sling/testing/mock/sling/oak/OakMockResourceResolverAdapter.java?rev=1705787&r1=1705786&r2=1705787&view=diff
==============================================================================
--- sling/trunk/testing/mocks/sling-mock-oak/src/main/java/org/apache/sling/testing/mock/sling/oak/OakMockResourceResolverAdapter.java (original)
+++ sling/trunk/testing/mocks/sling-mock-oak/src/main/java/org/apache/sling/testing/mock/sling/oak/OakMockResourceResolverAdapter.java Mon Sep 28 22:16:38 2015
@@ -18,14 +18,9 @@
  */
 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;
 
 /**
@@ -40,30 +35,7 @@ public class OakMockResourceResolverAdap
 
     @Override
     public SlingRepository newSlingRepository() {
-        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();
-          }
-      }
+        return new RepositoryWrapper(new Jcr().createRepository());
     }
 
 }

Added: sling/trunk/testing/mocks/sling-mock-oak/src/main/java/org/apache/sling/testing/mock/sling/oak/RepositoryWrapper.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/mocks/sling-mock-oak/src/main/java/org/apache/sling/testing/mock/sling/oak/RepositoryWrapper.java?rev=1705787&view=auto
==============================================================================
--- sling/trunk/testing/mocks/sling-mock-oak/src/main/java/org/apache/sling/testing/mock/sling/oak/RepositoryWrapper.java (added)
+++ sling/trunk/testing/mocks/sling-mock-oak/src/main/java/org/apache/sling/testing/mock/sling/oak/RepositoryWrapper.java Mon Sep 28 22:16:38 2015
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.testing.mock.sling.oak;
+
+import javax.jcr.Credentials;
+import javax.jcr.LoginException;
+import javax.jcr.NoSuchWorkspaceException;
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
+import javax.jcr.Value;
+
+import org.apache.sling.jcr.api.SlingRepository;
+
+public final class RepositoryWrapper implements SlingRepository {
+
+    private static final String ADMIN_NAME = "admin";
+    private static final String ADMIN_PASSWORD = "admin";
+
+    protected final Repository wrapped;
+
+    public RepositoryWrapper(Repository r) {
+        wrapped = r;
+    }
+
+    public String getDescriptor(String key) {
+        return wrapped.getDescriptor(key);
+    }
+
+    public String[] getDescriptorKeys() {
+        return wrapped.getDescriptorKeys();
+    }
+
+    public String getDefaultWorkspace() {
+        return "default";
+    }
+
+    public Session login() throws LoginException, RepositoryException {
+        return wrapped.login();
+    }
+
+    public Session login(Credentials credentials, String workspaceName) 
+            throws LoginException, NoSuchWorkspaceException, RepositoryException {
+        return wrapped.login(credentials, (workspaceName == null ? getDefaultWorkspace() : workspaceName));
+    }
+
+    public Session login(Credentials credentials) 
+            throws LoginException, RepositoryException {
+        return wrapped.login(credentials);
+    }
+
+    public Session login(String workspaceName) 
+            throws LoginException, NoSuchWorkspaceException, RepositoryException {
+        return wrapped.login((workspaceName == null ? getDefaultWorkspace() : workspaceName));
+    }
+
+    public Session loginAdministrative(String workspaceName) 
+            throws RepositoryException {
+        final Credentials credentials = new SimpleCredentials(ADMIN_NAME, ADMIN_PASSWORD.toCharArray());
+        return this.login(credentials, (workspaceName == null ? getDefaultWorkspace() : workspaceName));
+    }
+
+    @Override
+    public Session loginService(String subServiceName, String workspaceName) 
+            throws LoginException, RepositoryException {
+        return loginAdministrative(workspaceName);
+    }
+    
+    public Value getDescriptorValue(String key) {
+        return wrapped.getDescriptorValue(key);
+    }
+
+    public Value[] getDescriptorValues(String key) {
+        return wrapped.getDescriptorValues(key);
+    }
+
+    public boolean isSingleValueDescriptor(String key) {
+        return wrapped.isSingleValueDescriptor(key);
+    }
+
+    public boolean isStandardDescriptor(String key) {
+        return wrapped.isStandardDescriptor(key);
+    }
+
+}
\ No newline at end of file

Propchange: sling/trunk/testing/mocks/sling-mock-oak/src/main/java/org/apache/sling/testing/mock/sling/oak/RepositoryWrapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/testing/mocks/sling-mock-oak/src/main/java/org/apache/sling/testing/mock/sling/oak/RepositoryWrapper.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Mon Sep 28 22:16:38 2015
@@ -0,0 +1 @@
+LastChangedDate LastChangedRevision LastChangedBy HeadURL Id Author

Propchange: sling/trunk/testing/mocks/sling-mock-oak/src/main/java/org/apache/sling/testing/mock/sling/oak/RepositoryWrapper.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: sling/trunk/testing/mocks/sling-mock-oak/src/test/java/org/apache/sling/testing/mock/sling/oak/contentimport/ContentLoaderBinaryTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/mocks/sling-mock-oak/src/test/java/org/apache/sling/testing/mock/sling/oak/contentimport/ContentLoaderBinaryTest.java?rev=1705787&r1=1705786&r2=1705787&view=diff
==============================================================================
--- sling/trunk/testing/mocks/sling-mock-oak/src/test/java/org/apache/sling/testing/mock/sling/oak/contentimport/ContentLoaderBinaryTest.java (original)
+++ sling/trunk/testing/mocks/sling-mock-oak/src/test/java/org/apache/sling/testing/mock/sling/oak/contentimport/ContentLoaderBinaryTest.java Mon Sep 28 22:16:38 2015
@@ -18,14 +18,6 @@
  */
 package org.apache.sling.testing.mock.sling.oak.contentimport;
 
-import java.io.IOException;
-
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-
-import org.apache.sling.api.resource.ResourceResolver;
-import org.apache.sling.commons.testing.jcr.RepositoryUtil;
-import org.apache.sling.testing.mock.sling.MockSling;
 import org.apache.sling.testing.mock.sling.ResourceResolverType;
 import org.apache.sling.testing.mock.sling.loader.AbstractContentLoaderBinaryTest;
 
@@ -36,20 +28,4 @@ public class ContentLoaderBinaryTest ext
         return ResourceResolverType.JCR_OAK;
     }
 
-    @Override
-    protected ResourceResolver newResourceResolver() {
-        ResourceResolver resolver = MockSling.newResourceResolver(getResourceResolverType());
-
-        // register sling node types
-        try {
-            RepositoryUtil.registerSlingNodeTypes(resolver.adaptTo(Session.class));
-        } catch (IOException ex) {
-            throw new RuntimeException("Unable to register sling node types.", ex);
-        } catch (RepositoryException ex) {
-            throw new RuntimeException("Unable to register sling node types.", ex);
-        }
-
-        return resolver;
-    }
-
 }

Modified: sling/trunk/testing/mocks/sling-mock-oak/src/test/java/org/apache/sling/testing/mock/sling/oak/contentimport/ContentLoaderJsonDamTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/mocks/sling-mock-oak/src/test/java/org/apache/sling/testing/mock/sling/oak/contentimport/ContentLoaderJsonDamTest.java?rev=1705787&r1=1705786&r2=1705787&view=diff
==============================================================================
--- sling/trunk/testing/mocks/sling-mock-oak/src/test/java/org/apache/sling/testing/mock/sling/oak/contentimport/ContentLoaderJsonDamTest.java (original)
+++ sling/trunk/testing/mocks/sling-mock-oak/src/test/java/org/apache/sling/testing/mock/sling/oak/contentimport/ContentLoaderJsonDamTest.java Mon Sep 28 22:16:38 2015
@@ -18,14 +18,6 @@
  */
 package org.apache.sling.testing.mock.sling.oak.contentimport;
 
-import java.io.IOException;
-
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-
-import org.apache.sling.api.resource.ResourceResolver;
-import org.apache.sling.commons.testing.jcr.RepositoryUtil;
-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;
 
@@ -35,24 +27,5 @@ public class ContentLoaderJsonDamTest ex
     protected ResourceResolverType getResourceResolverType() {
         return ResourceResolverType.JCR_OAK;
     }
-
-    @Override
-    protected ResourceResolver newResourceResolver() {
-        ResourceResolver resolver = MockSling.newResourceResolver(getResourceResolverType());
-
-        // register sling and app node types
-        try {
-            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) {
-            throw new RuntimeException("Unable to register sling node types.", ex);
-        }
-
-        return resolver;
-    }
-
+    
 }

Modified: sling/trunk/testing/mocks/sling-mock-oak/src/test/java/org/apache/sling/testing/mock/sling/oak/contentimport/ContentLoaderJsonTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/mocks/sling-mock-oak/src/test/java/org/apache/sling/testing/mock/sling/oak/contentimport/ContentLoaderJsonTest.java?rev=1705787&r1=1705786&r2=1705787&view=diff
==============================================================================
--- sling/trunk/testing/mocks/sling-mock-oak/src/test/java/org/apache/sling/testing/mock/sling/oak/contentimport/ContentLoaderJsonTest.java (original)
+++ sling/trunk/testing/mocks/sling-mock-oak/src/test/java/org/apache/sling/testing/mock/sling/oak/contentimport/ContentLoaderJsonTest.java Mon Sep 28 22:16:38 2015
@@ -18,14 +18,6 @@
  */
 package org.apache.sling.testing.mock.sling.oak.contentimport;
 
-import java.io.IOException;
-
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-
-import org.apache.sling.api.resource.ResourceResolver;
-import org.apache.sling.commons.testing.jcr.RepositoryUtil;
-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;
 
@@ -36,23 +28,4 @@ public class ContentLoaderJsonTest exten
         return ResourceResolverType.JCR_OAK;
     }
 
-    @Override
-    protected ResourceResolver newResourceResolver() {
-        ResourceResolver resolver = MockSling.newResourceResolver(getResourceResolverType());
-
-        // register sling and app node types
-        try {
-            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) {
-            throw new RuntimeException("Unable to register sling node types.", ex);
-        }
-
-        return resolver;
-    }
-
 }

Modified: sling/trunk/testing/mocks/sling-mock-oak/src/test/java/org/apache/sling/testing/mock/sling/oak/resource/JcrNamespaceTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/mocks/sling-mock-oak/src/test/java/org/apache/sling/testing/mock/sling/oak/resource/JcrNamespaceTest.java?rev=1705787&r1=1705786&r2=1705787&view=diff
==============================================================================
--- sling/trunk/testing/mocks/sling-mock-oak/src/test/java/org/apache/sling/testing/mock/sling/oak/resource/JcrNamespaceTest.java (original)
+++ sling/trunk/testing/mocks/sling-mock-oak/src/test/java/org/apache/sling/testing/mock/sling/oak/resource/JcrNamespaceTest.java Mon Sep 28 22:16:38 2015
@@ -20,10 +20,7 @@ package org.apache.sling.testing.mock.sl
 
 import org.apache.sling.testing.mock.sling.ResourceResolverType;
 import org.apache.sling.testing.mock.sling.resource.AbstractJcrNamespaceTest;
-import org.junit.Ignore;
 
-//TEST IS DISABLED currently, it does not work with oak repository yet
-@Ignore
 public class JcrNamespaceTest extends AbstractJcrNamespaceTest {
 
     @Override

Modified: sling/trunk/testing/mocks/sling-mock-oak/src/test/java/org/apache/sling/testing/mock/sling/oak/resource/MultipleResourceResolverTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/mocks/sling-mock-oak/src/test/java/org/apache/sling/testing/mock/sling/oak/resource/MultipleResourceResolverTest.java?rev=1705787&r1=1705786&r2=1705787&view=diff
==============================================================================
--- sling/trunk/testing/mocks/sling-mock-oak/src/test/java/org/apache/sling/testing/mock/sling/oak/resource/MultipleResourceResolverTest.java (original)
+++ sling/trunk/testing/mocks/sling-mock-oak/src/test/java/org/apache/sling/testing/mock/sling/oak/resource/MultipleResourceResolverTest.java Mon Sep 28 22:16:38 2015
@@ -18,46 +18,14 @@
  */
 package org.apache.sling.testing.mock.sling.oak.resource;
 
-import java.io.IOException;
-
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-
-import org.apache.sling.api.resource.LoginException;
-import org.apache.sling.api.resource.ResourceResolver;
-import org.apache.sling.api.resource.ResourceResolverFactory;
-import org.apache.sling.commons.testing.jcr.RepositoryUtil;
-import org.apache.sling.testing.mock.sling.MockSling;
 import org.apache.sling.testing.mock.sling.ResourceResolverType;
 import org.apache.sling.testing.mock.sling.resource.AbstractMultipleResourceResolverTest;
-import org.junit.Ignore;
 
-//TEST IS DISABLED currently, it does not work with jackrabbit repository yet
-@Ignore
 public class MultipleResourceResolverTest extends AbstractMultipleResourceResolverTest {
 
     @Override
     protected ResourceResolverType getResourceResolverType() {
         return ResourceResolverType.JCR_OAK;
     }
-
-    @Override
-    protected ResourceResolverFactory newResourceResolerFactory() {
-        ResourceResolverFactory factory = MockSling.newResourceResolverFactory(getResourceResolverType());
-
-        // register sling node types
-        try {
-            ResourceResolver resolver = factory.getResourceResolver(null);
-            RepositoryUtil.registerSlingNodeTypes(resolver.adaptTo(Session.class));
-        } catch (LoginException ex) {
-            throw new RuntimeException("Unable to register sling node types.", ex);
-        } catch (IOException ex) {
-            throw new RuntimeException("Unable to register sling node types.", ex);
-        } catch (RepositoryException ex) {
-            throw new RuntimeException("Unable to register sling node types.", ex);
-        }
-
-        return factory;
-    }
-
+    
 }

Modified: sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/MockJcrResourceResolverAdapter.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/MockJcrResourceResolverAdapter.java?rev=1705787&r1=1705786&r2=1705787&view=diff
==============================================================================
--- sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/MockJcrResourceResolverAdapter.java (original)
+++ sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/MockJcrResourceResolverAdapter.java Mon Sep 28 22:16:38 2015
@@ -18,10 +18,7 @@
  */
 package org.apache.sling.testing.mock.sling;
 
-import javax.jcr.NamespaceRegistry;
 import javax.jcr.Repository;
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
 
 import org.apache.sling.api.resource.ResourceResolverFactory;
 import org.apache.sling.jcr.api.SlingRepository;
@@ -41,17 +38,6 @@ class MockJcrResourceResolverAdapter imp
     @Override
     public SlingRepository newSlingRepository() {
         Repository repository = MockJcr.newRepository();
-        
-        try {
-            Session session = repository.login();
-            NamespaceRegistry namespaceRegistry = session.getWorkspace().getNamespaceRegistry();
-            namespaceRegistry.registerNamespace("sling", "http://sling.apache.org/jcr/sling/1.0");
-            session.logout();
-        }
-        catch (RepositoryException ex) {
-            throw new RuntimeException("Unable to register namespaces in JCR Mock repository.", ex);
-        }
-        
         return new MockSlingRepository(repository);
     }
 

Modified: sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/MockSling.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/MockSling.java?rev=1705787&r1=1705786&r2=1705787&view=diff
==============================================================================
--- sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/MockSling.java (original)
+++ sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/MockSling.java Mon Sep 28 22:16:38 2015
@@ -18,6 +18,9 @@
  */
 package org.apache.sling.testing.mock.sling;
 
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
 import org.apache.sling.api.SlingHttpServletRequest;
 import org.apache.sling.api.SlingHttpServletResponse;
 import org.apache.sling.api.adapter.SlingAdaptable;
@@ -76,12 +79,34 @@ public final class MockSling {
                 factory = new MockNoneResourceResolverFactory(bundleContext);
             }
             else {
+                registerJcrNodeTypes(repository, type);
                 factory = new MockJcrResourceResolverFactory(repository, bundleContext);
             }
         }
         return factory;
     }
 
+    /**
+     * Registers all JCR node types found in classpath.
+     * @param slingRepository Sling repository
+     */
+    @SuppressWarnings("deprecation")
+    private static void registerJcrNodeTypes(final SlingRepository slingRepository, final ResourceResolverType type) {
+      Session session = null;
+      try {
+          session =  slingRepository.loginAdministrative(null);
+          NodeTypeDefinitionScanner.get().register(session, type.getNodeTypeMode());
+      }
+      catch (RepositoryException ex) {
+          throw new RuntimeException("Error registering JCR nodetypes: " + ex.getMessage(), ex);
+      }
+      finally {
+          if (session != null) {
+              session.logout();
+          }
+      }
+    }
+    
     private static ResourceResolverTypeAdapter getResourceResolverTypeAdapter(final ResourceResolverType type) {
         try {
             Class clazz = Class.forName(type.getResourceResolverTypeAdapterClass());

Copied: sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/NodeTypeDefinitionScanner.java (from r1705759, sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/context/NodeTypeDefinitionScanner.java)
URL: http://svn.apache.org/viewvc/sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/NodeTypeDefinitionScanner.java?p2=sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/NodeTypeDefinitionScanner.java&p1=sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/context/NodeTypeDefinitionScanner.java&r1=1705759&r2=1705787&rev=1705787&view=diff
==============================================================================
--- sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/context/NodeTypeDefinitionScanner.java (original)
+++ sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/NodeTypeDefinitionScanner.java Mon Sep 28 22:16:38 2015
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.sling.testing.mock.sling.context;
+package org.apache.sling.testing.mock.sling;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -34,13 +34,25 @@ import java.util.jar.Manifest;
 import javax.jcr.NamespaceRegistry;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
+import javax.jcr.Value;
 import javax.jcr.ValueFactory;
 import javax.jcr.Workspace;
+import javax.jcr.nodetype.NodeDefinition;
+import javax.jcr.nodetype.NodeDefinitionTemplate;
+import javax.jcr.nodetype.NodeType;
+import javax.jcr.nodetype.NodeTypeDefinition;
+import javax.jcr.nodetype.NodeTypeIterator;
 import javax.jcr.nodetype.NodeTypeManager;
+import javax.jcr.nodetype.NodeTypeTemplate;
+import javax.jcr.nodetype.PropertyDefinition;
+import javax.jcr.nodetype.PropertyDefinitionTemplate;
 
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.jackrabbit.commons.cnd.CndImporter;
+import org.apache.jackrabbit.commons.cnd.CompactNodeTypeDefReader;
+import org.apache.jackrabbit.commons.cnd.DefinitionBuilderFactory;
+import org.apache.jackrabbit.commons.cnd.TemplateBuilderFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -74,9 +86,9 @@ public final class NodeTypeDefinitionSca
      * Registers node types found in classpath in JCR repository.
      * @param session Session
      */
-    public void register(Session session) throws RepositoryException {
+    public void register(Session session, NodeTypeMode nodeTypeMode) throws RepositoryException {
       List<String> nodeTypeResources = getNodeTypeDefinitions();
-      register(session, nodeTypeResources);
+      register(session, nodeTypeResources, nodeTypeMode);
     }
     
     /**
@@ -84,25 +96,91 @@ public final class NodeTypeDefinitionSca
      * @param session Session
      * @param nodeTypeResources List of classpath resource URLs pointing to node type definitions
      */
-    public void register(Session session, List<String> nodeTypeResources) throws RepositoryException {
+    public void register(Session session, List<String> nodeTypeResources, NodeTypeMode nodeTypeMode) throws RepositoryException {
+      switch (nodeTypeMode) {
+      case NOT_SUPPORTED:
+          // do nothing
+          break;
+      case NAMESPACES_ONLY:
+          registerNamespaces(session, nodeTypeResources);
+          break;
+      case NODETYPES_REQUIRED:
+          registerNodeTypes(session, nodeTypeResources);
+          break;
+         default:
+             throw new IllegalArgumentException("Node type mode not supported: " + nodeTypeMode);
+      }
+    }
+    
+    /**
+     * Registers only the namespaces found in node type definitions in classpath in JCR repository.
+     * @param session Session
+     * @param nodeTypeResources List of classpath resource URLs pointing to node type definitions
+     */
+    private void registerNamespaces(Session session, List<String> nodeTypeResources) throws RepositoryException {
+        ClassLoader classLoader = getClass().getClassLoader();
+        Workspace workspace = session.getWorkspace();
+        NamespaceRegistry namespaceRegistry = workspace.getNamespaceRegistry();
+        ValueFactory valueFactory = session.getValueFactory();
+
+      DefinitionBuilderFactory<NodeTypeTemplate, NamespaceRegistry> factory =
+              new TemplateBuilderFactory(new DummyNodeTypeManager(), valueFactory, namespaceRegistry);
+
+      for (String nodeTypeResource : nodeTypeResources) {
+          InputStream is = classLoader.getResourceAsStream(nodeTypeResource);
+          if (is == null) {
+              continue;
+          }
+          try {
+              Reader reader = new InputStreamReader(is);
+              CompactNodeTypeDefReader<NodeTypeTemplate, NamespaceRegistry> cndReader 
+                      = new CompactNodeTypeDefReader<NodeTypeTemplate, NamespaceRegistry>(reader, nodeTypeResource, factory);
+              NamespaceRegistry mapping = cndReader.getNamespaceMapping();
+              for (int i=0; i<mapping.getURIs().length; i++) {
+                  String uri = mapping.getURIs()[i];
+                  String prefix = mapping.getPrefix(uri);
+                  try {
+                      namespaceRegistry.registerNamespace(prefix, uri);
+                  }
+                  catch (RepositoryException ex) {
+                      // ignore
+                  }
+              }
+          }
+          catch (Throwable ex) {
+              log.warn("Unable to parse node type definition: " + nodeTypeResource, ex);
+          }
+          finally {
+              IOUtils.closeQuietly(is);
+          }
+      }
+      
+    }
+    
+    /**
+     * Registers node types found in classpath in JCR repository.
+     * @param session Session
+     * @param nodeTypeResources List of classpath resource URLs pointing to node type definitions
+     */
+    private void registerNodeTypes(Session session, List<String> nodeTypeResources) throws RepositoryException {
       ClassLoader classLoader = getClass().getClassLoader();
       Workspace workspace = session.getWorkspace();
       NodeTypeManager nodeTypeManager = workspace.getNodeTypeManager();
       NamespaceRegistry namespaceRegistry = workspace.getNamespaceRegistry();
       ValueFactory valueFactory = session.getValueFactory();
 
-      // try registering node types multiple times because the eyact order is not known
+      // try registering node types multiple times because the exact order is not known
       int iteration = 0;
       List<String> remainingNodeTypeResources = new ArrayList<String>(nodeTypeResources);
       while (!remainingNodeTypeResources.isEmpty()) {
-          registerAndRemoveSucceeds(remainingNodeTypeResources, classLoader, nodeTypeManager, namespaceRegistry, valueFactory, false);
+          registerNodeTypesAndRemoveSucceeds(remainingNodeTypeResources, classLoader, nodeTypeManager, namespaceRegistry, valueFactory, false);
           iteration++;
           if (iteration >= MAX_ITERATIONS) {
               break;
           }
       }
       if (!remainingNodeTypeResources.isEmpty()) {
-          registerAndRemoveSucceeds(remainingNodeTypeResources, classLoader, nodeTypeManager, namespaceRegistry, valueFactory, true);
+          registerNodeTypesAndRemoveSucceeds(remainingNodeTypeResources, classLoader, nodeTypeManager, namespaceRegistry, valueFactory, true);
       }
     }
     
@@ -115,7 +193,7 @@ public final class NodeTypeDefinitionSca
      * @param valueFactory
      * @param logError if true, and error is logged if node type registration failed. Otherwise it is ignored.
      */
-    private void registerAndRemoveSucceeds(List<String> nodeTypeResources, ClassLoader classLoader,
+    private void registerNodeTypesAndRemoveSucceeds(List<String> nodeTypeResources, ClassLoader classLoader,
             NodeTypeManager nodeTypeManager, NamespaceRegistry namespaceRegistry, ValueFactory valueFactory,
             boolean logError) {
         Iterator<String> nodeTypeResourcesIterator = nodeTypeResources.iterator();
@@ -190,4 +268,291 @@ public final class NodeTypeDefinitionSca
         return SINGLETON;
     }
     
+    
+    /**
+     * Some dummy classes to allow usage of CompactNodeTypeDefReader with underlying JCR mock
+     */
+    private static class DummyNodeTypeManager implements NodeTypeManager {
+        @Override
+        public NodeType getNodeType(String nodeTypeName) {
+            return null;
+        }
+        @Override
+        public boolean hasNodeType(String name) {
+            return false;
+        }
+        @Override
+        public NodeTypeIterator getAllNodeTypes() {
+            return null;
+        }
+        @Override
+        public NodeTypeIterator getPrimaryNodeTypes() {
+            return null;
+        }
+        @Override
+        public NodeTypeIterator getMixinNodeTypes() {
+            return null;
+        }
+        @Override
+        public NodeTypeTemplate createNodeTypeTemplate() {
+            return new DummyNodeTypeTemplate();
+        }
+        @Override
+        public NodeTypeTemplate createNodeTypeTemplate(NodeTypeDefinition ntd) {
+            return new DummyNodeTypeTemplate();
+        }
+        @Override
+        public NodeDefinitionTemplate createNodeDefinitionTemplate() {
+            return new DummyNodeDefinitionTemplate();
+        }
+        @Override
+        public PropertyDefinitionTemplate createPropertyDefinitionTemplate() {
+            return new DummyPropertyDefinitionTemplate();
+        }
+        @Override
+        public NodeType registerNodeType(NodeTypeDefinition ntd, boolean allowUpdate) {
+            return null;
+        }
+        @Override
+        public NodeTypeIterator registerNodeTypes(NodeTypeDefinition[] ntds, boolean allowUpdate) {
+            return null;
+        }
+        @Override
+        public void unregisterNodeType(String name) {
+        }
+        @Override
+        public void unregisterNodeTypes(String[] names) {
+        }
+    }
+    
+    private static class DummyNodeTypeTemplate implements NodeTypeTemplate {
+        @Override
+        public String getName() {
+            return null;
+        }
+        @Override
+        public String[] getDeclaredSupertypeNames() {
+            return null;
+        }
+        @Override
+        public boolean isAbstract() {
+            return false;
+        }
+        @Override
+        public boolean isMixin() {
+            return false;
+        }
+        @Override
+        public boolean hasOrderableChildNodes() {
+            return false;
+        }
+        @Override
+        public boolean isQueryable() {
+            return false;
+        }
+        @Override
+        public String getPrimaryItemName() {
+            return null;
+        }
+        @Override
+        public PropertyDefinition[] getDeclaredPropertyDefinitions() {
+            return null;
+        }
+        @Override
+        public NodeDefinition[] getDeclaredChildNodeDefinitions() {
+            return null;
+        }
+        @Override
+        public void setName(String name) {
+        }
+        @Override
+        public void setDeclaredSuperTypeNames(String[] names) {
+        }
+        @Override
+        public void setAbstract(boolean abstractStatus) {
+        }
+        @Override
+        public void setMixin(boolean mixin) {
+        }
+        @Override
+        public void setOrderableChildNodes(boolean orderable) {
+        }
+        @Override
+        public void setPrimaryItemName(String name) {
+        }
+        @Override
+        public void setQueryable(boolean queryable) {
+        }
+        @Override
+        public List getPropertyDefinitionTemplates() {
+            return new ArrayList();
+        }
+        @Override
+        public List getNodeDefinitionTemplates() {
+            return new ArrayList();
+        }        
+    }
+    
+    private static class DummyNodeDefinitionTemplate implements NodeDefinitionTemplate {
+        @Override
+        public NodeType[] getRequiredPrimaryTypes() {
+            return null;
+        }
+        @Override
+        public String[] getRequiredPrimaryTypeNames() {
+            return null;
+        }
+        @Override
+        public NodeType getDefaultPrimaryType() {
+            return null;
+        }
+        @Override
+        public String getDefaultPrimaryTypeName() {
+            return null;
+        }
+        @Override
+        public boolean allowsSameNameSiblings() {
+            return false;
+        }
+        @Override
+        public NodeType getDeclaringNodeType() {
+            return null;
+        }
+        @Override
+        public String getName() {
+            return null;
+        }
+        @Override
+        public boolean isAutoCreated() {
+            return false;
+        }
+        @Override
+        public boolean isMandatory() {
+            return false;
+        }
+        @Override
+        public int getOnParentVersion() {
+            return 0;
+        }
+        @Override
+        public boolean isProtected() {
+            return false;
+        }
+        @Override
+        public void setName(String name) {
+        }
+        @Override
+        public void setAutoCreated(boolean autoCreated) {
+        }
+        @Override
+        public void setMandatory(boolean mandatory) {
+        }
+        @Override
+        public void setOnParentVersion(int opv) {
+        }
+        @Override
+        public void setProtected(boolean protectedStatus) {
+        }
+        @Override
+        public void setRequiredPrimaryTypeNames(String[] names) {
+        }
+        @Override
+        public void setDefaultPrimaryTypeName(String name) {
+        }
+        @Override
+        public void setSameNameSiblings(boolean allowSameNameSiblings) {
+        }
+    }
+    
+    private static class DummyPropertyDefinitionTemplate implements PropertyDefinitionTemplate {
+        @Override
+        public int getRequiredType() {
+            return 0;
+        }
+        @Override
+        public String[] getValueConstraints() {
+            return null;
+        }
+        @Override
+        public Value[] getDefaultValues() {
+            return null;
+        }
+        @Override
+        public boolean isMultiple() {
+            return false;
+        }
+        @Override
+        public String[] getAvailableQueryOperators() {
+            return null;
+        }
+        @Override
+        public boolean isFullTextSearchable() {
+            return false;
+        }
+        @Override
+        public boolean isQueryOrderable() {
+            return false;
+        }
+        @Override
+        public NodeType getDeclaringNodeType() {
+            return null;
+        }
+        @Override
+        public String getName() {
+            return null;
+        }
+        @Override
+        public boolean isAutoCreated() {
+            return false;
+        }
+        @Override
+        public boolean isMandatory() {
+            return false;
+        }
+        @Override
+        public int getOnParentVersion() {
+            return 0;
+        }
+        @Override
+        public boolean isProtected() {
+            return false;
+        }
+        @Override
+        public void setName(String name) {
+        }
+        @Override
+        public void setAutoCreated(boolean autoCreated) {
+        }
+        @Override
+        public void setMandatory(boolean mandatory) {
+        }
+        @Override
+        public void setOnParentVersion(int opv) {
+        }
+        @Override
+        public void setProtected(boolean protectedStatus) {
+        }
+        @Override
+        public void setRequiredType(int type) {
+        }
+        @Override
+        public void setValueConstraints(String[] constraints) {
+        }
+        @Override
+        public void setDefaultValues(Value[] defaultValues) {
+        }
+        @Override
+        public void setMultiple(boolean multiple) {
+        }
+        @Override
+        public void setAvailableQueryOperators(String[] operators) {
+        }
+        @Override
+        public void setFullTextSearchable(boolean fullTextSearchable) {
+        }
+        @Override
+        public void setQueryOrderable(boolean queryOrderable) {
+        }
+    }
+
 }

Added: sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/NodeTypeMode.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/NodeTypeMode.java?rev=1705787&view=auto
==============================================================================
--- sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/NodeTypeMode.java (added)
+++ sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/NodeTypeMode.java Mon Sep 28 22:16:38 2015
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.testing.mock.sling;
+
+/**
+ * How to handle node types for different {@link ResourceResolverType} types.
+ */
+public enum NodeTypeMode {
+
+    /**
+     * Neither registration of namespaces or node types required (no underlying JCR).
+     */
+    NOT_SUPPORTED,
+    
+    /**
+     * Namespaces have to be registered, but nodetypes are not supported.
+     */
+    NAMESPACES_ONLY,
+    
+    /**
+     * Nodetypes including namespaces have to be registered.
+     */
+    NODETYPES_REQUIRED
+    
+}

Propchange: sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/NodeTypeMode.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/NodeTypeMode.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Mon Sep 28 22:16:38 2015
@@ -0,0 +1 @@
+LastChangedDate LastChangedRevision LastChangedBy HeadURL Id Author

Propchange: sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/NodeTypeMode.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/ResourceResolverType.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/ResourceResolverType.java?rev=1705787&r1=1705786&r2=1705787&view=diff
==============================================================================
--- sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/ResourceResolverType.java (original)
+++ sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/ResourceResolverType.java Mon Sep 28 22:16:38 2015
@@ -37,7 +37,7 @@ public enum ResourceResolverType {
      * <li>This resource resolver type is very fast.</li>
      * </ul>
      */
-    RESOURCERESOLVER_MOCK(RRMockMockResourceResolverAdapter.class.getName(), null),
+    RESOURCERESOLVER_MOCK(RRMockMockResourceResolverAdapter.class.getName(), null, NodeTypeMode.NOT_SUPPORTED),
 
     /**
      * Uses a simple JCR "in-memory" mock as underlying repository.
@@ -51,7 +51,7 @@ public enum ResourceResolverType {
      * <li>This resource resolver type is quite fast.</li>
      * </ul>
      */
-    JCR_MOCK(MockJcrResourceResolverAdapter.class.getName(), null),
+    JCR_MOCK(MockJcrResourceResolverAdapter.class.getName(), null, NodeTypeMode.NAMESPACES_ONLY),
 
     /**
      * Uses a real JCR Jackrabbit repository.
@@ -65,7 +65,7 @@ public enum ResourceResolverType {
      * </ul>
      */
     JCR_JACKRABBIT("org.apache.sling.testing.mock.sling.jackrabbit.JackrabbitMockResourceResolverAdapter",
-            "org.apache.sling:org.apache.sling.testing.sling-mock-jackrabbit"),
+            "org.apache.sling:org.apache.sling.testing.sling-mock-jackrabbit", NodeTypeMode.NODETYPES_REQUIRED),
 
     /**
      * Uses a real JCR Jackrabbit Oak repository.
@@ -79,7 +79,7 @@ public enum ResourceResolverType {
      * </ul>
      */
     JCR_OAK("org.apache.sling.testing.mock.sling.oak.OakMockResourceResolverAdapter",
-            "org.apache.sling:org.apache.sling.testing.sling-mock-jackrabbit-oak"),
+            "org.apache.sling:org.apache.sling.testing.sling-mock-jackrabbit-oak", NodeTypeMode.NODETYPES_REQUIRED),
             
     /**
      * Provides resource resolver environment without any ResourceProvider.
@@ -89,16 +89,20 @@ public enum ResourceResolverType {
      * <li>The performance of this resource resolver type depends on the resource provider registered.</li>
      * </ul>
      */
-    NONE(MockNoneResourceResolverAdapter.class.getName(), null);
+    NONE(MockNoneResourceResolverAdapter.class.getName(), null, NodeTypeMode.NOT_SUPPORTED);
 
             
 
     private final String resourceResolverTypeAdapterClass;
     private final String artifactCoordinates;
+    private final NodeTypeMode nodeTypeMode;
+    
 
-    private ResourceResolverType(final String resourceResolverTypeAdapterClass, final String artifactCoordinates) {
+    private ResourceResolverType(final String resourceResolverTypeAdapterClass, final String artifactCoordinates,
+            final NodeTypeMode nodeTypeMode) {
         this.resourceResolverTypeAdapterClass = resourceResolverTypeAdapterClass;
         this.artifactCoordinates = artifactCoordinates;
+        this.nodeTypeMode = nodeTypeMode;
     }
 
     String getResourceResolverTypeAdapterClass() {
@@ -109,4 +113,11 @@ public enum ResourceResolverType {
         return this.artifactCoordinates;
     }
 
+    /**
+     * @return How JCR namespaces and node types have to be handled.
+     */
+    public NodeTypeMode getNodeTypeMode() {
+        return nodeTypeMode;
+    }
+
 }

Modified: sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/package-info.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/package-info.java?rev=1705787&r1=1705786&r2=1705787&view=diff
==============================================================================
--- sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/package-info.java (original)
+++ sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/package-info.java Mon Sep 28 22:16:38 2015
@@ -19,5 +19,5 @@
 /**
  * Mock implementation of selected Sling APIs.
  */
-@aQute.bnd.annotation.Version("1.4")
+@aQute.bnd.annotation.Version("1.5")
 package org.apache.sling.testing.mock.sling;

Copied: sling/trunk/testing/mocks/sling-mock/src/test/java/org/apache/sling/testing/mock/sling/NodeTypeDefinitionScannerTest.java (from r1705759, sling/trunk/testing/mocks/sling-mock/src/test/java/org/apache/sling/testing/mock/sling/context/NodeTypeDefinitionScannerTest.java)
URL: http://svn.apache.org/viewvc/sling/trunk/testing/mocks/sling-mock/src/test/java/org/apache/sling/testing/mock/sling/NodeTypeDefinitionScannerTest.java?p2=sling/trunk/testing/mocks/sling-mock/src/test/java/org/apache/sling/testing/mock/sling/NodeTypeDefinitionScannerTest.java&p1=sling/trunk/testing/mocks/sling-mock/src/test/java/org/apache/sling/testing/mock/sling/context/NodeTypeDefinitionScannerTest.java&r1=1705759&r2=1705787&rev=1705787&view=diff
==============================================================================
--- sling/trunk/testing/mocks/sling-mock/src/test/java/org/apache/sling/testing/mock/sling/context/NodeTypeDefinitionScannerTest.java (original)
+++ sling/trunk/testing/mocks/sling-mock/src/test/java/org/apache/sling/testing/mock/sling/NodeTypeDefinitionScannerTest.java Mon Sep 28 22:16:38 2015
@@ -16,12 +16,13 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.sling.testing.mock.sling.context;
+package org.apache.sling.testing.mock.sling;
 
 import static org.junit.Assert.assertTrue;
 
 import java.util.List;
 
+import org.apache.sling.testing.mock.sling.NodeTypeDefinitionScanner;
 import org.junit.Test;
 
 

Modified: sling/trunk/testing/mocks/sling-mock/src/test/java/org/apache/sling/testing/mock/sling/jcrmock/resource/MultipleResourceResolverTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/mocks/sling-mock/src/test/java/org/apache/sling/testing/mock/sling/jcrmock/resource/MultipleResourceResolverTest.java?rev=1705787&r1=1705786&r2=1705787&view=diff
==============================================================================
--- sling/trunk/testing/mocks/sling-mock/src/test/java/org/apache/sling/testing/mock/sling/jcrmock/resource/MultipleResourceResolverTest.java (original)
+++ sling/trunk/testing/mocks/sling-mock/src/test/java/org/apache/sling/testing/mock/sling/jcrmock/resource/MultipleResourceResolverTest.java Mon Sep 28 22:16:38 2015
@@ -27,5 +27,5 @@ public class MultipleResourceResolverTes
     protected ResourceResolverType getResourceResolverType() {
         return ResourceResolverType.JCR_MOCK;
     }
-
+    
 }

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=1705787&r1=1705786&r2=1705787&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 Mon Sep 28 22:16:38 2015
@@ -26,7 +26,6 @@ import static org.junit.Assert.assertNot
 import java.io.IOException;
 import java.io.InputStream;
 
-import javax.jcr.NamespaceRegistry;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 
@@ -37,11 +36,14 @@ import org.apache.sling.api.resource.Res
 import org.apache.sling.api.resource.ResourceUtil;
 import org.apache.sling.api.resource.ValueMap;
 import org.apache.sling.testing.mock.sling.MockSling;
+import org.apache.sling.testing.mock.sling.NodeTypeDefinitionScanner;
 import org.apache.sling.testing.mock.sling.ResourceResolverType;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
+import com.google.common.collect.ImmutableList;
+
 public abstract class AbstractContentLoaderJsonDamTest {
 
     private ResourceResolver resourceResolver;
@@ -51,18 +53,13 @@ public abstract class AbstractContentLoa
     protected ResourceResolver newResourceResolver() {
         ResourceResolver resolver = MockSling.newResourceResolver(getResourceResolverType());
 
-        if (getResourceResolverType() == ResourceResolverType.JCR_MOCK) {
-            try {
-                // dummy namespace registrations to make sure sling JCR resolver
-                // does not get mixed up with the prefixes
-                NamespaceRegistry namespaceRegistry = resolver.adaptTo(Session.class).getWorkspace()
-                        .getNamespaceRegistry();
-                namespaceRegistry.registerNamespace("sling", "http://mock/sling");
-                namespaceRegistry.registerNamespace("app", "http://mock/app");
-                namespaceRegistry.registerNamespace("dam", "http://mock/dam");
-            } catch (RepositoryException ex) {
-                throw new RuntimeException("Unable to register namespaces.", ex);
-            }
+        try {
+            NodeTypeDefinitionScanner.get().register(resolver.adaptTo(Session.class), 
+                    ImmutableList.of("SLING-INF/nodetypes/app.cnd"),
+                    getResourceResolverType().getNodeTypeMode());
+        }
+        catch (RepositoryException ex) {
+            throw new RuntimeException("Unable to register namespaces.", ex);
         }
 
         return resolver;

Modified: sling/trunk/testing/mocks/sling-mock/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderJsonTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/mocks/sling-mock/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderJsonTest.java?rev=1705787&r1=1705786&r2=1705787&view=diff
==============================================================================
--- sling/trunk/testing/mocks/sling-mock/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderJsonTest.java (original)
+++ sling/trunk/testing/mocks/sling-mock/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderJsonTest.java Mon Sep 28 22:16:38 2015
@@ -26,7 +26,6 @@ import static org.junit.Assert.assertNot
 import java.util.Calendar;
 import java.util.TimeZone;
 
-import javax.jcr.NamespaceRegistry;
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
@@ -37,11 +36,14 @@ import org.apache.sling.api.resource.Res
 import org.apache.sling.api.resource.ResourceUtil;
 import org.apache.sling.api.resource.ValueMap;
 import org.apache.sling.testing.mock.sling.MockSling;
+import org.apache.sling.testing.mock.sling.NodeTypeDefinitionScanner;
 import org.apache.sling.testing.mock.sling.ResourceResolverType;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
+import com.google.common.collect.ImmutableList;
+
 public abstract class AbstractContentLoaderJsonTest {
 
     private ResourceResolver resourceResolver;
@@ -51,18 +53,13 @@ public abstract class AbstractContentLoa
     protected ResourceResolver newResourceResolver() {
         ResourceResolver resolver = MockSling.newResourceResolver(getResourceResolverType());
 
-        if (getResourceResolverType() == ResourceResolverType.JCR_MOCK) {
-            try {
-                // dummy namespace registrations to make sure sling JCR resolver
-                // does not get mixed up with the prefixes
-                NamespaceRegistry namespaceRegistry = resolver.adaptTo(Session.class).getWorkspace()
-                        .getNamespaceRegistry();
-                namespaceRegistry.registerNamespace("sling", "http://mock/sling");
-                namespaceRegistry.registerNamespace("app", "http://mock/app");
-                namespaceRegistry.registerNamespace("dam", "http://mock/dam");
-            } catch (RepositoryException ex) {
-                throw new RuntimeException("Unable to register namespaces.", ex);
-            }
+        try {
+            NodeTypeDefinitionScanner.get().register(resolver.adaptTo(Session.class), 
+                    ImmutableList.of("SLING-INF/nodetypes/app.cnd"),
+                    getResourceResolverType().getNodeTypeMode());
+        }
+        catch (RepositoryException ex) {
+            throw new RuntimeException("Unable to register namespaces.", ex);
         }
 
         return resolver;

Modified: sling/trunk/testing/mocks/sling-mock/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractJcrNamespaceTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/mocks/sling-mock/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractJcrNamespaceTest.java?rev=1705787&r1=1705786&r2=1705787&view=diff
==============================================================================
--- sling/trunk/testing/mocks/sling-mock/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractJcrNamespaceTest.java (original)
+++ sling/trunk/testing/mocks/sling-mock/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractJcrNamespaceTest.java Mon Sep 28 22:16:38 2015
@@ -21,9 +21,7 @@ package org.apache.sling.testing.mock.sl
 import static org.apache.sling.jcr.resource.JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY;
 import static org.junit.Assert.assertEquals;
 
-import javax.jcr.NamespaceRegistry;
 import javax.jcr.RepositoryException;
-import javax.jcr.Session;
 
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceResolver;
@@ -47,16 +45,13 @@ public abstract class AbstractJcrNamespa
     protected abstract ResourceResolverType getResourceResolverType();
     
     @Test
-    public void testSling4362_WithSlingNamespace() throws RepositoryException {
+    public void testSling4362() throws RepositoryException {
         ResourceResolver resolver = MockSling.newResourceResolver(getResourceResolverType());
         
-        NamespaceRegistry namespaceRegistry = resolver.adaptTo(Session.class).getWorkspace().getNamespaceRegistry();
-        namespaceRegistry.registerNamespace("sling", "http://mock/sling");
-        
         ContentLoader contentLoader = new ContentLoader(resolver);
-        contentLoader.json("/json-import-samples/SLING-4362.json", "/content/foo");
+        contentLoader.json("/json-import-samples/SLING-4362.json", context.uniqueRoot().content() + "/foo");
 
-        Resource resource = resolver.getResource("/content/foo");
+        Resource resource = resolver.getResource(context.uniqueRoot().content() + "/foo");
         
         ValueMap props = ResourceUtil.getValueMap(resource);
         assertEquals("fooType", props.get(SLING_RESOURCE_TYPE_PROPERTY));
@@ -64,29 +59,13 @@ public abstract class AbstractJcrNamespa
     }
 
     @Test
-    public void testSling4362_WithoutSlingNamespace() throws RepositoryException {
-        ResourceResolver resolver = MockSling.newResourceResolver(getResourceResolverType());
-        
-        ContentLoader contentLoader = new ContentLoader(resolver);
-        contentLoader.json("/json-import-samples/SLING-4362.json", "/content/foo");
-
-        Resource resource = resolver.getResource("/content/foo");
-        
-        ValueMap props = ResourceUtil.getValueMap(resource);
-        assertEquals("fooType", props.get(SLING_RESOURCE_TYPE_PROPERTY));
-        
-        // since SLING-4773 sling namespace is readly registered in the MockJcrResourceResolverAdapter, so this will still work here
-        assertEquals("fooType", resource.getResourceType());
-    }
-
-    @Test
-    public void testSling4362_WithoutSlingNamespace_ViaContextRule() throws RepositoryException {
+    public void testSling4362_ViaContextRule() throws RepositoryException {
         ResourceResolver resolver = context.resourceResolver();
         
         ContentLoader contentLoader = new ContentLoader(resolver);
-        contentLoader.json("/json-import-samples/SLING-4362.json", "/content/foo");
+        contentLoader.json("/json-import-samples/SLING-4362.json", context.uniqueRoot().content() + "/foo");
 
-        Resource resource = resolver.getResource("/content/foo");
+        Resource resource = resolver.getResource(context.uniqueRoot().content() + "/foo");
         
         ValueMap props = ResourceUtil.getValueMap(resource);
         assertEquals("fooType", props.get(SLING_RESOURCE_TYPE_PROPERTY));

Modified: sling/trunk/testing/mocks/sling-mock/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractMultipleResourceResolverTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/mocks/sling-mock/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractMultipleResourceResolverTest.java?rev=1705787&r1=1705786&r2=1705787&view=diff
==============================================================================
--- sling/trunk/testing/mocks/sling-mock/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractMultipleResourceResolverTest.java (original)
+++ sling/trunk/testing/mocks/sling-mock/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractMultipleResourceResolverTest.java Mon Sep 28 22:16:38 2015
@@ -18,7 +18,6 @@
  */
 package org.apache.sling.testing.mock.sling.resource;
 
-import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 
@@ -39,8 +38,9 @@ import com.google.common.collect.Immutab
 public abstract class AbstractMultipleResourceResolverTest {
 
     private final BundleContext bundleContext = MockOsgi.newBundleContext();
+    
     protected abstract ResourceResolverType getResourceResolverType();
-
+    
     protected ResourceResolverFactory newResourceResolerFactory() {
         return MockSling.newResourceResolverFactory(getResourceResolverType(), bundleContext);
     }
@@ -48,14 +48,8 @@ public abstract class AbstractMultipleRe
     @Test
     public void testMultipleResourceResolver() throws Exception {
         ResourceResolverFactory factory = newResourceResolerFactory();
-        ResourceResolver resolver1 = factory.getResourceResolver(ImmutableMap.<String, Object>of(
-                ResourceResolverFactory.USER, "user1"));
-        ResourceResolver resolver2 = factory.getResourceResolver(ImmutableMap.<String, Object>of(
-                ResourceResolverFactory.USER, "user2"));
-        
-        // validate user names
-        assertEquals("user1", resolver1.getAttribute(ResourceResolverFactory.USER));
-        assertEquals("user2", resolver2.getAttribute(ResourceResolverFactory.USER));
+        ResourceResolver resolver1 = factory.getAdministrativeResourceResolver(null);
+        ResourceResolver resolver2 = factory.getAdministrativeResourceResolver(null);
         
         // add a resource in resolver 1
         Resource root = resolver1.getResource("/");

Added: sling/trunk/testing/mocks/sling-mock/src/test/resources/SLING-INF/nodetypes/app.cnd
URL: http://svn.apache.org/viewvc/sling/trunk/testing/mocks/sling-mock/src/test/resources/SLING-INF/nodetypes/app.cnd?rev=1705787&view=auto
==============================================================================
--- sling/trunk/testing/mocks/sling-mock/src/test/resources/SLING-INF/nodetypes/app.cnd (added)
+++ sling/trunk/testing/mocks/sling-mock/src/test/resources/SLING-INF/nodetypes/app.cnd Mon Sep 28 22:16:38 2015
@@ -0,0 +1,26 @@
+//
+//  Licensed to the Apache Software Foundation (ASF) under one
+//  or more contributor license agreements.  See the NOTICE file
+//  distributed with this work for additional information
+//  regarding copyright ownership.  The ASF licenses this file
+//  to you under the Apache License, Version 2.0 (the
+//  "License"); you may not use this file except in compliance
+//  with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing,
+//  software distributed under the License is distributed on an
+//  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+//  KIND, either express or implied.  See the License for the
+//  specific language governing permissions and limitations
+//  under the License.
+//
+<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/src/test/resources/SLING-INF/nodetypes/app.cnd
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/testing/mocks/sling-mock/src/test/resources/SLING-INF/nodetypes/app.cnd
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Mon Sep 28 22:16:38 2015
@@ -0,0 +1 @@
+LastChangedDate LastChangedRevision LastChangedBy HeadURL Id Author

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



Mime
View raw message