Skip to content

Commit cdbab6c

Browse files
committed
Introduce new witEnterpriseImage method.
Deprecate the existing withEnterpriseEdition method and adjust the documentation accordingly.
1 parent b762d88 commit cdbab6c

File tree

3 files changed

+54
-25
lines changed

3 files changed

+54
-25
lines changed

docs/modules/databases/neo4j.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,12 @@ If you need the Neo4j enterprise license, you can declare your Neo4j container l
104104
[Enterprise edition](../../../modules/neo4j/src/test/java/org/testcontainers/containers/Neo4jContainerTest.java) inside_block:enterpriseEdition
105105
<!--/codeinclude-->
106106

107-
This creates a Testcontainers based on the Docker image build with the Enterprise version of Neo4j 4.4.
108-
The call to `withEnterpriseEdition` adds the required environment variable that you accepted the terms and condition of the enterprise version.
109-
You accept those by adding a file named `container-license-acceptance.txt` to the root of your classpath containing the text `neo4j:4.4-enterprise` in one line.
107+
!!! warning
108+
the `withEnterpriseEdition` method is deprecated because it was implicitly changing the image tag to be always version 4.4.
110109

111-
If you are planning to run a newer Neo4j 5.x enterprise edition image, you have to manually define the proper enterprise image (e.g. `neo4j:5-enterprise`)
112-
and set the environment variable `NEO4J_ACCEPT_LICENSE_AGREEMENT` by adding `.withEnv("NEO4J_ACCEPT_LICENSE_AGREEMENT", "yes")` to your container definition.
110+
This creates a Testcontainers based on the Docker image build with the Enterprise version of the defined tag.
111+
The call to `withEnterpriseImage` adds the required environment variable that you accepted the terms and condition of the enterprise version.
112+
You accept those by adding a file named `container-license-acceptance.txt` to the root of your classpath containing the text `neo4j:<tag>-enterprise` in one line.
113113

114114
You'll find more information about licensing Neo4j here: [About Neo4j Licenses](https://neo4j.com/licensing/).
115115

modules/neo4j/src/main/java/org/testcontainers/containers/Neo4jContainer.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public class Neo4jContainer extends GenericContainer<Neo4jContainer> {
3535

3636
/**
3737
* The default tag (version) to use.
38+
* @deprecated this should not be used anywhere besides also deprecated method {@link #withEnterpriseEdition()}
3839
*/
3940
private static final String ENTERPRISE_TAG_4_4 = "4.4-enterprise";
4041

@@ -204,6 +205,9 @@ public String getHttpsUrl() {
204205
* needs either a commercial, education or evaluation license.
205206
*
206207
* @return This container.
208+
* @deprecated This method will force the use of the old 4.4. (LTS) version to be used as the enterprise image,
209+
* use {@link #withEnterpriseImage} to actively accept the license and use the enterprise version of
210+
* the initial defined community version.
207211
*/
208212
public Neo4jContainer withEnterpriseEdition() {
209213
if (!standardImage) {
@@ -219,6 +223,29 @@ public Neo4jContainer withEnterpriseEdition() {
219223
return self();
220224
}
221225

226+
/**
227+
* Configures the container to use the enterprise edition of the default docker image.
228+
* <br><br>
229+
* Please have a look at the <a href="https://neo4j.com/licensing/">Neo4j Licensing page</a>. While the Neo4j
230+
* Community Edition can be used for free in your projects under the GPL v3 license, Neo4j Enterprise edition
231+
* needs either a commercial, education or evaluation license.
232+
*
233+
* @return This container
234+
**/
235+
public Neo4jContainer withEnterpriseImage() {
236+
if (!standardImage) {
237+
throw new IllegalStateException(
238+
String.format("Cannot use enterprise version with alternative image %s.", getDockerImageName())
239+
);
240+
}
241+
setDockerImageName(DockerImageName.parse(getDockerImageName() + ENTERPRISE_SUFFIX).asCanonicalNameString());
242+
LicenseAcceptance.assertLicenseAccepted(getDockerImageName());
243+
244+
addEnv("NEO4J_ACCEPT_LICENSE_AGREEMENT", "yes");
245+
246+
return self();
247+
}
248+
222249
/**
223250
* Sets the admin password for the default account (which is <pre>neo4j</pre>). A null value or an empty string
224251
* disables authentication.

modules/neo4j/src/test/java/org/testcontainers/containers/Neo4jContainerTest.java

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ class Neo4jContainerTest {
3131
// See org.testcontainers.utility.LicenseAcceptance#ACCEPTANCE_FILE_NAME
3232
private static final String ACCEPTANCE_FILE_LOCATION = "/container-license-acceptance.txt";
3333

34+
private static final String DOCKER_IMAGE_NAME = "neo4j:5.26";
35+
3436
@Test
3537
void shouldDisableAuthentication() {
3638
try (
3739
// spotless:off
3840
// withoutAuthentication {
39-
Neo4jContainer neo4jContainer = new Neo4jContainer("neo4j:5.26")
41+
Neo4jContainer neo4jContainer = new Neo4jContainer(DOCKER_IMAGE_NAME)
4042
.withoutAuthentication()
4143
// }
4244
// spotless:on
@@ -99,7 +101,7 @@ void shouldFailOnCopyDatabaseForCustomNonSemverNeo4j4Image() {
99101
void shouldCopyPlugins() {
100102
try (
101103
// registerPluginsPath {
102-
Neo4jContainer neo4jContainer = new Neo4jContainer("neo4j:5.26")
104+
Neo4jContainer neo4jContainer = new Neo4jContainer(DOCKER_IMAGE_NAME)
103105
.withPlugins(MountableFile.forClasspathResource("/custom-plugins"))
104106
// }
105107
) {
@@ -114,7 +116,7 @@ void shouldCopyPlugins() {
114116
void shouldCopyPlugin() {
115117
try (
116118
// registerPluginsJar {
117-
Neo4jContainer neo4jContainer = new Neo4jContainer("neo4j:5.26")
119+
Neo4jContainer neo4jContainer = new Neo4jContainer(DOCKER_IMAGE_NAME)
118120
.withPlugins(MountableFile.forClasspathResource("/custom-plugins/hello-world.jar"))
119121
// }
120122
) {
@@ -149,8 +151,8 @@ void shouldRunEnterprise() {
149151

150152
try (
151153
// enterpriseEdition {
152-
Neo4jContainer neo4jContainer = new Neo4jContainer("neo4j:5.26")
153-
.withEnterpriseEdition()
154+
Neo4jContainer neo4jContainer = new Neo4jContainer(DOCKER_IMAGE_NAME)
155+
.withEnterpriseImage()
154156
// }
155157
.withAdminPassword("Picard123")
156158
) {
@@ -169,7 +171,7 @@ void shouldRunEnterprise() {
169171
@Test
170172
void shouldAddConfigToEnvironment() {
171173
// neo4jConfiguration {
172-
Neo4jContainer neo4jContainer = new Neo4jContainer("neo4j:5.26")
174+
Neo4jContainer neo4jContainer = new Neo4jContainer(DOCKER_IMAGE_NAME)
173175
.withNeo4jConfig("dbms.security.procedures.unrestricted", "apoc.*,algo.*")
174176
.withNeo4jConfig("dbms.tx_log.rotation.size", "42M");
175177
// }
@@ -181,7 +183,7 @@ void shouldAddConfigToEnvironment() {
181183

182184
@Test
183185
void shouldRespectEnvironmentAuth() {
184-
Neo4jContainer neo4jContainer = new Neo4jContainer("neo4j:5.26").withEnv("NEO4J_AUTH", "neo4j/secret");
186+
Neo4jContainer neo4jContainer = new Neo4jContainer(DOCKER_IMAGE_NAME).withEnv("NEO4J_AUTH", "neo4j/secret");
185187

186188
neo4jContainer.configure();
187189

@@ -191,7 +193,7 @@ void shouldRespectEnvironmentAuth() {
191193
@Test
192194
void shouldSetCustomPasswordCorrectly() {
193195
// withAdminPassword {
194-
Neo4jContainer neo4jContainer = new Neo4jContainer("neo4j:5.26").withAdminPassword("verySecret");
196+
Neo4jContainer neo4jContainer = new Neo4jContainer(DOCKER_IMAGE_NAME).withAdminPassword("verySecret");
195197
// }
196198

197199
neo4jContainer.configure();
@@ -201,7 +203,7 @@ void shouldSetCustomPasswordCorrectly() {
201203

202204
@Test
203205
void containerAdminPasswordOverrulesEnvironmentAuth() {
204-
Neo4jContainer neo4jContainer = new Neo4jContainer("neo4j:5.26")
206+
Neo4jContainer neo4jContainer = new Neo4jContainer(DOCKER_IMAGE_NAME)
205207
.withEnv("NEO4J_AUTH", "neo4j/secret")
206208
.withAdminPassword("anotherSecret");
207209

@@ -212,7 +214,7 @@ void containerAdminPasswordOverrulesEnvironmentAuth() {
212214

213215
@Test
214216
void containerWithoutAuthenticationOverrulesEnvironmentAuth() {
215-
Neo4jContainer neo4jContainer = new Neo4jContainer("neo4j:5.26")
217+
Neo4jContainer neo4jContainer = new Neo4jContainer(DOCKER_IMAGE_NAME)
216218
.withEnv("NEO4J_AUTH", "neo4j/secret")
217219
.withoutAuthentication();
218220

@@ -223,7 +225,7 @@ void containerWithoutAuthenticationOverrulesEnvironmentAuth() {
223225

224226
@Test
225227
void shouldRespectAlreadyDefinedPortMappingsBolt() {
226-
Neo4jContainer neo4jContainer = new Neo4jContainer("neo4j:5.26").withExposedPorts(7687);
228+
Neo4jContainer neo4jContainer = new Neo4jContainer(DOCKER_IMAGE_NAME).withExposedPorts(7687);
227229

228230
neo4jContainer.configure();
229231

@@ -232,7 +234,7 @@ void shouldRespectAlreadyDefinedPortMappingsBolt() {
232234

233235
@Test
234236
void shouldRespectAlreadyDefinedPortMappingsHttp() {
235-
Neo4jContainer neo4jContainer = new Neo4jContainer("neo4j:5.26").withExposedPorts(7474);
237+
Neo4jContainer neo4jContainer = new Neo4jContainer(DOCKER_IMAGE_NAME).withExposedPorts(7474);
236238

237239
neo4jContainer.configure();
238240

@@ -241,7 +243,7 @@ void shouldRespectAlreadyDefinedPortMappingsHttp() {
241243

242244
@Test
243245
void shouldRespectAlreadyDefinedPortMappingsWithoutHttps() {
244-
Neo4jContainer neo4jContainer = new Neo4jContainer("neo4j:5.26").withExposedPorts(7687, 7474);
246+
Neo4jContainer neo4jContainer = new Neo4jContainer(DOCKER_IMAGE_NAME).withExposedPorts(7687, 7474);
245247

246248
neo4jContainer.configure();
247249

@@ -250,7 +252,7 @@ void shouldRespectAlreadyDefinedPortMappingsWithoutHttps() {
250252

251253
@Test
252254
void shouldDefaultExportBoltHttpAndHttps() {
253-
Neo4jContainer neo4jContainer = new Neo4jContainer("neo4j:5.26");
255+
Neo4jContainer neo4jContainer = new Neo4jContainer(DOCKER_IMAGE_NAME);
254256

255257
neo4jContainer.configure();
256258

@@ -259,7 +261,7 @@ void shouldDefaultExportBoltHttpAndHttps() {
259261

260262
@Test
261263
void shouldRespectCustomWaitStrategy() {
262-
Neo4jContainer neo4jContainer = new Neo4jContainer("neo4j:5.26").waitingFor(new CustomDummyWaitStrategy());
264+
Neo4jContainer neo4jContainer = new Neo4jContainer(DOCKER_IMAGE_NAME).waitingFor(new CustomDummyWaitStrategy());
263265

264266
neo4jContainer.configure();
265267

@@ -268,7 +270,7 @@ void shouldRespectCustomWaitStrategy() {
268270

269271
@Test
270272
void shouldConfigureSinglePluginByName() {
271-
try (Neo4jContainer neo4jContainer = new Neo4jContainer("neo4j:5.26").withPlugins("apoc")) {
273+
try (Neo4jContainer neo4jContainer = new Neo4jContainer(DOCKER_IMAGE_NAME).withPlugins("apoc")) {
272274
// needs to get called explicitly for setup
273275
neo4jContainer.configure();
274276

@@ -280,7 +282,7 @@ void shouldConfigureSinglePluginByName() {
280282
void shouldConfigureMultiplePluginsByName() {
281283
try (
282284
// configureLabsPlugins {
283-
Neo4jContainer neo4jContainer = new Neo4jContainer("neo4j:5.26") //
285+
Neo4jContainer neo4jContainer = new Neo4jContainer(DOCKER_IMAGE_NAME) //
284286
.withPlugins("apoc", "bloom");
285287
// }
286288
) {
@@ -296,7 +298,7 @@ void shouldConfigureMultiplePluginsByName() {
296298
void shouldCreateRandomUuidBasedPasswords() {
297299
try (
298300
// withRandomPassword {
299-
Neo4jContainer neo4jContainer = new Neo4jContainer("neo4j:5.26").withRandomPassword();
301+
Neo4jContainer neo4jContainer = new Neo4jContainer(DOCKER_IMAGE_NAME).withRandomPassword();
300302
// }
301303
) {
302304
// It will throw an exception if it's not UUID parsable.
@@ -309,8 +311,8 @@ void shouldCreateRandomUuidBasedPasswords() {
309311

310312
@Test
311313
void shouldWarnOnPasswordTooShort() {
312-
try (Neo4jContainer neo4jContainer = new Neo4jContainer("neo4j:5.26");) {
313-
Logger logger = (Logger) DockerLoggerFactory.getLogger("neo4j:5.26");
314+
try (Neo4jContainer neo4jContainer = new Neo4jContainer(DOCKER_IMAGE_NAME);) {
315+
Logger logger = (Logger) DockerLoggerFactory.getLogger(DOCKER_IMAGE_NAME);
314316
TestLogAppender testLogAppender = new TestLogAppender();
315317
logger.addAppender(testLogAppender);
316318
testLogAppender.start();

0 commit comments

Comments
 (0)