Skip to content

Commit ddae79c

Browse files
KyleAurernorth
andauthored
Add acceptLicense method to MSSQLServerContainer (#2085)
Co-authored-by: Richard North <[email protected]>
1 parent ff73a5e commit ddae79c

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

docs/modules/databases/mssqlserver.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ Running MS SQL Server as a stand-in for in a test:
1010
public class SomeTest {
1111

1212
@Rule
13-
public MSSQLServerContainer mssqlserver = new MSSQLServerContainer();
13+
public MSSQLServerContainer mssqlserver = new MSSQLServerContainer()
14+
.acceptLicense();
1415

1516
@Test
1617
public void someTestMethod() {
@@ -20,7 +21,7 @@ public class SomeTest {
2021
```
2122

2223
!!! warning "EULA Acceptance"
23-
Due to licencing restrictions you are required to accept an EULA for this container image. To indicate that you accept the MS SQL Server image EULA, Please place a file at the root of the classpath named `container-license-acceptance.txt`, e.g. at `src/test/resources/container-license-acceptance.txt`. This file should contain the line: `mcr.microsoft.com/mssql/server:2017-CU12` (or, if you are overriding the docker image name/tag, update accordingly).
24+
Due to licencing restrictions you are required to accept an EULA for this container image. To indicate that you accept the MS SQL Server image EULA, call the `acceptLicense()` method, or place a file at the root of the classpath named `container-license-acceptance.txt`, e.g. at `src/test/resources/container-license-acceptance.txt`. This file should contain the line: `mcr.microsoft.com/mssql/server:2017-CU12` (or, if you are overriding the docker image name/tag, update accordingly).
2425

2526
Please see the [`microsoft-mssql-server` image documentation](https://hub.docker.com/_/microsoft-mssql-server#environment-variables) for a link to the EULA document.
2627

modules/mssqlserver/src/main/java/org/testcontainers/containers/MSSQLServerContainer.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,24 @@ protected Integer getLivenessCheckPort() {
5050

5151
@Override
5252
protected void configure() {
53-
LicenseAcceptance.assertLicenseAccepted(this.getDockerImageName());
54-
addEnv("ACCEPT_EULA", "Y");
53+
// If license was not accepted programatically, check if it was accepted via resource file
54+
if (!getEnvMap().containsKey("ACCEPT_EULA")) {
55+
LicenseAcceptance.assertLicenseAccepted(this.getDockerImageName());
56+
acceptLicense();
57+
}
58+
5559
addEnv("SA_PASSWORD", password);
5660
}
5761

62+
/**
63+
* Accepts the license for the SQLServer container by setting the ACCEPT_EULA=Y
64+
* variable as described at <a href="https://hub.docker.com/_/microsoft-mssql-server">https://hub.docker.com/_/microsoft-mssql-server</a>
65+
*/
66+
public SELF acceptLicense() {
67+
addEnv("ACCEPT_EULA", "Y");
68+
return self();
69+
}
70+
5871
@Override
5972
public String getDriverClassName() {
6073
return "com.microsoft.sqlserver.jdbc.SQLServerDriver";
@@ -116,6 +129,5 @@ private void checkPasswordStrength(String password) {
116129
"or percent (%)."
117130
);
118131
}
119-
120132
}
121133
}

0 commit comments

Comments
 (0)