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 2021/03/15 16:58:04 UTC

[sling-org-apache-sling-junit-core] branch master updated (9744c2d -> 2811d3b)

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

bdelacretaz pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-junit-core.git.


    from 9744c2d  SLING-9935 - NoClassDefFoundError org/junit/platform/engine/TestEngine
     new 729ac85  SLING-9980 - refactor for clarity
     new 2811d3b  SLING-9980 - fix integration tests for Java 11

The 2 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.


Summary of changes:
 src/it/annotations-it/pom.xml                      |  19 +++-
 .../junit/annotations/AnnotationsTestSupport.java  | 103 ++++++++++++++++++
 .../sling/junit/annotations/ReferenceIT.java       | 119 +++------------------
 3 files changed, 133 insertions(+), 108 deletions(-)
 create mode 100644 src/it/annotations-it/src/test/java/org/apache/sling/junit/annotations/AnnotationsTestSupport.java


[sling-org-apache-sling-junit-core] 02/02: SLING-9980 - fix integration tests for Java 11

Posted by bd...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

bdelacretaz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-junit-core.git

commit 2811d3b8f086a309ff9e79562db26cec53932bb5
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Mon Mar 15 17:55:57 2021 +0100

    SLING-9980 - fix integration tests for Java 11
---
 src/it/annotations-it/pom.xml                      |  19 +++-
 .../junit/annotations/AnnotationsTestSupport.java  | 111 ++++++++-------------
 .../sling/junit/annotations/ReferenceIT.java       |  17 +++-
 3 files changed, 72 insertions(+), 75 deletions(-)

diff --git a/src/it/annotations-it/pom.xml b/src/it/annotations-it/pom.xml
index 4e08087..c7f194e 100644
--- a/src/it/annotations-it/pom.xml
+++ b/src/it/annotations-it/pom.xml
@@ -61,10 +61,13 @@
           </execution>
         </executions>
         <configuration>
+          <redirectTestOutputToFile>true</redirectTestOutputToFile>
           <systemPropertyVariables>
             <bundle.filename>${bundle.filename}</bundle.filename>
             <pax.vm.options>${pax.vm.options}</pax.vm.options>
           </systemPropertyVariables>
+          <!-- pax exam bug, often times out at exit -->
+          <forkedProcessExitTimeoutInSeconds>1</forkedProcessExitTimeoutInSeconds>
         </configuration>
       </plugin>
       <plugin>
@@ -148,10 +151,22 @@
       <version>6.0.3</version>
       <scope>test</scope>
     </dependency>
+     <dependency>
+        <groupId>org.ops4j.pax.logging</groupId>
+        <artifactId>pax-logging-api</artifactId>
+        <version>2.0.6</version>
+        <scope>test</scope>
+    </dependency>
+    <dependency>
+        <groupId>org.ops4j.pax.logging</groupId>
+        <artifactId>pax-logging-logback</artifactId>
+        <version>2.0.6</version>
+        <scope>test</scope>
+    </dependency>
     <dependency>
       <groupId>org.apache.sling</groupId>
       <artifactId>org.apache.sling.testing.paxexam</artifactId>
-      <version>3.1.0</version>
+       <version>4.0.0-SNAPSHOT</version>
       <scope>test</scope>
     </dependency>
     <dependency>
@@ -191,4 +206,4 @@
       <scope>test</scope>
     </dependency>
   </dependencies>
-</project>
\ No newline at end of file
+</project>
diff --git a/src/it/annotations-it/src/test/java/org/apache/sling/junit/annotations/AnnotationsTestSupport.java b/src/it/annotations-it/src/test/java/org/apache/sling/junit/annotations/AnnotationsTestSupport.java
index 74c813b..e762f35 100644
--- a/src/it/annotations-it/src/test/java/org/apache/sling/junit/annotations/AnnotationsTestSupport.java
+++ b/src/it/annotations-it/src/test/java/org/apache/sling/junit/annotations/AnnotationsTestSupport.java
@@ -17,48 +17,41 @@
 package org.apache.sling.junit.annotations;
 
 import org.apache.commons.lang3.StringUtils;
-import org.apache.sling.junit.it.impl.MyLameServiceForTestingIT;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
 import org.apache.sling.testing.clients.osgi.OsgiConsoleClient;
-
-import java.net.ServerSocket;
-import java.net.URI;
-
+import org.apache.sling.testing.paxexam.TestSupport;
+import org.junit.Before;
+import org.junit.ClassRule;
 import org.ops4j.pax.exam.Configuration;
 import org.ops4j.pax.exam.Option;
 import org.ops4j.pax.exam.junit.PaxExamServer;
 import org.ops4j.pax.exam.options.extra.VMOption;
-import org.apache.sling.testing.paxexam.SlingOptions;
-import static org.apache.sling.testing.paxexam.SlingOptions.logback;
+
+import org.apache.sling.junit.it.impl.MyCoolServiceForTestingIT;
+import org.apache.sling.junit.it.impl.MyLameServiceForTestingIT;
 import static org.apache.sling.testing.paxexam.SlingOptions.slingQuickstartOakTar;
-import static org.ops4j.pax.exam.CoreOptions.composite;
+import static org.apache.sling.testing.paxexam.SlingOptions.versionResolver;
+import static org.apache.sling.testing.paxexam.SlingOptions.logback;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.CoreOptions.when;
 import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+import static org.ops4j.pax.exam.CoreOptions.wrappedBundle;
 import static org.ops4j.pax.exam.CoreOptions.systemProperty;
-import static org.ops4j.pax.exam.CoreOptions.when;
-import org.apache.sling.testing.paxexam.TestSupport;
 
+import java.net.URI;
 
 public class AnnotationsTestSupport extends TestSupport {
-    protected static int httpPort;
-    protected static OsgiConsoleClient CLIENT;
+
     private final static int STARTUP_WAIT_SECONDS = 60;
 
+    protected OsgiConsoleClient CLIENT;
+    protected static int httpPort;
+
     @ClassRule
-    public static PaxExamServer serverRule = new PaxExamServer() {
-        @Override
-        protected void before() throws Exception {
-            // Use a different port for each OSGi framework instance
-            // that's started - they can overlap if the previous one
-            // is not fully stopped when the next one starts.
-            setHttpPort();
-            super.before();
-        }
-    };
+    public static PaxExamServer serverRule = new PaxExamServer();
 
     @Configuration
     public Option[] configuration() throws Exception {
-
+        httpPort = findFreePort();
         final String vmOpt = System.getProperty("pax.vm.options");
         VMOption vmOption = null;
         if (StringUtils.isNotEmpty(vmOpt)) {
@@ -71,58 +64,40 @@ public class AnnotationsTestSupport extends TestSupport {
             jacocoCommand = new VMOption(jacocoOpt);
         }
 
-        final String workingDirectory = workingDirectory();
+        return options(
+            when(vmOption != null).useOptions(vmOption),
+            when(jacocoCommand != null).useOptions(jacocoCommand),
 
-        // Need recent commons.johnzon for the osgi.contract=JavaJSONP capability
-        SlingOptions.versionResolver.setVersion("org.apache.sling", "org.apache.sling.commons.johnzon", "1.2.6");
+            // For some reason, Jetty starts first on port 8080 without this
+            systemProperty("org.osgi.service.http.port").value(String.valueOf(httpPort)),
 
-        return composite(
-                // TODO not sure why the below list of bundles is different from
-                // running tests with PaxExam.class (SLING-9929)
-                //super.baseConfiguration(),
+            serverBaseConfiguration(),
+            slingQuickstartOakTar(workingDirectory(), httpPort),
 
-                when(vmOption != null).useOptions(vmOption),
-                when(jacocoCommand != null).useOptions(jacocoCommand),
+            testBundle("bundle.filename"),
+            mavenBundle().groupId("org.apache.sling").artifactId("org.apache.sling.junit.core").versionAsInProject(),
+            mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.webconsole.plugins.ds").version(versionResolver),
 
-                // For some reason, Jetty starts first on port 8080 without this
-                systemProperty("org.osgi.service.http.port").value(String.valueOf(httpPort)),
-
-                slingQuickstartOakTar(workingDirectory, httpPort),
-
-                testBundle("bundle.filename"),
-                mavenBundle().groupId("org.apache.sling").artifactId("org.apache.sling.junit.core").versionAsInProject(),
-
-                logback(),
-                mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.log").version("1.2.4"),
-                mavenBundle().groupId("log4j").artifactId("log4j").version("1.2.17"),
-                mavenBundle().groupId("org.apache.aries.spifly").artifactId("org.apache.aries.spifly.dynamic.framework.extension").version("1.3.2"),
-                mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.webconsole.plugins.ds").version("2.1.0")
-        ).getOptions();
+            // logging
+            mavenBundle().groupId("ch.qos.logback").artifactId("logback-classic").versionAsInProject(),
+            mavenBundle().groupId("ch.qos.logback").artifactId("logback-core").versionAsInProject(),
+            mavenBundle().groupId("org.ops4j.pax.logging").artifactId("pax-logging-api").versionAsInProject(),
+            mavenBundle().groupId("org.ops4j.pax.logging").artifactId("pax-logging-logback").versionAsInProject()
+        );
     }
 
-    @BeforeClass
-    public static void waitForSling() throws Exception {
+    @Before
+    public void waitForSling() throws Exception {
         final URI url = new URI(String.format("http://localhost:%d", httpPort));
         CLIENT = new OsgiConsoleClient(url, "admin", "admin");
-        
         CLIENT.waitExists("/", STARTUP_WAIT_SECONDS * 1000, 500);
 
-        CLIENT.waitComponentRegistered(MyLameServiceForTestingIT.class.getName(), 10 * 1000, 500);
-
-        // Verify stable status for a bit
-        for(int i=0; i < 10 ; i++) {
-            CLIENT.waitComponentRegistered(MyLameServiceForTestingIT.class.getName(), 1000, 100);
-            Thread.sleep(100);
-        }
-    }
-
-    static void setHttpPort() {
-        try {
-            final ServerSocket serverSocket = new ServerSocket(0);
-            httpPort = serverSocket.getLocalPort();
-            serverSocket.close();
-        } catch (Exception e) {
-            throw new RuntimeException(e);
+        final String [] waitFor = {
+            MyCoolServiceForTestingIT.class.getName(),
+            MyLameServiceForTestingIT.class.getName()
+        };
+        for(String clazz : waitFor) {
+            CLIENT.waitComponentRegistered(clazz, 10 * 1000, 500);
         }
     }
-}
+}
\ No newline at end of file
diff --git a/src/it/annotations-it/src/test/java/org/apache/sling/junit/annotations/ReferenceIT.java b/src/it/annotations-it/src/test/java/org/apache/sling/junit/annotations/ReferenceIT.java
index 338aaeb..bc23215 100644
--- a/src/it/annotations-it/src/test/java/org/apache/sling/junit/annotations/ReferenceIT.java
+++ b/src/it/annotations-it/src/test/java/org/apache/sling/junit/annotations/ReferenceIT.java
@@ -34,13 +34,20 @@ import static org.ops4j.pax.exam.CoreOptions.when;
 public class ReferenceIT extends AnnotationsTestSupport {
     @Test
     public void testReferenceJITest() throws ClientException, UnsupportedEncodingException {
-        SlingHttpResponse response = CLIENT.doPost("/system/sling/junit/org.apache.sling.junit.it.TestReferenceJITest.html",
+        final SlingHttpResponse response = CLIENT.doPost("/system/sling/junit/org.apache.sling.junit.it.TestReferenceJITest.html",
                 new StringEntity("some text"),
                 Collections.emptyList(),
                 200);
-        response.checkContentContains("TEST RUN FINISHED");
-        response.checkContentContains("failures:0");
-        response.checkContentContains("ignored:0");
-        response.checkContentContains("tests:4");
+        final String [] toCheck = {
+            "TEST RUN FINISHED",
+            "failures:0",
+            "ignored:0",
+            "tests:4",
+            "testTargetReferences",
+            "testOsgiReferences",
+        };
+        for(String check : toCheck) {
+            response.checkContentContains(check);
+        }
     }
 }


[sling-org-apache-sling-junit-core] 01/02: SLING-9980 - refactor for clarity

Posted by bd...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

bdelacretaz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-junit-core.git

commit 729ac859396b3668b07f81e4d876a2063c8bb095
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Mon Mar 15 16:54:35 2021 +0100

    SLING-9980 - refactor for clarity
---
 ...eferenceIT.java => AnnotationsTestSupport.java} |  22 +----
 .../sling/junit/annotations/ReferenceIT.java       | 102 +--------------------
 2 files changed, 3 insertions(+), 121 deletions(-)

diff --git a/src/it/annotations-it/src/test/java/org/apache/sling/junit/annotations/ReferenceIT.java b/src/it/annotations-it/src/test/java/org/apache/sling/junit/annotations/AnnotationsTestSupport.java
similarity index 85%
copy from src/it/annotations-it/src/test/java/org/apache/sling/junit/annotations/ReferenceIT.java
copy to src/it/annotations-it/src/test/java/org/apache/sling/junit/annotations/AnnotationsTestSupport.java
index d9389f7..74c813b 100644
--- a/src/it/annotations-it/src/test/java/org/apache/sling/junit/annotations/ReferenceIT.java
+++ b/src/it/annotations-it/src/test/java/org/apache/sling/junit/annotations/AnnotationsTestSupport.java
@@ -17,19 +17,13 @@
 package org.apache.sling.junit.annotations;
 
 import org.apache.commons.lang3.StringUtils;
-import org.apache.http.entity.StringEntity;
 import org.apache.sling.junit.it.impl.MyLameServiceForTestingIT;
-import org.apache.sling.testing.clients.ClientException;
-import org.apache.sling.testing.clients.SlingHttpResponse;
 import org.junit.BeforeClass;
 import org.junit.ClassRule;
-import org.junit.Test;
 import org.apache.sling.testing.clients.osgi.OsgiConsoleClient;
 
-import java.io.UnsupportedEncodingException;
 import java.net.ServerSocket;
 import java.net.URI;
-import java.util.Collections;
 
 import org.ops4j.pax.exam.Configuration;
 import org.ops4j.pax.exam.Option;
@@ -45,10 +39,10 @@ import static org.ops4j.pax.exam.CoreOptions.when;
 import org.apache.sling.testing.paxexam.TestSupport;
 
 
-public class ReferenceIT extends TestSupport {
+public class AnnotationsTestSupport extends TestSupport {
     protected static int httpPort;
     protected static OsgiConsoleClient CLIENT;
-    private final static int STARTUP_WAIT_SECONDS = 30;
+    private final static int STARTUP_WAIT_SECONDS = 60;
 
     @ClassRule
     public static PaxExamServer serverRule = new PaxExamServer() {
@@ -131,16 +125,4 @@ public class ReferenceIT extends TestSupport {
             throw new RuntimeException(e);
         }
     }
-
-    @Test
-    public void testReferenceJITest() throws ClientException, UnsupportedEncodingException {
-        SlingHttpResponse response = CLIENT.doPost("/system/sling/junit/org.apache.sling.junit.it.TestReferenceJITest.html",
-                new StringEntity("some text"),
-                Collections.emptyList(),
-                200);
-        response.checkContentContains("TEST RUN FINISHED");
-        response.checkContentContains("failures:0");
-        response.checkContentContains("ignored:0");
-        response.checkContentContains("tests:4");
-    }
 }
diff --git a/src/it/annotations-it/src/test/java/org/apache/sling/junit/annotations/ReferenceIT.java b/src/it/annotations-it/src/test/java/org/apache/sling/junit/annotations/ReferenceIT.java
index d9389f7..338aaeb 100644
--- a/src/it/annotations-it/src/test/java/org/apache/sling/junit/annotations/ReferenceIT.java
+++ b/src/it/annotations-it/src/test/java/org/apache/sling/junit/annotations/ReferenceIT.java
@@ -16,122 +16,22 @@
  */
 package org.apache.sling.junit.annotations;
 
-import org.apache.commons.lang3.StringUtils;
 import org.apache.http.entity.StringEntity;
-import org.apache.sling.junit.it.impl.MyLameServiceForTestingIT;
 import org.apache.sling.testing.clients.ClientException;
 import org.apache.sling.testing.clients.SlingHttpResponse;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
 import org.junit.Test;
-import org.apache.sling.testing.clients.osgi.OsgiConsoleClient;
-
 import java.io.UnsupportedEncodingException;
-import java.net.ServerSocket;
-import java.net.URI;
 import java.util.Collections;
 
-import org.ops4j.pax.exam.Configuration;
-import org.ops4j.pax.exam.Option;
-import org.ops4j.pax.exam.junit.PaxExamServer;
-import org.ops4j.pax.exam.options.extra.VMOption;
-import org.apache.sling.testing.paxexam.SlingOptions;
 import static org.apache.sling.testing.paxexam.SlingOptions.logback;
 import static org.apache.sling.testing.paxexam.SlingOptions.slingQuickstartOakTar;
 import static org.ops4j.pax.exam.CoreOptions.composite;
 import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
 import static org.ops4j.pax.exam.CoreOptions.systemProperty;
 import static org.ops4j.pax.exam.CoreOptions.when;
-import org.apache.sling.testing.paxexam.TestSupport;
-
-
-public class ReferenceIT extends TestSupport {
-    protected static int httpPort;
-    protected static OsgiConsoleClient CLIENT;
-    private final static int STARTUP_WAIT_SECONDS = 30;
-
-    @ClassRule
-    public static PaxExamServer serverRule = new PaxExamServer() {
-        @Override
-        protected void before() throws Exception {
-            // Use a different port for each OSGi framework instance
-            // that's started - they can overlap if the previous one
-            // is not fully stopped when the next one starts.
-            setHttpPort();
-            super.before();
-        }
-    };
-
-    @Configuration
-    public Option[] configuration() throws Exception {
-
-        final String vmOpt = System.getProperty("pax.vm.options");
-        VMOption vmOption = null;
-        if (StringUtils.isNotEmpty(vmOpt)) {
-            vmOption = new VMOption(vmOpt);
-        }
-
-        final String jacocoOpt = System.getProperty("jacoco.command");
-        VMOption jacocoCommand = null;
-        if (StringUtils.isNotEmpty(jacocoOpt)) {
-            jacocoCommand = new VMOption(jacocoOpt);
-        }
-
-        final String workingDirectory = workingDirectory();
-
-        // Need recent commons.johnzon for the osgi.contract=JavaJSONP capability
-        SlingOptions.versionResolver.setVersion("org.apache.sling", "org.apache.sling.commons.johnzon", "1.2.6");
-
-        return composite(
-                // TODO not sure why the below list of bundles is different from
-                // running tests with PaxExam.class (SLING-9929)
-                //super.baseConfiguration(),
-
-                when(vmOption != null).useOptions(vmOption),
-                when(jacocoCommand != null).useOptions(jacocoCommand),
 
-                // For some reason, Jetty starts first on port 8080 without this
-                systemProperty("org.osgi.service.http.port").value(String.valueOf(httpPort)),
-
-                slingQuickstartOakTar(workingDirectory, httpPort),
-
-                testBundle("bundle.filename"),
-                mavenBundle().groupId("org.apache.sling").artifactId("org.apache.sling.junit.core").versionAsInProject(),
-
-                logback(),
-                mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.log").version("1.2.4"),
-                mavenBundle().groupId("log4j").artifactId("log4j").version("1.2.17"),
-                mavenBundle().groupId("org.apache.aries.spifly").artifactId("org.apache.aries.spifly.dynamic.framework.extension").version("1.3.2"),
-                mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.webconsole.plugins.ds").version("2.1.0")
-        ).getOptions();
-    }
-
-    @BeforeClass
-    public static void waitForSling() throws Exception {
-        final URI url = new URI(String.format("http://localhost:%d", httpPort));
-        CLIENT = new OsgiConsoleClient(url, "admin", "admin");
-        
-        CLIENT.waitExists("/", STARTUP_WAIT_SECONDS * 1000, 500);
-
-        CLIENT.waitComponentRegistered(MyLameServiceForTestingIT.class.getName(), 10 * 1000, 500);
-
-        // Verify stable status for a bit
-        for(int i=0; i < 10 ; i++) {
-            CLIENT.waitComponentRegistered(MyLameServiceForTestingIT.class.getName(), 1000, 100);
-            Thread.sleep(100);
-        }
-    }
-
-    static void setHttpPort() {
-        try {
-            final ServerSocket serverSocket = new ServerSocket(0);
-            httpPort = serverSocket.getLocalPort();
-            serverSocket.close();
-        } catch (Exception e) {
-            throw new RuntimeException(e);
-        }
-    }
 
+public class ReferenceIT extends AnnotationsTestSupport {
     @Test
     public void testReferenceJITest() throws ClientException, UnsupportedEncodingException {
         SlingHttpResponse response = CLIENT.doPost("/system/sling/junit/org.apache.sling.junit.it.TestReferenceJITest.html",