@@ -30,18 +30,33 @@ class Neo4jContainerTest {
3030 // See org.testcontainers.utility.LicenseAcceptance#ACCEPTANCE_FILE_NAME
3131 private static final String ACCEPTANCE_FILE_LOCATION = "/container-license-acceptance.txt" ;
3232
33+ @ Test
34+ void authenticated () {
35+ try (
36+ // container {
37+ Neo4jContainer neo4j = new Neo4jContainer ("neo4j:4.4" )
38+ // }
39+ ) {
40+ neo4j .start ();
41+ try (Driver driver = getDriver (neo4j ); Session session = driver .session ()) {
42+ long one = session .run ("RETURN 1" , Collections .emptyMap ()).next ().get (0 ).asLong ();
43+ assertThat (one ).isEqualTo (1L );
44+ }
45+ }
46+ }
47+
3348 @ Test
3449 void shouldDisableAuthentication () {
3550 try (
3651 // spotless:off
3752 // withoutAuthentication {
38- Neo4jContainer neo4jContainer = new Neo4jContainer ("neo4j:4.4" )
53+ Neo4jContainer neo4j = new Neo4jContainer ("neo4j:4.4" )
3954 .withoutAuthentication ()
4055 // }
4156 // spotless:on
4257 ) {
43- neo4jContainer .start ();
44- try (Driver driver = getDriver (neo4jContainer ); Session session = driver .session ()) {
58+ neo4j .start ();
59+ try (Driver driver = getDriver (neo4j ); Session session = driver .session ()) {
4560 long one = session .run ("RETURN 1" , Collections .emptyMap ()).next ().get (0 ).asLong ();
4661 assertThat (one ).isEqualTo (1L );
4762 }
@@ -54,12 +69,12 @@ void shouldCopyDatabase() {
5469 assumeThat (DockerClientFactory .instance ().getInfo ().getArchitecture ()).isNotEqualTo ("aarch64" );
5570 try (
5671 // copyDatabase {
57- Neo4jContainer neo4jContainer = new Neo4jContainer ("neo4j:3.5.30" )
72+ Neo4jContainer neo4j = new Neo4jContainer ("neo4j:3.5.30" )
5873 .withDatabase (MountableFile .forClasspathResource ("/test-graph.db" ))
5974 // }
6075 ) {
61- neo4jContainer .start ();
62- try (Driver driver = getDriver (neo4jContainer ); Session session = driver .session ()) {
76+ neo4j .start ();
77+ try (Driver driver = getDriver (neo4j ); Session session = driver .session ()) {
6378 Result result = session .run ("MATCH (t:Thing) RETURN t" );
6479 assertThat (result .list ().stream ().map (r -> r .get ("t" ).get ("name" ).asString ()))
6580 .containsExactlyInAnyOrder ("Thing" , "Thing 2" , "Thing 3" , "A box" );
@@ -98,12 +113,12 @@ void shouldFailOnCopyDatabaseForCustomNonSemverNeo4j4Image() {
98113 void shouldCopyPlugins () {
99114 try (
100115 // registerPluginsPath {
101- Neo4jContainer neo4jContainer = new Neo4jContainer ("neo4j:4.4" )
116+ Neo4jContainer neo4j = new Neo4jContainer ("neo4j:4.4" )
102117 .withPlugins (MountableFile .forClasspathResource ("/custom-plugins" ))
103118 // }
104119 ) {
105- neo4jContainer .start ();
106- try (Driver driver = getDriver (neo4jContainer ); Session session = driver .session ()) {
120+ neo4j .start ();
121+ try (Driver driver = getDriver (neo4j ); Session session = driver .session ()) {
107122 assertThatCustomPluginWasCopied (session );
108123 }
109124 }
@@ -113,12 +128,12 @@ void shouldCopyPlugins() {
113128 void shouldCopyPlugin () {
114129 try (
115130 // registerPluginsJar {
116- Neo4jContainer neo4jContainer = new Neo4jContainer ("neo4j:4.4" )
131+ Neo4jContainer neo4j = new Neo4jContainer ("neo4j:4.4" )
117132 .withPlugins (MountableFile .forClasspathResource ("/custom-plugins/hello-world.jar" ))
118133 // }
119134 ) {
120- neo4jContainer .start ();
121- try (Driver driver = getDriver (neo4jContainer ); Session session = driver .session ()) {
135+ neo4j .start ();
136+ try (Driver driver = getDriver (neo4j ); Session session = driver .session ()) {
122137 assertThatCustomPluginWasCopied (session );
123138 }
124139 }
@@ -137,13 +152,13 @@ void shouldRunEnterprise() {
137152
138153 try (
139154 // enterpriseEdition {
140- Neo4jContainer neo4jContainer = new Neo4jContainer ("neo4j:4.4-enterprise" )
155+ Neo4jContainer neo4j = new Neo4jContainer ("neo4j:4.4-enterprise" )
141156 .acceptLicense ()
142157 // }
143158 .withAdminPassword ("Picard123" )
144159 ) {
145- neo4jContainer .start ();
146- try (Driver driver = getDriver (neo4jContainer ); Session session = driver .session ()) {
160+ neo4j .start ();
161+ try (Driver driver = getDriver (neo4j ); Session session = driver .session ()) {
147162 String edition = session
148163 .run ("CALL dbms.components() YIELD edition RETURN edition" , Collections .emptyMap ())
149164 .next ()
@@ -157,125 +172,124 @@ void shouldRunEnterprise() {
157172 @ Test
158173 void shouldAddConfigToEnvironment () {
159174 // neo4jConfiguration {
160- Neo4jContainer neo4jContainer = new Neo4jContainer ("neo4j:4.4" )
175+ Neo4jContainer neo4j = new Neo4jContainer ("neo4j:4.4" )
161176 .withNeo4jConfig ("dbms.security.procedures.unrestricted" , "apoc.*,algo.*" )
162177 .withNeo4jConfig ("dbms.tx_log.rotation.size" , "42M" );
163178 // }
164179
165- assertThat (neo4jContainer .getEnvMap ())
166- .containsEntry ("NEO4J_dbms_security_procedures_unrestricted" , "apoc.*,algo.*" );
167- assertThat (neo4jContainer .getEnvMap ()).containsEntry ("NEO4J_dbms_tx__log_rotation_size" , "42M" );
180+ assertThat (neo4j .getEnvMap ()).containsEntry ("NEO4J_dbms_security_procedures_unrestricted" , "apoc.*,algo.*" );
181+ assertThat (neo4j .getEnvMap ()).containsEntry ("NEO4J_dbms_tx__log_rotation_size" , "42M" );
168182 }
169183
170184 @ Test
171185 void shouldRespectEnvironmentAuth () {
172- Neo4jContainer neo4jContainer = new Neo4jContainer ("neo4j:4.4" ).withEnv ("NEO4J_AUTH" , "neo4j/secret" );
186+ Neo4jContainer neo4j = new Neo4jContainer ("neo4j:4.4" ).withEnv ("NEO4J_AUTH" , "neo4j/secret" );
173187
174- neo4jContainer .configure ();
188+ neo4j .configure ();
175189
176- assertThat (neo4jContainer .getEnvMap ()).containsEntry ("NEO4J_AUTH" , "neo4j/secret" );
190+ assertThat (neo4j .getEnvMap ()).containsEntry ("NEO4J_AUTH" , "neo4j/secret" );
177191 }
178192
179193 @ Test
180194 void shouldSetCustomPasswordCorrectly () {
181195 // withAdminPassword {
182- Neo4jContainer neo4jContainer = new Neo4jContainer ("neo4j:4.4" ).withAdminPassword ("verySecret" );
196+ Neo4jContainer neo4j = new Neo4jContainer ("neo4j:4.4" ).withAdminPassword ("verySecret" );
183197 // }
184198
185- neo4jContainer .configure ();
199+ neo4j .configure ();
186200
187- assertThat (neo4jContainer .getEnvMap ()).containsEntry ("NEO4J_AUTH" , "neo4j/verySecret" );
201+ assertThat (neo4j .getEnvMap ()).containsEntry ("NEO4J_AUTH" , "neo4j/verySecret" );
188202 }
189203
190204 @ Test
191- void containerAdminPasswordOverrulesEnvironmentAuth () {
192- Neo4jContainer neo4jContainer = new Neo4jContainer ("neo4j:4.4" )
205+ void adminPasswordOverrulesEnvironmentAuth () {
206+ Neo4jContainer neo4j = new Neo4jContainer ("neo4j:4.4" )
193207 .withEnv ("NEO4J_AUTH" , "neo4j/secret" )
194208 .withAdminPassword ("anotherSecret" );
195209
196- neo4jContainer .configure ();
210+ neo4j .configure ();
197211
198- assertThat (neo4jContainer .getEnvMap ()).containsEntry ("NEO4J_AUTH" , "neo4j/anotherSecret" );
212+ assertThat (neo4j .getEnvMap ()).containsEntry ("NEO4J_AUTH" , "neo4j/anotherSecret" );
199213 }
200214
201215 @ Test
202- void containerWithoutAuthenticationOverrulesEnvironmentAuth () {
203- Neo4jContainer neo4jContainer = new Neo4jContainer ("neo4j:4.4" )
216+ void shouldWithoutAuthenticationOverrulesEnvironmentAuth () {
217+ Neo4jContainer neo4j = new Neo4jContainer ("neo4j:4.4" )
204218 .withEnv ("NEO4J_AUTH" , "neo4j/secret" )
205219 .withoutAuthentication ();
206220
207- neo4jContainer .configure ();
221+ neo4j .configure ();
208222
209- assertThat (neo4jContainer .getEnvMap ()).containsEntry ("NEO4J_AUTH" , "none" );
223+ assertThat (neo4j .getEnvMap ()).containsEntry ("NEO4J_AUTH" , "none" );
210224 }
211225
212226 @ Test
213227 void shouldRespectAlreadyDefinedPortMappingsBolt () {
214- Neo4jContainer neo4jContainer = new Neo4jContainer ("neo4j:4.4" ).withExposedPorts (7687 );
228+ Neo4jContainer neo4j = new Neo4jContainer ("neo4j:4.4" ).withExposedPorts (7687 );
215229
216- neo4jContainer .configure ();
230+ neo4j .configure ();
217231
218- assertThat (neo4jContainer .getExposedPorts ()).containsExactly (7687 );
232+ assertThat (neo4j .getExposedPorts ()).containsExactly (7687 );
219233 }
220234
221235 @ Test
222236 void shouldRespectAlreadyDefinedPortMappingsHttp () {
223- Neo4jContainer neo4jContainer = new Neo4jContainer ("neo4j:4.4" ).withExposedPorts (7474 );
237+ Neo4jContainer neo4j = new Neo4jContainer ("neo4j:4.4" ).withExposedPorts (7474 );
224238
225- neo4jContainer .configure ();
239+ neo4j .configure ();
226240
227- assertThat (neo4jContainer .getExposedPorts ()).containsExactly (7474 );
241+ assertThat (neo4j .getExposedPorts ()).containsExactly (7474 );
228242 }
229243
230244 @ Test
231245 void shouldRespectAlreadyDefinedPortMappingsWithoutHttps () {
232- Neo4jContainer neo4jContainer = new Neo4jContainer ("neo4j:4.4" ).withExposedPorts (7687 , 7474 );
246+ Neo4jContainer neo4j = new Neo4jContainer ("neo4j:4.4" ).withExposedPorts (7687 , 7474 );
233247
234- neo4jContainer .configure ();
248+ neo4j .configure ();
235249
236- assertThat (neo4jContainer .getExposedPorts ()).containsExactlyInAnyOrder (7474 , 7687 );
250+ assertThat (neo4j .getExposedPorts ()).containsExactlyInAnyOrder (7474 , 7687 );
237251 }
238252
239253 @ Test
240254 void shouldDefaultExportBoltHttpAndHttps () {
241- Neo4jContainer neo4jContainer = new Neo4jContainer ("neo4j:4.4" );
255+ Neo4jContainer neo4j = new Neo4jContainer ("neo4j:4.4" );
242256
243- neo4jContainer .configure ();
257+ neo4j .configure ();
244258
245- assertThat (neo4jContainer .getExposedPorts ()).containsExactlyInAnyOrder (7473 , 7474 , 7687 );
259+ assertThat (neo4j .getExposedPorts ()).containsExactlyInAnyOrder (7473 , 7474 , 7687 );
246260 }
247261
248262 @ Test
249263 void shouldRespectCustomWaitStrategy () {
250- Neo4jContainer neo4jContainer = new Neo4jContainer ("neo4j:4.4" ).waitingFor (new CustomDummyWaitStrategy ());
264+ Neo4jContainer neo4j = new Neo4jContainer ("neo4j:4.4" ).waitingFor (new CustomDummyWaitStrategy ());
251265
252- neo4jContainer .configure ();
266+ neo4j .configure ();
253267
254- assertThat (neo4jContainer ).extracting ("waitStrategy" ).isInstanceOf (CustomDummyWaitStrategy .class );
268+ assertThat (neo4j ).extracting ("waitStrategy" ).isInstanceOf (CustomDummyWaitStrategy .class );
255269 }
256270
257271 @ Test
258272 void shouldConfigureSinglePluginByName () {
259- try (Neo4jContainer neo4jContainer = new Neo4jContainer ("neo4j:4.4" ).withPlugins ("apoc" )) {
273+ try (Neo4jContainer neo4j = new Neo4jContainer ("neo4j:4.4" ).withPlugins ("apoc" )) {
260274 // needs to get called explicitly for setup
261- neo4jContainer .configure ();
275+ neo4j .configure ();
262276
263- assertThat (neo4jContainer .getEnvMap ()).containsEntry ("NEO4JLABS_PLUGINS" , "[\" apoc\" ]" );
277+ assertThat (neo4j .getEnvMap ()).containsEntry ("NEO4JLABS_PLUGINS" , "[\" apoc\" ]" );
264278 }
265279 }
266280
267281 @ Test
268282 void shouldConfigureMultiplePluginsByName () {
269283 try (
270284 // configureLabsPlugins {
271- Neo4jContainer neo4jContainer = new Neo4jContainer ("neo4j:4.4" ) //
285+ Neo4jContainer neo4j = new Neo4jContainer ("neo4j:4.4" ) //
272286 .withPlugins ("apoc" , "bloom" );
273287 // }
274288 ) {
275289 // needs to get called explicitly for setup
276- neo4jContainer .configure ();
290+ neo4j .configure ();
277291
278- assertThat (neo4jContainer .getEnvMap ().get ("NEO4JLABS_PLUGINS" ))
292+ assertThat (neo4j .getEnvMap ().get ("NEO4JLABS_PLUGINS" ))
279293 .containsAnyOf ("[\" apoc\" ,\" bloom\" ]" , "[\" bloom\" ,\" apoc\" ]" );
280294 }
281295 }
@@ -284,26 +298,26 @@ void shouldConfigureMultiplePluginsByName() {
284298 void shouldCreateRandomUuidBasedPasswords () {
285299 try (
286300 // withRandomPassword {
287- Neo4jContainer neo4jContainer = new Neo4jContainer ("neo4j:4.4" ).withRandomPassword ();
301+ Neo4jContainer neo4j = new Neo4jContainer ("neo4j:4.4" ).withRandomPassword ();
288302 // }
289303 ) {
290304 // It will throw an exception if it's not UUID parsable.
291- assertThatNoException ().isThrownBy (neo4jContainer ::configure );
305+ assertThatNoException ().isThrownBy (neo4j ::configure );
292306 // This basically is always true at if the random password is UUID-like.
293- assertThat (neo4jContainer .getAdminPassword ())
307+ assertThat (neo4j .getAdminPassword ())
294308 .satisfies (password -> assertThat (UUID .fromString (password ).toString ()).isEqualTo (password ));
295309 }
296310 }
297311
298312 @ Test
299313 void shouldWarnOnPasswordTooShort () {
300- try (Neo4jContainer neo4jContainer = new Neo4jContainer ("neo4j:4.4" );) {
314+ try (Neo4jContainer neo4j = new Neo4jContainer ("neo4j:4.4" );) {
301315 Logger logger = (Logger ) DockerLoggerFactory .getLogger ("neo4j:4.4" );
302316 TestLogAppender testLogAppender = new TestLogAppender ();
303317 logger .addAppender (testLogAppender );
304318 testLogAppender .start ();
305319
306- neo4jContainer .withAdminPassword ("short" );
320+ neo4j .withAdminPassword ("short" );
307321
308322 testLogAppender .stop ();
309323
@@ -337,11 +351,11 @@ protected void append(ILoggingEvent eventObject) {
337351 }
338352 }
339353
340- private static Driver getDriver (Neo4jContainer container ) {
354+ private static Driver getDriver (Neo4jContainer neo4j ) {
341355 AuthToken authToken = AuthTokens .none ();
342- if (container .getAdminPassword () != null ) {
343- authToken = AuthTokens .basic ("neo4j" , container .getAdminPassword ());
356+ if (neo4j .getAdminPassword () != null ) {
357+ authToken = AuthTokens .basic ("neo4j" , neo4j .getAdminPassword ());
344358 }
345- return GraphDatabase .driver (container .getBoltUrl (), authToken );
359+ return GraphDatabase .driver (neo4j .getBoltUrl (), authToken );
346360 }
347361}
0 commit comments