You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 10:23:16 UTC

[sling-org-apache-sling-testing-sling-mock] annotated tag org.apache.sling.testing.sling-mock-1.6.0 created (now b5291e1)

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

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


      at b5291e1  (tag)
 tagging e05f6cafb3e378dc3e25b3a6b8d2d43d247f084d (commit)
      by Stefan Seifert
      on Mon Oct 5 17:29:02 2015 +0000

- Log -----------------------------------------------------------------
org.apache.sling.testing.sling-mock-1.6.0
-----------------------------------------------------------------------

This annotated tag includes the following new commits:

     new 2aa4712  SLING-4042 Donate sling-mock, jcr-mock, osgi-mock implementation
     new d63d89c  svn:ignore
     new a6e7c1a  SLING-4042 move all mock projects to mocks/ subdirectory
     new d1f839a  SLING-4042 add missing package-info files
     new e9e968a  SLING-4042 per default no charencoding should be set in mock response
     new 43eb350  SLING-4042 do not forget to register ResourceResolverFactory in OSGi context as well
     new 3d36daf  SLING-4042 make sure JCR mock supports accessing data using multiple sessions
     new 4fc4baf  SLING-4042 add README files
     new 4aa90b9  add/update SCM urls
     new 22c8024  update to released versions
     new 1ba5459  [maven-release-plugin] prepare release org.apache.sling.testing.sling-mock-1.0.0
     new 5dcb3d7  [maven-release-plugin] prepare for next development iteration
     new 5b0b3fe  update dependencies in release process to next snapshot version
     new 1f52235  SLING-4085 NPE when using SlingContext rule without constructor argument
     new 9442dd8  SLING-4086 SlingHttpServlerRequest should support getResourceBundle() methods
     new 2f5faf4  set to released version now available on maven central
     new 6964d49  SLING-4090 Define package versions for Sling Mock, JCR Mock, OSGi Mock
     new 448fe45  SLING-4108 JCR/Sling/ResourceResolver Mock: Support providing authentication info
     new 5b4c01c  fix some javadoc errors and warnings
     new cb5f237  SLING-4162 Introduce "OsgiContext" junit rule for OSGi and OsgiContextImpl
     new e72ad4b  SLING-4229 add test cases for deep path access support in sling-mock as well
     new a07abf8  SLING-4108 default to getAdministrativeResourceResolver in sling-mock to support jackrabbit resource resolver adapter as well
     new 3cbedc6  fix some javadoc errors/warnings
     new 47cc45e  update to released versions
     new fccd947  [maven-release-plugin] prepare release org.apache.sling.testing.sling-mock-1.1.0
     new 4b72ed2  [maven-release-plugin] prepare for next development iteration
     new 85cdaa4  update to next snapshot version until releases available in maven central
     new 2de8a96  SLING-4266 - SlingContext always uses the default resourceResolverType
     new 0a167f6  SLING-4268 - ContentLoader should not try to import ACLs
     new 9ee66c6  SLING-4269 - SlingContextImpl's resource resolver should be an administrative one
     new 6f6321b  switch back to released versions for dependencies
     new a969262  SLING-4267 add some more property names to be ignored on import because they are managed by JCR internally
     new 62e7e2a  SLING-4267 support importing nt:resource noded in jackrabbit with empty binary data enable content loader unit tests in sling-mock-jackrabbit
     new 6569ce2  assertions can be activated now after updating to latest mock dependencies
     new b816e47  SLING-4267 support importing nt:resource nodes in jackrabbit with empty binary data
     new 32c3978  update dependencies to released versions
     new c05aeae  [maven-release-plugin] prepare release org.apache.sling.testing.sling-mock-1.1.2
     new e57b7e1  [maven-release-plugin] prepare for next development iteration
     new d9fcb59  update to next development snapshot unit released artifacts are in maven central
     new c0e8f71  switch back to released versions now available in maven central
     new e8d2807  SLING-4362 make sure JCR namespaces are correctly registered in JCR mock on initialization through sling mock
     new 90ddb94  SLING-4376 ResourceResolver.resolve(null) should resolve to root resource
     new c49b0e1  SLING-4394 Sling Mock with JCR-based Resource Resolver: Support default search paths
     new 5e1c2d6  SLING-848 Support getting versioned resources by using uri path parameters
     new 4e72c06  Use the recent resourceresolver SNAPSHOT in sling-mock
     new eb9da99  SLING-848 revert updating sling api/resource resolver/jcr resource dependenciens - using sling mock in a project should not enforce using the latest version of those keep adding of getThreadResourceResolver() method, but throw UnsupportedOperationException
     new 2259bfe  SLING-4431 Sling Mocks: Remove Dependency on ResourceResolverInjector
     new 74de88f  cosmetic code formatting changes
     new 9e35c02  SLING-4434 refactor integration with sling models: remove MockModelAdapterFactory and directly integrate the original ModelAdapterFactory using the new osgi mock dynamic service reference feature
     new 71bbb5c  SLING-4437 MockJcrResourceResolverFactory should allow to register services dynamically
     new fc5346f  SLING-4433 use real AdapterManagerImpl implementation with support for ADAPTER_CLASSES/ADAPTABLE_CLASSES
     new a4d3ac9  SLING-4433 remove dependency to org.apache.sling.adapter and inline helper classes instead
     new 58f81ee  update to release versions
     new ac35a62  update package version
     new 29e7fda  [maven-release-plugin] prepare release org.apache.sling.testing.sling-mock-1.2.0
     new f96f34a  [maven-release-plugin] prepare for next development iteration
     new 93110e5  remove service description and vendor for this mock service - makes problems with baseline check
     new f187b33  remove service description and vendor for this mock service - makes problems with baseline check
     new 1b68139  update to next development snapshot unit released artifacts are in maven central
     new 53be964  switch to released versions
     new 34954fa  SLING-4522 Sling Mocks: ContentLoader fails for UTF8 encoded json files on Windows Systems
     new 75d379a  Fix scr xml parsing when updating to new scr plugin by using fix for SLING-4670
     new b0f4a0a  SLING-4698 - Set parent.relativePath to empty for all modules
     new 28f1b00  SLING-4654 Support ResourceResolver.findResources with JCR_MOCK
     new 6728203  SLING-4721 sling-mock: Fully support ResourceResolverFactoryActivator for jcr-mock
     new 8a9b3c4  SLING-4729 Sling Mock: Add "NONE" resource resolver type
     new 5d2ffa2  SLING-4470 introduce separate "logging-mock" project for default log configuration in mock tests, remove compile-dependency on slf4j-simple
     new 192936d  update dependencies for release
     new ab204bb  update dependencies for release
     new 5482f51  [maven-release-plugin] prepare release org.apache.sling.testing.sling-mock-1.3.0
     new 7baf341  [maven-release-plugin] prepare for next development iteration
     new 9a0fa2b  update to next development snapshot unit released artifacts are in maven central
     new bb58061  SLING-4605 - Add support for an Oak resource resolver type mock
     new 3601bfd  Mocks: use latest snapshots
     new b6207fb  SLING-4605 - Add support for an Oak resource resolver type mock
     new bac4c7f  update to released mock versions
     new 37c868a  SLING-4756 add support for filtering via felix.framework FilterImpl implementation
     new 546986a  SLING-4605 javadoc updates and add initializing for ContextResourceResolverFactory
     new 6e3e339  Minor wording fixes when the ResourceResolverTypeAdapter can't be found.
     new f4c6d5d  SLING-4775 - MockSlingSettingService shoud support getSlingId()
     new 7a57b01  SLING-4775 move the now supported method out of the "unsupported operations" block
     new e0cc675  SLING-4773 ensure sling namespace is always registered when using JCR_MOCK resource resolver adapter
     new d39a8a6  update to released versions
     new 54d3fe0  [maven-release-plugin] prepare release org.apache.sling.testing.sling-mock-1.4.0
     new 8913f6c  [maven-release-plugin] prepare for next development iteration
     new 37fa126  update to latest development snapshots
     new df31839  Update to Sling Parent 23
     new e497760  Testing: remove superflous sling.java.version=6 as it's the default now
     new d8691fa  switch to released versions
     new a3f2ae9  set parent version to 24 and add empty relativePath where missing
     new 05758ef  SLING-4932, make compatible with o.a.s.jcr.resource 2.5 (requires also an upgrade to Sling API 2.9)
     new 169f6e0  SLING-4932 switch back to old api/jcr.resource versions and ensure compatibility by initiating PathMapper service by reflection if it exists
     new 9ab5f09  SLING-4938 exclude optional transitive dependencies of reflections
     new 347ce2a  SLING-4990 Support HttpSession invalidate, new, lastAccessedTime, maxInteractiveInterval
     new 602f4a9  SLING-4993 Support RequestParameter in MockSlingHttpServlerRequest
     new ec0efee  SLING-4994 Support InputStream, ContentLenght, ContentType and CharacterEncoding in Request
     new 489ae34  SLING-4998 ResponseBodySupport - use default charset if no response charset is set
     new 9832809  cosmetic: beautify error messages when setup/teardown fails
     new da53509  SLING-5002 - [sling-mock] Update dependency version of org.reflections
     new 3fafd8e  SLING-5003 Support request dispatcher in MockSlingHttpServletRequest
     new b4037bf  SLING-5002 switch back to 0.9.9 due to threading issues in 0.9.10 when running junit tests in parallel
     new e52575e  update other mocks to latest releases
     new 2a934a4  [maven-release-plugin] prepare release org.apache.sling.testing.sling-mock-1.5.0
     new 8f19c45  [maven-release-plugin] prepare for next development iteration
     new d58abbe  switch to latest snapshot version until release is available in maven central
     new 07c6650  SLING-5007 add unit test to explicitly test root path child listing in sling-mock as well
     new d5ebb42  SLING-5007 realx unit test to test root path child listing in sling-mock-jackrabbit and sling-mock-jackrabbit and sling-mock-oak because in real repositories multiple root test nodes may be created in parallel, or nodes already exist
     new 8580a55  update release versions
     new 5846795  update to next snapshot version until releases are available in maven central
     new f960880  SLING-5007 use same unit tests for root node tests for all resource resolver types without counting the number of children.
     new 0ac864b  switch back to released version
     new add520f  SLING-5042 ResourceResolver.commit() does not call session.save() on the backing JCR Session
     new 8123868  SLING-5043 sling-mocks: Execute commit() after ContentLoader operations
     new c1ce2e6  SLING-5057 - Support HttpServletRequest#getRemoteUser
     new b10d3bb  SLING-5057 - Support HttpServletRequest#getRemoteUser
     new 53bfbe5  SLING-5064 sling-mock: Register JCR node types for OSGi bundles in class path
     new 853e02b  SLING-5064 sling-mock: Register JCR node types for OSGi bundles in class path
     new c7551b3  cosmetic: fix log message
     new 317bf58  SLING-5066 sling-mock: Close ResourceResolver on JUnit test tearDown
     new f008644  SLING-5064 sling-mock: Register JCR node types for OSGi bundles in class path
     new 8c79b81  SLING-5067 sling-mock: "uniqueRoot()" to simplify creation and cleanup of unique root paths in repository
     new b24a116  SLING-5067 rewrite unit tests to use new "uniqueRoot" feature
     new 3c296a7  SLING-5064 manual registration of node types no longer required; register namespaces and node types centrally depending on NodeTypeMode
     new d795bcc  SLING-5067 fix cleanup issue with "uniqueRoot" feature
     new d74181d  SLING-5086 sling-mock: Add SlingContext.registerAdapter convenience method
     new fd0b260  SLING-5086 sling-mock: Add SlingContext.registerAdapter convenience method
     new cf03565  cosmetic: eliminate some javadoc warnings
     new 5c7c77d  SLING-5088 update to latest osgi-mock to make sure all services are deactivated properly
     new 856784c  SLING-5088 refactor unit test to make sure resource resolver and bundle contexts are properly shutdown
     new b90bd44  SLING-5088 refactor resource resolver initialization
     new 81f87d0  SLING-5088 rewrite setup code for resource resolver factory
     new 1b9e8db  SLING-5088 deprecate all methods that may lead to thread leaks
     new 8801d99  SLING-5088 control SlingRepository resources via activate/deactivate methods; make sure all oak ExecutorServices are shutdown properly
     new c1525db  cosmetic: fix javadoc errors
     new 47f0035  SLING-5088 avoid registering ResourceResolverFactory twice
     new 21a5c64  SLING-5088 register default service user mapping for mock bundle
     new 2b7ac22  Update the main reactor to parent 25
     new 1089980  update dependency
     new 8949c00  [maven-release-plugin] prepare release org.apache.sling.testing.sling-mock-1.6.0
     new e05f6ca  [maven-release-plugin] copy for tag org.apache.sling.testing.sling-mock-1.6.0

The 140 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


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

[sling-org-apache-sling-testing-sling-mock] 14/37: SLING-5064 sling-mock: Register JCR node types for OSGi bundles in class path

Posted by ro...@apache.org.
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-1.6.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git

commit 853e02b00aaf0750d56a20ce5d91c644bf6fd3e8
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Sat Sep 26 21:47:39 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@1705487 13f79535-47bb-0310-9956-ffa450edef68
---
 .../sling/context/NodeTypeDefinitionScanner.java   | 27 ++++++++++++++++------
 1 file changed, 20 insertions(+), 7 deletions(-)

diff --git a/src/main/java/org/apache/sling/testing/mock/sling/context/NodeTypeDefinitionScanner.java b/src/main/java/org/apache/sling/testing/mock/sling/context/NodeTypeDefinitionScanner.java
index da5f33a..bec7900 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/context/NodeTypeDefinitionScanner.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/context/NodeTypeDefinitionScanner.java
@@ -58,33 +58,46 @@ public final class NodeTypeDefinitionScanner {
         nodeTypeDefinitions = findeNodeTypeDefinitions();
     }
     
+    /**
+     * @return Node type definitions found in classpath as registered in OSGi bundle headers
+     */
     public List<String> getNodeTypeDefinitions() {
         return nodeTypeDefinitions;
     }
 
     /**
      * Registers node types found in classpath in JCR repository.
-     * @param Session session
+     * @param session Session
      */
     public void register(Session session) throws RepositoryException {
+      List<String> nodeTypeResources = getNodeTypeDefinitions();
+      register(session, nodeTypeResources);
+    }
+    
+    /**
+     * Registers node types found in classpath in JCR repository.
+     * @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 {
       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 ecact order is not known
-      List<String> nodeTypeResources = new ArrayList<String>(NodeTypeDefinitionScanner.get().getNodeTypeDefinitions());
+      // try registering node types multiple times because the eyact order is not known
       int iteration = 0;
-      while (!nodeTypeResources.isEmpty()) {
-          registerAndRemoveSucceeds(nodeTypeResources, classLoader, nodeTypeManager, namespaceRegistry, valueFactory, false);
+      List<String> remainingNodeTypeResources = new ArrayList<String>(nodeTypeResources);
+      while (!remainingNodeTypeResources.isEmpty()) {
+          registerAndRemoveSucceeds(remainingNodeTypeResources, classLoader, nodeTypeManager, namespaceRegistry, valueFactory, false);
           iteration++;
           if (iteration >= MAX_ITERATIONS) {
               break;
           }
       }
-      if (!nodeTypeResources.isEmpty()) {
-          registerAndRemoveSucceeds(nodeTypeResources, classLoader, nodeTypeManager, namespaceRegistry, valueFactory, true);
+      if (!remainingNodeTypeResources.isEmpty()) {
+          registerAndRemoveSucceeds(remainingNodeTypeResources, classLoader, nodeTypeManager, namespaceRegistry, valueFactory, true);
       }
     }
     

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

[sling-org-apache-sling-testing-sling-mock] 01/37: [maven-release-plugin] prepare for next development iteration

Posted by ro...@apache.org.
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-1.6.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git

commit 8f19c45b44839d0d5f0252b597de6461967d4a4e
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Mon Sep 7 21:43:06 2015 +0000

    [maven-release-plugin] prepare for next development iteration
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock@1701704 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/pom.xml b/pom.xml
index 2edc18f..0e59375 100644
--- a/pom.xml
+++ b/pom.xml
@@ -28,16 +28,16 @@
     </parent>
 
     <artifactId>org.apache.sling.testing.sling-mock</artifactId>
-    <version>1.5.0</version>
+    <version>1.5.1-SNAPSHOT</version>
     <packaging>bundle</packaging>
 
     <name>Apache Sling Testing Sling Mock</name>
     <description>Mock implementation of selected Sling APIs.</description>
 
     <scm>
-        <connection>scm:svn:http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.testing.sling-mock-1.5.0</connection>
-        <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.testing.sling-mock-1.5.0</developerConnection>
-        <url>http://svn.apache.org/viewvc/sling/tags/org.apache.sling.testing.sling-mock-1.5.0</url>
+        <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock</connection>
+        <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock</developerConnection>
+        <url>http://svn.apache.org/viewvc/sling/trunk/testing/mocks/sling-mock</url>
     </scm>
 
     <dependencies>

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

[sling-org-apache-sling-testing-sling-mock] 08/37: switch back to released version

Posted by ro...@apache.org.
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-1.6.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git

commit 0ac864b3bf7976160ebc3689e6e183491022ca58
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Thu Sep 17 22:36:40 2015 +0000

    switch back to released version
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock@1703724 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index 85a526d..5d6f3f8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -57,7 +57,7 @@
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.testing.resourceresolver-mock</artifactId>
-            <version>1.1.11-SNAPSHOT</version>
+            <version>1.1.10</version>
             <scope>compile</scope>
         </dependency>
 

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

[sling-org-apache-sling-testing-sling-mock] 02/37: switch to latest snapshot version until release is available in maven central

Posted by ro...@apache.org.
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-1.6.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git

commit d58abbeddbc643830f39fa949d59ca658139961d
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Mon Sep 7 21:50:21 2015 +0000

    switch to latest snapshot version until release is available in maven central
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock@1701705 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index 0e59375..be9a4c1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -51,7 +51,7 @@
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.testing.jcr-mock</artifactId>
-            <version>1.1.10</version>
+            <version>1.1.9-SNAPSHOT</version>
             <scope>compile</scope>
         </dependency>
         <dependency>

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

[sling-org-apache-sling-testing-sling-mock] 22/37: SLING-5086 sling-mock: Add SlingContext.registerAdapter convenience method

Posted by ro...@apache.org.
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-1.6.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git

commit d74181d3bbeebf153926ab23a0f16f29633ecce8
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Thu Oct 1 22:00:32 2015 +0000

    SLING-5086 sling-mock: Add SlingContext.registerAdapter convenience method
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock@1706325 13f79535-47bb-0310-9956-ffa450edef68
---
 .../mock/sling/context/SlingContextImpl.java       | 46 ++++++++++++++++++++++
 .../testing/mock/sling/junit/SlingContextTest.java | 23 +++++++++++
 2 files changed, 69 insertions(+)

diff --git a/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java b/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java
index 76439f0..0fe023f 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java
@@ -23,6 +23,7 @@ import java.util.Set;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 
+import org.apache.sling.api.adapter.AdapterFactory;
 import org.apache.sling.api.resource.LoginException;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceResolver;
@@ -56,6 +57,8 @@ import org.osgi.framework.ServiceReference;
 
 import aQute.bnd.annotation.ConsumerType;
 
+import com.google.common.base.Function;
+import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
 
 /**
@@ -326,5 +329,48 @@ public class SlingContextImpl extends OsgiContextImpl {
         }
         return uniqueRoot;
     }
+    
+    /**
+     * Create a Sling AdapterFactory on the fly which can adapt from <code>adaptableClass</code>
+     * to <code>adapterClass</code> and just returns the given value as result.
+     * @param adaptableClass Class to adapt from
+     * @param adapterClass Class to adapt to
+     * @param adapter Object which is always returned for this adaption.
+     */
+    public <T1, T2> void registerAdapter(final Class<T1> adaptableClass, final Class<T2> adapterClass,
+            final T2 adapter) {
+        registerAdapter(adaptableClass, adapterClass, new Function<T1, T2>() {
+            @Override
+            public T2 apply(T1 input) {
+                return adapter;
+            }
+        });
+    }
+
+    /**
+     * Create a Sling AdapterFactory on the fly which can adapt from <code>adaptableClass</code>
+     * to <code>adapterClass</code> and delegates the adapter mapping to the given <code>adaptHandler</code> function.
+     * @param adaptableClass Class to adapt from
+     * @param adapterClass Class to adapt to
+     * @param adaptHandler Function to handle the adaption
+     */
+    public <T1, T2> void registerAdapter(final Class<T1> adaptableClass, final Class<T2> adapterClass,
+            final Function<T1,T2> adaptHandler) {
+        AdapterFactory adapterFactory = new AdapterFactory() {
+            @SuppressWarnings("unchecked")
+            @Override
+            public <AdapterType> AdapterType getAdapter(Object adaptable, Class<AdapterType> type) {
+                return (AdapterType)adaptHandler.apply((T1)adaptable);
+            }
+        };
+        registerService(AdapterFactory.class, adapterFactory, ImmutableMap.<String, Object>builder()
+                .put(AdapterFactory.ADAPTABLE_CLASSES, new String[] {
+                    adaptableClass.getName()
+                })
+                .put(AdapterFactory.ADAPTER_CLASSES, new String[] {
+                        adapterClass.getName()
+                })
+                .build());
+    }
 
 }
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/junit/SlingContextTest.java b/src/test/java/org/apache/sling/testing/mock/sling/junit/SlingContextTest.java
index 8af0b55..b785f28 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/junit/SlingContextTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/junit/SlingContextTest.java
@@ -18,13 +18,16 @@
  */
 package org.apache.sling.testing.mock.sling.junit;
 
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 
 import java.io.IOException;
 
 import org.apache.sling.api.resource.PersistenceException;
+import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.testing.mock.sling.ResourceResolverType;
 import org.junit.Before;
 import org.junit.Rule;
@@ -32,6 +35,8 @@ import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.runners.MockitoJUnitRunner;
 
+import com.google.common.base.Function;
+
 @RunWith(MockitoJUnitRunner.class)
 public class SlingContextTest {
 
@@ -53,4 +58,22 @@ public class SlingContextTest {
         assertNotNull(context.request());
     }
 
+    @Test
+    public void testRegisterAdapter() {
+        
+        // prepare some adapter factories
+        context.registerAdapter(ResourceResolver.class, Integer.class, 5);
+        context.registerAdapter(ResourceResolver.class, String.class, new Function<ResourceResolver,String>() {
+            @Override
+            public String apply(ResourceResolver input) {
+                return ">" + input.toString();
+            }
+        });
+        
+        // test adaption
+        assertEquals(Integer.valueOf(5), context.resourceResolver().adaptTo(Integer.class));
+        assertEquals(">" + context.resourceResolver().toString(), context.resourceResolver().adaptTo(String.class));
+        assertNull(context.resourceResolver().adaptTo(Double.class));
+    }
+
 }

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

[sling-org-apache-sling-testing-sling-mock] 25/37: SLING-5088 update to latest osgi-mock to make sure all services are deactivated properly

Posted by ro...@apache.org.
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-1.6.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git

commit 5c7c77df63591ef43b1d755cb3376b80c9aa66dc
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Fri Oct 2 17:03:22 2015 +0000

    SLING-5088 update to latest osgi-mock to make sure all services are deactivated properly
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock@1706448 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml                                                              | 2 +-
 .../apache/sling/testing/mock/sling/context/SlingContextImpl.java    | 5 ++---
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/pom.xml b/pom.xml
index 5d6f3f8..65ec4e0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -45,7 +45,7 @@
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.testing.osgi-mock</artifactId>
-            <version>1.5.0</version>
+            <version>1.5.1-SNAPSHOT</version>
             <scope>compile</scope>
         </dependency>
         <dependency>
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java b/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java
index b561325..bc6f808 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java
@@ -163,7 +163,8 @@ public class SlingContextImpl extends OsgiContextImpl {
             this.resourceResolver.close();
         }
 
-        this.componentContext = null;
+        MockSling.clearAdapterManagerBundleContext();
+        
         this.resourceResolver = null;
         this.request = null;
         this.response = null;
@@ -171,8 +172,6 @@ public class SlingContextImpl extends OsgiContextImpl {
         this.contentLoader = null;
         this.contentBuilder = null;
         this.uniqueRoot = null;
-
-        MockSling.clearAdapterManagerBundleContext();
         
         super.tearDown();
     }

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

[sling-org-apache-sling-testing-sling-mock] 35/37: update dependency

Posted by ro...@apache.org.
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-1.6.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git

commit 1089980c2833f87314c8c9c21ce6e85de9ebeecb
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Mon Oct 5 17:27:13 2015 +0000

    update dependency
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock@1706879 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index 241586e..99393f4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -45,7 +45,7 @@
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.testing.osgi-mock</artifactId>
-            <version>1.5.1-SNAPSHOT</version>
+            <version>1.6.0</version>
             <scope>compile</scope>
         </dependency>
         <dependency>

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

[sling-org-apache-sling-testing-sling-mock] 23/37: SLING-5086 sling-mock: Add SlingContext.registerAdapter convenience method

Posted by ro...@apache.org.
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-1.6.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git

commit fd0b26066f3986b16ccd76d1c23f9c7f05ceeaef
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Thu Oct 1 22:21:42 2015 +0000

    SLING-5086 sling-mock: Add SlingContext.registerAdapter convenience method
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock@1706326 13f79535-47bb-0310-9956-ffa450edef68
---
 .../sling/testing/mock/sling/context/SlingContextImpl.java     | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java b/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java
index 0fe023f..b561325 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java
@@ -336,8 +336,10 @@ public class SlingContextImpl extends OsgiContextImpl {
      * @param adaptableClass Class to adapt from
      * @param adapterClass Class to adapt to
      * @param adapter Object which is always returned for this adaption.
+     * @param <T1> Adaptable type
+     * @param <T2> Adapter type
      */
-    public <T1, T2> void registerAdapter(final Class<T1> adaptableClass, final Class<T2> adapterClass,
+    public final <T1, T2> void registerAdapter(final Class<T1> adaptableClass, final Class<T2> adapterClass,
             final T2 adapter) {
         registerAdapter(adaptableClass, adapterClass, new Function<T1, T2>() {
             @Override
@@ -353,8 +355,10 @@ public class SlingContextImpl extends OsgiContextImpl {
      * @param adaptableClass Class to adapt from
      * @param adapterClass Class to adapt to
      * @param adaptHandler Function to handle the adaption
+     * @param <T1> Adaptable type
+     * @param <T2> Adapter type
      */
-    public <T1, T2> void registerAdapter(final Class<T1> adaptableClass, final Class<T2> adapterClass,
+    public final <T1, T2> void registerAdapter(final Class<T1> adaptableClass, final Class<T2> adapterClass,
             final Function<T1,T2> adaptHandler) {
         AdapterFactory adapterFactory = new AdapterFactory() {
             @SuppressWarnings("unchecked")
@@ -368,7 +372,7 @@ public class SlingContextImpl extends OsgiContextImpl {
                     adaptableClass.getName()
                 })
                 .put(AdapterFactory.ADAPTER_CLASSES, new String[] {
-                        adapterClass.getName()
+                    adapterClass.getName()
                 })
                 .build());
     }

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

[sling-org-apache-sling-testing-sling-mock] 09/37: SLING-5042 ResourceResolver.commit() does not call session.save() on the backing JCR Session

Posted by ro...@apache.org.
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-1.6.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git

commit add520f7cc6d83b257185f88ad673275cca13aab
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Thu Sep 17 23:54:42 2015 +0000

    SLING-5042 ResourceResolver.commit() does not call session.save() on the backing JCR Session
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock@1703732 13f79535-47bb-0310-9956-ffa450edef68
---
 .../sling/AbstractMockResourceResolverFactory.java | 11 ++---
 .../mock/sling/MockJcrResourceResolverFactory.java | 50 +++-------------------
 .../resource/AbstractJcrResourceResolverTest.java  | 18 ++++++++
 .../AbstractSlingCrudResourceResolverTest.java     | 15 +++++++
 4 files changed, 46 insertions(+), 48 deletions(-)

diff --git a/src/main/java/org/apache/sling/testing/mock/sling/AbstractMockResourceResolverFactory.java b/src/main/java/org/apache/sling/testing/mock/sling/AbstractMockResourceResolverFactory.java
index c1377c3..1a6915d 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/AbstractMockResourceResolverFactory.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/AbstractMockResourceResolverFactory.java
@@ -28,8 +28,6 @@ import org.apache.sling.api.resource.ResourceResolverFactory;
 import org.apache.sling.resourceresolver.impl.CommonResourceResolverFactoryImpl;
 import org.apache.sling.resourceresolver.impl.ResourceAccessSecurityTracker;
 import org.apache.sling.resourceresolver.impl.ResourceResolverFactoryActivator;
-import org.apache.sling.resourceresolver.impl.ResourceResolverImpl;
-import org.apache.sling.resourceresolver.impl.helper.ResourceResolverContext;
 import org.apache.sling.serviceusermapping.ServiceUserMapper;
 import org.apache.sling.serviceusermapping.impl.ServiceUserMapperImpl;
 import org.apache.sling.testing.mock.osgi.MockEventAdmin;
@@ -64,9 +62,12 @@ abstract class AbstractMockResourceResolverFactory implements ResourceResolverFa
         MockOsgi.activate(activator, resourceProviderFactoryFactoryProps);
         
         CommonResourceResolverFactoryImpl commonFactoryImpl = new CommonResourceResolverFactoryImpl(activator);
-        ResourceResolverContext context = new ResourceResolverContext(true, authenticationInfo, new ResourceAccessSecurityTracker());
-        ResourceResolverImpl resourceResolver = new ResourceResolverImpl(commonFactoryImpl, context);
-        return resourceResolver;
+        if (isAdmin) {
+            return commonFactoryImpl.getAdministrativeResourceResolver(authenticationInfo);
+        }
+        else {
+            return commonFactoryImpl.getResourceResolver(authenticationInfo);
+        }
     }
     
     /**
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/MockJcrResourceResolverFactory.java b/src/main/java/org/apache/sling/testing/mock/sling/MockJcrResourceResolverFactory.java
index 8de58a1..bc1a83d 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/MockJcrResourceResolverFactory.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/MockJcrResourceResolverFactory.java
@@ -24,20 +24,15 @@ import java.util.Map;
 
 import javax.jcr.query.Query;
 
-import org.apache.commons.lang3.ArrayUtils;
 import org.apache.sling.api.resource.LoginException;
 import org.apache.sling.api.resource.QueriableResourceProvider;
 import org.apache.sling.api.resource.ResourceProvider;
+import org.apache.sling.api.resource.ResourceProviderFactory;
 import org.apache.sling.api.resource.ResourceResolver;
-import org.apache.sling.commons.osgi.PropertiesUtil;
 import org.apache.sling.jcr.api.SlingRepository;
 import org.apache.sling.jcr.resource.internal.helper.jcr.JcrResourceProviderFactory;
 import org.apache.sling.testing.mock.osgi.MockOsgi;
 import org.osgi.framework.BundleContext;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceReference;
-
-import com.google.common.collect.ImmutableMap;
 
 /**
  * Mock {@link ResourceResolverFactory} implementation.
@@ -64,49 +59,18 @@ class MockJcrResourceResolverFactory extends AbstractMockResourceResolverFactory
         // use reflection to not depend on it if running with older version of org.apache.sling.jcr.resource
         registerServiceIfFoundInClasspath("org.apache.sling.jcr.resource.internal.helper.jcr.PathMapper");
 
-        // setup real sling JCR resource provider implementation for use in
-        // mocked context
+        // setup real sling JCR resource provider implementation for use in mocked context
         JcrResourceProviderFactory jcrResourceProviderFactory = new JcrResourceProviderFactory();
+        Dictionary<String, Object> resourceProviderProps = new Hashtable<String, Object>();
+        resourceProviderProps.put(ResourceProvider.ROOTS, new String[] { "/" });
+        resourceProviderProps.put(QueriableResourceProvider.LANGUAGES, new String[] { Query.XPATH, Query.SQL, Query.JCR_SQL2 });
         MockOsgi.injectServices(jcrResourceProviderFactory, bundleContext);
-        MockOsgi.activate(jcrResourceProviderFactory, bundleContext, ImmutableMap.<String, Object> of());
-
-        ResourceProvider resourceProvider;
-        if (isAdmin) {
-            resourceProvider = jcrResourceProviderFactory.getAdministrativeResourceProvider(authenticationInfo);
-        }
-        else {
-            resourceProvider = jcrResourceProviderFactory.getResourceProvider(authenticationInfo);
-        }
+        MockOsgi.activate(jcrResourceProviderFactory, bundleContext, resourceProviderProps);
+        bundleContext.registerService(ResourceProviderFactory.class.getName(), jcrResourceProviderFactory, resourceProviderProps);
 
-        // register JCR resource provider if not already registered
-        if (!isRootServiceProviderRegistered(bundleContext)) {
-            Dictionary<Object, Object> resourceProviderProps = new Hashtable<Object, Object>();
-            resourceProviderProps.put(ResourceProvider.ROOTS, new String[] { "/" });
-            resourceProviderProps.put(QueriableResourceProvider.LANGUAGES, new String[] { Query.XPATH, Query.SQL, Query.JCR_SQL2 });
-            bundleContext.registerService(ResourceProvider.class.getName(), resourceProvider, resourceProviderProps);
-        }
-        
         return super.getResourceResolverInternal(authenticationInfo, isAdmin);
     }
     
-    private boolean isRootServiceProviderRegistered(BundleContext bundleContext) {
-        try {
-            ServiceReference[] serviceReferences = bundleContext.getServiceReferences(ResourceProvider.class.getName(), null) ;
-            if (serviceReferences != null) {
-                for (ServiceReference serviceReference : serviceReferences) {
-                    String[] roots = PropertiesUtil.toStringArray(serviceReference.getProperty(ResourceProvider.ROOTS));
-                    if (ArrayUtils.contains(roots, "/")) {
-                        return true;
-                    }
-                }
-            }
-            return false;
-        }
-        catch (InvalidSyntaxException ex) {
-            throw new RuntimeException(ex);
-        }
-    }
-    
     private void registerServiceIfFoundInClasspath(String className) {
         try {
             Class pathMapperClass = Class.forName(className);
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractJcrResourceResolverTest.java b/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractJcrResourceResolverTest.java
index c5867f6..12960dd 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractJcrResourceResolverTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractJcrResourceResolverTest.java
@@ -20,7 +20,9 @@ package org.apache.sling.testing.mock.sling.resource;
 
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
 
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
@@ -176,4 +178,20 @@ public abstract class AbstractJcrResourceResolverTest {
         assertEquals("sling/resource/type", child.getResourceType());
     }
 
+    @Test
+    public void testPendingChangesCommit() throws Exception {
+        
+        // skip this test for JCR_MOCK because it does not track pending changes
+        if (getResourceResolverType()==ResourceResolverType.JCR_MOCK) {
+            return;
+        }
+        
+        Resource testRootResource = resourceResolver.getResource(getTestRootNode().getPath());
+        resourceResolver.delete(testRootResource);
+        assertTrue(session.hasPendingChanges());
+        
+        resourceResolver.commit();
+        assertFalse(session.hasPendingChanges());
+    }
+
 }
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractSlingCrudResourceResolverTest.java b/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractSlingCrudResourceResolverTest.java
index 316d61d..5226486 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractSlingCrudResourceResolverTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractSlingCrudResourceResolverTest.java
@@ -281,4 +281,19 @@ public abstract class AbstractSlingCrudResourceResolverTest {
         assertEquals("/apps/any/path", resource.getPath());
     }
 
+    @Test
+    public void testPendingChangesCommit() throws PersistenceException {
+        
+        // skip this test for JCR_MOCK because it does not track pending changes
+        if (getResourceResolverType()==ResourceResolverType.JCR_MOCK) {
+            return;
+        }
+        
+        resourceResolver.delete(getTestRootResource());
+        assertTrue(resourceResolver.hasChanges());
+        
+        resourceResolver.commit();
+        assertFalse(resourceResolver.hasChanges());
+    }
+
 }

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

[sling-org-apache-sling-testing-sling-mock] 32/37: SLING-5088 avoid registering ResourceResolverFactory twice

Posted by ro...@apache.org.
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-1.6.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git

commit 47f0035c5885311d9ea79598c00d319dafcbdb60
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Sat Oct 3 00:36:11 2015 +0000

    SLING-5088 avoid registering ResourceResolverFactory twice
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock@1706513 13f79535-47bb-0310-9956-ffa450edef68
---
 src/main/java/org/apache/sling/testing/mock/sling/MockSling.java  | 3 +++
 .../apache/sling/testing/mock/sling/context/SlingContextImpl.java | 3 ---
 .../testing/mock/sling/context/AbstractSlingContextImplTest.java  | 8 --------
 3 files changed, 3 insertions(+), 11 deletions(-)

diff --git a/src/main/java/org/apache/sling/testing/mock/sling/MockSling.java b/src/main/java/org/apache/sling/testing/mock/sling/MockSling.java
index 5e76000..843f9e8 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/MockSling.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/MockSling.java
@@ -87,6 +87,9 @@ public final class MockSling {
             SlingRepository repository = adapter.newSlingRepository();
             factory = ResourceResolverFactoryInitializer.setUp(repository, bundleContext, type.getNodeTypeMode());
         }
+        else {
+            bundleContext.registerService(ResourceResolverFactory.class.getName(), factory, null);
+        }
         return factory;
     }
 
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java b/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java
index bc6f808..c1be12f 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java
@@ -112,9 +112,6 @@ public class SlingContextImpl extends OsgiContextImpl {
      */
     protected void registerDefaultServices() {
 
-        // resource resolver factory
-        registerService(ResourceResolverFactory.class, this.resourceResolverFactory);
-        
         // adapter factories
         registerInjectActivateService(new ModelAdapterFactory());
 
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/context/AbstractSlingContextImplTest.java b/src/test/java/org/apache/sling/testing/mock/sling/context/AbstractSlingContextImplTest.java
index 391cce6..b32dc1d 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/context/AbstractSlingContextImplTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/context/AbstractSlingContextImplTest.java
@@ -147,14 +147,6 @@ public abstract class AbstractSlingContextImplTest {
         assertNotNull(factory);
     }
 
-    @Test
-    public void testWithoutResourceResolverType() {
-        SlingContextImpl contextTest = new SlingContextImpl();
-        contextTest.setUp();
-        ResourceResolverFactory factory = contextTest.getService(ResourceResolverFactory.class);
-        assertNotNull(factory);
-    }
-
     @Model(adaptables = SlingHttpServletRequest.class)
     public interface RequestAttributeModel {
         @Inject

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

[sling-org-apache-sling-testing-sling-mock] 28/37: SLING-5088 rewrite setup code for resource resolver factory

Posted by ro...@apache.org.
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-1.6.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git

commit 81f87d01468c2517d2f02d372f92255cada97eaa
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Fri Oct 2 22:09:28 2015 +0000

    SLING-5088 rewrite setup code for resource resolver factory
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock@1706495 13f79535-47bb-0310-9956-ffa450edef68
---
 .../sling/AbstractMockResourceResolverFactory.java | 122 ------------------
 .../mock/sling/MockJcrResourceResolverFactory.java |  95 --------------
 .../sling/MockNoneResourceResolverFactory.java     |  34 ------
 .../sling/ResourceResolverFactoryInitializer.java  | 136 +++++++++++++++++++--
 4 files changed, 129 insertions(+), 258 deletions(-)

diff --git a/src/main/java/org/apache/sling/testing/mock/sling/AbstractMockResourceResolverFactory.java b/src/main/java/org/apache/sling/testing/mock/sling/AbstractMockResourceResolverFactory.java
deleted file mode 100644
index 7b47918..0000000
--- a/src/main/java/org/apache/sling/testing/mock/sling/AbstractMockResourceResolverFactory.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * 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;
-
-import java.util.Dictionary;
-import java.util.Hashtable;
-import java.util.Map;
-
-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.resourceresolver.impl.CommonResourceResolverFactoryImpl;
-import org.apache.sling.resourceresolver.impl.ResourceAccessSecurityTracker;
-import org.apache.sling.resourceresolver.impl.ResourceResolverFactoryActivator;
-import org.apache.sling.serviceusermapping.ServiceUserMapper;
-import org.apache.sling.serviceusermapping.impl.ServiceUserMapperImpl;
-import org.apache.sling.testing.mock.osgi.MockEventAdmin;
-import org.apache.sling.testing.mock.osgi.MockOsgi;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.service.event.EventAdmin;
-
-/**
- * Mock {@link ResourceResolverFactory} implementation.
- * Uses real Sling ResourceResolverFactory in simulated OSGi environment. 
- */
-@Deprecated
-abstract class AbstractMockResourceResolverFactory implements ResourceResolverFactory {
-
-    protected final BundleContext bundleContext;
-
-    public AbstractMockResourceResolverFactory(BundleContext bundleContext) {
-        this.bundleContext = bundleContext;
-    }
-
-    protected ResourceResolver getResourceResolverInternal(Map<String, Object> authenticationInfo, boolean isAdmin) throws LoginException {
-        // setup real sling resource resolver implementation for use in mocked context
-        Dictionary<String, Object> resourceProviderFactoryFactoryProps = new Hashtable<String, Object>();
-        resourceProviderFactoryFactoryProps.put(Constants.SERVICE_VENDOR, "sling-mock");
-        resourceProviderFactoryFactoryProps.put(Constants.SERVICE_DESCRIPTION, "sling-mock");
-        resourceProviderFactoryFactoryProps.put("resource.resolver.manglenamespaces", true);
-        resourceProviderFactoryFactoryProps.put("resource.resolver.searchpath", new String[] { "/apps", "/libs" });
-
-        ensureResourceResolverFactoryActivatorDependencies();
-        ResourceResolverFactoryActivator activator = new ResourceResolverFactoryActivator();
-        MockOsgi.injectServices(activator, bundleContext);
-        MockOsgi.activate(activator, resourceProviderFactoryFactoryProps);
-        
-        CommonResourceResolverFactoryImpl commonFactoryImpl = new CommonResourceResolverFactoryImpl(activator);
-        if (isAdmin) {
-            return commonFactoryImpl.getAdministrativeResourceResolver(authenticationInfo);
-        }
-        else {
-            return commonFactoryImpl.getResourceResolver(authenticationInfo);
-        }
-    }
-    
-    /**
-     * Make sure all dependencies required by {@link ResourceResolverFactoryActivator} exist - if not register them.
-     */
-    private void ensureResourceResolverFactoryActivatorDependencies() {
-        if (bundleContext.getServiceReference(ServiceUserMapper.class.getName()) == null) {
-            ServiceUserMapper serviceUserMapper = new ServiceUserMapperImpl();
-            MockOsgi.injectServices(serviceUserMapper, bundleContext);
-            MockOsgi.activate(serviceUserMapper);
-            bundleContext.registerService(ServiceUserMapper.class.getName(), serviceUserMapper, null);
-        }
-
-        if (bundleContext.getServiceReference(ResourceAccessSecurityTracker.class.getName()) == null) {
-            ResourceAccessSecurityTracker resourceAccessSecurityTracker = new ResourceAccessSecurityTracker();
-            MockOsgi.injectServices(resourceAccessSecurityTracker, bundleContext);
-            MockOsgi.activate(resourceAccessSecurityTracker);
-            bundleContext.registerService(ResourceAccessSecurityTracker.class.getName(), resourceAccessSecurityTracker, null);
-        }
-
-        if (bundleContext.getServiceReference(EventAdmin.class.getName()) == null) {
-            EventAdmin eventAdmin = new MockEventAdmin();
-            MockOsgi.injectServices(eventAdmin, bundleContext);
-            MockOsgi.activate(eventAdmin);
-            bundleContext.registerService(EventAdmin.class.getName(), eventAdmin, null);
-        }
-    }
-
-    @Override
-    public ResourceResolver getResourceResolver(final Map<String, Object> authenticationInfo) throws LoginException {
-        return getResourceResolverInternal(authenticationInfo, false);
-    }
-
-    @Override
-    public ResourceResolver getAdministrativeResourceResolver(final Map<String, Object> authenticationInfo)
-            throws LoginException {
-        return getResourceResolverInternal(authenticationInfo, true);
-    }
-
-    // part of Sling API 2.7
-    public ResourceResolver getServiceResourceResolver(final Map<String, Object> authenticationInfo)
-            throws LoginException {
-        return getResourceResolverInternal(authenticationInfo, true);
-    }
-
-    // part of Sling API 2.8
-    public ResourceResolver getThreadResourceResolver() {
-        throw new UnsupportedOperationException();
-    }
-
-}
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/MockJcrResourceResolverFactory.java b/src/main/java/org/apache/sling/testing/mock/sling/MockJcrResourceResolverFactory.java
deleted file mode 100644
index 0890cd0..0000000
--- a/src/main/java/org/apache/sling/testing/mock/sling/MockJcrResourceResolverFactory.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * 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;
-
-import java.util.Dictionary;
-import java.util.Hashtable;
-import java.util.Map;
-
-import javax.jcr.query.Query;
-
-import org.apache.sling.api.resource.LoginException;
-import org.apache.sling.api.resource.QueriableResourceProvider;
-import org.apache.sling.api.resource.ResourceProvider;
-import org.apache.sling.api.resource.ResourceProviderFactory;
-import org.apache.sling.api.resource.ResourceResolver;
-import org.apache.sling.jcr.api.SlingRepository;
-import org.apache.sling.jcr.resource.internal.helper.jcr.JcrResourceProviderFactory;
-import org.apache.sling.testing.mock.osgi.MockOsgi;
-import org.osgi.framework.BundleContext;
-
-/**
- * Mock {@link ResourceResolverFactory} implementation.
- * Uses real Sling ResourceResolverFactory in simulated OSGi environment
- * with a mocked JCR repository implementation underneath.
- */
-@Deprecated
-class MockJcrResourceResolverFactory extends AbstractMockResourceResolverFactory {
-
-    private final SlingRepository slingRepository;
-
-    public MockJcrResourceResolverFactory(final SlingRepository repository, BundleContext bundleContext) {
-        super(bundleContext);
-        this.slingRepository = repository;
-    }
-
-    protected ResourceResolver getResourceResolverInternal(Map<String, Object> authenticationInfo, boolean isAdmin) throws LoginException {
-        // setup mocked JCR environment
-        if (bundleContext.getServiceReference(SlingRepository.class.getName()) == null) {
-            bundleContext.registerService(SlingRepository.class.getName(), this.slingRepository, null);
-        }
-        
-        // setup PathMapper which is a mandatory service for JcrProviderFactory (since org.apache.sling.jcr.resource 2.5.4)
-        // use reflection to not depend on it if running with older version of org.apache.sling.jcr.resource
-        registerServiceIfFoundInClasspath("org.apache.sling.jcr.resource.internal.helper.jcr.PathMapper");
-
-        // setup real sling JCR resource provider implementation for use in mocked context
-        JcrResourceProviderFactory jcrResourceProviderFactory = new JcrResourceProviderFactory();
-        Dictionary<String, Object> resourceProviderProps = new Hashtable<String, Object>();
-        resourceProviderProps.put(ResourceProvider.ROOTS, new String[] { "/" });
-        resourceProviderProps.put(QueriableResourceProvider.LANGUAGES, new String[] { Query.XPATH, Query.SQL, Query.JCR_SQL2 });
-        MockOsgi.injectServices(jcrResourceProviderFactory, bundleContext);
-        MockOsgi.activate(jcrResourceProviderFactory, bundleContext, resourceProviderProps);
-        bundleContext.registerService(ResourceProviderFactory.class.getName(), jcrResourceProviderFactory, resourceProviderProps);
-
-        return super.getResourceResolverInternal(authenticationInfo, isAdmin);
-    }
-    
-    private void registerServiceIfFoundInClasspath(String className) {
-        try {
-            Class pathMapperClass = Class.forName(className);
-            if (bundleContext.getServiceReference(className) == null) {
-                Object instance = pathMapperClass.newInstance();
-                MockOsgi.injectServices(instance, bundleContext);
-                MockOsgi.activate(instance);
-                bundleContext.registerService(className, instance, null);
-            }
-        }
-        catch (ClassNotFoundException ex) {
-            // skip service registration
-        }
-        catch (InstantiationException e) {
-            // skip service registration
-        }
-        catch (IllegalAccessException e) {
-            // skip service registration
-        }
-    }
-    
-}
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/MockNoneResourceResolverFactory.java b/src/main/java/org/apache/sling/testing/mock/sling/MockNoneResourceResolverFactory.java
deleted file mode 100644
index e18b097..0000000
--- a/src/main/java/org/apache/sling/testing/mock/sling/MockNoneResourceResolverFactory.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * 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;
-
-import org.osgi.framework.BundleContext;
-
-/**
- * Mock {@link ResourceResolverFactory} implementation.
- * Uses real Sling ResourceResolverFactory in simulated OSGi environment.
- * Resource Resolver factory has no ResourceProvider registered; you have to registere one yourself to do anything useful with it. 
- */
-@Deprecated
-class MockNoneResourceResolverFactory extends AbstractMockResourceResolverFactory {
-
-    public MockNoneResourceResolverFactory(BundleContext bundleContext) {
-        super(bundleContext);
-    }
-}
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/ResourceResolverFactoryInitializer.java b/src/main/java/org/apache/sling/testing/mock/sling/ResourceResolverFactoryInitializer.java
index 99af56a..ae1f129 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/ResourceResolverFactoryInitializer.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/ResourceResolverFactoryInitializer.java
@@ -18,12 +18,31 @@
  */
 package org.apache.sling.testing.mock.sling;
 
+import java.util.Dictionary;
+import java.util.Hashtable;
+
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
+import javax.jcr.query.Query;
 
+import org.apache.sling.api.resource.QueriableResourceProvider;
+import org.apache.sling.api.resource.ResourceProvider;
+import org.apache.sling.api.resource.ResourceProviderFactory;
 import org.apache.sling.api.resource.ResourceResolverFactory;
 import org.apache.sling.jcr.api.SlingRepository;
+import org.apache.sling.jcr.resource.internal.helper.jcr.JcrResourceProviderFactory;
+import org.apache.sling.resourceresolver.impl.ResourceAccessSecurityTracker;
+import org.apache.sling.resourceresolver.impl.ResourceResolverFactoryActivator;
+import org.apache.sling.serviceusermapping.ServiceUserMapper;
+import org.apache.sling.serviceusermapping.impl.ServiceUserMapperImpl;
+import org.apache.sling.testing.mock.osgi.MockEventAdmin;
+import org.apache.sling.testing.mock.osgi.MockOsgi;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.event.EventAdmin;
+
+import sun.util.BuddhistCalendar;
 
 /**
  * Initializes Sling Resource Resolver factories with JCR-resource mapping.
@@ -41,15 +60,118 @@ class ResourceResolverFactoryInitializer {
      */
     public static ResourceResolverFactory setUp(SlingRepository slingRepository, 
             BundleContext bundleContext, NodeTypeMode nodeTypeMode) {
-        ResourceResolverFactory factory;
-        if (slingRepository == null) {
-            factory = new MockNoneResourceResolverFactory(bundleContext);
-        }
-        else {
+        
+        if (slingRepository != null) {
+            // register JCR node types found in classpath
             registerJcrNodeTypes(slingRepository, nodeTypeMode);
-            factory = new MockJcrResourceResolverFactory(slingRepository, bundleContext);
+            
+            // register sling repository as OSGi service
+            bundleContext.registerService(SlingRepository.class.getName(), slingRepository, null);
+            
+            // initialize JCR resource provider factory
+            ensureJcrResourceProviderFactoryDependencies(bundleContext);
+            initializeJcrResourceProviderFactory(bundleContext);
+        }
+        
+        // initialize resource resolver factory activator
+        ensureResourceResolverFactoryActivatorDependencies(bundleContext);
+        initializeResourceResolverFactoryActivator(bundleContext);
+
+        ServiceReference factoryRef = bundleContext.getServiceReference(ResourceResolverFactory.class.getName());
+        if (factoryRef == null) {
+            throw new IllegalStateException("Unable to get ResourceResolverFactory.");
+        }
+        return (ResourceResolverFactory)bundleContext.getService(factoryRef);
+    }
+    
+    /**
+     * Ensure dependencies for JcrResourceProviderFactory are present.
+     * @param bundleContext Bundle context
+     */
+    private static void ensureJcrResourceProviderFactoryDependencies(BundleContext bundleContext) {
+        // setup PathMapper which is a mandatory service for JcrProviderFactory (since org.apache.sling.jcr.resource 2.5.4)
+        // use reflection to not depend on it if running with older version of org.apache.sling.jcr.resource
+        registerServiceIfFoundInClasspath(bundleContext, "org.apache.sling.jcr.resource.internal.helper.jcr.PathMapper");
+    }
+ 
+    /**
+     * Initialize JCR resource provider factory.
+     * @param bundleContext Bundle context
+     */
+    @SuppressWarnings("deprecation")
+    private static void initializeJcrResourceProviderFactory(BundleContext bundleContext) {
+        Dictionary<String, Object> config = new Hashtable<String, Object>();
+        config.put(ResourceProvider.ROOTS, new String[] { "/" });
+        config.put(QueriableResourceProvider.LANGUAGES, new String[] { Query.XPATH, Query.SQL, Query.JCR_SQL2 });
+
+        JcrResourceProviderFactory factory = new JcrResourceProviderFactory();
+        MockOsgi.injectServices(factory, bundleContext);
+        MockOsgi.activate(factory, bundleContext, config);
+        bundleContext.registerService(ResourceProviderFactory.class.getName(), factory, config);
+    }
+    
+    /**
+     * Ensure dependencies for ResourceResolverFactoryActivator are present.
+     * @param bundleContext Bundle context
+     */
+    private static void ensureResourceResolverFactoryActivatorDependencies(BundleContext bundleContext) {
+        registerServiceIfNotPresent(bundleContext, ServiceUserMapper.class, new ServiceUserMapperImpl());
+        registerServiceIfNotPresent(bundleContext, ResourceAccessSecurityTracker.class, new ResourceAccessSecurityTracker());
+        registerServiceIfNotPresent(bundleContext, EventAdmin.class, new MockEventAdmin());
+    }
+ 
+    /**
+     * Initialize resource resolver factory activator.
+     * @param bundleContext Bundle context
+     */
+    private static void initializeResourceResolverFactoryActivator(BundleContext bundleContext) {
+        Dictionary<String, Object> config = new Hashtable<String, Object>();
+        config.put(Constants.SERVICE_VENDOR, "sling-mock");
+        config.put(Constants.SERVICE_DESCRIPTION, "sling-mock");
+        config.put("resource.resolver.manglenamespaces", true);
+        config.put("resource.resolver.searchpath", new String[] { "/apps", "/libs" });
+        config.put("resource.resolver.required.providers", new String[0]);
+
+        ResourceResolverFactoryActivator activator = new ResourceResolverFactoryActivator();
+        MockOsgi.injectServices(activator, bundleContext);
+        MockOsgi.activate(activator, bundleContext, config);
+        bundleContext.registerService(ResourceResolverFactoryActivator.class.getName(), activator, config);
+    }
+    
+    /**
+     * Registers a service if the service class is found in classpath,
+     * and if no service with this class is already registered.
+     * @param className Service class name
+     */
+    private static void registerServiceIfNotPresent(BundleContext bundleContext, Class<?> serviceClass, Object instance) {
+        if (bundleContext.getServiceReference(serviceClass.getName()) == null) {
+            Dictionary<String,Object> properties = new Hashtable<String, Object>();
+            MockOsgi.injectServices(instance, bundleContext);
+            MockOsgi.activate(instance, bundleContext, properties);
+            bundleContext.registerService(serviceClass.getName(), instance, properties);
+        }
+    }
+    
+    /**
+     * Registers a service if the service class is found in classpath,
+     * and if no service with this class is already registered.
+     * @param className Service class name
+     */
+    private static void registerServiceIfFoundInClasspath(BundleContext bundleContext, String className) {
+        try {
+            Class<?> serviceClass = Class.forName(className);
+            Object instance = serviceClass.newInstance();
+            registerServiceIfNotPresent(bundleContext, serviceClass, instance);
+        }
+        catch (ClassNotFoundException ex) {
+            // skip service registration
+        }
+        catch (InstantiationException e) {
+            // skip service registration
+        }
+        catch (IllegalAccessException e) {
+            // skip service registration
         }
-        return factory;
     }
     
     /**

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

[sling-org-apache-sling-testing-sling-mock] 17/37: SLING-5064 sling-mock: Register JCR node types for OSGi bundles in class path

Posted by ro...@apache.org.
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-1.6.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git

commit f0086449f4be80cc374ab20194eb5f7c5c5990fe
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Sun Sep 27 09:04:13 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@1705517 13f79535-47bb-0310-9956-ffa450edef68
---
 .../sling/context/NodeTypeDefinitionScanner.java    | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/src/main/java/org/apache/sling/testing/mock/sling/context/NodeTypeDefinitionScanner.java b/src/main/java/org/apache/sling/testing/mock/sling/context/NodeTypeDefinitionScanner.java
index bec7900..441c0c8 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/context/NodeTypeDefinitionScanner.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/context/NodeTypeDefinitionScanner.java
@@ -44,6 +44,11 @@ import org.apache.jackrabbit.commons.cnd.CndImporter;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+/**
+ * Singleton class that fetches all node type definitions from OSGi bundle MANIFEST.MF files
+ * with "Sling-Nodetypes" definitions in the classpath.
+ * Additionally it support registering them to a JCR repository. 
+ */
 public final class NodeTypeDefinitionScanner {
     
     private static final NodeTypeDefinitionScanner SINGLETON = new NodeTypeDefinitionScanner();
@@ -101,6 +106,15 @@ public final class NodeTypeDefinitionScanner {
       }
     }
     
+    /**
+     * Register node types found in classpath in JCR repository, and remove those that succeeded to register from the list.
+     * @param nodeTypeResources List of nodetype classpath resources
+     * @param classLoader
+     * @param nodeTypeManager
+     * @param namespaceRegistry
+     * @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,
             NodeTypeManager nodeTypeManager, NamespaceRegistry namespaceRegistry, ValueFactory valueFactory,
             boolean logError) {
@@ -127,6 +141,13 @@ public final class NodeTypeDefinitionScanner {
         }
     }
     
+    /**
+     * Find all node type definition classpath paths by searching all MANIFEST.MF files in the classpath and reading
+     * the paths from the "Sling-Nodetypes" entry.
+     * The order of the paths from each entry is preserved, but the overall order when multiple bundles define such an entry
+     * is not deterministic and may not be correct according to the dependencies between the node type definitions.
+     * @return List of node type definition class paths
+     */
     private static List<String> findeNodeTypeDefinitions() {
         List<String> nodeTypeDefinitions = new ArrayList<String>();
         try {

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

[sling-org-apache-sling-testing-sling-mock] 15/37: cosmetic: fix log message

Posted by ro...@apache.org.
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-1.6.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git

commit c7551b3ae4d4b90eb5b08113b5b4b4620e65347a
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Sun Sep 27 07:16:02 2015 +0000

    cosmetic: fix log message
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock@1705509 13f79535-47bb-0310-9956-ffa450edef68
---
 .../apache/sling/testing/mock/sling/builder/ContentBuilder.java  | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/src/main/java/org/apache/sling/testing/mock/sling/builder/ContentBuilder.java b/src/main/java/org/apache/sling/testing/mock/sling/builder/ContentBuilder.java
index 19b3979..b6bf6d4 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/builder/ContentBuilder.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/builder/ContentBuilder.java
@@ -71,7 +71,7 @@ public class ContentBuilder {
         try {
             return resourceResolver.create(parentResource, name, properties);
         } catch (PersistenceException ex) {
-            throw new RuntimeException("Unable to create page at " + path, ex);
+            throw new RuntimeException("Unable to create resource at " + path, ex);
         }
     }
 
@@ -93,11 +93,10 @@ public class ContentBuilder {
         String name = ResourceUtil.getName(path);
         Resource parentResource = ensureResourceExists(parentPath);
         try {
-            resource = resourceResolver.create(
-                    parentResource,
-                    name,
+            resource = resourceResolver.create(parentResource, name,
                     ImmutableMap.<String, Object> builder()
-                            .put(JcrConstants.JCR_PRIMARYTYPE, JcrConstants.NT_UNSTRUCTURED).build());
+                            .put(JcrConstants.JCR_PRIMARYTYPE, JcrConstants.NT_UNSTRUCTURED)
+                            .build());
             resourceResolver.commit();
             return resource;
         } catch (PersistenceException ex) {

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

[sling-org-apache-sling-testing-sling-mock] 03/37: SLING-5007 add unit test to explicitly test root path child listing in sling-mock as well

Posted by ro...@apache.org.
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-1.6.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git

commit 07c66509ad47a4331918a5ca461e3037b3d99ada
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Tue Sep 8 16:10:12 2015 +0000

    SLING-5007 add unit test to explicitly test root path child listing in sling-mock as well
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock@1701830 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml                                                    |  2 +-
 .../resource/AbstractSlingCrudResourceResolverTest.java    | 14 ++++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index be9a4c1..0d23971 100644
--- a/pom.xml
+++ b/pom.xml
@@ -57,7 +57,7 @@
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.testing.resourceresolver-mock</artifactId>
-            <version>1.1.8</version>
+            <version>1.1.9-SNAPSHOT</version>
             <scope>compile</scope>
         </dependency>
 
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractSlingCrudResourceResolverTest.java b/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractSlingCrudResourceResolverTest.java
index a3d2411..b840b0f 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractSlingCrudResourceResolverTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractSlingCrudResourceResolverTest.java
@@ -47,6 +47,7 @@ import org.junit.Test;
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Lists;
 
 /**
  * Implements simple write and read resource and values test. Sling CRUD API is
@@ -209,6 +210,19 @@ public abstract class AbstractSlingCrudResourceResolverTest {
     }
 
     @Test
+    public void testListChildren_RootNode() throws IOException {
+        Resource resource1 = resourceResolver.getResource("/");
+
+        List<Resource> children = Lists.newArrayList(resource1.listChildren());
+        assertEquals(1, children.size());
+        assertEquals(getTestRootResource().getName(), children.get(0).getName());
+
+        children = Lists.newArrayList(resource1.getChildren());
+        assertEquals(1, children.size());
+        assertEquals(getTestRootResource().getName(), children.get(0).getName());
+    }
+
+    @Test
     public void testBinaryData() throws IOException {
         Resource resource1 = this.resourceResolver.getResource(getTestRootResource().getPath() + "/node1");
 

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

[sling-org-apache-sling-testing-sling-mock] 21/37: SLING-5067 fix cleanup issue with "uniqueRoot" feature

Posted by ro...@apache.org.
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-1.6.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git

commit d795bccee0d1054ca472b5d039ff5ddb30331f0a
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Tue Sep 29 07:53:37 2015 +0000

    SLING-5067 fix cleanup issue with "uniqueRoot" feature
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock@1705808 13f79535-47bb-0310-9956-ffa450edef68
---
 .../apache/sling/testing/mock/sling/context/SlingContextImpl.java    | 5 +++++
 .../java/org/apache/sling/testing/mock/sling/context/UniqueRoot.java | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java b/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java
index 8c31c06..76439f0 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java
@@ -167,6 +167,7 @@ public class SlingContextImpl extends OsgiContextImpl {
         this.slingScriptHelper = null;
         this.contentLoader = null;
         this.contentBuilder = null;
+        this.uniqueRoot = null;
 
         MockSling.clearAdapterManagerBundleContext();
         
@@ -315,6 +316,10 @@ public class SlingContextImpl extends OsgiContextImpl {
         }
     }
     
+    /**
+     * Create unique root paths for unit tests (and clean them up after the test run automatically).
+     * @return Unique root path helper
+     */
     public UniqueRoot uniqueRoot() {
         if (uniqueRoot == null) {
             uniqueRoot = new UniqueRoot(this);
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/context/UniqueRoot.java b/src/main/java/org/apache/sling/testing/mock/sling/context/UniqueRoot.java
index 471c657..39bc2cc 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/context/UniqueRoot.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/context/UniqueRoot.java
@@ -122,7 +122,7 @@ public class UniqueRoot {
      */
     protected final void deleteResources(Resource... resources) {
         for (Resource resource : resources) {
-            if (resource != null) {
+            if (resource != null && context.resourceResolver.getResource(resource.getPath()) != null) {
                 try {
                     context.resourceResolver().delete(resource);
                 }

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

[sling-org-apache-sling-testing-sling-mock] 07/37: SLING-5007 use same unit tests for root node tests for all resource resolver types without counting the number of children.

Posted by ro...@apache.org.
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-1.6.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git

commit f96088046c8177b145e54478efb84b1e10b6aa6d
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Wed Sep 16 09:35:50 2015 +0000

    SLING-5007 use same unit tests for root node tests for all resource resolver types without counting the number of children.
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock@1703373 13f79535-47bb-0310-9956-ffa450edef68
---
 .../AbstractSlingCrudResourceResolverTest.java     | 30 +++++++++++++++-------
 1 file changed, 21 insertions(+), 9 deletions(-)

diff --git a/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractSlingCrudResourceResolverTest.java b/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractSlingCrudResourceResolverTest.java
index 4c17620..316d61d 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractSlingCrudResourceResolverTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractSlingCrudResourceResolverTest.java
@@ -20,7 +20,9 @@ package org.apache.sling.testing.mock.sling.resource;
 
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
 
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
@@ -32,6 +34,7 @@ import java.util.List;
 import java.util.Map;
 
 import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.jackrabbit.JcrConstants;
 import org.apache.sling.api.resource.PersistenceException;
 import org.apache.sling.api.resource.Resource;
@@ -115,12 +118,12 @@ public abstract class AbstractSlingCrudResourceResolverTest {
             Map<String, Object> props = new HashMap<String, Object>();
             props.put(JcrConstants.JCR_PRIMARYTYPE, JcrConstants.NT_UNSTRUCTURED);
             final Resource root = this.resourceResolver.getResource("/");
-            if (getResourceResolverType() == ResourceResolverType.JCR_JACKRABBIT) {
-                final Resource classRoot = this.resourceResolver.create(root, getClass().getSimpleName(), props);
-                this.testRoot = this.resourceResolver.create(classRoot, System.currentTimeMillis() + "_"
-                        + (rootNodeCounter++), props);
-            } else {
+            if (getResourceResolverType() == ResourceResolverType.JCR_MOCK
+                    || getResourceResolverType() == ResourceResolverType.RESOURCERESOLVER_MOCK) {
                 this.testRoot = this.resourceResolver.create(root, "test", props);
+            } else {
+                this.testRoot = this.resourceResolver.create(root, getClass().getSimpleName() + "_"
+                        + System.currentTimeMillis() + "_" + (rootNodeCounter++), props);
             }
         }
         return this.testRoot;
@@ -214,12 +217,21 @@ public abstract class AbstractSlingCrudResourceResolverTest {
         Resource resource1 = resourceResolver.getResource("/");
 
         List<Resource> children = Lists.newArrayList(resource1.listChildren());
-        assertEquals(1, children.size());
-        assertEquals(getTestRootResource().getName(), children.get(0).getName());
+        assertFalse(children.isEmpty());
+        assertTrue(containsResource(children, getTestRootResource()));
 
         children = Lists.newArrayList(resource1.getChildren());
-        assertEquals(1, children.size());
-        assertEquals(getTestRootResource().getName(), children.get(0).getName());
+        assertFalse(children.isEmpty());
+        assertTrue(containsResource(children, getTestRootResource()));
+    }
+    
+    private boolean containsResource(List<Resource> children, Resource resource) {
+        for (Resource child : children) {
+            if (StringUtils.equals(child.getPath(), resource.getPath())) {
+                return true;
+            }
+        }
+        return false;
     }
 
     @Test

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

[sling-org-apache-sling-testing-sling-mock] 16/37: SLING-5066 sling-mock: Close ResourceResolver on JUnit test tearDown

Posted by ro...@apache.org.
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-1.6.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git

commit 317bf58c46ff0e8243a053b06e1b505329912d7b
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Sun Sep 27 07:16:13 2015 +0000

    SLING-5066 sling-mock: Close ResourceResolver on JUnit test tearDown
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock@1705510 13f79535-47bb-0310-9956-ffa450edef68
---
 .../org/apache/sling/testing/mock/sling/context/SlingContextImpl.java    | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java b/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java
index a1e5463..2370420 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java
@@ -148,6 +148,7 @@ public class SlingContextImpl extends OsgiContextImpl {
                     // ignore
                 }
             }
+            this.resourceResolver.close();
         }
 
         this.componentContext = null;

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

[sling-org-apache-sling-testing-sling-mock] 11/37: SLING-5057 - Support HttpServletRequest#getRemoteUser

Posted by ro...@apache.org.
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-1.6.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git

commit c1ce2e6659db2169808bc250a390fb31e818b4b7
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Thu Sep 24 09:38:44 2015 +0000

    SLING-5057 - Support HttpServletRequest#getRemoteUser
    
    Implementation and tests
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock@1705021 13f79535-47bb-0310-9956-ffa450edef68
---
 .../mock/sling/servlet/MockSlingHttpServletRequest.java    | 14 +++++++++-----
 .../sling/servlet/MockSlingHttpServletRequestTest.java     |  9 +++++++++
 2 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/src/main/java/org/apache/sling/testing/mock/sling/servlet/MockSlingHttpServletRequest.java b/src/main/java/org/apache/sling/testing/mock/sling/servlet/MockSlingHttpServletRequest.java
index c7755e2..4349cac 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/servlet/MockSlingHttpServletRequest.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/servlet/MockSlingHttpServletRequest.java
@@ -96,6 +96,7 @@ public class MockSlingHttpServletRequest extends SlingAdaptable implements Sling
     private String contentType;
     private String characterEncoding;
     private byte[] content;
+    private String remoteUser;
     private MockRequestDispatcherFactory requestDispatcherFactory;
     
     private static final ResourceBundle EMPTY_RESOURCE_BUNDLE = new ListResourceBundle() {
@@ -605,6 +606,14 @@ public class MockSlingHttpServletRequest extends SlingAdaptable implements Sling
         this.requestDispatcherFactory = requestDispatcherFactory;
     }
 
+    @Override
+    public String getRemoteUser() {
+        return remoteUser;
+    }
+
+    public void setRemoteUser(String remoteUser) {
+        this.remoteUser = remoteUser;
+    }
 
     // --- unsupported operations ---
 
@@ -639,11 +648,6 @@ public class MockSlingHttpServletRequest extends SlingAdaptable implements Sling
     }
 
     @Override
-    public String getRemoteUser() {
-        throw new UnsupportedOperationException();
-    }
-
-    @Override
     public String getRequestURI() {
         throw new UnsupportedOperationException();
     }
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/servlet/MockSlingHttpServletRequestTest.java b/src/test/java/org/apache/sling/testing/mock/sling/servlet/MockSlingHttpServletRequestTest.java
index 2451540..97201f8 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/servlet/MockSlingHttpServletRequestTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/servlet/MockSlingHttpServletRequestTest.java
@@ -320,4 +320,13 @@ public class MockSlingHttpServletRequestTest {
         request.getRequestDispatcher("/path");
     }
     
+    @Test
+    public void testGetRemoteUserN() {
+        
+        assertNull(null, request.getRemoteUser());
+        
+        request.setRemoteUser("admin");
+        assertEquals("admin", request.getRemoteUser());
+    }
+    
 }

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

[sling-org-apache-sling-testing-sling-mock] 24/37: cosmetic: eliminate some javadoc warnings

Posted by ro...@apache.org.
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-1.6.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git

commit cf03565d448dd55e29059c5ee55886e5f3d9d788
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Thu Oct 1 22:24:56 2015 +0000

    cosmetic: eliminate some javadoc warnings
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock@1706327 13f79535-47bb-0310-9956-ffa450edef68
---
 .../org/apache/sling/testing/mock/sling/MockAdapterManagerImpl.java   | 4 +++-
 src/main/java/org/apache/sling/testing/mock/sling/MockSling.java      | 1 +
 .../apache/sling/testing/mock/sling/NodeTypeDefinitionScanner.java    | 4 ++++
 3 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/sling/testing/mock/sling/MockAdapterManagerImpl.java b/src/main/java/org/apache/sling/testing/mock/sling/MockAdapterManagerImpl.java
index df56615..889022b 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/MockAdapterManagerImpl.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/MockAdapterManagerImpl.java
@@ -181,6 +181,7 @@ public class MockAdapterManagerImpl implements AdapterManager {
 
     /**
      * Bind a new adapter factory.
+     * @param reference Service reference
      */
     protected void bindAdapterFactory(final ServiceReference reference) {
         boolean create = true;
@@ -198,7 +199,8 @@ public class MockAdapterManagerImpl implements AdapterManager {
     }
 
     /**
-     * Unbind a adapter factory.
+     * Unbind an adapter factory.
+     * @param reference Service reference
      */
     protected void unbindAdapterFactory(final ServiceReference reference) {
         unregisterAdapterFactory(reference);
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/MockSling.java b/src/main/java/org/apache/sling/testing/mock/sling/MockSling.java
index 638d4c9..d32126a 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/MockSling.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/MockSling.java
@@ -67,6 +67,7 @@ public final class MockSling {
     /**
      * Creates new sling resource resolver factory instance.
      * @param type Type of underlying repository.
+     * @param bundleContext Bundle context
      * @return Resource resolver factory instance
      */
     public static ResourceResolverFactory newResourceResolverFactory(final ResourceResolverType type,
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/NodeTypeDefinitionScanner.java b/src/main/java/org/apache/sling/testing/mock/sling/NodeTypeDefinitionScanner.java
index 948fb34..fed6cd7 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/NodeTypeDefinitionScanner.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/NodeTypeDefinitionScanner.java
@@ -85,6 +85,8 @@ public final class NodeTypeDefinitionScanner {
     /**
      * Registers node types found in classpath in JCR repository.
      * @param session Session
+     * @param nodeTypeMode Node type mode
+     * @throws RepositoryException Repository exception
      */
     public void register(Session session, NodeTypeMode nodeTypeMode) throws RepositoryException {
       List<String> nodeTypeResources = getNodeTypeDefinitions();
@@ -95,6 +97,8 @@ public final class NodeTypeDefinitionScanner {
      * Registers node types found in classpath in JCR repository.
      * @param session Session
      * @param nodeTypeResources List of classpath resource URLs pointing to node type definitions
+     * @param nodeTypeMode Node type mode
+     * @throws RepositoryException Repository exception
      */
     public void register(Session session, List<String> nodeTypeResources, NodeTypeMode nodeTypeMode) throws RepositoryException {
       switch (nodeTypeMode) {

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

[sling-org-apache-sling-testing-sling-mock] 13/37: SLING-5064 sling-mock: Register JCR node types for OSGi bundles in class path

Posted by ro...@apache.org.
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-1.6.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git

commit 53bfbe5d2c121fe8666a5e45e496f96b1a01fe17
Author: Stefan Seifert <ss...@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@1705475 13f79535-47bb-0310-9956-ffa450edef68
---
 .../context/ContextResourceResolverFactory.java    |   2 +-
 .../sling/context/NodeTypeDefinitionScanner.java   | 159 +++++++++++++++++++++
 .../testing/mock/sling/context/package-info.java   |   2 +-
 .../mock/sling/MockSlingScriptHelperTest.java      |   6 +
 .../context/AbstractSlingContextImplTest.java      |   1 +
 .../sling/context/ModelAdapterFactoryUtilTest.java |   1 +
 .../context/NodeTypeDefinitionScannerTest.java}    |  24 +++-
 .../loader/AbstractContentLoaderBinaryTest.java    |   1 +
 .../loader/AbstractContentLoaderJsonDamTest.java   |   1 +
 .../loader/AbstractContentLoaderJsonTest.java      |   1 +
 .../resource/AbstractJcrResourceResolverTest.java  |   1 +
 .../AbstractSlingCrudResourceResolverTest.java     |   1 +
 12 files changed, 194 insertions(+), 6 deletions(-)

diff --git a/src/main/java/org/apache/sling/testing/mock/sling/context/ContextResourceResolverFactory.java b/src/main/java/org/apache/sling/testing/mock/sling/context/ContextResourceResolverFactory.java
index 0b12486..2448e07 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/context/ContextResourceResolverFactory.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/context/ContextResourceResolverFactory.java
@@ -66,7 +66,7 @@ final class ContextResourceResolverFactory {
 
             return factory;
         } catch (Throwable ex) {
-            throw new RuntimeException("Unable to initialize " + type + " resource resolver factory.", ex);
+            throw new RuntimeException("Unable to initialize " + type + " resource resolver factory: " + ex.getMessage(), ex);
         }
     }
 
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/context/NodeTypeDefinitionScanner.java b/src/main/java/org/apache/sling/testing/mock/sling/context/NodeTypeDefinitionScanner.java
new file mode 100644
index 0000000..da5f33a
--- /dev/null
+++ b/src/main/java/org/apache/sling/testing/mock/sling/context/NodeTypeDefinitionScanner.java
@@ -0,0 +1,159 @@
+/*
+ * 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.context;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.List;
+import java.util.jar.Attributes;
+import java.util.jar.JarFile;
+import java.util.jar.Manifest;
+
+import javax.jcr.NamespaceRegistry;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.ValueFactory;
+import javax.jcr.Workspace;
+import javax.jcr.nodetype.NodeTypeManager;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.jackrabbit.commons.cnd.CndImporter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public final class NodeTypeDefinitionScanner {
+    
+    private static final NodeTypeDefinitionScanner SINGLETON = new NodeTypeDefinitionScanner();
+    
+    private static final int MAX_ITERATIONS = 5;
+
+    private static final Logger log = LoggerFactory.getLogger(NodeTypeDefinitionScanner.class);
+    
+    private final List<String> nodeTypeDefinitions;
+        
+    private NodeTypeDefinitionScanner() {
+        nodeTypeDefinitions = findeNodeTypeDefinitions();
+    }
+    
+    public List<String> getNodeTypeDefinitions() {
+        return nodeTypeDefinitions;
+    }
+
+    /**
+     * Registers node types found in classpath in JCR repository.
+     * @param Session session
+     */
+    public void register(Session session) 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 ecact order is not known
+      List<String> nodeTypeResources = new ArrayList<String>(NodeTypeDefinitionScanner.get().getNodeTypeDefinitions());
+      int iteration = 0;
+      while (!nodeTypeResources.isEmpty()) {
+          registerAndRemoveSucceeds(nodeTypeResources, classLoader, nodeTypeManager, namespaceRegistry, valueFactory, false);
+          iteration++;
+          if (iteration >= MAX_ITERATIONS) {
+              break;
+          }
+      }
+      if (!nodeTypeResources.isEmpty()) {
+          registerAndRemoveSucceeds(nodeTypeResources, classLoader, nodeTypeManager, namespaceRegistry, valueFactory, true);
+      }
+    }
+    
+    private void registerAndRemoveSucceeds(List<String> nodeTypeResources, ClassLoader classLoader,
+            NodeTypeManager nodeTypeManager, NamespaceRegistry namespaceRegistry, ValueFactory valueFactory,
+            boolean logError) {
+        Iterator<String> nodeTypeResourcesIterator = nodeTypeResources.iterator();
+        while (nodeTypeResourcesIterator.hasNext()) {
+            String nodeTypeResource = nodeTypeResourcesIterator.next();
+            InputStream is = classLoader.getResourceAsStream(nodeTypeResource);
+            if (is == null) {
+                continue;
+            }
+            try {
+                Reader reader = new InputStreamReader(is);
+                CndImporter.registerNodeTypes(reader, nodeTypeResource, nodeTypeManager, namespaceRegistry, valueFactory, false);
+                nodeTypeResourcesIterator.remove();
+            }
+            catch (Throwable ex) {
+                if (logError) {
+                    log.warn("Unable to register node type: " + nodeTypeResource, ex);
+                }
+            }
+            finally {
+                IOUtils.closeQuietly(is);
+            }
+        }
+    }
+    
+    private static List<String> findeNodeTypeDefinitions() {
+        List<String> nodeTypeDefinitions = new ArrayList<String>();
+        try {
+            Enumeration<URL> resEnum = NodeTypeDefinitionScanner.class.getClassLoader().getResources(JarFile.MANIFEST_NAME);
+            while (resEnum.hasMoreElements()) {
+                try {
+                    URL url = (URL)resEnum.nextElement();
+                    InputStream is = url.openStream();
+                    if (is != null) {
+                        try {
+                            Manifest manifest = new Manifest(is);
+                            Attributes mainAttribs = manifest.getMainAttributes();
+                            String nodeTypeDefinitionList = mainAttribs.getValue("Sling-Nodetypes");
+                            String[] nodeTypeDefinitionArray = StringUtils.split(nodeTypeDefinitionList, ",");
+                            if (nodeTypeDefinitionArray != null) {
+                                for (String nodeTypeDefinition : nodeTypeDefinitionArray) {
+                                    if (!StringUtils.isBlank(nodeTypeDefinition)) {
+                                        nodeTypeDefinitions.add(StringUtils.trim(nodeTypeDefinition));
+                                    }
+                                }
+                            }
+                        }
+                        finally {
+                            is.close();
+                        }
+                    }
+                }
+                catch (Throwable ex) {
+                    log.warn("Unable to read JAR manifest.", ex);
+                }
+            }
+        }
+        catch (IOException ex2) {
+            log.warn("Unable to read JAR manifests.", ex2);
+        }
+        return nodeTypeDefinitions; 
+    }
+    
+    public static NodeTypeDefinitionScanner get() {
+        return SINGLETON;
+    }
+    
+}
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/context/package-info.java b/src/main/java/org/apache/sling/testing/mock/sling/context/package-info.java
index da3413d..827160f 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/context/package-info.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/context/package-info.java
@@ -19,5 +19,5 @@
 /**
  * Sling context implementation for unit tests.
  */
-@aQute.bnd.annotation.Version("3.0")
+@aQute.bnd.annotation.Version("3.1")
 package org.apache.sling.testing.mock.sling.context;
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/MockSlingScriptHelperTest.java b/src/test/java/org/apache/sling/testing/mock/sling/MockSlingScriptHelperTest.java
index bde6899..1096f0a 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/MockSlingScriptHelperTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/MockSlingScriptHelperTest.java
@@ -29,6 +29,7 @@ import org.apache.sling.api.scripting.SlingScriptHelper;
 import org.apache.sling.testing.mock.osgi.MockOsgi;
 import org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest;
 import org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletResponse;
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.osgi.framework.BundleContext;
@@ -49,6 +50,11 @@ public class MockSlingScriptHelperTest {
         this.bundleContext = MockOsgi.newBundleContext();
         this.scriptHelper = MockSling.newSlingScriptHelper(this.request, this.response, this.bundleContext);
     }
+    
+    @After
+    public void tearDown() {
+        this.resourceResolver.close();
+    }
 
     @Test
     public void testRequest() {
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/context/AbstractSlingContextImplTest.java b/src/test/java/org/apache/sling/testing/mock/sling/context/AbstractSlingContextImplTest.java
index ddfa08a..514d063 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/context/AbstractSlingContextImplTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/context/AbstractSlingContextImplTest.java
@@ -123,6 +123,7 @@ public abstract class AbstractSlingContextImplTest {
         OsgiServiceModel model = resolver.adaptTo(OsgiServiceModel.class);
         assertNotNull(model.getMimeTypeService());
         assertEquals("text/html", model.getMimeTypeService().getMimeType("html"));
+        resolver.close();
     }
 
     @Test
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/context/ModelAdapterFactoryUtilTest.java b/src/test/java/org/apache/sling/testing/mock/sling/context/ModelAdapterFactoryUtilTest.java
index f150f07..b6d5850 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/context/ModelAdapterFactoryUtilTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/context/ModelAdapterFactoryUtilTest.java
@@ -71,6 +71,7 @@ public class ModelAdapterFactoryUtilTest {
         assertNotNull(model);
         assertNotNull(model.getMimeTypeService());
         assertEquals("text/html", model.getMimeTypeService().getMimeType("html"));
+        resolver.close();
     }
 
     @Test
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/context/package-info.java b/src/test/java/org/apache/sling/testing/mock/sling/context/NodeTypeDefinitionScannerTest.java
similarity index 61%
copy from src/main/java/org/apache/sling/testing/mock/sling/context/package-info.java
copy to src/test/java/org/apache/sling/testing/mock/sling/context/NodeTypeDefinitionScannerTest.java
index da3413d..63bdb50 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/context/package-info.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/context/NodeTypeDefinitionScannerTest.java
@@ -16,8 +16,24 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/**
- * Sling context implementation for unit tests.
- */
-@aQute.bnd.annotation.Version("3.0")
 package org.apache.sling.testing.mock.sling.context;
+
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+
+import org.junit.Test;
+
+
+public class NodeTypeDefinitionScannerTest {
+
+    @Test
+    public void testGetNodeTypeDefinitions() throws Exception {
+        List<String> definitions = NodeTypeDefinitionScanner.get().getNodeTypeDefinitions();
+        
+        // ensure some node types from jcr.resource exist
+        assertTrue(definitions.contains("SLING-INF/nodetypes/folder.cnd"));
+        assertTrue(definitions.contains("SLING-INF/nodetypes/resource.cnd"));
+    }
+
+}
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderBinaryTest.java b/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderBinaryTest.java
index df41247..1194cdd 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderBinaryTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderBinaryTest.java
@@ -82,6 +82,7 @@ public abstract class AbstractContentLoaderBinaryTest {
             resourceResolver.delete(content);
             resourceResolver.commit();
         }
+        resourceResolver.close();
     }
     
     @Test
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderJsonDamTest.java b/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderJsonDamTest.java
index db83b99..15bb442 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderJsonDamTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderJsonDamTest.java
@@ -85,6 +85,7 @@ public abstract class AbstractContentLoaderJsonDamTest {
             resourceResolver.delete(content);
             resourceResolver.commit();
         }
+        this.resourceResolver.close();
     }
             
     @Test
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderJsonTest.java b/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderJsonTest.java
index ff1471b..38a3b58 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderJsonTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderJsonTest.java
@@ -85,6 +85,7 @@ public abstract class AbstractContentLoaderJsonTest {
             resourceResolver.delete(content);
             resourceResolver.commit();
         }
+        this.resourceResolver.close();
     }
             
     @Test
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractJcrResourceResolverTest.java b/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractJcrResourceResolverTest.java
index 12960dd..2681fdd 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractJcrResourceResolverTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractJcrResourceResolverTest.java
@@ -105,6 +105,7 @@ public abstract class AbstractJcrResourceResolverTest {
     @After
     public final void tearDown() {
         testRoot = null;
+        resourceResolver.close();
     }
 
     /**
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractSlingCrudResourceResolverTest.java b/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractSlingCrudResourceResolverTest.java
index 5226486..9880ef5 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractSlingCrudResourceResolverTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractSlingCrudResourceResolverTest.java
@@ -107,6 +107,7 @@ public abstract class AbstractSlingCrudResourceResolverTest {
     @After
     public final void tearDown() {
         this.testRoot = null;
+        this.resourceResolver.close();
     }
 
     /**

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

[sling-org-apache-sling-testing-sling-mock] 31/37: cosmetic: fix javadoc errors

Posted by ro...@apache.org.
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-1.6.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git

commit c1525dbca751808942bd1ce2b3839f243c059cd3
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Sat Oct 3 00:18:13 2015 +0000

    cosmetic: fix javadoc errors
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock@1706512 13f79535-47bb-0310-9956-ffa450edef68
---
 src/main/java/org/apache/sling/testing/mock/sling/MockSling.java       | 3 +++
 .../sling/testing/mock/sling/servlet/MockSlingHttpServletRequest.java  | 1 +
 2 files changed, 4 insertions(+)

diff --git a/src/main/java/org/apache/sling/testing/mock/sling/MockSling.java b/src/main/java/org/apache/sling/testing/mock/sling/MockSling.java
index a6e1440..5e76000 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/MockSling.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/MockSling.java
@@ -159,6 +159,7 @@ public final class MockSling {
     /**
      * Creates new sling resource resolver instance.
      * @param type Type of underlying repository.
+     * @param bundleContext Bundle context
      * @return Resource resolver instance
      */
     public static ResourceResolver newResourceResolver(final ResourceResolverType type, BundleContext bundleContext) {
@@ -173,6 +174,7 @@ public final class MockSling {
     /**
      * Creates new sling resource resolver instance using
      * {@link #DEFAULT_RESOURCERESOLVER_TYPE}.
+     * @param bundleContext Bundle context
      * @return Resource resolver instance
      */
     public static ResourceResolver newResourceResolver(BundleContext bundleContext) {
@@ -207,6 +209,7 @@ public final class MockSling {
     /**
      * Creates a new sling script helper instance using
      * {@link #DEFAULT_RESOURCERESOLVER_TYPE} for the resource resolver.
+     * @param bundleContext Bundle context
      * @return Sling script helper instance
      */
     public static SlingScriptHelper newSlingScriptHelper(BundleContext bundleContext) {
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/servlet/MockSlingHttpServletRequest.java b/src/main/java/org/apache/sling/testing/mock/sling/servlet/MockSlingHttpServletRequest.java
index 02130cd..667edeb 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/servlet/MockSlingHttpServletRequest.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/servlet/MockSlingHttpServletRequest.java
@@ -118,6 +118,7 @@ public class MockSlingHttpServletRequest extends SlingAdaptable implements Sling
 
     /**
      * Instantiate with default resource resolver
+     * @param bundleContext Bundle context
      */
     public MockSlingHttpServletRequest(BundleContext bundleContext) {
         this(MockSling.newResourceResolver(bundleContext));

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

[sling-org-apache-sling-testing-sling-mock] 37/37: [maven-release-plugin] copy for tag org.apache.sling.testing.sling-mock-1.6.0

Posted by ro...@apache.org.
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-1.6.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git

commit e05f6cafb3e378dc3e25b3a6b8d2d43d247f084d
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Mon Oct 5 17:29:02 2015 +0000

    [maven-release-plugin] copy for tag org.apache.sling.testing.sling-mock-1.6.0
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.testing.sling-mock-1.6.0@1706881 13f79535-47bb-0310-9956-ffa450edef68

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

[sling-org-apache-sling-testing-sling-mock] 26/37: SLING-5088 refactor unit test to make sure resource resolver and bundle contexts are properly shutdown

Posted by ro...@apache.org.
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-1.6.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git

commit 856784c048b8fe3a370dcde7fceb5030e2bcf18c
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Fri Oct 2 19:58:44 2015 +0000

    SLING-5088 refactor unit test to make sure resource resolver and bundle contexts are properly shutdown
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock@1706483 13f79535-47bb-0310-9956-ffa450edef68
---
 .../mock/sling/MockSlingRepositoryTest.java        | 15 ++++--
 .../mock/sling/MockSlingScriptHelperTest.java      |  1 +
 .../context/AbstractSlingContextImplTest.java      | 15 ++----
 .../sling/context/ModelAdapterFactoryUtilTest.java |  6 ---
 .../sling/junit/SlingContextDefaultRRTypeTest.java |  1 -
 .../loader/AbstractContentLoaderBinaryTest.java    | 62 +++++++---------------
 .../loader/AbstractContentLoaderJsonDamTest.java   | 42 ++++++---------
 .../loader/AbstractContentLoaderJsonTest.java      | 56 ++++++++-----------
 .../AbstractMultipleResourceResolverTest.java      |  6 +++
 .../rrmock/loader/ContentLoaderBinaryTest.java     |  7 ---
 .../rrmock/loader/ContentLoaderJsonDamTest.java    |  7 ---
 .../sling/rrmock/loader/ContentLoaderJsonTest.java |  7 ---
 .../servlet/MockSlingHttpServletRequestTest.java   |  6 +++
 13 files changed, 87 insertions(+), 144 deletions(-)

diff --git a/src/test/java/org/apache/sling/testing/mock/sling/MockSlingRepositoryTest.java b/src/test/java/org/apache/sling/testing/mock/sling/MockSlingRepositoryTest.java
index e1aa2e1..82e7555 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/MockSlingRepositoryTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/MockSlingRepositoryTest.java
@@ -21,6 +21,7 @@ package org.apache.sling.testing.mock.sling;
 import static org.junit.Assert.assertNotNull;
 
 import javax.jcr.RepositoryException;
+import javax.jcr.Session;
 
 import org.apache.sling.jcr.api.SlingRepository;
 import org.apache.sling.testing.mock.jcr.MockJcr;
@@ -38,9 +39,17 @@ public class MockSlingRepositoryTest {
 
     @SuppressWarnings("deprecation")
     @Test
-    public void testLogin() throws RepositoryException {
-        assertNotNull(this.repository.loginAdministrative(MockJcr.DEFAULT_WORKSPACE));
-        assertNotNull(this.repository.loginService("test", MockJcr.DEFAULT_WORKSPACE));
+    public void testLoginAdministrative() throws RepositoryException {
+        Session session = this.repository.loginAdministrative(MockJcr.DEFAULT_WORKSPACE);
+        assertNotNull(session);
+        session.logout();
+    }
+
+    @Test
+    public void testLoginService() throws RepositoryException {
+        Session session = this.repository.loginService("test", MockJcr.DEFAULT_WORKSPACE);
+        assertNotNull(session);
+        session.logout();
     }
 
 }
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/MockSlingScriptHelperTest.java b/src/test/java/org/apache/sling/testing/mock/sling/MockSlingScriptHelperTest.java
index 1096f0a..9f5bebd 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/MockSlingScriptHelperTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/MockSlingScriptHelperTest.java
@@ -54,6 +54,7 @@ public class MockSlingScriptHelperTest {
     @After
     public void tearDown() {
         this.resourceResolver.close();
+        MockOsgi.shutdown(this.bundleContext);
     }
 
     @Test
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/context/AbstractSlingContextImplTest.java b/src/test/java/org/apache/sling/testing/mock/sling/context/AbstractSlingContextImplTest.java
index 514d063..c129ee1 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/context/AbstractSlingContextImplTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/context/AbstractSlingContextImplTest.java
@@ -38,34 +38,27 @@ import org.apache.sling.models.annotations.Model;
 import org.apache.sling.settings.SlingSettingsService;
 import org.apache.sling.testing.mock.sling.MockSling;
 import org.apache.sling.testing.mock.sling.ResourceResolverType;
+import org.apache.sling.testing.mock.sling.junit.SlingContext;
 import org.apache.sling.testing.mock.sling.loader.ContentLoader;
 import org.apache.sling.testing.mock.sling.services.MockMimeTypeService;
 import org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest;
-import org.junit.After;
 import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
 
 public abstract class AbstractSlingContextImplTest {
 
-    private SlingContextImpl context;
+    @Rule
+    public SlingContext context = new SlingContext(getResourceResolverType());
 
     @Before
     public void setUp() throws Exception {
-        this.context = new SlingContextImpl();
-        this.context.setResourceResolverType(getResourceResolverType());
-        this.context.setUp();
-
         context.addModelsForPackage("org.apache.sling.testing.mock.sling.context");
         
         ContentLoader contentLoader = this.context.load();
         contentLoader.json("/json-import-samples/content.json", "/content/sample/en");
     }
 
-    @After
-    public void tearDown() throws Exception {
-        this.context.tearDown();
-    }
-    
     protected abstract ResourceResolverType getResourceResolverType();
     
     @Test
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/context/ModelAdapterFactoryUtilTest.java b/src/test/java/org/apache/sling/testing/mock/sling/context/ModelAdapterFactoryUtilTest.java
index b6d5850..13df440 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/context/ModelAdapterFactoryUtilTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/context/ModelAdapterFactoryUtilTest.java
@@ -32,7 +32,6 @@ import org.apache.sling.testing.mock.sling.MockSling;
 import org.apache.sling.testing.mock.sling.junit.SlingContext;
 import org.apache.sling.testing.mock.sling.services.MockMimeTypeService;
 import org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest;
-import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
@@ -48,11 +47,6 @@ public class ModelAdapterFactoryUtilTest {
         context.addModelsForPackage("org.apache.sling.testing.mock.sling.context");
     }
 
-    @After
-    public void tearDown() throws Exception {
-        MockSling.clearAdapterManagerBundleContext();
-    }
-
     @Test
     public void testRequestAttribute() {
         MockSlingHttpServletRequest request = new MockSlingHttpServletRequest();
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/junit/SlingContextDefaultRRTypeTest.java b/src/test/java/org/apache/sling/testing/mock/sling/junit/SlingContextDefaultRRTypeTest.java
index d5579af..3ac4bb2 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/junit/SlingContextDefaultRRTypeTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/junit/SlingContextDefaultRRTypeTest.java
@@ -25,7 +25,6 @@ import org.junit.Test;
 
 public class SlingContextDefaultRRTypeTest {
 
-    // Run all unit tests for each resource resolver types listed here
     @Rule
     public SlingContext context = new SlingContext();
 
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderBinaryTest.java b/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderBinaryTest.java
index 1194cdd..81a2aa8 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderBinaryTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderBinaryTest.java
@@ -21,102 +21,78 @@ package org.apache.sling.testing.mock.sling.loader;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
-import static org.mockito.Mockito.when;
 
 import java.io.IOException;
 import java.io.InputStream;
-import java.util.Hashtable;
 
 import org.apache.commons.io.IOUtils;
 import org.apache.jackrabbit.JcrConstants;
 import org.apache.sling.api.resource.Resource;
-import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.api.resource.ResourceUtil;
-import org.apache.sling.commons.mime.MimeTypeService;
-import org.apache.sling.testing.mock.osgi.MockOsgi;
-import org.apache.sling.testing.mock.sling.MockSling;
 import org.apache.sling.testing.mock.sling.ResourceResolverType;
+import org.apache.sling.testing.mock.sling.junit.SlingContext;
 import org.junit.After;
 import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
 import org.junit.runner.RunWith;
-import org.mockito.Mock;
 import org.mockito.runners.MockitoJUnitRunner;
-import org.osgi.framework.BundleContext;
 
 @RunWith(MockitoJUnitRunner.class)
 public abstract class AbstractContentLoaderBinaryTest {
 
     private static final int SAMPLE_IMAGE_FILESIZE = 62;
-
-    private BundleContext bundleContext;
-    private ResourceResolver resourceResolver;
-    private ContentLoader contentLoader;
-
-    @Mock
-    private MimeTypeService mimeTypeService;
+    
+    @Rule
+    public SlingContext context = new SlingContext(getResourceResolverType());
 
     protected abstract ResourceResolverType getResourceResolverType();
-
-    protected ResourceResolver newResourceResolver() {
-        return MockSling.newResourceResolver(getResourceResolverType());
-    }
-
+    
+    private String path;
+    
     @Before
-    public final void setUp() {
-        bundleContext = MockOsgi.newBundleContext();
-        bundleContext.registerService(MimeTypeService.class.getName(), mimeTypeService, new Hashtable());
-        resourceResolver = newResourceResolver();
-        contentLoader = new ContentLoader(this.resourceResolver, this.bundleContext);
-
-        when(mimeTypeService.getMimeType("gif")).thenReturn("image/gif");
+    public void setUp() {
+        path = context.uniqueRoot().content();
     }
 
     @After
     public final void tearDown() throws Exception {
         // make sure all changes from ContentLoader are committed
-        assertFalse(resourceResolver.hasChanges());
-        // remove everything below /content
-        Resource content = resourceResolver.getResource("/content");
-        if (content != null) {
-            resourceResolver.delete(content);
-            resourceResolver.commit();
-        }
-        resourceResolver.close();
+        assertFalse(context.resourceResolver().hasChanges());
     }
     
     @Test
     public void testBinaryFile() throws IOException {
-        contentLoader.binaryFile("/sample-image.gif", "/content/binary/sample-image.gif");
+        context.load().binaryFile("/sample-image.gif", path + "/sample-image.gif");
 
-        Resource fileResource = resourceResolver.getResource("/content/binary/sample-image.gif");
+        Resource fileResource = context.resourceResolver().getResource(path + "/sample-image.gif");
         assertSampleImageFileSize(fileResource);
         assertMimeType(fileResource.getChild(JcrConstants.JCR_CONTENT), "image/gif");
     }
 
     @Test
     public void testBinaryFileWithMimeType() throws IOException {
-        contentLoader.binaryFile("/sample-image.gif", "/content/binary/sample-image.gif", "mime/test");
+        context.load().binaryFile("/sample-image.gif", path + "/sample-image.gif", "mime/test");
 
-        Resource fileResource = resourceResolver.getResource("/content/binary/sample-image.gif");
+        Resource fileResource = context.resourceResolver().getResource(path + "/sample-image.gif");
         assertSampleImageFileSize(fileResource);
         assertMimeType(fileResource.getChild(JcrConstants.JCR_CONTENT), "mime/test");
     }
 
     @Test
     public void testBinaryResource() throws IOException {
-        contentLoader.binaryResource("/sample-image.gif", "/content/binary/sample-image.gif");
+        context.load().binaryResource("/sample-image.gif", path + "/sample-image.gif");
 
-        Resource fileResource = resourceResolver.getResource("/content/binary/sample-image.gif");
+        Resource fileResource = context.resourceResolver().getResource(path + "/sample-image.gif");
         assertSampleImageFileSize(fileResource);
         assertMimeType(fileResource, "image/gif");
     }
 
     @Test
     public void testBinaryResourceWithMimeType() throws IOException {
-        contentLoader.binaryResource("/sample-image.gif", "/content/binary/sample-image.gif", "mime/test");
+        context.load().binaryResource("/sample-image.gif", path + "/sample-image.gif", "mime/test");
 
-        Resource fileResource = resourceResolver.getResource("/content/binary/sample-image.gif");
+        Resource fileResource = context.resourceResolver().getResource(path + "/sample-image.gif");
         assertSampleImageFileSize(fileResource);
         assertMimeType(fileResource, "mime/test");
     }
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderJsonDamTest.java b/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderJsonDamTest.java
index 9f87ba4..a4ccb6a 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderJsonDamTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderJsonDamTest.java
@@ -32,29 +32,33 @@ import javax.jcr.Session;
 import org.apache.commons.io.IOUtils;
 import org.apache.jackrabbit.JcrConstants;
 import org.apache.sling.api.resource.Resource;
-import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.api.resource.ResourceUtil;
 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.apache.sling.testing.mock.sling.junit.SlingContext;
 import org.junit.After;
 import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
 
 import com.google.common.collect.ImmutableList;
 
 public abstract class AbstractContentLoaderJsonDamTest {
 
-    private ResourceResolver resourceResolver;
+    @Rule
+    public SlingContext context = new SlingContext(getResourceResolverType());
 
     protected abstract ResourceResolverType getResourceResolverType();
 
-    protected ResourceResolver newResourceResolver() {
-        ResourceResolver resolver = MockSling.newResourceResolver(getResourceResolverType());
+    private String path;
+    
+    @Before
+    public void setUp() {
+        path = context.uniqueRoot().content() + "/dam";
 
         try {
-            NodeTypeDefinitionScanner.get().register(resolver.adaptTo(Session.class), 
+            NodeTypeDefinitionScanner.get().register(context.resourceResolver().adaptTo(Session.class), 
                     ImmutableList.of("SLING-INF/nodetypes/app.cnd"),
                     getResourceResolverType().getNodeTypeMode());
         }
@@ -62,33 +66,19 @@ public abstract class AbstractContentLoaderJsonDamTest {
             throw new RuntimeException("Unable to register namespaces.", ex);
         }
 
-        return resolver;
-    }
-
-    @Before
-    public final void setUp() {
-        this.resourceResolver = newResourceResolver();
-        ContentLoader contentLoader = new ContentLoader(this.resourceResolver);
-        contentLoader.json("/json-import-samples/dam.json", "/content/dam/sample");
+        context.load().json("/json-import-samples/dam.json", path + "/sample");
     }
 
     @After
     public final void tearDown() throws Exception {
         // make sure all changes from ContentLoader are committed
-        assertFalse(resourceResolver.hasChanges());
-        // remove everything below /content
-        Resource content = resourceResolver.getResource("/content");
-        if (content != null) {
-            resourceResolver.delete(content);
-            resourceResolver.commit();
-        }
-        this.resourceResolver.close();
+        assertFalse(context.resourceResolver().hasChanges());
     }
             
     @Test
     public void testDamAssetMetadata() throws IOException {
-        Resource assetMetadata = this.resourceResolver
-                .getResource("/content/dam/sample/portraits/scott_reynolds.jpg/jcr:content/metadata");
+        Resource assetMetadata = context.resourceResolver()
+                .getResource(path + "/sample/portraits/scott_reynolds.jpg/jcr:content/metadata");
         ValueMap props = ResourceUtil.getValueMap(assetMetadata);
 
         assertEquals("Canon\u0000", props.get("tiff:Make", String.class));
@@ -100,8 +90,8 @@ public abstract class AbstractContentLoaderJsonDamTest {
                 "properties:orientation/landscape" }, props.get("app:tags", String[].class));
 
         // validate that a binary data node is present, but empty
-        Resource binaryMetadata = this.resourceResolver
-                .getResource("/content/dam/sample/portraits/scott_reynolds.jpg/jcr:content/renditions/original/jcr:content");
+        Resource binaryMetadata = context.resourceResolver()
+                .getResource(path + "/sample/portraits/scott_reynolds.jpg/jcr:content/renditions/original/jcr:content");
         ValueMap binaryProps = ResourceUtil.getValueMap(binaryMetadata);
         InputStream is = binaryProps.get(JcrConstants.JCR_DATA, InputStream.class);
         assertNotNull(is);
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderJsonTest.java b/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderJsonTest.java
index 4d4267f..bf5aa95 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderJsonTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderJsonTest.java
@@ -32,29 +32,33 @@ import javax.jcr.Session;
 
 import org.apache.jackrabbit.JcrConstants;
 import org.apache.sling.api.resource.Resource;
-import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.api.resource.ResourceUtil;
 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.apache.sling.testing.mock.sling.junit.SlingContext;
 import org.junit.After;
 import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
 
 import com.google.common.collect.ImmutableList;
 
 public abstract class AbstractContentLoaderJsonTest {
 
-    private ResourceResolver resourceResolver;
+    @Rule
+    public SlingContext context = new SlingContext(getResourceResolverType());
 
     protected abstract ResourceResolverType getResourceResolverType();
+    
+    private String path;
 
-    protected ResourceResolver newResourceResolver() {
-        ResourceResolver resolver = MockSling.newResourceResolver(getResourceResolverType());
+    @Before
+    public void setUp() {
+        path = context.uniqueRoot().content();
 
         try {
-            NodeTypeDefinitionScanner.get().register(resolver.adaptTo(Session.class), 
+            NodeTypeDefinitionScanner.get().register(context.resourceResolver().adaptTo(Session.class), 
                     ImmutableList.of("SLING-INF/nodetypes/app.cnd"),
                     getResourceResolverType().getNodeTypeMode());
         }
@@ -62,56 +66,42 @@ public abstract class AbstractContentLoaderJsonTest {
             throw new RuntimeException("Unable to register namespaces.", ex);
         }
 
-        return resolver;
-    }
-
-    @Before
-    public final void setUp() {
-        this.resourceResolver = newResourceResolver();
-        ContentLoader contentLoader = new ContentLoader(this.resourceResolver);
-        contentLoader.json("/json-import-samples/content.json", "/content/sample/en");
+        context.load().json("/json-import-samples/content.json", path + "/sample/en");
     }
 
     @After
     public final void tearDown() throws Exception {
         // make sure all changes from ContentLoader are committed
-        assertFalse(resourceResolver.hasChanges());
-        // remove everything below /content
-        Resource content = resourceResolver.getResource("/content");
-        if (content != null) {
-            resourceResolver.delete(content);
-            resourceResolver.commit();
-        }
-        this.resourceResolver.close();
+        assertFalse(context.resourceResolver().hasChanges());
     }
             
     @Test
     public void testPageResourceType() {
-        Resource resource = this.resourceResolver.getResource("/content/sample/en");
+        Resource resource = context.resourceResolver().getResource(path + "/sample/en");
         assertEquals("app:Page", resource.getResourceType());
     }
 
     @Test
     public void testPageJcrPrimaryType() throws RepositoryException {
-        Resource resource = this.resourceResolver.getResource("/content/sample/en");
+        Resource resource = context.resourceResolver().getResource(path + "/sample/en");
         assertPrimaryNodeType(resource, "app:Page");
     }
 
     @Test
     public void testPageContentResourceType() {
-        Resource resource = this.resourceResolver.getResource("/content/sample/en/toolbar/profiles/jcr:content");
+        Resource resource = context.resourceResolver().getResource(path + "/sample/en/toolbar/profiles/jcr:content");
         assertEquals("sample/components/contentpage", resource.getResourceType());
     }
 
     @Test
     public void testPageContentJcrPrimaryType() throws RepositoryException {
-        Resource resource = this.resourceResolver.getResource("/content/sample/en/toolbar/profiles/jcr:content");
+        Resource resource = context.resourceResolver().getResource(path + "/sample/en/toolbar/profiles/jcr:content");
         assertPrimaryNodeType(resource, "app:PageContent");
     }
 
     @Test
     public void testPageContentProperties() {
-        Resource resource = this.resourceResolver.getResource("/content/sample/en/toolbar/profiles/jcr:content");
+        Resource resource = context.resourceResolver().getResource(path + "/sample/en/toolbar/profiles/jcr:content");
         ValueMap props = ResourceUtil.getValueMap(resource);
         assertEquals(true, props.get("hideInNav", Boolean.class));
 
@@ -126,19 +116,19 @@ public abstract class AbstractContentLoaderJsonTest {
 
     @Test
     public void testContentResourceType() {
-        Resource resource = this.resourceResolver.getResource("/content/sample/en/jcr:content/header");
+        Resource resource = context.resourceResolver().getResource(path + "/sample/en/jcr:content/header");
         assertEquals("sample/components/header", resource.getResourceType());
     }
 
     @Test
     public void testContentJcrPrimaryType() throws RepositoryException {
-        Resource resource = this.resourceResolver.getResource("/content/sample/en/jcr:content/header");
+        Resource resource = context.resourceResolver().getResource(path + "/sample/en/jcr:content/header");
         assertPrimaryNodeType(resource, JcrConstants.NT_UNSTRUCTURED);
     }
 
     @Test
     public void testContentProperties() {
-        Resource resource = this.resourceResolver.getResource("/content/sample/en/jcr:content/header");
+        Resource resource = context.resourceResolver().getResource(path + "/sample/en/jcr:content/header");
         ValueMap props = ResourceUtil.getValueMap(resource);
         assertEquals("/content/dam/sample/header.png", props.get("imageReference", String.class));
     }
@@ -155,7 +145,7 @@ public abstract class AbstractContentLoaderJsonTest {
 
     @Test
     public void testCalendarEcmaFormat() {
-        Resource resource = this.resourceResolver.getResource("/content/sample/en/jcr:content");
+        Resource resource = context.resourceResolver().getResource(path + "/sample/en/jcr:content");
         ValueMap props = ResourceUtil.getValueMap(resource);
 
         Calendar calendar = props.get("app:lastModified", Calendar.class);
@@ -174,7 +164,7 @@ public abstract class AbstractContentLoaderJsonTest {
     
     @Test
     public void testCalendarISO8601Format() {
-        Resource resource = this.resourceResolver.getResource("/content/sample/en/jcr:content");
+        Resource resource = context.resourceResolver().getResource(path + "/sample/en/jcr:content");
         ValueMap props = ResourceUtil.getValueMap(resource);
 
         Calendar calendar = props.get("dateISO8601String", Calendar.class);
@@ -193,7 +183,7 @@ public abstract class AbstractContentLoaderJsonTest {
     
     @Test
     public void testUTF8Chars() {
-        Resource resource = this.resourceResolver.getResource("/content/sample/en/jcr:content");
+        Resource resource = context.resourceResolver().getResource(path + "/sample/en/jcr:content");
         ValueMap props = ResourceUtil.getValueMap(resource);
         
         assertEquals("äöü߀", props.get("utf8Property"));
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractMultipleResourceResolverTest.java b/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractMultipleResourceResolverTest.java
index 4944dba..cb4e6e2 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractMultipleResourceResolverTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractMultipleResourceResolverTest.java
@@ -27,6 +27,7 @@ import org.apache.sling.api.resource.ResourceResolverFactory;
 import org.apache.sling.testing.mock.osgi.MockOsgi;
 import org.apache.sling.testing.mock.sling.MockSling;
 import org.apache.sling.testing.mock.sling.ResourceResolverType;
+import org.junit.After;
 import org.junit.Test;
 import org.osgi.framework.BundleContext;
 
@@ -45,6 +46,11 @@ public abstract class AbstractMultipleResourceResolverTest {
         return MockSling.newResourceResolverFactory(getResourceResolverType(), bundleContext);
     }
     
+    @After
+    public void tearDown() {
+        MockOsgi.shutdown(bundleContext);
+    }
+    
     @Test
     public void testMultipleResourceResolver() throws Exception {
         ResourceResolverFactory factory = newResourceResolerFactory();
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/rrmock/loader/ContentLoaderBinaryTest.java b/src/test/java/org/apache/sling/testing/mock/sling/rrmock/loader/ContentLoaderBinaryTest.java
index 4d5eebf..fd5beb6 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/rrmock/loader/ContentLoaderBinaryTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/rrmock/loader/ContentLoaderBinaryTest.java
@@ -18,8 +18,6 @@
  */
 package org.apache.sling.testing.mock.sling.rrmock.loader;
 
-import org.apache.sling.api.resource.ResourceResolver;
-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;
 
@@ -30,9 +28,4 @@ public class ContentLoaderBinaryTest extends AbstractContentLoaderBinaryTest {
         return ResourceResolverType.RESOURCERESOLVER_MOCK;
     }
 
-    @Override
-    protected ResourceResolver newResourceResolver() {
-        return MockSling.newResourceResolver(getResourceResolverType());
-    }
-
 }
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/rrmock/loader/ContentLoaderJsonDamTest.java b/src/test/java/org/apache/sling/testing/mock/sling/rrmock/loader/ContentLoaderJsonDamTest.java
index 4f6678d..bb84270 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/rrmock/loader/ContentLoaderJsonDamTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/rrmock/loader/ContentLoaderJsonDamTest.java
@@ -18,8 +18,6 @@
  */
 package org.apache.sling.testing.mock.sling.rrmock.loader;
 
-import org.apache.sling.api.resource.ResourceResolver;
-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;
 
@@ -30,9 +28,4 @@ public class ContentLoaderJsonDamTest extends AbstractContentLoaderJsonDamTest {
         return ResourceResolverType.RESOURCERESOLVER_MOCK;
     }
 
-    @Override
-    protected ResourceResolver newResourceResolver() {
-        return MockSling.newResourceResolver(getResourceResolverType());
-    }
-
 }
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/rrmock/loader/ContentLoaderJsonTest.java b/src/test/java/org/apache/sling/testing/mock/sling/rrmock/loader/ContentLoaderJsonTest.java
index 0c33fd5..5397cb5 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/rrmock/loader/ContentLoaderJsonTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/rrmock/loader/ContentLoaderJsonTest.java
@@ -18,8 +18,6 @@
  */
 package org.apache.sling.testing.mock.sling.rrmock.loader;
 
-import org.apache.sling.api.resource.ResourceResolver;
-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;
 
@@ -30,9 +28,4 @@ public class ContentLoaderJsonTest extends AbstractContentLoaderJsonTest {
         return ResourceResolverType.RESOURCERESOLVER_MOCK;
     }
 
-    @Override
-    protected ResourceResolver newResourceResolver() {
-        return MockSling.newResourceResolver(getResourceResolverType());
-    }
-
 }
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/servlet/MockSlingHttpServletRequestTest.java b/src/test/java/org/apache/sling/testing/mock/sling/servlet/MockSlingHttpServletRequestTest.java
index 97201f8..3ab99ad 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/servlet/MockSlingHttpServletRequestTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/servlet/MockSlingHttpServletRequestTest.java
@@ -51,6 +51,7 @@ import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.api.servlets.HttpConstants;
 import org.apache.sling.i18n.ResourceBundleProvider;
 import org.apache.sling.testing.mock.osgi.MockOsgi;
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -73,6 +74,11 @@ public class MockSlingHttpServletRequestTest {
     public void setUp() throws Exception {
         request = new MockSlingHttpServletRequest(resourceResolver, bundleContext);
     }
+    
+    @After
+    public void tearDown() {
+        MockOsgi.shutdown(bundleContext);
+    }
 
     @Test
     public void testResourceResolver() {

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

[sling-org-apache-sling-testing-sling-mock] 20/37: SLING-5064 manual registration of node types no longer required; register namespaces and node types centrally depending on NodeTypeMode

Posted by ro...@apache.org.
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-1.6.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git

commit 3c296a7cfce23fb2c4dc76bd49e0130c749730e6
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Mon Sep 28 22:16:38 2015 +0000

    SLING-5064 manual registration of node types no longer required; register namespaces and node types centrally depending on NodeTypeMode
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock@1705787 13f79535-47bb-0310-9956-ffa450edef68
---
 .../mock/sling/MockJcrResourceResolverAdapter.java |  14 -
 .../apache/sling/testing/mock/sling/MockSling.java |  25 +
 .../mock/sling/NodeTypeDefinitionScanner.java      | 558 +++++++++++++++++++++
 .../sling/{package-info.java => NodeTypeMode.java} |  24 +-
 .../testing/mock/sling/ResourceResolverType.java   |  23 +-
 .../sling/context/NodeTypeDefinitionScanner.java   | 193 -------
 .../sling/testing/mock/sling/package-info.java     |   2 +-
 .../NodeTypeDefinitionScannerTest.java             |   3 +-
 .../resource/MultipleResourceResolverTest.java     |   2 +-
 .../loader/AbstractContentLoaderJsonDamTest.java   |  23 +-
 .../loader/AbstractContentLoaderJsonTest.java      |  23 +-
 .../sling/resource/AbstractJcrNamespaceTest.java   |  33 +-
 .../AbstractMultipleResourceResolverTest.java      |  14 +-
 src/test/resources/SLING-INF/nodetypes/app.cnd     |  26 +
 14 files changed, 681 insertions(+), 282 deletions(-)

diff --git a/src/main/java/org/apache/sling/testing/mock/sling/MockJcrResourceResolverAdapter.java b/src/main/java/org/apache/sling/testing/mock/sling/MockJcrResourceResolverAdapter.java
index 4ec0f72..87705b6 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/MockJcrResourceResolverAdapter.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/MockJcrResourceResolverAdapter.java
@@ -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 implements ResourceResolverTypeAdapter {
     @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);
     }
 
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/MockSling.java b/src/main/java/org/apache/sling/testing/mock/sling/MockSling.java
index dcdebcb..638d4c9 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/MockSling.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/MockSling.java
@@ -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());
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/NodeTypeDefinitionScanner.java b/src/main/java/org/apache/sling/testing/mock/sling/NodeTypeDefinitionScanner.java
new file mode 100644
index 0000000..948fb34
--- /dev/null
+++ b/src/main/java/org/apache/sling/testing/mock/sling/NodeTypeDefinitionScanner.java
@@ -0,0 +1,558 @@
+/*
+ * 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;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.List;
+import java.util.jar.Attributes;
+import java.util.jar.JarFile;
+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;
+
+/**
+ * Singleton class that fetches all node type definitions from OSGi bundle MANIFEST.MF files
+ * with "Sling-Nodetypes" definitions in the classpath.
+ * Additionally it support registering them to a JCR repository. 
+ */
+public final class NodeTypeDefinitionScanner {
+    
+    private static final NodeTypeDefinitionScanner SINGLETON = new NodeTypeDefinitionScanner();
+    
+    private static final int MAX_ITERATIONS = 5;
+
+    private static final Logger log = LoggerFactory.getLogger(NodeTypeDefinitionScanner.class);
+    
+    private final List<String> nodeTypeDefinitions;
+        
+    private NodeTypeDefinitionScanner() {
+        nodeTypeDefinitions = findeNodeTypeDefinitions();
+    }
+    
+    /**
+     * @return Node type definitions found in classpath as registered in OSGi bundle headers
+     */
+    public List<String> getNodeTypeDefinitions() {
+        return nodeTypeDefinitions;
+    }
+
+    /**
+     * Registers node types found in classpath in JCR repository.
+     * @param session Session
+     */
+    public void register(Session session, NodeTypeMode nodeTypeMode) throws RepositoryException {
+      List<String> nodeTypeResources = getNodeTypeDefinitions();
+      register(session, nodeTypeResources, nodeTypeMode);
+    }
+    
+    /**
+     * Registers node types found in classpath in JCR repository.
+     * @param session Session
+     * @param nodeTypeResources List of classpath resource URLs pointing to node type definitions
+     */
+    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 exact order is not known
+      int iteration = 0;
+      List<String> remainingNodeTypeResources = new ArrayList<String>(nodeTypeResources);
+      while (!remainingNodeTypeResources.isEmpty()) {
+          registerNodeTypesAndRemoveSucceeds(remainingNodeTypeResources, classLoader, nodeTypeManager, namespaceRegistry, valueFactory, false);
+          iteration++;
+          if (iteration >= MAX_ITERATIONS) {
+              break;
+          }
+      }
+      if (!remainingNodeTypeResources.isEmpty()) {
+          registerNodeTypesAndRemoveSucceeds(remainingNodeTypeResources, classLoader, nodeTypeManager, namespaceRegistry, valueFactory, true);
+      }
+    }
+    
+    /**
+     * Register node types found in classpath in JCR repository, and remove those that succeeded to register from the list.
+     * @param nodeTypeResources List of nodetype classpath resources
+     * @param classLoader
+     * @param nodeTypeManager
+     * @param namespaceRegistry
+     * @param valueFactory
+     * @param logError if true, and error is logged if node type registration failed. Otherwise it is ignored.
+     */
+    private void registerNodeTypesAndRemoveSucceeds(List<String> nodeTypeResources, ClassLoader classLoader,
+            NodeTypeManager nodeTypeManager, NamespaceRegistry namespaceRegistry, ValueFactory valueFactory,
+            boolean logError) {
+        Iterator<String> nodeTypeResourcesIterator = nodeTypeResources.iterator();
+        while (nodeTypeResourcesIterator.hasNext()) {
+            String nodeTypeResource = nodeTypeResourcesIterator.next();
+            InputStream is = classLoader.getResourceAsStream(nodeTypeResource);
+            if (is == null) {
+                continue;
+            }
+            try {
+                Reader reader = new InputStreamReader(is);
+                CndImporter.registerNodeTypes(reader, nodeTypeResource, nodeTypeManager, namespaceRegistry, valueFactory, false);
+                nodeTypeResourcesIterator.remove();
+            }
+            catch (Throwable ex) {
+                if (logError) {
+                    log.warn("Unable to register node type: " + nodeTypeResource, ex);
+                }
+            }
+            finally {
+                IOUtils.closeQuietly(is);
+            }
+        }
+    }
+    
+    /**
+     * Find all node type definition classpath paths by searching all MANIFEST.MF files in the classpath and reading
+     * the paths from the "Sling-Nodetypes" entry.
+     * The order of the paths from each entry is preserved, but the overall order when multiple bundles define such an entry
+     * is not deterministic and may not be correct according to the dependencies between the node type definitions.
+     * @return List of node type definition class paths
+     */
+    private static List<String> findeNodeTypeDefinitions() {
+        List<String> nodeTypeDefinitions = new ArrayList<String>();
+        try {
+            Enumeration<URL> resEnum = NodeTypeDefinitionScanner.class.getClassLoader().getResources(JarFile.MANIFEST_NAME);
+            while (resEnum.hasMoreElements()) {
+                try {
+                    URL url = (URL)resEnum.nextElement();
+                    InputStream is = url.openStream();
+                    if (is != null) {
+                        try {
+                            Manifest manifest = new Manifest(is);
+                            Attributes mainAttribs = manifest.getMainAttributes();
+                            String nodeTypeDefinitionList = mainAttribs.getValue("Sling-Nodetypes");
+                            String[] nodeTypeDefinitionArray = StringUtils.split(nodeTypeDefinitionList, ",");
+                            if (nodeTypeDefinitionArray != null) {
+                                for (String nodeTypeDefinition : nodeTypeDefinitionArray) {
+                                    if (!StringUtils.isBlank(nodeTypeDefinition)) {
+                                        nodeTypeDefinitions.add(StringUtils.trim(nodeTypeDefinition));
+                                    }
+                                }
+                            }
+                        }
+                        finally {
+                            is.close();
+                        }
+                    }
+                }
+                catch (Throwable ex) {
+                    log.warn("Unable to read JAR manifest.", ex);
+                }
+            }
+        }
+        catch (IOException ex2) {
+            log.warn("Unable to read JAR manifests.", ex2);
+        }
+        return nodeTypeDefinitions; 
+    }
+    
+    public static NodeTypeDefinitionScanner get() {
+        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) {
+        }
+    }
+
+}
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/package-info.java b/src/main/java/org/apache/sling/testing/mock/sling/NodeTypeMode.java
similarity index 65%
copy from src/main/java/org/apache/sling/testing/mock/sling/package-info.java
copy to src/main/java/org/apache/sling/testing/mock/sling/NodeTypeMode.java
index 41f438c..9587feb 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/package-info.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/NodeTypeMode.java
@@ -16,8 +16,26 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+package org.apache.sling.testing.mock.sling;
+
 /**
- * Mock implementation of selected Sling APIs.
+ * How to handle node types for different {@link ResourceResolverType} types.
  */
-@aQute.bnd.annotation.Version("1.4")
-package org.apache.sling.testing.mock.sling;
+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
+    
+}
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/ResourceResolverType.java b/src/main/java/org/apache/sling/testing/mock/sling/ResourceResolverType.java
index a32f86e..bf77a6f 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/ResourceResolverType.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/ResourceResolverType.java
@@ -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;
+    }
+
 }
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/context/NodeTypeDefinitionScanner.java b/src/main/java/org/apache/sling/testing/mock/sling/context/NodeTypeDefinitionScanner.java
deleted file mode 100644
index 441c0c8..0000000
--- a/src/main/java/org/apache/sling/testing/mock/sling/context/NodeTypeDefinitionScanner.java
+++ /dev/null
@@ -1,193 +0,0 @@
-/*
- * 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.context;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.Reader;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.Iterator;
-import java.util.List;
-import java.util.jar.Attributes;
-import java.util.jar.JarFile;
-import java.util.jar.Manifest;
-
-import javax.jcr.NamespaceRegistry;
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-import javax.jcr.ValueFactory;
-import javax.jcr.Workspace;
-import javax.jcr.nodetype.NodeTypeManager;
-
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.jackrabbit.commons.cnd.CndImporter;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Singleton class that fetches all node type definitions from OSGi bundle MANIFEST.MF files
- * with "Sling-Nodetypes" definitions in the classpath.
- * Additionally it support registering them to a JCR repository. 
- */
-public final class NodeTypeDefinitionScanner {
-    
-    private static final NodeTypeDefinitionScanner SINGLETON = new NodeTypeDefinitionScanner();
-    
-    private static final int MAX_ITERATIONS = 5;
-
-    private static final Logger log = LoggerFactory.getLogger(NodeTypeDefinitionScanner.class);
-    
-    private final List<String> nodeTypeDefinitions;
-        
-    private NodeTypeDefinitionScanner() {
-        nodeTypeDefinitions = findeNodeTypeDefinitions();
-    }
-    
-    /**
-     * @return Node type definitions found in classpath as registered in OSGi bundle headers
-     */
-    public List<String> getNodeTypeDefinitions() {
-        return nodeTypeDefinitions;
-    }
-
-    /**
-     * Registers node types found in classpath in JCR repository.
-     * @param session Session
-     */
-    public void register(Session session) throws RepositoryException {
-      List<String> nodeTypeResources = getNodeTypeDefinitions();
-      register(session, nodeTypeResources);
-    }
-    
-    /**
-     * Registers node types found in classpath in JCR repository.
-     * @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 {
-      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
-      int iteration = 0;
-      List<String> remainingNodeTypeResources = new ArrayList<String>(nodeTypeResources);
-      while (!remainingNodeTypeResources.isEmpty()) {
-          registerAndRemoveSucceeds(remainingNodeTypeResources, classLoader, nodeTypeManager, namespaceRegistry, valueFactory, false);
-          iteration++;
-          if (iteration >= MAX_ITERATIONS) {
-              break;
-          }
-      }
-      if (!remainingNodeTypeResources.isEmpty()) {
-          registerAndRemoveSucceeds(remainingNodeTypeResources, classLoader, nodeTypeManager, namespaceRegistry, valueFactory, true);
-      }
-    }
-    
-    /**
-     * Register node types found in classpath in JCR repository, and remove those that succeeded to register from the list.
-     * @param nodeTypeResources List of nodetype classpath resources
-     * @param classLoader
-     * @param nodeTypeManager
-     * @param namespaceRegistry
-     * @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,
-            NodeTypeManager nodeTypeManager, NamespaceRegistry namespaceRegistry, ValueFactory valueFactory,
-            boolean logError) {
-        Iterator<String> nodeTypeResourcesIterator = nodeTypeResources.iterator();
-        while (nodeTypeResourcesIterator.hasNext()) {
-            String nodeTypeResource = nodeTypeResourcesIterator.next();
-            InputStream is = classLoader.getResourceAsStream(nodeTypeResource);
-            if (is == null) {
-                continue;
-            }
-            try {
-                Reader reader = new InputStreamReader(is);
-                CndImporter.registerNodeTypes(reader, nodeTypeResource, nodeTypeManager, namespaceRegistry, valueFactory, false);
-                nodeTypeResourcesIterator.remove();
-            }
-            catch (Throwable ex) {
-                if (logError) {
-                    log.warn("Unable to register node type: " + nodeTypeResource, ex);
-                }
-            }
-            finally {
-                IOUtils.closeQuietly(is);
-            }
-        }
-    }
-    
-    /**
-     * Find all node type definition classpath paths by searching all MANIFEST.MF files in the classpath and reading
-     * the paths from the "Sling-Nodetypes" entry.
-     * The order of the paths from each entry is preserved, but the overall order when multiple bundles define such an entry
-     * is not deterministic and may not be correct according to the dependencies between the node type definitions.
-     * @return List of node type definition class paths
-     */
-    private static List<String> findeNodeTypeDefinitions() {
-        List<String> nodeTypeDefinitions = new ArrayList<String>();
-        try {
-            Enumeration<URL> resEnum = NodeTypeDefinitionScanner.class.getClassLoader().getResources(JarFile.MANIFEST_NAME);
-            while (resEnum.hasMoreElements()) {
-                try {
-                    URL url = (URL)resEnum.nextElement();
-                    InputStream is = url.openStream();
-                    if (is != null) {
-                        try {
-                            Manifest manifest = new Manifest(is);
-                            Attributes mainAttribs = manifest.getMainAttributes();
-                            String nodeTypeDefinitionList = mainAttribs.getValue("Sling-Nodetypes");
-                            String[] nodeTypeDefinitionArray = StringUtils.split(nodeTypeDefinitionList, ",");
-                            if (nodeTypeDefinitionArray != null) {
-                                for (String nodeTypeDefinition : nodeTypeDefinitionArray) {
-                                    if (!StringUtils.isBlank(nodeTypeDefinition)) {
-                                        nodeTypeDefinitions.add(StringUtils.trim(nodeTypeDefinition));
-                                    }
-                                }
-                            }
-                        }
-                        finally {
-                            is.close();
-                        }
-                    }
-                }
-                catch (Throwable ex) {
-                    log.warn("Unable to read JAR manifest.", ex);
-                }
-            }
-        }
-        catch (IOException ex2) {
-            log.warn("Unable to read JAR manifests.", ex2);
-        }
-        return nodeTypeDefinitions; 
-    }
-    
-    public static NodeTypeDefinitionScanner get() {
-        return SINGLETON;
-    }
-    
-}
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/package-info.java b/src/main/java/org/apache/sling/testing/mock/sling/package-info.java
index 41f438c..85ce5c4 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/package-info.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/package-info.java
@@ -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;
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/context/NodeTypeDefinitionScannerTest.java b/src/test/java/org/apache/sling/testing/mock/sling/NodeTypeDefinitionScannerTest.java
similarity index 92%
rename from src/test/java/org/apache/sling/testing/mock/sling/context/NodeTypeDefinitionScannerTest.java
rename to src/test/java/org/apache/sling/testing/mock/sling/NodeTypeDefinitionScannerTest.java
index 63bdb50..1b1f888 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/context/NodeTypeDefinitionScannerTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/NodeTypeDefinitionScannerTest.java
@@ -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;
 
 
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/jcrmock/resource/MultipleResourceResolverTest.java b/src/test/java/org/apache/sling/testing/mock/sling/jcrmock/resource/MultipleResourceResolverTest.java
index cc02db4..2b12d79 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/jcrmock/resource/MultipleResourceResolverTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/jcrmock/resource/MultipleResourceResolverTest.java
@@ -27,5 +27,5 @@ public class MultipleResourceResolverTest extends AbstractMultipleResourceResolv
     protected ResourceResolverType getResourceResolverType() {
         return ResourceResolverType.JCR_MOCK;
     }
-
+    
 }
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderJsonDamTest.java b/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderJsonDamTest.java
index 15bb442..9f87ba4 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderJsonDamTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderJsonDamTest.java
@@ -26,7 +26,6 @@ import static org.junit.Assert.assertNotNull;
 import java.io.IOException;
 import java.io.InputStream;
 
-import javax.jcr.NamespaceRegistry;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 
@@ -37,11 +36,14 @@ import org.apache.sling.api.resource.ResourceResolver;
 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 AbstractContentLoaderJsonDamTest {
     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;
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderJsonTest.java b/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderJsonTest.java
index 38a3b58..4d4267f 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderJsonTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderJsonTest.java
@@ -26,7 +26,6 @@ import static org.junit.Assert.assertNotNull;
 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.ResourceResolver;
 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 AbstractContentLoaderJsonTest {
     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;
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractJcrNamespaceTest.java b/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractJcrNamespaceTest.java
index 5185419..71b93b7 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractJcrNamespaceTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractJcrNamespaceTest.java
@@ -21,9 +21,7 @@ package org.apache.sling.testing.mock.sling.resource;
 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 AbstractJcrNamespaceTest {
     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 AbstractJcrNamespaceTest {
     }
 
     @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));
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractMultipleResourceResolverTest.java b/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractMultipleResourceResolverTest.java
index cdd0aee..4944dba 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractMultipleResourceResolverTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractMultipleResourceResolverTest.java
@@ -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.ImmutableMap;
 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 AbstractMultipleResourceResolverTest {
     @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("/");
diff --git a/src/test/resources/SLING-INF/nodetypes/app.cnd b/src/test/resources/SLING-INF/nodetypes/app.cnd
new file mode 100644
index 0000000..105d39f
--- /dev/null
+++ b/src/test/resources/SLING-INF/nodetypes/app.cnd
@@ -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

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

[sling-org-apache-sling-testing-sling-mock] 12/37: SLING-5057 - Support HttpServletRequest#getRemoteUser

Posted by ro...@apache.org.
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-1.6.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git

commit b10d3bb0718ffed77edc7a90c3cf3e9b5b886f51
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Thu Sep 24 10:35:50 2015 +0000

    SLING-5057 - Support HttpServletRequest#getRemoteUser
    
    Fix exported package version
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock@1705025 13f79535-47bb-0310-9956-ffa450edef68
---
 .../java/org/apache/sling/testing/mock/sling/servlet/package-info.java  | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/sling/testing/mock/sling/servlet/package-info.java b/src/main/java/org/apache/sling/testing/mock/sling/servlet/package-info.java
index 88f0f19..cfc5f97 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/servlet/package-info.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/servlet/package-info.java
@@ -19,5 +19,5 @@
 /**
  * Mock implementation of selected Servlet-related Sling APIs.
  */
-@aQute.bnd.annotation.Version("1.2")
+@aQute.bnd.annotation.Version("1.3")
 package org.apache.sling.testing.mock.sling.servlet;

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

[sling-org-apache-sling-testing-sling-mock] 27/37: SLING-5088 refactor resource resolver initialization

Posted by ro...@apache.org.
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-1.6.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git

commit b90bd444040f2862d11b9aceba817de198b42435
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Fri Oct 2 20:52:05 2015 +0000

    SLING-5088 refactor resource resolver initialization
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock@1706488 13f79535-47bb-0310-9956-ffa450edef68
---
 .../sling/AbstractMockResourceResolverFactory.java |  1 +
 .../mock/sling/MockJcrResourceResolverAdapter.java |  2 +-
 .../mock/sling/MockJcrResourceResolverFactory.java |  2 +-
 ...Repository.java => MockJcrSlingRepository.java} |  4 +-
 .../sling/MockNoneResourceResolverFactory.java     |  1 +
 .../apache/sling/testing/mock/sling/MockSling.java | 32 +--------
 .../sling/ResourceResolverFactoryInitializer.java  | 77 ++++++++++++++++++++++
 ...ryTest.java => MockJcrSlingRepositoryTest.java} |  4 +-
 8 files changed, 86 insertions(+), 37 deletions(-)

diff --git a/src/main/java/org/apache/sling/testing/mock/sling/AbstractMockResourceResolverFactory.java b/src/main/java/org/apache/sling/testing/mock/sling/AbstractMockResourceResolverFactory.java
index 1a6915d..7b47918 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/AbstractMockResourceResolverFactory.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/AbstractMockResourceResolverFactory.java
@@ -40,6 +40,7 @@ import org.osgi.service.event.EventAdmin;
  * Mock {@link ResourceResolverFactory} implementation.
  * Uses real Sling ResourceResolverFactory in simulated OSGi environment. 
  */
+@Deprecated
 abstract class AbstractMockResourceResolverFactory implements ResourceResolverFactory {
 
     protected final BundleContext bundleContext;
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/MockJcrResourceResolverAdapter.java b/src/main/java/org/apache/sling/testing/mock/sling/MockJcrResourceResolverAdapter.java
index 87705b6..8eafd59 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/MockJcrResourceResolverAdapter.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/MockJcrResourceResolverAdapter.java
@@ -38,7 +38,7 @@ class MockJcrResourceResolverAdapter implements ResourceResolverTypeAdapter {
     @Override
     public SlingRepository newSlingRepository() {
         Repository repository = MockJcr.newRepository();
-        return new MockSlingRepository(repository);
+        return new MockJcrSlingRepository(repository);
     }
 
 }
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/MockJcrResourceResolverFactory.java b/src/main/java/org/apache/sling/testing/mock/sling/MockJcrResourceResolverFactory.java
index bc1a83d..0890cd0 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/MockJcrResourceResolverFactory.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/MockJcrResourceResolverFactory.java
@@ -39,6 +39,7 @@ import org.osgi.framework.BundleContext;
  * Uses real Sling ResourceResolverFactory in simulated OSGi environment
  * with a mocked JCR repository implementation underneath.
  */
+@Deprecated
 class MockJcrResourceResolverFactory extends AbstractMockResourceResolverFactory {
 
     private final SlingRepository slingRepository;
@@ -48,7 +49,6 @@ class MockJcrResourceResolverFactory extends AbstractMockResourceResolverFactory
         this.slingRepository = repository;
     }
 
-    @SuppressWarnings("deprecation")
     protected ResourceResolver getResourceResolverInternal(Map<String, Object> authenticationInfo, boolean isAdmin) throws LoginException {
         // setup mocked JCR environment
         if (bundleContext.getServiceReference(SlingRepository.class.getName()) == null) {
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/MockSlingRepository.java b/src/main/java/org/apache/sling/testing/mock/sling/MockJcrSlingRepository.java
similarity index 96%
rename from src/main/java/org/apache/sling/testing/mock/sling/MockSlingRepository.java
rename to src/main/java/org/apache/sling/testing/mock/sling/MockJcrSlingRepository.java
index eec41f5..c5e0f58 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/MockSlingRepository.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/MockJcrSlingRepository.java
@@ -32,11 +32,11 @@ import org.apache.sling.testing.mock.jcr.MockJcr;
 /**
  * Mock {@link SlingRepository} implementation.
  */
-class MockSlingRepository implements SlingRepository {
+class MockJcrSlingRepository implements SlingRepository {
 
     private final Repository delegate;
 
-    public MockSlingRepository(final Repository delegate) {
+    public MockJcrSlingRepository(final Repository delegate) {
         this.delegate = delegate;
     }
 
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/MockNoneResourceResolverFactory.java b/src/main/java/org/apache/sling/testing/mock/sling/MockNoneResourceResolverFactory.java
index 2ee1ac6..e18b097 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/MockNoneResourceResolverFactory.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/MockNoneResourceResolverFactory.java
@@ -25,6 +25,7 @@ import org.osgi.framework.BundleContext;
  * Uses real Sling ResourceResolverFactory in simulated OSGi environment.
  * Resource Resolver factory has no ResourceProvider registered; you have to registere one yourself to do anything useful with it. 
  */
+@Deprecated
 class MockNoneResourceResolverFactory extends AbstractMockResourceResolverFactory {
 
     public MockNoneResourceResolverFactory(BundleContext bundleContext) {
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/MockSling.java b/src/main/java/org/apache/sling/testing/mock/sling/MockSling.java
index d32126a..db85756 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/MockSling.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/MockSling.java
@@ -18,9 +18,6 @@
  */
 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,38 +73,11 @@ public final class MockSling {
         ResourceResolverFactory factory = adapter.newResourceResolverFactory();
         if (factory == null) {
             SlingRepository repository = adapter.newSlingRepository();
-            if (repository == null) {
-                factory = new MockNoneResourceResolverFactory(bundleContext);
-            }
-            else {
-                registerJcrNodeTypes(repository, type);
-                factory = new MockJcrResourceResolverFactory(repository, bundleContext);
-            }
+            factory = ResourceResolverFactoryInitializer.setUp(repository, bundleContext, type.getNodeTypeMode());
         }
         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());
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/ResourceResolverFactoryInitializer.java b/src/main/java/org/apache/sling/testing/mock/sling/ResourceResolverFactoryInitializer.java
new file mode 100644
index 0000000..99af56a
--- /dev/null
+++ b/src/main/java/org/apache/sling/testing/mock/sling/ResourceResolverFactoryInitializer.java
@@ -0,0 +1,77 @@
+/*
+ * 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;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
+import org.apache.sling.api.resource.ResourceResolverFactory;
+import org.apache.sling.jcr.api.SlingRepository;
+import org.osgi.framework.BundleContext;
+
+/**
+ * Initializes Sling Resource Resolver factories with JCR-resource mapping.
+ */
+class ResourceResolverFactoryInitializer {
+    
+    private ResourceResolverFactoryInitializer() {
+        // static methods only
+    }
+
+    /**
+     * Setup resource resolver factory.
+     * @param slingRepository Sling repository. If null resource resolver factory is setup without any resource provider.
+     * @param bundleContext Bundle context
+     */
+    public static ResourceResolverFactory setUp(SlingRepository slingRepository, 
+            BundleContext bundleContext, NodeTypeMode nodeTypeMode) {
+        ResourceResolverFactory factory;
+        if (slingRepository == null) {
+            factory = new MockNoneResourceResolverFactory(bundleContext);
+        }
+        else {
+            registerJcrNodeTypes(slingRepository, nodeTypeMode);
+            factory = new MockJcrResourceResolverFactory(slingRepository, 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 NodeTypeMode nodeTypeMode) {
+      Session session = null;
+      try {
+          session = slingRepository.loginAdministrative(null);
+          NodeTypeDefinitionScanner.get().register(session, nodeTypeMode);
+      }
+      catch (RepositoryException ex) {
+          throw new RuntimeException("Error registering JCR nodetypes: " + ex.getMessage(), ex);
+      }
+      finally {
+          if (session != null) {
+              session.logout();
+          }
+      }
+    }
+    
+}
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/MockSlingRepositoryTest.java b/src/test/java/org/apache/sling/testing/mock/sling/MockJcrSlingRepositoryTest.java
similarity index 93%
rename from src/test/java/org/apache/sling/testing/mock/sling/MockSlingRepositoryTest.java
rename to src/test/java/org/apache/sling/testing/mock/sling/MockJcrSlingRepositoryTest.java
index 82e7555..9d425a9 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/MockSlingRepositoryTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/MockJcrSlingRepositoryTest.java
@@ -28,13 +28,13 @@ import org.apache.sling.testing.mock.jcr.MockJcr;
 import org.junit.Before;
 import org.junit.Test;
 
-public class MockSlingRepositoryTest {
+public class MockJcrSlingRepositoryTest {
 
     private SlingRepository repository;
 
     @Before
     public void setUp() {
-        this.repository = new MockSlingRepository(MockJcr.newRepository());
+        this.repository = new MockJcrSlingRepository(MockJcr.newRepository());
     }
 
     @SuppressWarnings("deprecation")

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

[sling-org-apache-sling-testing-sling-mock] 04/37: SLING-5007 realx unit test to test root path child listing in sling-mock-jackrabbit and sling-mock-jackrabbit and sling-mock-oak because in real repositories multiple root test nodes may be created in parallel, or nodes already exist

Posted by ro...@apache.org.
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-1.6.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git

commit d5ebb42bec63a6c1309b99e720ab3f9741c823dc
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Wed Sep 9 10:22:46 2015 +0000

    SLING-5007 realx unit test to test root path child listing in sling-mock-jackrabbit and sling-mock-jackrabbit and sling-mock-oak because in real repositories multiple root test nodes may be created in parallel, or nodes already exist
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock@1701971 13f79535-47bb-0310-9956-ffa450edef68
---
 .../mock/sling/resource/AbstractSlingCrudResourceResolverTest.java    | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractSlingCrudResourceResolverTest.java b/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractSlingCrudResourceResolverTest.java
index b840b0f..4c17620 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractSlingCrudResourceResolverTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractSlingCrudResourceResolverTest.java
@@ -64,7 +64,7 @@ public abstract class AbstractSlingCrudResourceResolverTest {
     private static final Calendar CALENDAR_VALUE = Calendar.getInstance();
     private static final byte[] BINARY_VALUE = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };
 
-    private ResourceResolver resourceResolver;
+    protected ResourceResolver resourceResolver;
     protected Resource testRoot;
     private static volatile long rootNodeCounter;
 
@@ -110,7 +110,7 @@ public abstract class AbstractSlingCrudResourceResolverTest {
      * Return a test root resource, created on demand, with a unique path
      * @throws PersistenceException
      */
-    private Resource getTestRootResource() throws PersistenceException {
+    protected Resource getTestRootResource() throws PersistenceException {
         if (this.testRoot == null) {
             Map<String, Object> props = new HashMap<String, Object>();
             props.put(JcrConstants.JCR_PRIMARYTYPE, JcrConstants.NT_UNSTRUCTURED);

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

[sling-org-apache-sling-testing-sling-mock] 10/37: SLING-5043 sling-mocks: Execute commit() after ContentLoader operations

Posted by ro...@apache.org.
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-1.6.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git

commit 81238685c332d76339bf5b36b65fa0dca3704d64
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Fri Sep 18 08:05:36 2015 +0000

    SLING-5043 sling-mocks: Execute commit() after ContentLoader operations
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock@1703762 13f79535-47bb-0310-9956-ffa450edef68
---
 .../sling/testing/mock/sling/loader/ContentLoader.java     | 10 ++++++++--
 .../mock/sling/loader/AbstractContentLoaderBinaryTest.java | 14 ++++++++++++++
 .../sling/loader/AbstractContentLoaderJsonDamTest.java     | 14 ++++++++++++++
 .../mock/sling/loader/AbstractContentLoaderJsonTest.java   | 14 ++++++++++++++
 4 files changed, 50 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/apache/sling/testing/mock/sling/loader/ContentLoader.java b/src/main/java/org/apache/sling/testing/mock/sling/loader/ContentLoader.java
index 8473527..7729618 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/loader/ContentLoader.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/loader/ContentLoader.java
@@ -52,6 +52,7 @@ import com.google.common.collect.ImmutableSet;
 
 /**
  * Imports JSON data and binary data into Sling resource hierarchy.
+ * After all import operations from json or binaries {@link ResourceResolver#commit()} is called.
  */
 public final class ContentLoader {
 
@@ -173,7 +174,9 @@ public final class ContentLoader {
 
             String jsonString = convertToJsonString(inputStream).trim();
             JSONObject json = new JSONObject(jsonString);
-            return this.createResource(parentResource, childName, json);
+            Resource resource = this.createResource(parentResource, childName, json);
+            resourceResolver.commit();
+            return resource;
         } catch (JSONException ex) {
             throw new RuntimeException(ex);
         } catch (IOException ex) {
@@ -467,6 +470,7 @@ public final class ContentLoader {
             resourceResolver.create(file, JcrConstants.JCR_CONTENT,
                     ImmutableMap.<String, Object> builder().put(JcrConstants.JCR_PRIMARYTYPE, JcrConstants.NT_RESOURCE)
                             .put(JcrConstants.JCR_DATA, inputStream).put(JcrConstants.JCR_MIMETYPE, mimeType).build());
+            resourceResolver.commit();
             return file;
         } catch (PersistenceException ex) {
             throw new RuntimeException("Unable to create resource at " + parentResource.getPath() + "/" + name, ex);
@@ -579,9 +583,11 @@ public final class ContentLoader {
      */
     public Resource binaryResource(InputStream inputStream, Resource parentResource, String name, String mimeType) {
         try {
-            return resourceResolver.create(parentResource, name,
+            Resource resource = resourceResolver.create(parentResource, name,
                     ImmutableMap.<String, Object> builder().put(JcrConstants.JCR_PRIMARYTYPE, JcrConstants.NT_RESOURCE)
                             .put(JcrConstants.JCR_DATA, inputStream).put(JcrConstants.JCR_MIMETYPE, mimeType).build());
+            resourceResolver.commit();
+            return resource;
         } catch (PersistenceException ex) {
             throw new RuntimeException("Unable to create resource at " + parentResource.getPath() + "/" + name, ex);
         }
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderBinaryTest.java b/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderBinaryTest.java
index 5765612..df41247 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderBinaryTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderBinaryTest.java
@@ -19,6 +19,7 @@
 package org.apache.sling.testing.mock.sling.loader;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.mockito.Mockito.when;
 
@@ -35,6 +36,7 @@ import org.apache.sling.commons.mime.MimeTypeService;
 import org.apache.sling.testing.mock.osgi.MockOsgi;
 import org.apache.sling.testing.mock.sling.MockSling;
 import org.apache.sling.testing.mock.sling.ResourceResolverType;
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -70,6 +72,18 @@ public abstract class AbstractContentLoaderBinaryTest {
         when(mimeTypeService.getMimeType("gif")).thenReturn("image/gif");
     }
 
+    @After
+    public final void tearDown() throws Exception {
+        // make sure all changes from ContentLoader are committed
+        assertFalse(resourceResolver.hasChanges());
+        // remove everything below /content
+        Resource content = resourceResolver.getResource("/content");
+        if (content != null) {
+            resourceResolver.delete(content);
+            resourceResolver.commit();
+        }
+    }
+    
     @Test
     public void testBinaryFile() throws IOException {
         contentLoader.binaryFile("/sample-image.gif", "/content/binary/sample-image.gif");
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderJsonDamTest.java b/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderJsonDamTest.java
index 54fdb67..db83b99 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderJsonDamTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderJsonDamTest.java
@@ -20,6 +20,7 @@ package org.apache.sling.testing.mock.sling.loader;
 
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 
 import java.io.IOException;
@@ -37,6 +38,7 @@ 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.ResourceResolverType;
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -73,6 +75,18 @@ public abstract class AbstractContentLoaderJsonDamTest {
         contentLoader.json("/json-import-samples/dam.json", "/content/dam/sample");
     }
 
+    @After
+    public final void tearDown() throws Exception {
+        // make sure all changes from ContentLoader are committed
+        assertFalse(resourceResolver.hasChanges());
+        // remove everything below /content
+        Resource content = resourceResolver.getResource("/content");
+        if (content != null) {
+            resourceResolver.delete(content);
+            resourceResolver.commit();
+        }
+    }
+            
     @Test
     public void testDamAssetMetadata() throws IOException {
         Resource assetMetadata = this.resourceResolver
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderJsonTest.java b/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderJsonTest.java
index 702294a..ff1471b 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderJsonTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/loader/AbstractContentLoaderJsonTest.java
@@ -20,6 +20,7 @@ package org.apache.sling.testing.mock.sling.loader;
 
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 
 import java.util.Calendar;
@@ -37,6 +38,7 @@ 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.ResourceResolverType;
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -73,6 +75,18 @@ public abstract class AbstractContentLoaderJsonTest {
         contentLoader.json("/json-import-samples/content.json", "/content/sample/en");
     }
 
+    @After
+    public final void tearDown() throws Exception {
+        // make sure all changes from ContentLoader are committed
+        assertFalse(resourceResolver.hasChanges());
+        // remove everything below /content
+        Resource content = resourceResolver.getResource("/content");
+        if (content != null) {
+            resourceResolver.delete(content);
+            resourceResolver.commit();
+        }
+    }
+            
     @Test
     public void testPageResourceType() {
         Resource resource = this.resourceResolver.getResource("/content/sample/en");

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

[sling-org-apache-sling-testing-sling-mock] 33/37: SLING-5088 register default service user mapping for mock bundle

Posted by ro...@apache.org.
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-1.6.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git

commit 21a5c64e2732e8b96ce7ded55420e55498076cb7
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Sat Oct 3 00:57:36 2015 +0000

    SLING-5088 register default service user mapping for mock bundle
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock@1706516 13f79535-47bb-0310-9956-ffa450edef68
---
 .../sling/ResourceResolverFactoryInitializer.java  | 27 ++++++++++++++++++----
 1 file changed, 22 insertions(+), 5 deletions(-)

diff --git a/src/main/java/org/apache/sling/testing/mock/sling/ResourceResolverFactoryInitializer.java b/src/main/java/org/apache/sling/testing/mock/sling/ResourceResolverFactoryInitializer.java
index fef5f6c..0780aee 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/ResourceResolverFactoryInitializer.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/ResourceResolverFactoryInitializer.java
@@ -113,7 +113,10 @@ class ResourceResolverFactoryInitializer {
      * @param bundleContext Bundle context
      */
     private static void ensureResourceResolverFactoryActivatorDependencies(BundleContext bundleContext) {
-        registerServiceIfNotPresent(bundleContext, ServiceUserMapper.class, new ServiceUserMapperImpl());
+        Dictionary<String, Object> config = new Hashtable<String, Object>();
+        config.put("user.mapping", bundleContext.getBundle().getSymbolicName() + "=admin");
+        registerServiceIfNotPresent(bundleContext, ServiceUserMapper.class, new ServiceUserMapperImpl(), config);
+        
         registerServiceIfNotPresent(bundleContext, ResourceAccessSecurityTracker.class, new ResourceAccessSecurityTracker());
         registerServiceIfNotPresent(bundleContext, EventAdmin.class, new MockEventAdmin());
     }
@@ -140,13 +143,27 @@ class ResourceResolverFactoryInitializer {
      * Registers a service if the service class is found in classpath,
      * and if no service with this class is already registered.
      * @param className Service class name
+     * @param serviceClass Service class
+     * @param instance Service instance
+     */
+    private static void registerServiceIfNotPresent(BundleContext bundleContext, Class<?> serviceClass, 
+            Object instance) {
+        registerServiceIfNotPresent(bundleContext, serviceClass, instance, new Hashtable<String, Object>());
+    }
+    /**
+     * Registers a service if the service class is found in classpath,
+     * and if no service with this class is already registered.
+     * @param className Service class name
+     * @param serviceClass Service class
+     * @param instance Service instance
+     * @param config OSGi config
      */
-    private static void registerServiceIfNotPresent(BundleContext bundleContext, Class<?> serviceClass, Object instance) {
+    private static void registerServiceIfNotPresent(BundleContext bundleContext, Class<?> serviceClass, 
+            Object instance, Dictionary<String, Object> config) {
         if (bundleContext.getServiceReference(serviceClass.getName()) == null) {
-            Dictionary<String,Object> properties = new Hashtable<String, Object>();
             MockOsgi.injectServices(instance, bundleContext);
-            MockOsgi.activate(instance, bundleContext, properties);
-            bundleContext.registerService(serviceClass.getName(), instance, properties);
+            MockOsgi.activate(instance, bundleContext, config);
+            bundleContext.registerService(serviceClass.getName(), instance, config);
         }
     }
     

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

[sling-org-apache-sling-testing-sling-mock] 34/37: Update the main reactor to parent 25

Posted by ro...@apache.org.
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-1.6.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git

commit 2b7ac2275353ac34e043d0133640d93db799dc8a
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Mon Oct 5 10:03:45 2015 +0000

    Update the main reactor to parent 25
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock@1706780 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index 65ec4e0..241586e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@
     <parent>
         <groupId>org.apache.sling</groupId>
         <artifactId>sling</artifactId>
-        <version>24</version>
+        <version>25</version>
         <relativePath />
     </parent>
 

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

[sling-org-apache-sling-testing-sling-mock] 36/37: [maven-release-plugin] prepare release org.apache.sling.testing.sling-mock-1.6.0

Posted by ro...@apache.org.
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-1.6.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git

commit 8949c0019285615e714d4c0b65a5f37fcaa58c21
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Mon Oct 5 17:28:49 2015 +0000

    [maven-release-plugin] prepare release org.apache.sling.testing.sling-mock-1.6.0
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock@1706880 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/pom.xml b/pom.xml
index 99393f4..3791812 100644
--- a/pom.xml
+++ b/pom.xml
@@ -28,16 +28,16 @@
     </parent>
 
     <artifactId>org.apache.sling.testing.sling-mock</artifactId>
-    <version>1.5.1-SNAPSHOT</version>
+    <version>1.6.0</version>
     <packaging>bundle</packaging>
 
     <name>Apache Sling Testing Sling Mock</name>
     <description>Mock implementation of selected Sling APIs.</description>
 
     <scm>
-        <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock</connection>
-        <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock</developerConnection>
-        <url>http://svn.apache.org/viewvc/sling/trunk/testing/mocks/sling-mock</url>
+        <connection>scm:svn:http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.testing.sling-mock-1.6.0</connection>
+        <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.testing.sling-mock-1.6.0</developerConnection>
+        <url>http://svn.apache.org/viewvc/sling/tags/org.apache.sling.testing.sling-mock-1.6.0</url>
     </scm>
 
     <dependencies>

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

[sling-org-apache-sling-testing-sling-mock] 06/37: update to next snapshot version until releases are available in maven central

Posted by ro...@apache.org.
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-1.6.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git

commit 5846795e11d7302b216e405e1f1f905b6de96ef5
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Thu Sep 10 22:12:54 2015 +0000

    update to next snapshot version until releases are available in maven central
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock@1702342 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index c2885c9..85a526d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -57,7 +57,7 @@
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.testing.resourceresolver-mock</artifactId>
-            <version>1.1.9-SNAPSHOT</version>
+            <version>1.1.11-SNAPSHOT</version>
             <scope>compile</scope>
         </dependency>
 

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

[sling-org-apache-sling-testing-sling-mock] 30/37: SLING-5088 control SlingRepository resources via activate/deactivate methods; make sure all oak ExecutorServices are shutdown properly

Posted by ro...@apache.org.
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-1.6.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git

commit 8801d9987b1036e361e9e1486da7389263b95757
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Fri Oct 2 23:31:40 2015 +0000

    SLING-5088 control SlingRepository resources via activate/deactivate methods; make sure all oak ExecutorServices are shutdown properly
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock@1706505 13f79535-47bb-0310-9956-ffa450edef68
---
 .../mock/sling/MockJcrResourceResolverAdapter.java |  6 +---
 .../testing/mock/sling/MockJcrSlingRepository.java | 39 +++++++++++++---------
 .../sling/ResourceResolverFactoryInitializer.java  |  6 ++--
 .../mock/sling/MockJcrSlingRepositoryTest.java     |  9 +++--
 4 files changed, 34 insertions(+), 26 deletions(-)

diff --git a/src/main/java/org/apache/sling/testing/mock/sling/MockJcrResourceResolverAdapter.java b/src/main/java/org/apache/sling/testing/mock/sling/MockJcrResourceResolverAdapter.java
index 8eafd59..d9df564 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/MockJcrResourceResolverAdapter.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/MockJcrResourceResolverAdapter.java
@@ -18,11 +18,8 @@
  */
 package org.apache.sling.testing.mock.sling;
 
-import javax.jcr.Repository;
-
 import org.apache.sling.api.resource.ResourceResolverFactory;
 import org.apache.sling.jcr.api.SlingRepository;
-import org.apache.sling.testing.mock.jcr.MockJcr;
 import org.apache.sling.testing.mock.sling.spi.ResourceResolverTypeAdapter;
 
 /**
@@ -37,8 +34,7 @@ class MockJcrResourceResolverAdapter implements ResourceResolverTypeAdapter {
 
     @Override
     public SlingRepository newSlingRepository() {
-        Repository repository = MockJcr.newRepository();
-        return new MockJcrSlingRepository(repository);
+        return new MockJcrSlingRepository();
     }
 
 }
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/MockJcrSlingRepository.java b/src/main/java/org/apache/sling/testing/mock/sling/MockJcrSlingRepository.java
index c5e0f58..48fd567 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/MockJcrSlingRepository.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/MockJcrSlingRepository.java
@@ -26,18 +26,25 @@ import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.Value;
 
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Service;
 import org.apache.sling.jcr.api.SlingRepository;
 import org.apache.sling.testing.mock.jcr.MockJcr;
+import org.osgi.service.component.ComponentContext;
 
 /**
  * Mock {@link SlingRepository} implementation.
  */
-class MockJcrSlingRepository implements SlingRepository {
-
-    private final Repository delegate;
-
-    public MockJcrSlingRepository(final Repository delegate) {
-        this.delegate = delegate;
+@Component
+@Service(SlingRepository.class)
+public final class MockJcrSlingRepository implements SlingRepository {
+
+    private Repository repository;
+    
+    @Activate
+    protected void activate(ComponentContext componentContext) {
+        repository = MockJcr.newRepository();
     }
 
     @Override
@@ -59,54 +66,54 @@ class MockJcrSlingRepository implements SlingRepository {
     // delegated methods
     @Override
     public String[] getDescriptorKeys() {
-        return this.delegate.getDescriptorKeys();
+        return this.repository.getDescriptorKeys();
     }
 
     @Override
     public boolean isStandardDescriptor(final String key) {
-        return this.delegate.isStandardDescriptor(key);
+        return this.repository.isStandardDescriptor(key);
     }
 
     @Override
     public boolean isSingleValueDescriptor(final String key) {
-        return this.delegate.isSingleValueDescriptor(key);
+        return this.repository.isSingleValueDescriptor(key);
     }
 
     @Override
     public Value getDescriptorValue(final String key) {
-        return this.delegate.getDescriptorValue(key);
+        return this.repository.getDescriptorValue(key);
     }
 
     @Override
     public Value[] getDescriptorValues(final String key) {
-        return this.delegate.getDescriptorValues(key);
+        return this.repository.getDescriptorValues(key);
     }
 
     @Override
     public String getDescriptor(final String key) {
-        return this.delegate.getDescriptor(key);
+        return this.repository.getDescriptor(key);
     }
 
     @Override
     public Session login(final Credentials credentials, final String workspaceName) throws LoginException,
             NoSuchWorkspaceException, RepositoryException {
-        return this.delegate.login(credentials, workspaceName);
+        return this.repository.login(credentials, workspaceName);
     }
 
     @Override
     public Session login(final Credentials credentials) throws LoginException, RepositoryException {
-        return this.delegate.login(credentials);
+        return this.repository.login(credentials);
     }
 
     @Override
     public Session login(final String workspaceName) throws LoginException, NoSuchWorkspaceException,
             RepositoryException {
-        return this.delegate.login(workspaceName);
+        return this.repository.login(workspaceName);
     }
 
     @Override
     public Session login() throws LoginException, RepositoryException {
-        return this.delegate.login();
+        return this.repository.login();
     }
 
 }
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/ResourceResolverFactoryInitializer.java b/src/main/java/org/apache/sling/testing/mock/sling/ResourceResolverFactoryInitializer.java
index 0572ec9..fef5f6c 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/ResourceResolverFactoryInitializer.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/ResourceResolverFactoryInitializer.java
@@ -60,12 +60,12 @@ class ResourceResolverFactoryInitializer {
             BundleContext bundleContext, NodeTypeMode nodeTypeMode) {
         
         if (slingRepository != null) {
+            // register sling repository as OSGi service
+            registerServiceIfNotPresent(bundleContext, SlingRepository.class, slingRepository);
+            
             // register JCR node types found in classpath
             registerJcrNodeTypes(slingRepository, nodeTypeMode);
             
-            // register sling repository as OSGi service
-            bundleContext.registerService(SlingRepository.class.getName(), slingRepository, null);
-            
             // initialize JCR resource provider factory
             ensureJcrResourceProviderFactoryDependencies(bundleContext);
             initializeJcrResourceProviderFactory(bundleContext);
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/MockJcrSlingRepositoryTest.java b/src/test/java/org/apache/sling/testing/mock/sling/MockJcrSlingRepositoryTest.java
index 9d425a9..902aaca 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/MockJcrSlingRepositoryTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/MockJcrSlingRepositoryTest.java
@@ -25,18 +25,23 @@ import javax.jcr.Session;
 
 import org.apache.sling.jcr.api.SlingRepository;
 import org.apache.sling.testing.mock.jcr.MockJcr;
+import org.apache.sling.testing.mock.osgi.junit.OsgiContext;
 import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
 
 public class MockJcrSlingRepositoryTest {
 
+    @Rule
+    public OsgiContext context = new OsgiContext();
+    
     private SlingRepository repository;
 
     @Before
     public void setUp() {
-        this.repository = new MockJcrSlingRepository(MockJcr.newRepository());
+        this.repository = context.registerInjectActivateService(new MockJcrSlingRepository());
     }
-
+    
     @SuppressWarnings("deprecation")
     @Test
     public void testLoginAdministrative() throws RepositoryException {

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

[sling-org-apache-sling-testing-sling-mock] 29/37: SLING-5088 deprecate all methods that may lead to thread leaks

Posted by ro...@apache.org.
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-1.6.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git

commit 1b9e8dbc3de5145a80adac8bdf561b5fea41cc2b
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Fri Oct 2 22:35:50 2015 +0000

    SLING-5088 deprecate all methods that may lead to thread leaks
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock@1706500 13f79535-47bb-0310-9956-ffa450edef68
---
 .../apache/sling/testing/mock/sling/MockSling.java | 60 +++++++++++++++++++++-
 .../sling/ResourceResolverFactoryInitializer.java  |  2 -
 .../sling/servlet/MockSlingHttpServletRequest.java | 12 ++++-
 .../mock/sling/MockSlingScriptHelperTest.java      |  4 +-
 .../context/AbstractSlingContextImplTest.java      | 11 ++--
 .../sling/context/ModelAdapterFactoryUtilTest.java | 19 +++----
 .../sling/resource/AbstractJcrNamespaceTest.java   |  7 ++-
 .../servlet/MockSlingHttpServletRequestTest.java   |  2 +-
 8 files changed, 87 insertions(+), 30 deletions(-)

diff --git a/src/main/java/org/apache/sling/testing/mock/sling/MockSling.java b/src/main/java/org/apache/sling/testing/mock/sling/MockSling.java
index db85756..a6e1440 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/MockSling.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/MockSling.java
@@ -56,13 +56,25 @@ public final class MockSling {
      * Creates new sling resource resolver factory instance.
      * @param type Type of underlying repository.
      * @return Resource resolver factory instance
+     * @deprecated Please use {@link #newResourceResolverFactory(ResourceResolverType, BundleContext)}
+     *   and shutdown the bundle context after usage.
      */
+    @Deprecated
     public static ResourceResolverFactory newResourceResolverFactory(final ResourceResolverType type) {
         return newResourceResolverFactory(type, MockOsgi.newBundleContext());
     }
     
     /**
      * Creates new sling resource resolver factory instance.
+     * @param bundleContext Bundle context
+     * @return Resource resolver factory instance
+     */
+    public static ResourceResolverFactory newResourceResolverFactory(final BundleContext bundleContext) {
+        return newResourceResolverFactory(DEFAULT_RESOURCERESOLVER_TYPE, bundleContext);
+    }
+
+    /**
+     * Creates new sling resource resolver factory instance.
      * @param type Type of underlying repository.
      * @param bundleContext Bundle context
      * @return Resource resolver factory instance
@@ -107,7 +119,10 @@ public final class MockSling {
      * Creates new sling resource resolver factory instance using
      * {@link #DEFAULT_RESOURCERESOLVER_TYPE}.
      * @return Resource resolver factory instance
+     * @deprecated Please use {@link #newResourceResolverFactory(BundleContext)}
+     *   and shutdown the bundle context after usage.
      */
+    @Deprecated
     public static ResourceResolverFactory newResourceResolverFactory() {
         return newResourceResolverFactory(DEFAULT_RESOURCERESOLVER_TYPE);
     }
@@ -116,7 +131,10 @@ public final class MockSling {
      * Creates new sling resource resolver instance.
      * @param type Type of underlying repository.
      * @return Resource resolver instance
+     * @deprecated Please use {@link #newResourceResolver(ResourceResolverType, BundleContext)}
+     *   and shutdown the bundle context after usage.
      */
+    @Deprecated
     public static ResourceResolver newResourceResolver(final ResourceResolverType type) {
         ResourceResolverFactory factory = newResourceResolverFactory(type);
         try {
@@ -130,12 +148,38 @@ public final class MockSling {
      * Creates new sling resource resolver instance using
      * {@link #DEFAULT_RESOURCERESOLVER_TYPE}.
      * @return Resource resolver instance
+     * @deprecated Please use {@link #newResourceResolver(BundleContext)}
+     *   and shutdown the bundle context after usage.
      */
+    @Deprecated
     public static ResourceResolver newResourceResolver() {
         return newResourceResolver(DEFAULT_RESOURCERESOLVER_TYPE);
     }
 
     /**
+     * Creates new sling resource resolver instance.
+     * @param type Type of underlying repository.
+     * @return Resource resolver instance
+     */
+    public static ResourceResolver newResourceResolver(final ResourceResolverType type, BundleContext bundleContext) {
+        ResourceResolverFactory factory = newResourceResolverFactory(type, bundleContext);
+        try {
+            return factory.getAdministrativeResourceResolver(null);
+        } catch (LoginException ex) {
+            throw new RuntimeException("Mock resource resolver factory implementation seems to require login.", ex);
+        }
+    }
+
+    /**
+     * Creates new sling resource resolver instance using
+     * {@link #DEFAULT_RESOURCERESOLVER_TYPE}.
+     * @return Resource resolver instance
+     */
+    public static ResourceResolver newResourceResolver(BundleContext bundleContext) {
+        return newResourceResolver(DEFAULT_RESOURCERESOLVER_TYPE, bundleContext);
+    }
+
+    /**
      * Creates a new sling script helper instance.
      * @param request Request
      * @param response Response
@@ -151,11 +195,23 @@ public final class MockSling {
      * Creates a new sling script helper instance using
      * {@link #DEFAULT_RESOURCERESOLVER_TYPE} for the resource resolver.
      * @return Sling script helper instance
+     * @deprecated Please use {@link #newSlingScriptHelper(BundleContext)}
+     *   and shutdown the bundle context after usage.
      */
+    @Deprecated
     public static SlingScriptHelper newSlingScriptHelper() {
-        SlingHttpServletRequest request = new MockSlingHttpServletRequest(newResourceResolver());
-        SlingHttpServletResponse response = new MockSlingHttpServletResponse();
         BundleContext bundleContext = MockOsgi.newBundleContext();
+        return newSlingScriptHelper(bundleContext);
+    }
+
+    /**
+     * Creates a new sling script helper instance using
+     * {@link #DEFAULT_RESOURCERESOLVER_TYPE} for the resource resolver.
+     * @return Sling script helper instance
+     */
+    public static SlingScriptHelper newSlingScriptHelper(BundleContext bundleContext) {
+        SlingHttpServletRequest request = new MockSlingHttpServletRequest(newResourceResolver(bundleContext));
+        SlingHttpServletResponse response = new MockSlingHttpServletResponse();
         return newSlingScriptHelper(request, response, bundleContext);
     }
 
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/ResourceResolverFactoryInitializer.java b/src/main/java/org/apache/sling/testing/mock/sling/ResourceResolverFactoryInitializer.java
index ae1f129..0572ec9 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/ResourceResolverFactoryInitializer.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/ResourceResolverFactoryInitializer.java
@@ -42,8 +42,6 @@ import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.event.EventAdmin;
 
-import sun.util.BuddhistCalendar;
-
 /**
  * Initializes Sling Resource Resolver factories with JCR-resource mapping.
  */
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/servlet/MockSlingHttpServletRequest.java b/src/main/java/org/apache/sling/testing/mock/sling/servlet/MockSlingHttpServletRequest.java
index 4349cac..02130cd 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/servlet/MockSlingHttpServletRequest.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/servlet/MockSlingHttpServletRequest.java
@@ -108,9 +108,19 @@ public class MockSlingHttpServletRequest extends SlingAdaptable implements Sling
 
     /**
      * Instantiate with default resource resolver
+     * @deprecated Please use {@link #MockSlingHttpServletRequest(BundleContext)}
+     *   and shutdown the bundle context after usage.
      */
+    @Deprecated
     public MockSlingHttpServletRequest() {
-        this(MockSling.newResourceResolver());
+        this(MockOsgi.newBundleContext());
+    }
+
+    /**
+     * Instantiate with default resource resolver
+     */
+    public MockSlingHttpServletRequest(BundleContext bundleContext) {
+        this(MockSling.newResourceResolver(bundleContext));
     }
 
     /**
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/MockSlingScriptHelperTest.java b/src/test/java/org/apache/sling/testing/mock/sling/MockSlingScriptHelperTest.java
index 9f5bebd..c4098b7 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/MockSlingScriptHelperTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/MockSlingScriptHelperTest.java
@@ -44,10 +44,10 @@ public class MockSlingScriptHelperTest {
 
     @Before
     public void setUp() throws Exception {
-        this.resourceResolver = MockSling.newResourceResolver();
+        this.bundleContext = MockOsgi.newBundleContext();
+        this.resourceResolver = MockSling.newResourceResolver(bundleContext);
         this.request = new MockSlingHttpServletRequest(this.resourceResolver);
         this.response = new MockSlingHttpServletResponse();
-        this.bundleContext = MockOsgi.newBundleContext();
         this.scriptHelper = MockSling.newSlingScriptHelper(this.request, this.response, this.bundleContext);
     }
     
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/context/AbstractSlingContextImplTest.java b/src/test/java/org/apache/sling/testing/mock/sling/context/AbstractSlingContextImplTest.java
index c129ee1..391cce6 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/context/AbstractSlingContextImplTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/context/AbstractSlingContextImplTest.java
@@ -36,12 +36,10 @@ import org.apache.sling.api.scripting.SlingBindings;
 import org.apache.sling.commons.mime.MimeTypeService;
 import org.apache.sling.models.annotations.Model;
 import org.apache.sling.settings.SlingSettingsService;
-import org.apache.sling.testing.mock.sling.MockSling;
 import org.apache.sling.testing.mock.sling.ResourceResolverType;
 import org.apache.sling.testing.mock.sling.junit.SlingContext;
 import org.apache.sling.testing.mock.sling.loader.ContentLoader;
 import org.apache.sling.testing.mock.sling.services.MockMimeTypeService;
-import org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
@@ -112,11 +110,9 @@ public abstract class AbstractSlingContextImplTest {
     public void testSlingModelsOsgiService() {
         context.registerService(new MockMimeTypeService());
 
-        ResourceResolver resolver = MockSling.newResourceResolver();
-        OsgiServiceModel model = resolver.adaptTo(OsgiServiceModel.class);
+        OsgiServiceModel model = context.resourceResolver().adaptTo(OsgiServiceModel.class);
         assertNotNull(model.getMimeTypeService());
         assertEquals("text/html", model.getMimeTypeService().getMimeType("html"));
-        resolver.close();
     }
 
     @Test
@@ -127,9 +123,8 @@ public abstract class AbstractSlingContextImplTest {
 
     @Test
     public void testAdaptToInterface() {
-        MockSlingHttpServletRequest request = new MockSlingHttpServletRequest();
-        request.setAttribute("prop1", "myValue");
-        ServiceInterface model = request.adaptTo(ServiceInterface.class);
+        context.request().setAttribute("prop1", "myValue");
+        ServiceInterface model = context.request().adaptTo(ServiceInterface.class);
         assertNotNull(model);
         assertEquals("myValue", model.getPropValue());
     }
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/context/ModelAdapterFactoryUtilTest.java b/src/test/java/org/apache/sling/testing/mock/sling/context/ModelAdapterFactoryUtilTest.java
index 13df440..d935bbb 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/context/ModelAdapterFactoryUtilTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/context/ModelAdapterFactoryUtilTest.java
@@ -28,10 +28,8 @@ import org.apache.sling.api.SlingHttpServletRequest;
 import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.commons.mime.MimeTypeService;
 import org.apache.sling.models.annotations.Model;
-import org.apache.sling.testing.mock.sling.MockSling;
 import org.apache.sling.testing.mock.sling.junit.SlingContext;
 import org.apache.sling.testing.mock.sling.services.MockMimeTypeService;
-import org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
@@ -49,9 +47,8 @@ public class ModelAdapterFactoryUtilTest {
 
     @Test
     public void testRequestAttribute() {
-        MockSlingHttpServletRequest request = new MockSlingHttpServletRequest();
-        request.setAttribute("prop1", "myValue");
-        RequestAttributeModel model = request.adaptTo(RequestAttributeModel.class);
+        context.request().setAttribute("prop1", "myValue");
+        RequestAttributeModel model = context.request().adaptTo(RequestAttributeModel.class);
         assertNotNull(model);
         assertEquals("myValue", model.getProp1());
     }
@@ -60,26 +57,22 @@ public class ModelAdapterFactoryUtilTest {
     public void testOsgiService() {
         context.registerService(MimeTypeService.class, new MockMimeTypeService(), null);
 
-        ResourceResolver resolver = MockSling.newResourceResolver();
-        OsgiServiceModel model = resolver.adaptTo(OsgiServiceModel.class);
+        OsgiServiceModel model = context.resourceResolver().adaptTo(OsgiServiceModel.class);
         assertNotNull(model);
         assertNotNull(model.getMimeTypeService());
         assertEquals("text/html", model.getMimeTypeService().getMimeType("html"));
-        resolver.close();
     }
 
     @Test
     public void testInvalidAdapt() {
-        MockSlingHttpServletRequest request = new MockSlingHttpServletRequest();
-        OsgiServiceModel model = request.adaptTo(OsgiServiceModel.class);
+        OsgiServiceModel model = context.request().adaptTo(OsgiServiceModel.class);
         assertNull(model);
     }
 
     @Test
     public void testAdaptToInterface() {
-        MockSlingHttpServletRequest request = new MockSlingHttpServletRequest();
-        request.setAttribute("prop1", "myValue");
-        ServiceInterface model = request.adaptTo(ServiceInterface.class);
+        context.request().setAttribute("prop1", "myValue");
+        ServiceInterface model = context.request().adaptTo(ServiceInterface.class);
         assertNotNull(model);
         assertEquals("myValue", model.getPropValue());
     }
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractJcrNamespaceTest.java b/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractJcrNamespaceTest.java
index 71b93b7..427e338 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractJcrNamespaceTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractJcrNamespaceTest.java
@@ -27,12 +27,14 @@ import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.api.resource.ResourceUtil;
 import org.apache.sling.api.resource.ValueMap;
+import org.apache.sling.testing.mock.osgi.MockOsgi;
 import org.apache.sling.testing.mock.sling.MockSling;
 import org.apache.sling.testing.mock.sling.ResourceResolverType;
 import org.apache.sling.testing.mock.sling.junit.SlingContext;
 import org.apache.sling.testing.mock.sling.loader.ContentLoader;
 import org.junit.Rule;
 import org.junit.Test;
+import org.osgi.framework.BundleContext;
 
 /**
  * Validates correct registering and mapping of JCR namespaces, esp. the sling namespace. 
@@ -46,7 +48,8 @@ public abstract class AbstractJcrNamespaceTest {
     
     @Test
     public void testSling4362() throws RepositoryException {
-        ResourceResolver resolver = MockSling.newResourceResolver(getResourceResolverType());
+        BundleContext bundleContext = MockOsgi.newBundleContext();
+        ResourceResolver resolver = MockSling.newResourceResolver(getResourceResolverType(), bundleContext);
         
         ContentLoader contentLoader = new ContentLoader(resolver);
         contentLoader.json("/json-import-samples/SLING-4362.json", context.uniqueRoot().content() + "/foo");
@@ -56,6 +59,8 @@ public abstract class AbstractJcrNamespaceTest {
         ValueMap props = ResourceUtil.getValueMap(resource);
         assertEquals("fooType", props.get(SLING_RESOURCE_TYPE_PROPERTY));
         assertEquals("fooType", resource.getResourceType());
+        
+        MockOsgi.shutdown(bundleContext);
     }
 
     @Test
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/servlet/MockSlingHttpServletRequestTest.java b/src/test/java/org/apache/sling/testing/mock/sling/servlet/MockSlingHttpServletRequestTest.java
index 3ab99ad..953f52d 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/servlet/MockSlingHttpServletRequestTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/servlet/MockSlingHttpServletRequestTest.java
@@ -87,7 +87,7 @@ public class MockSlingHttpServletRequestTest {
 
     @Test
     public void testDefaultResourceResolver() {
-        assertNotNull(new MockSlingHttpServletRequest().getResourceResolver());
+        assertNotNull(new MockSlingHttpServletRequest(bundleContext).getResourceResolver());
     }
 
     @Test

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

[sling-org-apache-sling-testing-sling-mock] 05/37: update release versions

Posted by ro...@apache.org.
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-1.6.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git

commit 8580a5561b5b8d21621acfaf3edf7f122a4dc812
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Thu Sep 10 21:22:02 2015 +0000

    update release versions
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock@1702320 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index 0d23971..c2885c9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -51,7 +51,7 @@
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.testing.jcr-mock</artifactId>
-            <version>1.1.9-SNAPSHOT</version>
+            <version>1.1.10</version>
             <scope>compile</scope>
         </dependency>
         <dependency>

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

[sling-org-apache-sling-testing-sling-mock] 18/37: SLING-5067 sling-mock: "uniqueRoot()" to simplify creation and cleanup of unique root paths in repository

Posted by ro...@apache.org.
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-1.6.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git

commit 8c79b8109abc0ee3f7668982a8cb1fa721b27e5e
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Sun Sep 27 09:46:11 2015 +0000

    SLING-5067 sling-mock: "uniqueRoot()" to simplify creation and cleanup of unique root paths in repository
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock@1705520 13f79535-47bb-0310-9956-ffa450edef68
---
 .../mock/sling/context/SlingContextImpl.java       |  18 ++-
 .../testing/mock/sling/context/UniqueRoot.java     | 143 +++++++++++++++++++++
 .../testing/mock/sling/junit/package-info.java     |   2 +-
 .../sling/jcrmock/resource/UniqueRootTest.java}    |  18 ++-
 .../sling/resource/AbstractJcrNamespaceTest.java   |   7 +-
 .../resource/AbstractJcrResourceResolverTest.java  |   3 +-
 .../sling/resource/AbstractUniqueRootTest.java     |  57 ++++++++
 .../sling/rrmock/resource/UniqueRootTest.java}     |  18 ++-
 8 files changed, 250 insertions(+), 16 deletions(-)

diff --git a/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java b/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java
index 2370420..8c31c06 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java
@@ -77,6 +77,7 @@ public class SlingContextImpl extends OsgiContextImpl {
     protected SlingScriptHelper slingScriptHelper;
     protected ContentLoader contentLoader;
     protected ContentBuilder contentBuilder;
+    protected UniqueRoot uniqueRoot;
 
     /**
      * @param resourceResolverType Resource resolver type
@@ -136,8 +137,9 @@ public class SlingContextImpl extends OsgiContextImpl {
      * Teardown actions after test method execution
      */
     protected void tearDown() {
-
+        
         if (this.resourceResolver != null) {
+            
             // revert potential unsaved changes in resource resolver/JCR session
             this.resourceResolver.revert();
             Session session = this.resourceResolver.adaptTo(Session.class);
@@ -148,6 +150,13 @@ public class SlingContextImpl extends OsgiContextImpl {
                     // ignore
                 }
             }
+            
+            // remove unique roots
+            if (this.uniqueRoot != null) {
+                this.uniqueRoot.cleanUp();
+            }
+            
+            // close resource resolver
             this.resourceResolver.close();
         }
 
@@ -305,5 +314,12 @@ public class SlingContextImpl extends OsgiContextImpl {
             slingSettings.setRunModes(newRunModes);
         }
     }
+    
+    public UniqueRoot uniqueRoot() {
+        if (uniqueRoot == null) {
+            uniqueRoot = new UniqueRoot(this);
+        }
+        return uniqueRoot;
+    }
 
 }
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/context/UniqueRoot.java b/src/main/java/org/apache/sling/testing/mock/sling/context/UniqueRoot.java
new file mode 100644
index 0000000..20f836b
--- /dev/null
+++ b/src/main/java/org/apache/sling/testing/mock/sling/context/UniqueRoot.java
@@ -0,0 +1,143 @@
+/*
+ * 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.context;
+
+import static org.apache.sling.jcr.resource.JcrResourceConstants.NT_SLING_ORDERED_FOLDER;
+
+import java.util.UUID;
+
+import org.apache.jackrabbit.JcrConstants;
+import org.apache.sling.api.resource.PersistenceException;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.collect.ImmutableMap;
+
+/**
+ * Manages unique root paths in JCR repository.
+ * This is important for resource resolver types like JCR_JACKRABBIT and JCR_OAK 
+ * where the repository is not cleand for each test run. This class provides
+ * unique root paths for each run, and cleans them up when done.
+ */
+public class UniqueRoot {
+    
+    private final SlingContextImpl context;
+    
+    protected final String uniquePathPart;
+    
+    private Resource contentRoot;
+    private Resource appsRoot;
+    private Resource libsRoot;
+    
+    private static final Logger log = LoggerFactory.getLogger(UniqueRoot.class);
+    
+    protected UniqueRoot(SlingContextImpl context) {
+        this.context = context;
+        // generate unique path part by using a UUID
+        uniquePathPart = UUID.randomUUID().toString();
+    }
+    
+    /**
+     * Get or create resource with given JCR primary type
+     * @param path Path
+     * @param primaryType JCR primary type
+     * @return Resource (never null)
+     */
+    protected final Resource getOrCreateResource(String path, String primaryType) {
+        try {
+            return ResourceUtil.getOrCreateResource(context.resourceResolver(), path, 
+                    ImmutableMap.<String,Object>of(JcrConstants.JCR_PRIMARYTYPE, primaryType),
+                    null, true);
+        }
+        catch (PersistenceException ex) {
+            throw new RuntimeException("Unable to create resource at " + path + ": " + ex.getMessage(), ex);
+        }
+    }
+    
+    /**
+     * Gets (and creates if required) a unique path at <code>/content/xxx</code>.
+     * The path (incl. all children) is automatically removed when the unit test completes.
+     * @return Unique content path
+     */
+    public final String content() {
+        if (contentRoot == null) {
+            contentRoot = getOrCreateResource("/content/" + uniquePathPart, NT_SLING_ORDERED_FOLDER);
+        }
+        return contentRoot.getPath();
+    }
+        
+    /**
+     * Gets (and creates if required) a unique path at <code>/apps/xxx</code>.
+     * The path (incl. all children) is automatically removed when the unit test completes.
+     * @return Unique content path
+     */
+    public final String apps() {
+        if (appsRoot == null) {
+            appsRoot = getOrCreateResource("/apps/" + uniquePathPart, NT_SLING_ORDERED_FOLDER);
+        }
+        return appsRoot.getPath();
+    }
+        
+    /**
+     * Gets (and creates if required) a unique path at <code>/libs/xxx</code>.
+     * The path (incl. all children) is automatically removed when the unit test completes.
+     * @return Unique content path
+     */
+    public final String libs() {
+        if (libsRoot == null) {
+            libsRoot = getOrCreateResource("/libs/" + uniquePathPart, NT_SLING_ORDERED_FOLDER);
+        }
+        return libsRoot.getPath();
+    }
+    
+    /**
+     * Cleanup is called when the unit test rule completes a unit test run.
+     * All resources created have to be removed.
+     */
+    protected void cleanUp() {
+        deleteResources(contentRoot, appsRoot, libsRoot);
+    }
+    
+    /**
+     * Deletes the given set of resources and commits afterwards.
+     * @param resources Resources to be deleted
+     */
+    protected final void deleteResources(Resource... resources) {
+        for (Resource resource : resources) {
+            if (resource != null) {
+                try {
+                    context.resourceResolver().delete(resource);
+                }
+                catch (PersistenceException ex) {
+                    log.warn("Unable to delete root path " + resource.getPath(), ex);
+                }
+            }
+        }
+        try {
+            context.resourceResolver().commit();
+        }
+        catch (PersistenceException ex) {
+            log.warn("Unable to commit root path deletions.", ex);
+        }
+            
+    }
+    
+}
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/junit/package-info.java b/src/main/java/org/apache/sling/testing/mock/sling/junit/package-info.java
index f60a75d..b7888e3 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/junit/package-info.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/junit/package-info.java
@@ -19,5 +19,5 @@
 /**
  * Rule for providing easy access to Sling context in JUnit tests.
  */
-@aQute.bnd.annotation.Version("3.0")
+@aQute.bnd.annotation.Version("3.1")
 package org.apache.sling.testing.mock.sling.junit;
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/junit/package-info.java b/src/test/java/org/apache/sling/testing/mock/sling/jcrmock/resource/UniqueRootTest.java
similarity index 66%
copy from src/main/java/org/apache/sling/testing/mock/sling/junit/package-info.java
copy to src/test/java/org/apache/sling/testing/mock/sling/jcrmock/resource/UniqueRootTest.java
index f60a75d..73c6793 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/junit/package-info.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/jcrmock/resource/UniqueRootTest.java
@@ -16,8 +16,16 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/**
- * Rule for providing easy access to Sling context in JUnit tests.
- */
-@aQute.bnd.annotation.Version("3.0")
-package org.apache.sling.testing.mock.sling.junit;
+package org.apache.sling.testing.mock.sling.jcrmock.resource;
+
+import org.apache.sling.testing.mock.sling.ResourceResolverType;
+import org.apache.sling.testing.mock.sling.resource.AbstractUniqueRootTest;
+
+public class UniqueRootTest extends AbstractUniqueRootTest {
+
+    @Override
+    protected ResourceResolverType getResourceResolverType() {
+        return ResourceResolverType.JCR_MOCK;
+    }
+
+}
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractJcrNamespaceTest.java b/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractJcrNamespaceTest.java
index 297073d..5185419 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractJcrNamespaceTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractJcrNamespaceTest.java
@@ -18,6 +18,7 @@
  */
 package org.apache.sling.testing.mock.sling.resource;
 
+import static org.apache.sling.jcr.resource.JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY;
 import static org.junit.Assert.assertEquals;
 
 import javax.jcr.NamespaceRegistry;
@@ -58,7 +59,7 @@ public abstract class AbstractJcrNamespaceTest {
         Resource resource = resolver.getResource("/content/foo");
         
         ValueMap props = ResourceUtil.getValueMap(resource);
-        assertEquals("fooType", props.get("sling:resourceType"));
+        assertEquals("fooType", props.get(SLING_RESOURCE_TYPE_PROPERTY));
         assertEquals("fooType", resource.getResourceType());
     }
 
@@ -72,7 +73,7 @@ public abstract class AbstractJcrNamespaceTest {
         Resource resource = resolver.getResource("/content/foo");
         
         ValueMap props = ResourceUtil.getValueMap(resource);
-        assertEquals("fooType", props.get("sling:resourceType"));
+        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());
@@ -88,7 +89,7 @@ public abstract class AbstractJcrNamespaceTest {
         Resource resource = resolver.getResource("/content/foo");
         
         ValueMap props = ResourceUtil.getValueMap(resource);
-        assertEquals("fooType", props.get("sling:resourceType"));
+        assertEquals("fooType", props.get(SLING_RESOURCE_TYPE_PROPERTY));
         assertEquals("fooType", resource.getResourceType());
     }
 
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractJcrResourceResolverTest.java b/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractJcrResourceResolverTest.java
index 2681fdd..8012308 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractJcrResourceResolverTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractJcrResourceResolverTest.java
@@ -18,6 +18,7 @@
  */
 package org.apache.sling.testing.mock.sling.resource;
 
+import static org.apache.sling.jcr.resource.JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY;
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
@@ -162,7 +163,7 @@ public abstract class AbstractJcrResourceResolverTest {
         Resource parent = resourceResolver.getResource(getTestRootNode().getPath());
 
         Resource child = resourceResolver.create(parent, "nodeTypeResource", ImmutableMap.<String, Object> builder()
-                .put("sling:resourceType", JcrConstants.NT_UNSTRUCTURED).build());
+                .put(SLING_RESOURCE_TYPE_PROPERTY, JcrConstants.NT_UNSTRUCTURED).build());
         assertNotNull(child);
         assertEquals(JcrConstants.NT_UNSTRUCTURED, child.getResourceType());
         assertEquals(JcrConstants.NT_UNSTRUCTURED, child.adaptTo(Node.class).getPrimaryNodeType().getName());
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractUniqueRootTest.java b/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractUniqueRootTest.java
new file mode 100644
index 0000000..0ddd658
--- /dev/null
+++ b/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractUniqueRootTest.java
@@ -0,0 +1,57 @@
+/*
+ * 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.resource;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.sling.testing.mock.sling.ResourceResolverType;
+import org.apache.sling.testing.mock.sling.junit.SlingContext;
+import org.junit.Rule;
+import org.junit.Test;
+
+public abstract class AbstractUniqueRootTest {
+    
+    @Rule
+    public SlingContext context = new SlingContext(getResourceResolverType());
+
+    protected abstract ResourceResolverType getResourceResolverType();
+
+    @Test
+    public void testContent() {
+        String path = context.uniqueRoot().content();
+        assertNotNull(context.resourceResolver().getResource(path));
+        assertTrue(path.matches("^/content/[^/]+"));
+    }
+
+    @Test
+    public void testApps() throws Exception {
+        String path = context.uniqueRoot().apps();
+        assertNotNull(context.resourceResolver().getResource(path));
+        assertTrue(path.matches("^/apps/[^/]+"));
+    }
+
+    @Test
+    public void testLibs() throws Exception {
+        String path = context.uniqueRoot().libs();
+        assertNotNull(context.resourceResolver().getResource(path));
+        assertTrue(path.matches("^/libs/[^/]+"));
+    }
+
+}
diff --git a/src/main/java/org/apache/sling/testing/mock/sling/junit/package-info.java b/src/test/java/org/apache/sling/testing/mock/sling/rrmock/resource/UniqueRootTest.java
similarity index 66%
copy from src/main/java/org/apache/sling/testing/mock/sling/junit/package-info.java
copy to src/test/java/org/apache/sling/testing/mock/sling/rrmock/resource/UniqueRootTest.java
index f60a75d..879459d 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/junit/package-info.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/rrmock/resource/UniqueRootTest.java
@@ -16,8 +16,16 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/**
- * Rule for providing easy access to Sling context in JUnit tests.
- */
-@aQute.bnd.annotation.Version("3.0")
-package org.apache.sling.testing.mock.sling.junit;
+package org.apache.sling.testing.mock.sling.rrmock.resource;
+
+import org.apache.sling.testing.mock.sling.ResourceResolverType;
+import org.apache.sling.testing.mock.sling.resource.AbstractUniqueRootTest;
+
+public class UniqueRootTest extends AbstractUniqueRootTest {
+
+    @Override
+    protected ResourceResolverType getResourceResolverType() {
+        return ResourceResolverType.RESOURCERESOLVER_MOCK;
+    }
+
+}

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

[sling-org-apache-sling-testing-sling-mock] 19/37: SLING-5067 rewrite unit tests to use new "uniqueRoot" feature

Posted by ro...@apache.org.
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-1.6.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git

commit b24a116b3382692b57b999bc07d6b177a45ff57f
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Mon Sep 28 20:37:21 2015 +0000

    SLING-5067 rewrite unit tests to use new "uniqueRoot" feature
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock@1705765 13f79535-47bb-0310-9956-ffa450edef68
---
 .../testing/mock/sling/context/UniqueRoot.java     |  4 +-
 .../resource/AbstractJcrResourceResolverTest.java  | 46 +++++-------
 .../AbstractSlingCrudResourceResolverTest.java     | 81 ++++++++--------------
 3 files changed, 50 insertions(+), 81 deletions(-)

diff --git a/src/main/java/org/apache/sling/testing/mock/sling/context/UniqueRoot.java b/src/main/java/org/apache/sling/testing/mock/sling/context/UniqueRoot.java
index 20f836b..471c657 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/context/UniqueRoot.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/context/UniqueRoot.java
@@ -33,8 +33,8 @@ import com.google.common.collect.ImmutableMap;
 
 /**
  * Manages unique root paths in JCR repository.
- * This is important for resource resolver types like JCR_JACKRABBIT and JCR_OAK 
- * where the repository is not cleand for each test run. This class provides
+ * This is important for resource resolver types like JCR_JACKRABBIT  
+ * where the repository is not cleaned for each test run. This class provides
  * unique root paths for each run, and cleans them up when done.
  */
 public class UniqueRoot {
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractJcrResourceResolverTest.java b/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractJcrResourceResolverTest.java
index 8012308..2726da9 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractJcrResourceResolverTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractJcrResourceResolverTest.java
@@ -18,6 +18,7 @@
  */
 package org.apache.sling.testing.mock.sling.resource;
 
+import static org.apache.sling.jcr.resource.JcrResourceConstants.NT_SLING_ORDERED_FOLDER;
 import static org.apache.sling.jcr.resource.JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY;
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
@@ -41,13 +42,13 @@ import org.apache.commons.lang3.time.DateUtils;
 import org.apache.jackrabbit.JcrConstants;
 import org.apache.sling.api.resource.PersistenceException;
 import org.apache.sling.api.resource.Resource;
-import org.apache.sling.api.resource.ResourceResolver;
 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.ResourceResolverType;
+import org.apache.sling.testing.mock.sling.junit.SlingContext;
 import org.junit.After;
 import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
 
 import com.google.common.collect.ImmutableList;
@@ -59,6 +60,9 @@ import com.google.common.collect.ImmutableMap;
  */
 public abstract class AbstractJcrResourceResolverTest {
 
+    @Rule
+    public SlingContext context = new SlingContext(getResourceResolverType());
+    
     private static final String STRING_VALUE = "value1";
     private static final String[] STRING_ARRAY_VALUE = new String[] { "value1", "value2" };
     private static final int INTEGER_VALUE = 25;
@@ -68,21 +72,14 @@ public abstract class AbstractJcrResourceResolverTest {
     private static final Calendar CALENDAR_VALUE = Calendar.getInstance();
     private static final byte[] BINARY_VALUE = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };
 
-    private ResourceResolver resourceResolver;
     private Session session;
     protected Node testRoot;
-    private static volatile long rootNodeCounter;
 
     protected abstract ResourceResolverType getResourceResolverType();
 
-    protected ResourceResolver newResourceResolver() {
-        return MockSling.newResourceResolver(getResourceResolverType());
-    }
-
     @Before
     public final void setUp() throws RepositoryException {
-        resourceResolver = newResourceResolver();
-        session = resourceResolver.adaptTo(Session.class);
+        session = context.resourceResolver().adaptTo(Session.class);
 
         // prepare some test data using JCR API
         Node rootNode = getTestRootNode();
@@ -106,28 +103,21 @@ public abstract class AbstractJcrResourceResolverTest {
     @After
     public final void tearDown() {
         testRoot = null;
-        resourceResolver.close();
     }
 
     /**
      * Return a test root node, created on demand, with a unique path
      */
     private Node getTestRootNode() throws RepositoryException {
-        if (testRoot == null) {
-            final Node root = session.getRootNode();
-            if (getResourceResolverType() == ResourceResolverType.JCR_JACKRABBIT) {
-                final Node classRoot = root.addNode(getClass().getSimpleName());
-                testRoot = classRoot.addNode(System.currentTimeMillis() + "_" + (rootNodeCounter++));
-            } else {
-                testRoot = root.addNode("test", JcrConstants.NT_UNSTRUCTURED);
-            }
+        if (this.testRoot == null) {
+            this.testRoot = context.resourceResolver().getResource(context.uniqueRoot().content()).adaptTo(Node.class);
         }
         return testRoot;
     }
 
     @Test
     public void testGetResourcesAndValues() throws IOException, RepositoryException {
-        Resource resource1 = resourceResolver.getResource(getTestRootNode().getPath() + "/node1");
+        Resource resource1 = context.resourceResolver().getResource(getTestRootNode().getPath() + "/node1");
         assertNotNull(resource1);
         assertEquals("node1", resource1.getName());
 
@@ -160,9 +150,9 @@ public abstract class AbstractJcrResourceResolverTest {
 
     @Test
     public void testCreateNodeWithPrimaryType() throws RepositoryException, PersistenceException {
-        Resource parent = resourceResolver.getResource(getTestRootNode().getPath());
+        Resource parent = context.resourceResolver().getResource(getTestRootNode().getPath());
 
-        Resource child = resourceResolver.create(parent, "nodeTypeResource", ImmutableMap.<String, Object> builder()
+        Resource child = context.resourceResolver().create(parent, "nodeTypeResource", ImmutableMap.<String, Object> builder()
                 .put(SLING_RESOURCE_TYPE_PROPERTY, JcrConstants.NT_UNSTRUCTURED).build());
         assertNotNull(child);
         assertEquals(JcrConstants.NT_UNSTRUCTURED, child.getResourceType());
@@ -171,12 +161,12 @@ public abstract class AbstractJcrResourceResolverTest {
     
     @Test
     public void testCreateNodeWithResourceType() throws RepositoryException, PersistenceException {
-        Resource parent = resourceResolver.getResource(getTestRootNode().getPath());
+        Resource parent = context.resourceResolver().getResource(getTestRootNode().getPath());
 
-        Resource child = ResourceUtil.getOrCreateResource(resourceResolver, parent.getPath() + "/intermediate/child",
+        Resource child = ResourceUtil.getOrCreateResource(context.resourceResolver(), parent.getPath() + "/intermediate/child",
                 "sling/resource/type", JcrConstants.NT_UNSTRUCTURED, true);
         assertNotNull(child);
-        assertEquals(JcrConstants.NT_UNSTRUCTURED, parent.getResourceType());
+        assertEquals(NT_SLING_ORDERED_FOLDER, parent.getResourceType());
         assertEquals("sling/resource/type", child.getResourceType());
     }
 
@@ -188,11 +178,11 @@ public abstract class AbstractJcrResourceResolverTest {
             return;
         }
         
-        Resource testRootResource = resourceResolver.getResource(getTestRootNode().getPath());
-        resourceResolver.delete(testRootResource);
+        Resource testRootResource = context.resourceResolver().getResource(getTestRootNode().getPath());
+        context.resourceResolver().delete(testRootResource);
         assertTrue(session.hasPendingChanges());
         
-        resourceResolver.commit();
+        context.resourceResolver().commit();
         assertFalse(session.hasPendingChanges());
     }
 
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractSlingCrudResourceResolverTest.java b/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractSlingCrudResourceResolverTest.java
index 9880ef5..e9f4dbd 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractSlingCrudResourceResolverTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractSlingCrudResourceResolverTest.java
@@ -38,14 +38,13 @@ import org.apache.commons.lang3.StringUtils;
 import org.apache.jackrabbit.JcrConstants;
 import org.apache.sling.api.resource.PersistenceException;
 import org.apache.sling.api.resource.Resource;
-import org.apache.sling.api.resource.ResourceResolver;
 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.ResourceResolverType;
 import org.apache.sling.testing.mock.sling.builder.ContentBuilder;
-import org.junit.After;
+import org.apache.sling.testing.mock.sling.junit.SlingContext;
 import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
 
 import com.google.common.collect.ImmutableList;
@@ -57,6 +56,9 @@ import com.google.common.collect.Lists;
  * used to create the test data.
  */
 public abstract class AbstractSlingCrudResourceResolverTest {
+    
+    @Rule
+    public SlingContext context = new SlingContext(getResourceResolverType());
 
     private static final String STRING_VALUE = "value1";
     private static final String[] STRING_ARRAY_VALUE = new String[] { "value1", "value2" };
@@ -67,19 +69,11 @@ public abstract class AbstractSlingCrudResourceResolverTest {
     private static final Calendar CALENDAR_VALUE = Calendar.getInstance();
     private static final byte[] BINARY_VALUE = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };
 
-    protected ResourceResolver resourceResolver;
     protected Resource testRoot;
-    private static volatile long rootNodeCounter;
-
     protected abstract ResourceResolverType getResourceResolverType();
 
-    protected ResourceResolver newResourceResolver() {
-        return MockSling.newResourceResolver(getResourceResolverType());
-    }
-
     @Before
     public final void setUp() throws IOException {
-        this.resourceResolver = newResourceResolver();
 
         // prepare some test data using Sling CRUD API
         Resource rootNode = getTestRootResource();
@@ -94,20 +88,14 @@ public abstract class AbstractSlingCrudResourceResolverTest {
         props.put("dateProp", DATE_VALUE);
         props.put("calendarProp", CALENDAR_VALUE);
         props.put("binaryProp", new ByteArrayInputStream(BINARY_VALUE));
-        Resource node1 = this.resourceResolver.create(rootNode, "node1", props);
+        Resource node1 = context.resourceResolver().create(rootNode, "node1", props);
 
-        resourceResolver.create(node1, "node11", ImmutableMap.<String, Object>builder()
+        context.resourceResolver().create(node1, "node11", ImmutableMap.<String, Object>builder()
                 .put("stringProp11", STRING_VALUE)
                 .build());
-        this.resourceResolver.create(node1, "node12", ValueMap.EMPTY);
+        context.resourceResolver().create(node1, "node12", ValueMap.EMPTY);
 
-        this.resourceResolver.commit();
-    }
-
-    @After
-    public final void tearDown() {
-        this.testRoot = null;
-        this.resourceResolver.close();
+        context.resourceResolver().commit();
     }
 
     /**
@@ -116,23 +104,14 @@ public abstract class AbstractSlingCrudResourceResolverTest {
      */
     protected Resource getTestRootResource() throws PersistenceException {
         if (this.testRoot == null) {
-            Map<String, Object> props = new HashMap<String, Object>();
-            props.put(JcrConstants.JCR_PRIMARYTYPE, JcrConstants.NT_UNSTRUCTURED);
-            final Resource root = this.resourceResolver.getResource("/");
-            if (getResourceResolverType() == ResourceResolverType.JCR_MOCK
-                    || getResourceResolverType() == ResourceResolverType.RESOURCERESOLVER_MOCK) {
-                this.testRoot = this.resourceResolver.create(root, "test", props);
-            } else {
-                this.testRoot = this.resourceResolver.create(root, getClass().getSimpleName() + "_"
-                        + System.currentTimeMillis() + "_" + (rootNodeCounter++), props);
-            }
+            this.testRoot = context.resourceResolver().getResource(context.uniqueRoot().content());
         }
         return this.testRoot;
     }
 
     @Test
     public void testSimpleProperties() throws IOException {
-        Resource resource1 = this.resourceResolver.getResource(getTestRootResource().getPath() + "/node1");
+        Resource resource1 = context.resourceResolver().getResource(getTestRootResource().getPath() + "/node1");
         assertNotNull(resource1);
         assertEquals("node1", resource1.getName());
 
@@ -146,7 +125,7 @@ public abstract class AbstractSlingCrudResourceResolverTest {
 
     @Test
     public void testSimpleProperties_DeepPathAccess() throws IOException {
-        Resource resource1 = resourceResolver.getResource(testRoot.getPath());
+        Resource resource1 = context.resourceResolver().getResource(testRoot.getPath());
         assertNotNull(resource1);
         assertEquals(testRoot.getName(), resource1.getName());
 
@@ -161,7 +140,7 @@ public abstract class AbstractSlingCrudResourceResolverTest {
     
     @Test
     public void testDateProperty() throws IOException {
-        Resource resource1 = this.resourceResolver.getResource(getTestRootResource().getPath() + "/node1");
+        Resource resource1 = context.resourceResolver().getResource(getTestRootResource().getPath() + "/node1");
         ValueMap props = ResourceUtil.getValueMap(resource1);
         // TODO: enable this test when JCR resource implementation supports
         // writing Date objects (SLING-3846)
@@ -174,7 +153,7 @@ public abstract class AbstractSlingCrudResourceResolverTest {
 
     @Test
     public void testDatePropertyToCalendar() throws IOException {
-        Resource resource1 = this.resourceResolver.getResource(getTestRootResource().getPath() + "/node1");
+        Resource resource1 = context.resourceResolver().getResource(getTestRootResource().getPath() + "/node1");
         ValueMap props = ResourceUtil.getValueMap(resource1);
         // TODO: enable this test when JCR resource implementation supports
         // writing Date objects (SLING-3846)
@@ -189,14 +168,14 @@ public abstract class AbstractSlingCrudResourceResolverTest {
 
     @Test
     public void testCalendarProperty() throws IOException {
-        Resource resource1 = this.resourceResolver.getResource(getTestRootResource().getPath() + "/node1");
+        Resource resource1 = context.resourceResolver().getResource(getTestRootResource().getPath() + "/node1");
         ValueMap props = ResourceUtil.getValueMap(resource1);
         assertEquals(CALENDAR_VALUE.getTime(), props.get("calendarProp", Calendar.class).getTime());
     }
 
     @Test
     public void testCalendarPropertyToDate() throws IOException {
-        Resource resource1 = this.resourceResolver.getResource(getTestRootResource().getPath() + "/node1");
+        Resource resource1 = context.resourceResolver().getResource(getTestRootResource().getPath() + "/node1");
         ValueMap props = ResourceUtil.getValueMap(resource1);
         Date dateValue = props.get("calendarProp", Date.class);
         assertNotNull(dateValue);
@@ -205,7 +184,7 @@ public abstract class AbstractSlingCrudResourceResolverTest {
 
     @Test
     public void testListChildren() throws IOException {
-        Resource resource1 = this.resourceResolver.getResource(getTestRootResource().getPath() + "/node1");
+        Resource resource1 = context.resourceResolver().getResource(getTestRootResource().getPath() + "/node1");
 
         List<Resource> children = ImmutableList.copyOf(resource1.listChildren());
         assertEquals(2, children.size());
@@ -215,15 +194,15 @@ public abstract class AbstractSlingCrudResourceResolverTest {
 
     @Test
     public void testListChildren_RootNode() throws IOException {
-        Resource resource1 = resourceResolver.getResource("/");
+        Resource resource1 = context.resourceResolver().getResource("/");
 
         List<Resource> children = Lists.newArrayList(resource1.listChildren());
         assertFalse(children.isEmpty());
-        assertTrue(containsResource(children, getTestRootResource()));
+        assertTrue(containsResource(children, getTestRootResource().getParent()));
 
         children = Lists.newArrayList(resource1.getChildren());
         assertFalse(children.isEmpty());
-        assertTrue(containsResource(children, getTestRootResource()));
+        assertTrue(containsResource(children, getTestRootResource().getParent()));
     }
     
     private boolean containsResource(List<Resource> children, Resource resource) {
@@ -237,7 +216,7 @@ public abstract class AbstractSlingCrudResourceResolverTest {
 
     @Test
     public void testBinaryData() throws IOException {
-        Resource resource1 = this.resourceResolver.getResource(getTestRootResource().getPath() + "/node1");
+        Resource resource1 = context.resourceResolver().getResource(getTestRootResource().getPath() + "/node1");
 
         Resource binaryPropResource = resource1.getChild("binaryProp");
         InputStream is = binaryPropResource.adaptTo(InputStream.class);
@@ -255,29 +234,29 @@ public abstract class AbstractSlingCrudResourceResolverTest {
 
     @Test
     public void testPrimaryTypeResourceType() throws PersistenceException {
-        Resource resource = this.resourceResolver.getResource(getTestRootResource().getPath());
+        Resource resource = context.resourceResolver().getResource(getTestRootResource().getPath() + "/node1");
         assertEquals(JcrConstants.NT_UNSTRUCTURED, resource.getResourceType());
     }
 
     @Test
     public void testGetRootResourceByNullPath() {
-        Resource rootResource = this.resourceResolver.resolve((String)null);
+        Resource rootResource = context.resourceResolver().resolve((String)null);
         assertNotNull(rootResource);
         assertEquals("/", rootResource.getPath());
     }
 
     @Test
     public void testSearchPath() {
-        ContentBuilder builder = new ContentBuilder(this.resourceResolver);
+        ContentBuilder builder = new ContentBuilder(context.resourceResolver());
         builder.resource("/libs/any/path");
 
-        Resource resource = this.resourceResolver.getResource("any/path");
+        Resource resource = context.resourceResolver().getResource("any/path");
         assertNotNull(resource);
         assertEquals("/libs/any/path", resource.getPath());
 
         builder.resource("/apps/any/path");
 
-        resource = this.resourceResolver.getResource("any/path");
+        resource = context.resourceResolver().getResource("any/path");
         assertNotNull(resource);
         assertEquals("/apps/any/path", resource.getPath());
     }
@@ -290,11 +269,11 @@ public abstract class AbstractSlingCrudResourceResolverTest {
             return;
         }
         
-        resourceResolver.delete(getTestRootResource());
-        assertTrue(resourceResolver.hasChanges());
+        context.resourceResolver().delete(getTestRootResource());
+        assertTrue(context.resourceResolver().hasChanges());
         
-        resourceResolver.commit();
-        assertFalse(resourceResolver.hasChanges());
+        context.resourceResolver().commit();
+        assertFalse(context.resourceResolver().hasChanges());
     }
 
 }

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