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

[sling-org-apache-sling-jcr-resource] 01/01: SLING-9901 - switch to Sling Mocks to run tests on an Oak repository

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

bdelacretaz pushed a commit to branch improvement/SLING-9901
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-resource.git

commit 5936f3f00d874112cb5e79a2455cdfbb69dcd016
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Mon Nov 16 11:03:25 2020 +0100

    SLING-9901 - switch to Sling Mocks to run tests on an Oak repository
---
 pom.xml                                            | 19 ++++-
 .../internal/JcrSystemUserValidatorTest.java       | 91 ++++------------------
 2 files changed, 32 insertions(+), 78 deletions(-)

diff --git a/pom.xml b/pom.xml
index 94a24b1..aa47b79 100644
--- a/pom.xml
+++ b/pom.xml
@@ -182,7 +182,7 @@
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.scripting.api</artifactId>
-            <version>2.1.0</version>
+            <version>2.2.0</version>
             <scope>provided</scope>
         </dependency>
         <dependency>
@@ -238,6 +238,23 @@
             <scope>test</scope>
         </dependency>
         <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.testing.sling-mock</artifactId>
+            <version>2.6.2</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.testing.sling-mock-oak</artifactId>
+            <version>2.1.10-1.16.0</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>osgi.cmpn</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
             <groupId>junit-addons</groupId>
             <artifactId>junit-addons</artifactId>
             <version>1.4</version>
diff --git a/src/test/java/org/apache/sling/jcr/resource/internal/JcrSystemUserValidatorTest.java b/src/test/java/org/apache/sling/jcr/resource/internal/JcrSystemUserValidatorTest.java
index ae36024..9e3186e 100644
--- a/src/test/java/org/apache/sling/jcr/resource/internal/JcrSystemUserValidatorTest.java
+++ b/src/test/java/org/apache/sling/jcr/resource/internal/JcrSystemUserValidatorTest.java
@@ -16,102 +16,39 @@
  */
 package org.apache.sling.jcr.resource.internal;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
 import java.lang.reflect.Field;
 import java.util.Collections;
 
-import javax.jcr.Credentials;
-import javax.jcr.LoginException;
-import javax.jcr.NoSuchWorkspaceException;
 import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-import javax.jcr.Value;
 import javax.naming.NamingException;
 
-import org.apache.sling.commons.testing.jcr.RepositoryTestBase;
 import org.apache.sling.jcr.api.SlingRepository;
+import org.apache.sling.testing.mock.sling.ResourceResolverType;
+import org.apache.sling.testing.mock.sling.junit.SlingContext;
 import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
 
-
-public class JcrSystemUserValidatorTest extends RepositoryTestBase {
+public class JcrSystemUserValidatorTest {
     
     private static final String GROUP_ADMINISTRATORS = "administrators";
-
     private JcrSystemUserValidator jcrSystemUserValidator;
+
+    @Rule
+    public final SlingContext context = new SlingContext(ResourceResolverType.JCR_OAK);
     
     @Before
     public void setUp() throws IllegalArgumentException, IllegalAccessException, RepositoryException, NamingException, NoSuchFieldException, SecurityException {
         jcrSystemUserValidator = new JcrSystemUserValidator();
-        Field repositoryField = jcrSystemUserValidator.getClass().getDeclaredField("repository");
+        final Field repositoryField = jcrSystemUserValidator.getClass().getDeclaredField("repository");
         repositoryField.setAccessible(true);
-        final SlingRepository delegate = getRepository();
-
-        SlingRepository repository = new SlingRepository() {
-            @Override
-            public String getDefaultWorkspace() {
-                return delegate.getDefaultWorkspace();
-            }
-
-            @Override
-            public Session loginAdministrative(String s) throws LoginException, RepositoryException {
-                return delegate.loginAdministrative(s);
-            }
-
-            @Override
-            public Session loginService(String s, String s1) throws LoginException, RepositoryException {
-                return delegate.loginAdministrative(s1);
-            }
-
-            @Override
-            public String[] getDescriptorKeys() {
-                return delegate.getDescriptorKeys();
-            }
-
-            @Override
-            public boolean isStandardDescriptor(String s) {
-                return delegate.isStandardDescriptor(s);
-            }
-
-            @Override
-            public boolean isSingleValueDescriptor(String s) {
-                return delegate.isSingleValueDescriptor(s);
-            }
-
-            @Override
-            public Value getDescriptorValue(String s) {
-                return delegate.getDescriptorValue(s);
-            }
-
-            @Override
-            public Value[] getDescriptorValues(String s) {
-                return delegate.getDescriptorValues(s);
-            }
-
-            @Override
-            public String getDescriptor(String s) {
-                return delegate.getDescriptor(s);
-            }
-
-            @Override
-            public Session login(Credentials credentials, String s) throws LoginException, NoSuchWorkspaceException, RepositoryException {
-                return delegate.login(credentials, s);
-            }
-
-            @Override
-            public Session login(Credentials credentials) throws LoginException, RepositoryException {
-                return delegate.login(credentials);
-            }
-
-            @Override
-            public Session login(String s) throws LoginException, NoSuchWorkspaceException, RepositoryException {
-                return delegate.login(s);
-            }
 
-            @Override
-            public Session login() throws LoginException, RepositoryException {
-                return delegate.login();
-            }
-        };
+        final SlingRepository repository = context.getService(SlingRepository.class);
+        assertEquals("Apache Jackrabbit Oak", repository.getDescriptor("jcr.repository.name"));
         repositoryField.set(jcrSystemUserValidator, repository);
     }