You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ol...@apache.org on 2019/06/18 20:07:55 UTC
[sling-org-apache-sling-commons-classloader] branch master updated:
SLING-8522 Make testing compliant with Java 9 and higher
This is an automated email from the ASF dual-hosted git repository.
olli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-classloader.git
The following commit(s) were added to refs/heads/master by this push:
new dedb69a SLING-8522 Make testing compliant with Java 9 and higher
dedb69a is described below
commit dedb69a9fb0f8cb2ebf3050560311739b9f00ce4
Author: Oliver Lietz <ol...@apache.org>
AuthorDate: Tue Jun 18 22:07:28 2019 +0200
SLING-8522 Make testing compliant with Java 9 and higher
* Use Sling Bundle Parent 35
* Update Pax Exam to 4.13.1
* Use Testing PaxExam 3.0.0
* Update Felix Framework to 6.0.3
---
pom.xml | 111 ++++++++--------
.../classloader/it/ClassloaderTestSupport.java | 45 +++++++
.../classloader/it/DynamicClassLoaderIT.java | 140 ++-------------------
3 files changed, 111 insertions(+), 185 deletions(-)
diff --git a/pom.xml b/pom.xml
index 243cf22..2691521 100644
--- a/pom.xml
+++ b/pom.xml
@@ -22,8 +22,8 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.sling</groupId>
- <artifactId>sling</artifactId>
- <version>34</version>
+ <artifactId>sling-bundle-parent</artifactId>
+ <version>35</version>
<relativePath />
</parent>
@@ -43,14 +43,7 @@
</scm>
<properties>
- <bundle.build.name>
- ${basedir}/target
- </bundle.build.name>
- <bundle.file.name>
- ${bundle.build.name}/${project.build.finalName}.jar
- </bundle.file.name>
- <pax-exam.version>4.11.0</pax-exam.version>
- <pax-link.version>2.5.2</pax-link.version>
+ <org.ops4j.pax.exam.version>4.13.1</org.ops4j.pax.exam.version>
</properties>
<build>
@@ -76,16 +69,17 @@
<configuration>
<systemProperties>
<property>
- <name>project.bundle.file</name>
- <value>${bundle.file.name}</value>
+ <name>bundle.filename</name>
+ <value>${basedir}/target/${project.build.finalName}.jar</value>
</property>
</systemProperties>
- <includes>
- <include>**/*IT.java</include>
- </includes>
</configuration>
</plugin>
<plugin>
+ <groupId>org.apache.servicemix.tooling</groupId>
+ <artifactId>depends-maven-plugin</artifactId>
+ </plugin>
+ <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
@@ -97,9 +91,11 @@
</plugins>
</build>
<dependencies>
+ <!-- javax -->
<dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
+ <groupId>javax.inject</groupId>
+ <artifactId>javax.inject</artifactId>
+ <scope>test</scope>
</dependency>
<!-- OSGi -->
<dependency>
@@ -109,6 +105,11 @@
</dependency>
<dependency>
<groupId>org.osgi</groupId>
+ <artifactId>osgi.cmpn</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
<artifactId>osgi.core</artifactId>
<scope>provided</scope>
</dependency>
@@ -122,78 +123,76 @@
<artifactId>org.osgi.service.metatype.annotations</artifactId>
<scope>provided</scope>
</dependency>
- <!-- Unit Testing -->
+ <!-- Apache Felix -->
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.framework</artifactId>
+ <version>6.0.3</version>
+ <scope>test</scope>
</dependency>
+ <!-- Apache Sling -->
<dependency>
- <groupId>org.jmock</groupId>
- <artifactId>jmock-junit4</artifactId>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.testing.paxexam</artifactId>
+ <version>3.0.0</version>
+ <scope>test</scope>
</dependency>
+ <!-- logging -->
<dependency>
<groupId>org.slf4j</groupId>
- <artifactId>slf4j-simple</artifactId>
+ <artifactId>slf4j-api</artifactId>
+ <scope>provided</scope>
</dependency>
- <!-- Integration Testing with Pax Exam -->
+ <!-- testing -->
<dependency>
- <groupId>org.ops4j.pax.exam</groupId>
- <artifactId>pax-exam-container-native</artifactId>
- <version>${pax-exam.version}</version>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ops4j.pax.exam</groupId>
- <artifactId>pax-exam-junit4</artifactId>
- <version>${pax-exam.version}</version>
+ <artifactId>pax-exam</artifactId>
+ <version>${org.ops4j.pax.exam.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ops4j.pax.exam</groupId>
- <artifactId>pax-exam-link-mvn</artifactId>
- <version>${pax-exam.version}</version>
+ <artifactId>pax-exam-cm</artifactId>
+ <version>${org.ops4j.pax.exam.version}</version>
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.ops4j.pax.url</groupId>
- <artifactId>pax-url-aether</artifactId>
- <version>${pax-link.version}</version>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-container-forked</artifactId>
+ <version>${org.ops4j.pax.exam.version}</version>
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.ops4j.pax.url</groupId>
- <artifactId>pax-url-wrap</artifactId>
- <version>${pax-link.version}</version>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-junit4</artifactId>
+ <version>${org.ops4j.pax.exam.version}</version>
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.apache.geronimo.specs</groupId>
- <artifactId>geronimo-atinject_1.0_spec</artifactId>
- <version>1.0</version>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-link-mvn</artifactId>
+ <version>${org.ops4j.pax.exam.version}</version>
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.ops4j.base</groupId>
- <artifactId>ops4j-base-lang</artifactId>
- <version>1.2.3</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.ops4j.base</groupId>
- <artifactId>ops4j-base-net</artifactId>
- <version>1.2.3</version>
- <scope>provided</scope>
+ <groupId>org.jmock</groupId>
+ <artifactId>jmock-junit4</artifactId>
+ <scope>test</scope>
</dependency>
<dependency>
- <groupId>org.ops4j.pax.tinybundles</groupId>
- <artifactId>tinybundles</artifactId>
- <version>1.0.0</version>
+ <groupId>org.ops4j.pax.url</groupId>
+ <artifactId>pax-url-aether</artifactId>
+ <version>2.6.1</version>
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.framework</artifactId>
- <version>5.4.0</version>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
<!-- This bundle needs to be present at run time for the Pax-Exam tests -->
diff --git a/src/test/java/org/apache/sling/commons/classloader/it/ClassloaderTestSupport.java b/src/test/java/org/apache/sling/commons/classloader/it/ClassloaderTestSupport.java
new file mode 100644
index 0000000..9023d33
--- /dev/null
+++ b/src/test/java/org/apache/sling/commons/classloader/it/ClassloaderTestSupport.java
@@ -0,0 +1,45 @@
+/*
+ * 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.commons.classloader.it;
+
+import org.apache.sling.testing.paxexam.TestSupport;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
+
+import static org.apache.sling.testing.paxexam.SlingOptions.config;
+import static org.apache.sling.testing.paxexam.SlingOptions.paxUrl;
+import static org.ops4j.pax.exam.CoreOptions.junitBundles;
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+import static org.ops4j.pax.exam.CoreOptions.options;
+
+public abstract class ClassloaderTestSupport extends TestSupport {
+
+ @Configuration
+ public Option[] configuration() {
+ return options(
+ super.baseConfiguration(),
+ // Sling Commons Classloader
+ testBundle("bundle.filename"),
+ config(),
+ // testing
+ paxUrl(),
+ mavenBundle().groupId("org.ops4j.pax.url").artifactId("pax-url-aether").versionAsInProject(),
+ junitBundles()
+ );
+ }
+
+}
diff --git a/src/test/java/org/apache/sling/commons/classloader/it/DynamicClassLoaderIT.java b/src/test/java/org/apache/sling/commons/classloader/it/DynamicClassLoaderIT.java
index fc3b3c8..7446e12 100644
--- a/src/test/java/org/apache/sling/commons/classloader/it/DynamicClassLoaderIT.java
+++ b/src/test/java/org/apache/sling/commons/classloader/it/DynamicClassLoaderIT.java
@@ -16,43 +16,30 @@
*/
package org.apache.sling.commons.classloader.it;
-import static org.junit.Assert.*;
-import static org.ops4j.pax.exam.Constants.*;
-import static org.ops4j.pax.exam.CoreOptions.*;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
import java.io.InputStream;
-import java.nio.file.Path;
-import java.nio.file.Paths;
+import java.net.URL;
import javax.inject.Inject;
import org.apache.sling.commons.classloader.DynamicClassLoaderManager;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.ops4j.pax.exam.CoreOptions;
-import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.ProbeBuilder;
import org.ops4j.pax.exam.TestProbeBuilder;
-import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.junit.PaxExam;
-import org.ops4j.pax.exam.ProbeBuilder;
-import org.ops4j.pax.exam.options.AbstractDelegateProvisionOption;
-import org.ops4j.pax.exam.options.MavenArtifactProvisionOption;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceReference;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
@RunWith(PaxExam.class)
-public class DynamicClassLoaderIT {
+public class DynamicClassLoaderIT extends ClassloaderTestSupport {
- // the name of the system property providing the bundle file to be installed and tested
- private static final String BUNDLE_JAR_SYS_PROP = "project.bundle.file";
-
- private static MavenArtifactCoordinates commonsOsgi = new MavenArtifactCoordinates("org.apache.sling", "org.apache.sling.commons.osgi", "2.1.0");
+ private static String commonsOsgi = "mvn:org.apache.sling/org.apache.sling.commons.osgi/2.1.0";
@Inject
protected BundleContext bundleContext;
@@ -89,46 +76,21 @@ public class DynamicClassLoaderIT {
@ProbeBuilder
public TestProbeBuilder extendProbe(TestProbeBuilder builder) {
- builder.setHeader(Constants.IMPORT_PACKAGE, "org.osgi.framework,org.apache.sling.commons.classloader");
+ builder.setHeader(Constants.IMPORT_PACKAGE, "org.osgi.framework,org.apache.sling.commons.classloader,org.apache.sling.testing.paxexam");
builder.setHeader(Constants.DYNAMICIMPORT_PACKAGE, "org.ops4j.pax.exam,org.junit,javax.inject,org.ops4j.pax.exam.options");
builder.setHeader("Bundle-ManifestVersion", "2");
return builder;
}
- @Configuration
- public static Option[] configuration() {
-
- final String bundleFileName = System.getProperty( BUNDLE_JAR_SYS_PROP );
- final File bundleFile = new File( bundleFileName );
- if ( !bundleFile.canRead() ) {
- throw new IllegalArgumentException( "Cannot read from bundle file " + bundleFileName + " specified in the "
- + BUNDLE_JAR_SYS_PROP + " system property" );
- }
-
- return options(
- provision(
- CoreOptions.bundle( bundleFile.toURI().toString() ),
- mavenBundle( "org.ops4j.pax.tinybundles", "tinybundles", "1.0.0" ),
- mavenBundle("org.apache.sling", "org.apache.sling.commons.log", "2.1.2"),
- mavenBundle("org.apache.felix", "org.apache.felix.eventadmin", "1.2.14"),
- mavenBundle("org.ops4j.pax.url", "pax-url-mvn", "1.3.5")
- ),
- // below is instead of normal Pax Exam junitBundles() to deal
- // with build server issue
- new DirectURLJUnitBundlesOption(),
- systemProperty("pax.exam.invoker").value("junit"),
- bundle("link:classpath:META-INF/links/org.ops4j.pax.exam.invoker.junit.link")
- );
- }
-
@Test
public void testPackageAdminClassLoader() throws Exception {
// check class loader
assertNotNull(getDynamicClassLoader());
+ final URL url = new URL(commonsOsgi);
Bundle osgiBundle;
- try ( InputStream input = commonsOsgi.openInputStream() ) {
- osgiBundle = this.bundleContext.installBundle(commonsOsgi.getMavenBundle().getURL(), input);
+ try ( InputStream input = url.openStream() ) {
+ osgiBundle = this.bundleContext.installBundle(commonsOsgi, input);
}
assertNotNull(osgiBundle);
assertEquals(Bundle.INSTALLED, osgiBundle.getState());
@@ -164,85 +126,5 @@ public class DynamicClassLoaderIT {
fail("Class should be available");
}
}
-
- /**
- * Clone of Pax Exam's JunitBundlesOption which uses a direct
- * URL to the SpringSource JUnit bundle to avoid some weird
- * repository issues on the Apache build server.
- */
- private static class DirectURLJUnitBundlesOption
- extends AbstractDelegateProvisionOption<DirectURLJUnitBundlesOption> {
-
- /**
- * Constructor.
- */
- public DirectURLJUnitBundlesOption(){
- super(
- bundle("http://repository.springsource.com/ivy/bundles/external/org.junit/com.springsource.org.junit/4.9.0/com.springsource.org.junit-4.9.0.jar")
- );
- noUpdate();
- startLevel(START_LEVEL_SYSTEM_BUNDLES);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String toString() {
- return String.format("DirectURLJUnitBundlesOption{url=%s}", getURL());
- }
-
- /**
- * {@inheritDoc}
- */
- protected DirectURLJUnitBundlesOption itself() {
- return this;
- }
-
- }
-
- /**
- * Helper class which simplifies accesing a Maven artifact based on its coordinates
- */
- static class MavenArtifactCoordinates {
- private String groupId;
- private String artifactId;
- private String version;
-
- private MavenArtifactCoordinates(String groupId, String artifactId, String version) {
- this.groupId = groupId;
- this.artifactId = artifactId;
- this.version = version;
- }
-
- public InputStream openInputStream() throws FileNotFoundException {
-
- // note that this contains a lot of Maven-related logic, but I did not find the
- // right set of dependencies to make this work inside the OSGi container
- //
- // The tough part is making sure that this also works on Jenkins where a
- // private local repository is specified using -Dmaven.repo.local
- Path localRepo = Paths.get(System.getProperty("user.home"), ".m2", "repository");
- String overridenRepo = System.getProperty("maven.repo.local");
- if ( overridenRepo != null ) {
- localRepo = Paths.get(overridenRepo);
- }
-
- Path artifact = Paths.get(localRepo.toString(), groupId.replace('.', File.separatorChar), artifactId, version, artifactId+"-" + version+".jar");
-
- if ( !artifact.toFile().exists() ) {
- throw new RuntimeException("Artifact at " + artifact + " does not exist.");
- }
-
- return new FileInputStream(artifact.toFile());
- }
-
-
-
- public MavenArtifactProvisionOption getMavenBundle() {
-
- return mavenBundle(groupId, artifactId, version);
- }
- }
}
\ No newline at end of file