Browse Source

DATAJDBC-576 - Control test execution with missing licence via profile.

Running all tests with

```
./mvnw clean install -Pall-dbs
```

or similar now requires an appropriate `container-license-acceptance.txt` to be on the classpath.

In order to ignore the tests that require an explicit license acceptance one may add the maven profile `ignore-missing-license` like so

```
./mvnw clean install -Pall-dbs,ignore-missing-license
```

Original pull request: #239.
pull/240/head
Jens Schauder 6 years ago committed by Mark Paluch
parent
commit
a0b5ddad8d
No known key found for this signature in database
GPG Key ID: 51A00FA751B91849
  1. 30
      README.adoc
  2. 17
      pom.xml
  3. 19
      spring-data-jdbc/src/test/java/org/springframework/data/jdbc/testing/LicenseListener.java

30
README.adoc

@ -148,6 +148,36 @@ If you want to build with the regular `mvn` command, you will need https://maven @@ -148,6 +148,36 @@ If you want to build with the regular `mvn` command, you will need https://maven
_Also see link:CONTRIBUTING.adoc[CONTRIBUTING.adoc] if you wish to submit pull requests, and in particular please sign the https://cla.pivotal.io/sign/spring[Contributor’s Agreement] before your first non-trivial change._
=== Running Integration Tests
[source,bash]
----
$ ./mvnw clean install
----
Runs integration test against a single in memory database.
To run integration tests against all supported databases specify the Maven Profile `all-dbs`.
```
./mvnw clean install -Pall-dbs
```
This requires an appropriate `container-license-acceptance.txt` to be on the classpath, signaling that you accept the licence of the databases used.
If you don't want to accept these licences you may add the Maven Profile `ignore-missing-licence`.
This will ignore the tests that require an explicit license acceptance.
```
./mvnw clean install -Pall-dbs,ignore-missing-licence
```
If you want to run an integration tests against a different database you can do so by activating an apropriate Spring Profile.
Available are the following Spring Profiles:
`db2`, `h2`, `hsql` (default), `mariadb`, `mssql`, `mysql`, `oracle`, `postgres`
=== Building reference documentation
Building the documentation builds also the project without running tests.

17
pom.xml

@ -128,7 +128,6 @@ @@ -128,7 +128,6 @@
<includes>
<include>**/*IntegrationTests.java</include>
</includes>
<excludes>
<exclude>**/*HsqlIntegrationTests.java</exclude>
</excludes>
<systemPropertyVariables>
@ -231,6 +230,22 @@ @@ -231,6 +230,22 @@
</plugins>
</build>
</profile>
<profile>
<id>ignore-missing-licence</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<on-missing-licence>ignore-test</on-missing-licence>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<build>

19
spring-data-jdbc/src/test/java/org/springframework/data/jdbc/testing/LicenseListener.java

@ -16,13 +16,11 @@ @@ -16,13 +16,11 @@
package org.springframework.data.jdbc.testing;
import org.junit.AssumptionViolatedException;
import org.springframework.core.annotation.Order;
import org.springframework.core.env.Profiles;
import org.springframework.core.env.StandardEnvironment;
import org.springframework.test.context.TestContext;
import org.springframework.test.context.TestExecutionListener;
import org.testcontainers.containers.Db2Container;
import org.testcontainers.containers.MSSQLServerContainer;
import org.testcontainers.utility.LicenseAcceptance;
@ -32,14 +30,17 @@ import org.testcontainers.utility.LicenseAcceptance; @@ -32,14 +30,17 @@ import org.testcontainers.utility.LicenseAcceptance;
* accepted.
*
* @author Mark Paluch
* @author Jens Schauder
*/
@Order(Integer.MIN_VALUE)
public class LicenseListener implements TestExecutionListener {
private StandardEnvironment environment;
@Override
public void prepareTestInstance(TestContext testContext) {
StandardEnvironment environment = new StandardEnvironment();
environment = new StandardEnvironment();
if (environment.acceptsProfiles(Profiles.of("db2"))) {
assumeLicenseAccepted(Db2Container.DEFAULT_DB2_IMAGE_NAME + ":" + Db2Container.DEFAULT_TAG);
@ -50,12 +51,20 @@ public class LicenseListener implements TestExecutionListener { @@ -50,12 +51,20 @@ public class LicenseListener implements TestExecutionListener {
}
}
private static void assumeLicenseAccepted(String imageName) {
private void assumeLicenseAccepted(String imageName) {
try {
LicenseAcceptance.assertLicenseAccepted(imageName);
} catch (IllegalStateException e) {
throw new AssumptionViolatedException(e.getMessage());
if (environment.getProperty("on-missing-licence", "fail").equals("ignore-test")) {
throw new AssumptionViolatedException(e.getMessage());
} else {
throw new IllegalStateException(
"You need to accept the licence for the database with which you are testing or set \"ignore-missing-licence\" as active profile in order to skip tests for which a licence is missing.",
e);
}
}
}

Loading…
Cancel
Save