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.
This commit is contained in:
committed by
Mark Paluch
parent
2cf6efbe5c
commit
a0b5ddad8d
@@ -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;
|
||||
* 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 {
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user