Skip to content

Commit

Permalink
Add OSGi integration testing to build (#1888)
Browse files Browse the repository at this point in the history
We define a simple test class to verify basic operations.

Fixes #1888

Signed-off-by: BJ Hargrave <[email protected]>
  • Loading branch information
bjhargrave authored and joel-costigliola committed Sep 3, 2020
1 parent 7dec889 commit c9807b9
Show file tree
Hide file tree
Showing 3 changed files with 188 additions and 7 deletions.
115 changes: 113 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,37 @@
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<!-- required to resolve
These dependencies are required to workaround a bad
interaction using includeDependencyManagement=true for
the Bnd resolver and testing plugins and the enforcer
plugin which causes a false positive from the enforcer
plugin. The Bnd 5.2.0 resolver and testing plugins
don't have this problem, so these dependencies
can be removed when updating bnd.version to 5.2.0 and
configuring the Bnd resolver and testing plugins to use
includeDependencyManagement=true.
-->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-commons</artifactId>
<scope>provided</scope>
</dependency>
<!-- required to run JUnit4 tests in eclipse without to explicitly select JUnit 4 runner ... -->
<dependency>
<groupId>org.junit.vintage</groupId>
Expand Down Expand Up @@ -173,6 +204,12 @@
<version>3.4.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.osgi</artifactId>
<version>3.15.300</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down Expand Up @@ -218,6 +255,9 @@
<configuration>
<argLine>${argLine}</argLine>
<trimStackTrace>false</trimStackTrace>
<excludes>
<exclude>org/assertj/core/osgi/**</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
Expand Down Expand Up @@ -304,6 +344,21 @@
]]></bnd>
</configuration>
</execution>
<!-- Integration Test Configuration -->
<execution>
<id>bnd-process-tests</id>
<phase>process-test-classes</phase>
<goals>
<goal>bnd-process-tests</goal>
</goals>
<configuration>
<includeClassesDir>false</includeClassesDir>
<bnd><![CDATA[
-includepackage: org.assertj.core.osgi.*
-removeheaders: Bnd-LastModified,Private-Package
]]></bnd>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
Expand Down Expand Up @@ -367,6 +422,21 @@
</archive>
</configuration>
</execution>
<execution>
<id>test-jar</id>
<phase>package</phase>
<goals>
<goal>test-jar</goal>
</goals>
<configuration>
<archive>
<manifestFile>${project.build.testOutputDirectory}/META-INF/MANIFEST.MF</manifestFile>
</archive>
<includes>
<include>org/assertj/core/osgi/**</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
<!-- generate jacoco report -->
Expand Down Expand Up @@ -450,14 +520,14 @@
]]></footer>
</configuration>
</plugin>
<!-- Resolve bundles for OSGi integration tests -->
<plugin>
<!-- Verify that additional OSGi package imports didn't sneak in. -->
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-resolver-maven-plugin</artifactId>
<version>${bnd.version}</version>
<executions>
<execution>
<id>verify-osgi-metadata</id>
<id>osgi-integration-resolving</id>
<phase>pre-integration-test</phase>
<goals>
<goal>resolve</goal>
Expand All @@ -466,8 +536,49 @@
<bndruns>
<bndrun>verify.bndrun</bndrun>
</bndruns>
<bundles>
<bundle>target/${project.build.finalName}-tests.jar</bundle>
</bundles>
<failOnChanges>false</failOnChanges>
<reportOptional>false</reportOptional>
<includeDependencyManagement>false</includeDependencyManagement>
<scopes>
<scope>provided</scope>
<scope>compile</scope>
<scope>runtime</scope>
<scope>test</scope>
</scopes>
</configuration>
</execution>
</executions>
</plugin>
<!-- Run OSGi integration tests -->
<plugin>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-testing-maven-plugin</artifactId>
<version>${bnd.version}</version>
<executions>
<execution>
<id>osgi-integration-testing</id>
<goals>
<goal>testing</goal>
</goals>
<configuration>
<bndruns>
<bndrun>verify.bndrun</bndrun>
</bndruns>
<bundles>
<bundle>target/${project.build.finalName}-tests.jar</bundle>
</bundles>
<failOnChanges>false</failOnChanges>
<includeDependencyManagement>false</includeDependencyManagement>
<resolve>false</resolve>
<scopes>
<scope>provided</scope>
<scope>compile</scope>
<scope>runtime</scope>
<scope>test</scope>
</scopes>
</configuration>
</execution>
</executions>
Expand Down
35 changes: 35 additions & 0 deletions src/test/java/org/assertj/core/osgi/SimpleTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Licensed 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.
*
* Copyright 2012-2020 the original author or authors.
*/
package org.assertj.core.osgi;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;

import org.junit.jupiter.api.Test;

class SimpleTest {

@Test
void simple_success() {
assertThat("A String").isNotNull()
.isNotEmpty()
.contains("A", "String")
.isEqualTo("A String");
}

@Test
void simple_failure() {
assertThatCode(() -> assertThat("A String").isNull()).isInstanceOf(AssertionError.class);
}

}
45 changes: 40 additions & 5 deletions verify.bndrun
Original file line number Diff line number Diff line change
@@ -1,5 +1,40 @@
# It's ok if this version range changes. It's probably
# because assertj just changed it's version. A future
# version of bnd will solve this by not writing back
# -runbundles when being used for verification.
-runbundles: assertj-core;version='[3.17.1,3.17.2)'
# Licensed 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.
#
# Copyright 2020 the original author or authors.

-tester: biz.aQute.tester.junit-platform

-runfw: org.eclipse.osgi
-resolve.effective: active
-runproperties: \
org.osgi.framework.bootdelegation=sun.reflect,\
osgi.console=

-runrequires: \
bnd.identity;id='${project.artifactId}-tests',\
bnd.identity;id='junit-jupiter-engine',\
bnd.identity;id='junit-platform-launcher'

# This will help us keep -runbundles sorted
-runstartlevel: \
order=sortbynameversion,\
begin=-1

# The version ranges will change as the version of
# AssertJ and/or its dependencies change.
-runbundles: \
assertj-core;version='[3.17.2,3.17.3)',\
assertj-core-tests;version='[3.17.2,3.17.3)',\
junit-jupiter-api;version='[5.6.2,5.6.3)',\
junit-jupiter-engine;version='[5.6.2,5.6.3)',\
junit-platform-commons;version='[1.6.2,1.6.3)',\
junit-platform-engine;version='[1.6.2,1.6.3)',\
junit-platform-launcher;version='[1.6.2,1.6.3)',\
org.opentest4j;version='[1.2.0,1.2.1)'

2 comments on commit c9807b9

@scordio
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @bjhargrave, this commit added the test jar to the maven-jar-plugin configuration for the OSGi integration tests, but I assume it's not necessary to deploy it as part of a release, right?

@bjhargrave
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test jar is only needed for the osgi-integration-* executions. So no need to deploy it.

Please sign in to comment.