Skip to content

Commit a0b5dda

Browse files
schaudermp911de
authored andcommitted
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.
1 parent 2cf6efb commit a0b5dda

File tree

3 files changed

+60
-6
lines changed

3 files changed

+60
-6
lines changed

README.adoc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,36 @@ If you want to build with the regular `mvn` command, you will need https://maven
148148

149149
_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._
150150

151+
=== Running Integration Tests
152+
153+
[source,bash]
154+
----
155+
$ ./mvnw clean install
156+
----
157+
158+
Runs integration test against a single in memory database.
159+
160+
To run integration tests against all supported databases specify the Maven Profile `all-dbs`.
161+
162+
```
163+
./mvnw clean install -Pall-dbs
164+
```
165+
166+
This requires an appropriate `container-license-acceptance.txt` to be on the classpath, signaling that you accept the licence of the databases used.
167+
168+
If you don't want to accept these licences you may add the Maven Profile `ignore-missing-licence`.
169+
This will ignore the tests that require an explicit license acceptance.
170+
171+
```
172+
./mvnw clean install -Pall-dbs,ignore-missing-licence
173+
```
174+
175+
176+
If you want to run an integration tests against a different database you can do so by activating an apropriate Spring Profile.
177+
Available are the following Spring Profiles:
178+
179+
`db2`, `h2`, `hsql` (default), `mariadb`, `mssql`, `mysql`, `oracle`, `postgres`
180+
151181
=== Building reference documentation
152182

153183
Building the documentation builds also the project without running tests.

pom.xml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@
128128
<includes>
129129
<include>**/*IntegrationTests.java</include>
130130
</includes>
131-
<excludes>
132131
<exclude>**/*HsqlIntegrationTests.java</exclude>
133132
</excludes>
134133
<systemPropertyVariables>
@@ -231,6 +230,22 @@
231230
</plugins>
232231
</build>
233232
</profile>
233+
<profile>
234+
<id>ignore-missing-licence</id>
235+
<build>
236+
<plugins>
237+
<plugin>
238+
<groupId>org.apache.maven.plugins</groupId>
239+
<artifactId>maven-surefire-plugin</artifactId>
240+
<configuration>
241+
<systemPropertyVariables>
242+
<on-missing-licence>ignore-test</on-missing-licence>
243+
</systemPropertyVariables>
244+
</configuration>
245+
</plugin>
246+
</plugins>
247+
</build>
248+
</profile>
234249
</profiles>
235250

236251
<build>

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@
1616
package org.springframework.data.jdbc.testing;
1717

1818
import org.junit.AssumptionViolatedException;
19-
2019
import org.springframework.core.annotation.Order;
2120
import org.springframework.core.env.Profiles;
2221
import org.springframework.core.env.StandardEnvironment;
2322
import org.springframework.test.context.TestContext;
2423
import org.springframework.test.context.TestExecutionListener;
25-
2624
import org.testcontainers.containers.Db2Container;
2725
import org.testcontainers.containers.MSSQLServerContainer;
2826
import org.testcontainers.utility.LicenseAcceptance;
@@ -32,14 +30,17 @@
3230
* accepted.
3331
*
3432
* @author Mark Paluch
33+
* @author Jens Schauder
3534
*/
3635
@Order(Integer.MIN_VALUE)
3736
public class LicenseListener implements TestExecutionListener {
3837

38+
private StandardEnvironment environment;
39+
3940
@Override
4041
public void prepareTestInstance(TestContext testContext) {
4142

42-
StandardEnvironment environment = new StandardEnvironment();
43+
environment = new StandardEnvironment();
4344

4445
if (environment.acceptsProfiles(Profiles.of("db2"))) {
4546
assumeLicenseAccepted(Db2Container.DEFAULT_DB2_IMAGE_NAME + ":" + Db2Container.DEFAULT_TAG);
@@ -50,12 +51,20 @@ public void prepareTestInstance(TestContext testContext) {
5051
}
5152
}
5253

53-
private static void assumeLicenseAccepted(String imageName) {
54+
private void assumeLicenseAccepted(String imageName) {
5455

5556
try {
5657
LicenseAcceptance.assertLicenseAccepted(imageName);
5758
} catch (IllegalStateException e) {
58-
throw new AssumptionViolatedException(e.getMessage());
59+
60+
if (environment.getProperty("on-missing-licence", "fail").equals("ignore-test")) {
61+
throw new AssumptionViolatedException(e.getMessage());
62+
} else {
63+
64+
throw new IllegalStateException(
65+
"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.",
66+
e);
67+
}
5968
}
6069
}
6170

0 commit comments

Comments
 (0)