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

[sling-org-apache-sling-jcr-contentloader] branch master updated: SLING-9733 Refactor o.a.s.jcr.contentloader tests to make them work with java 11

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

enorman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-contentloader.git


The following commit(s) were added to refs/heads/master by this push:
     new 3f30ff3  SLING-9733 Refactor o.a.s.jcr.contentloader tests to make them work with java 11
3f30ff3 is described below

commit 3f30ff3a3b9bb8db4ee35cf7c1123367eb064e30
Author: Eric Norman <en...@apache.org>
AuthorDate: Tue Sep 15 21:00:58 2020 -0700

    SLING-9733 Refactor o.a.s.jcr.contentloader tests to make them work with
    java 11
---
 pom.xml                                            |  6 ---
 .../internal/BundleContentLoaderTest.java          |  6 ---
 .../internal/ContentLoaderServiceTest.java         | 37 ++++++++++------
 .../jcr/contentloader/internal/CreateNodeTest.java | 27 +++++-------
 .../internal/DefaultContentCreatorTest.java        | 51 +++++++++++++---------
 .../internal/readers/XmlReaderTest.java            |  1 -
 6 files changed, 66 insertions(+), 62 deletions(-)

diff --git a/pom.xml b/pom.xml
index b7bb20c..fb3aa58 100644
--- a/pom.xml
+++ b/pom.xml
@@ -173,12 +173,6 @@
         </dependency>
         <dependency>
             <groupId>org.apache.sling</groupId>
-            <artifactId>org.apache.sling.commons.testing</artifactId>
-            <version>2.1.2</version>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.commons.osgi</artifactId>
             <version>2.3.0</version>
             <scope>provided</scope>
diff --git a/src/test/java/org/apache/sling/jcr/contentloader/internal/BundleContentLoaderTest.java b/src/test/java/org/apache/sling/jcr/contentloader/internal/BundleContentLoaderTest.java
index e9b1404..a985701 100644
--- a/src/test/java/org/apache/sling/jcr/contentloader/internal/BundleContentLoaderTest.java
+++ b/src/test/java/org/apache/sling/jcr/contentloader/internal/BundleContentLoaderTest.java
@@ -26,7 +26,6 @@ import static org.junit.Assert.assertThat;
 import javax.jcr.Session;
 
 import org.apache.sling.api.resource.Resource;
-import org.apache.sling.commons.testing.jcr.RepositoryUtil;
 import org.apache.sling.jcr.contentloader.internal.readers.JsonReader;
 import org.apache.sling.jcr.contentloader.internal.readers.XmlReader;
 import org.apache.sling.jcr.contentloader.internal.readers.ZipReader;
@@ -56,11 +55,6 @@ public class BundleContentLoaderTest {
         // whiteboard which holds readers
         context.registerInjectActivateService(new ContentReaderWhiteboard());
 
-        // TODO - SlingRepository should be registered out of the box, not after calling context.resourceResolver()
-        // TODO - sling node types should _always_ be registered
-        Session session = context.resourceResolver().adaptTo(Session.class);
-        RepositoryUtil.registerSlingNodeTypes(session);
-
         // register the content loader service
         BundleHelper bundleHelper = context.registerInjectActivateService(new ContentLoaderService());
 
diff --git a/src/test/java/org/apache/sling/jcr/contentloader/internal/ContentLoaderServiceTest.java b/src/test/java/org/apache/sling/jcr/contentloader/internal/ContentLoaderServiceTest.java
index 031724a..2db48d5 100644
--- a/src/test/java/org/apache/sling/jcr/contentloader/internal/ContentLoaderServiceTest.java
+++ b/src/test/java/org/apache/sling/jcr/contentloader/internal/ContentLoaderServiceTest.java
@@ -18,8 +18,29 @@
  */
 package org.apache.sling.jcr.contentloader.internal;
 
-import junitx.util.PrivateAccessor;
-import org.apache.sling.commons.testing.jcr.RepositoryUtil;
+import static org.apache.sling.jcr.contentloader.internal.ContentLoaderService.BUNDLE_CONTENT_NODE;
+import static org.apache.sling.jcr.contentloader.internal.ContentLoaderService.PROPERTY_CONTENT_LOADED;
+import static org.apache.sling.jcr.contentloader.internal.ContentLoaderService.PROPERTY_CONTENT_LOADED_AT;
+import static org.apache.sling.jcr.contentloader.internal.ContentLoaderService.PROPERTY_UNINSTALL_PATHS;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Calendar;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.lock.LockManager;
+
 import org.apache.sling.testing.mock.osgi.MockBundle;
 import org.apache.sling.testing.mock.sling.ResourceResolverType;
 import org.apache.sling.testing.mock.sling.junit.SlingContext;
@@ -30,14 +51,7 @@ import org.junit.rules.ExpectedException;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleEvent;
 
-import javax.jcr.*;
-import javax.jcr.lock.LockManager;
-
-import java.util.*;
-
-import static org.junit.Assert.*;
-import static org.hamcrest.CoreMatchers.*;
-import static org.apache.sling.jcr.contentloader.internal.ContentLoaderService.*;
+import junitx.util.PrivateAccessor;
 
 public class ContentLoaderServiceTest {
 
@@ -56,10 +70,7 @@ public class ContentLoaderServiceTest {
         // whiteboard which holds readers
         context.registerInjectActivateService(new ContentReaderWhiteboard());
 
-        // TODO - SlingRepository should be registered out of the box, not after calling context.resourceResolver()
-        // TODO - sling node types should _always_ be registered
         session = context.resourceResolver().adaptTo(Session.class);
-        RepositoryUtil.registerSlingNodeTypes(session);
 
         // register the content loader service
         underTest = context.registerInjectActivateService(new ContentLoaderService());
diff --git a/src/test/java/org/apache/sling/jcr/contentloader/internal/CreateNodeTest.java b/src/test/java/org/apache/sling/jcr/contentloader/internal/CreateNodeTest.java
index 7bfd966..b54273b 100644
--- a/src/test/java/org/apache/sling/jcr/contentloader/internal/CreateNodeTest.java
+++ b/src/test/java/org/apache/sling/jcr/contentloader/internal/CreateNodeTest.java
@@ -16,22 +16,24 @@
  */
 package org.apache.sling.jcr.contentloader.internal;
 
+import static org.apache.sling.jcr.contentloader.internal.ImportOptionsFactory.AUTO_CHECKOUT;
+import static org.apache.sling.jcr.contentloader.internal.ImportOptionsFactory.OVERWRITE_NODE;
+import static org.apache.sling.jcr.contentloader.internal.ImportOptionsFactory.OVERWRITE_PROPERTIES;
+import static org.apache.sling.jcr.contentloader.internal.ImportOptionsFactory.createImportOptions;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
-import static org.apache.sling.jcr.contentloader.internal.ImportOptionsFactory.*;
 
 import java.util.HashMap;
 import java.util.UUID;
 
 import javax.jcr.Node;
-import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 
-import org.apache.sling.commons.testing.jcr.RepositoryProvider;
-import org.apache.sling.jcr.api.SlingRepository;
 import org.apache.sling.jcr.contentloader.ContentReader;
-import org.junit.After;
+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;
 
 /** TODO might need to consolidate this with DefaultContentCreatorTest */
@@ -43,29 +45,22 @@ public class CreateNodeTest {
     private final static String DEFAULT_NAME = "default-name";
     public static final String MIX_VERSIONABLE = "mix:versionable";  
     
+    @Rule
+    public final SlingContext context = new SlingContext(ResourceResolverType.JCR_OAK);
+
     private final String uniqueId() {
         return getClass().getSimpleName() + UUID.randomUUID();
     }
     
     @Before
     public void setup() throws Exception {
-        final SlingRepository repo = RepositoryProvider.instance().getRepository();
-        session = repo.loginAdministrative(null);
+    	session = context.resourceResolver().adaptTo(Session.class);
         contentCreator = new DefaultContentCreator(null);
         contentCreator.init(createImportOptions(OVERWRITE_NODE | OVERWRITE_PROPERTIES | AUTO_CHECKOUT),
                 new HashMap<String, ContentReader>(), null, null);
         testRoot = session.getRootNode().addNode(getClass().getSimpleName()).addNode(uniqueId());
     }
     
-    @After
-    public void cleanup() throws RepositoryException {
-        if(session != null) {
-            session.save(); // to detect any invalid transient content
-            session.logout();
-            session = null;
-        }
-    }
-    
     @Test
     public void testCreateNode() throws Exception {
         contentCreator.prepareParsing(testRoot, DEFAULT_NAME);
diff --git a/src/test/java/org/apache/sling/jcr/contentloader/internal/DefaultContentCreatorTest.java b/src/test/java/org/apache/sling/jcr/contentloader/internal/DefaultContentCreatorTest.java
index 06d4ca0..bd97172 100644
--- a/src/test/java/org/apache/sling/jcr/contentloader/internal/DefaultContentCreatorTest.java
+++ b/src/test/java/org/apache/sling/jcr/contentloader/internal/DefaultContentCreatorTest.java
@@ -16,28 +16,46 @@
  */
 package org.apache.sling.jcr.contentloader.internal;
 
-import java.text.ParseException;
-import java.util.*;
+import static org.apache.sling.jcr.contentloader.internal.ImportOptionsFactory.AUTO_CHECKOUT;
+import static org.apache.sling.jcr.contentloader.internal.ImportOptionsFactory.CHECK_IN;
+import static org.apache.sling.jcr.contentloader.internal.ImportOptionsFactory.NO_OPTIONS;
+import static org.apache.sling.jcr.contentloader.internal.ImportOptionsFactory.OVERWRITE_NODE;
+import static org.apache.sling.jcr.contentloader.internal.ImportOptionsFactory.OVERWRITE_PROPERTIES;
+import static org.apache.sling.jcr.contentloader.internal.ImportOptionsFactory.createImportOptions;
+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 javax.jcr.*;
+import java.text.ParseException;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Deque;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
 import javax.jcr.nodetype.NodeType;
 
-import junitx.util.PrivateAccessor;
-import org.apache.sling.commons.testing.jcr.RepositoryProvider;
-import org.apache.sling.jcr.api.SlingRepository;
 import org.apache.sling.jcr.contentloader.ContentImportListener;
 import org.apache.sling.jcr.contentloader.ContentReader;
+import org.apache.sling.testing.mock.sling.ResourceResolverType;
+import org.apache.sling.testing.mock.sling.junit.SlingContext;
 import org.jmock.Expectations;
 import org.jmock.Mockery;
 import org.jmock.integration.junit4.JUnit4Mockery;
-import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 
-import static org.junit.Assert.*;
-import static org.apache.sling.jcr.contentloader.internal.ImportOptionsFactory.*;
+import junitx.util.PrivateAccessor;
 
 public class DefaultContentCreatorTest {
 
@@ -50,27 +68,20 @@ public class DefaultContentCreatorTest {
     Property prop;
 
     @Rule
+    public final SlingContext context = new SlingContext(ResourceResolverType.JCR_OAK);
+
+    @Rule
     public ExpectedException thrown = ExpectedException.none();
 
     @Before
     public void setup() throws Exception {
-        final SlingRepository repo = RepositoryProvider.instance().getRepository();
-        session = repo.loginAdministrative(null);
+    	session = context.resourceResolver().adaptTo(Session.class);
         contentCreator = new DefaultContentCreator(null);
         contentCreator.init(createImportOptions(OVERWRITE_NODE|OVERWRITE_PROPERTIES|AUTO_CHECKOUT),
                 new HashMap<String, ContentReader>(), null, null);
         parentNode = session.getRootNode().addNode(getClass().getSimpleName()).addNode(uniqueId());
     }
 
-    @After
-    public void cleanup() throws RepositoryException {
-        if(session != null) {
-            session.save();
-            session.logout();
-            session = null;
-        }
-    }
-
     @Test
     public void willRewriteUndefinedPropertyType() throws RepositoryException {
         parentNode = mockery.mock(Node.class);
diff --git a/src/test/java/org/apache/sling/jcr/contentloader/internal/readers/XmlReaderTest.java b/src/test/java/org/apache/sling/jcr/contentloader/internal/readers/XmlReaderTest.java
index bdc76c1..304105b 100644
--- a/src/test/java/org/apache/sling/jcr/contentloader/internal/readers/XmlReaderTest.java
+++ b/src/test/java/org/apache/sling/jcr/contentloader/internal/readers/XmlReaderTest.java
@@ -191,7 +191,6 @@ public class XmlReaderTest extends TestCase {
 
         @Override
         public void finish() throws RepositoryException {
-            // TODO Auto-generated method stub
             
         }