From ecf9a5ef059d61c0c17d627cd3bfa3d16760d177 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edd=C3=BA=20Mel=C3=A9ndez?= Date: Thu, 4 Sep 2025 09:37:44 -0600 Subject: [PATCH] Move Neo4j tests to JUnit Jupiter --- modules/neo4j/build.gradle | 7 +++ .../Neo4jContainerJUnitIntegrationTest.java | 54 ------------------- .../containers/Neo4jContainerTest.java | 53 +++++++++--------- 3 files changed, 32 insertions(+), 82 deletions(-) delete mode 100644 modules/neo4j/src/test/java/org/testcontainers/containers/Neo4jContainerJUnitIntegrationTest.java diff --git a/modules/neo4j/build.gradle b/modules/neo4j/build.gradle index 9f347a9e34b..a1b49eac532 100644 --- a/modules/neo4j/build.gradle +++ b/modules/neo4j/build.gradle @@ -33,6 +33,9 @@ dependencies { api project(":testcontainers") + testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.11.0' + + testImplementation 'org.junit.jupiter:junit-jupiter:5.13.4' testImplementation 'org.neo4j.driver:neo4j-java-driver:4.4.20' testImplementation 'org.assertj:assertj-core:3.27.4' } @@ -43,3 +46,7 @@ tasks.japicmp { "org.testcontainers.containers.Neo4jLabsPlugin" ] } + +test { + useJUnitPlatform() +} diff --git a/modules/neo4j/src/test/java/org/testcontainers/containers/Neo4jContainerJUnitIntegrationTest.java b/modules/neo4j/src/test/java/org/testcontainers/containers/Neo4jContainerJUnitIntegrationTest.java deleted file mode 100644 index 868d7e29f2d..00000000000 --- a/modules/neo4j/src/test/java/org/testcontainers/containers/Neo4jContainerJUnitIntegrationTest.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.testcontainers.containers; - -import org.junit.ClassRule; -import org.junit.Test; -import org.neo4j.driver.AuthTokens; -import org.neo4j.driver.Driver; -import org.neo4j.driver.GraphDatabase; -import org.neo4j.driver.Session; - -import java.util.Collections; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.fail; - -/** - * Test for basic functionality when used as a @ClassRule. - */ -public class Neo4jContainerJUnitIntegrationTest { - - @ClassRule - public static Neo4jContainer neo4jContainer = new Neo4jContainer("neo4j:4.4"); - - @Test - public void shouldStart() { - boolean actual = neo4jContainer.isRunning(); - assertThat(actual).isTrue(); - - try ( - Driver driver = GraphDatabase.driver(neo4jContainer.getBoltUrl(), AuthTokens.basic("neo4j", "password")); - Session session = driver.session() - ) { - long one = session.run("RETURN 1", Collections.emptyMap()).next().get(0).asLong(); - assertThat(one).isEqualTo(1L); - } catch (Exception e) { - fail(e.getMessage()); - } - } - - @Test - public void shouldReturnBoltUrl() { - String actual = neo4jContainer.getBoltUrl(); - - assertThat(actual).isNotNull(); - assertThat(actual).startsWith("bolt://"); - } - - @Test - public void shouldReturnHttpUrl() { - String actual = neo4jContainer.getHttpUrl(); - - assertThat(actual).isNotNull(); - assertThat(actual).startsWith("http://"); - } -} diff --git a/modules/neo4j/src/test/java/org/testcontainers/containers/Neo4jContainerTest.java b/modules/neo4j/src/test/java/org/testcontainers/containers/Neo4jContainerTest.java index 9827eb09900..997e90c4788 100644 --- a/modules/neo4j/src/test/java/org/testcontainers/containers/Neo4jContainerTest.java +++ b/modules/neo4j/src/test/java/org/testcontainers/containers/Neo4jContainerTest.java @@ -4,7 +4,7 @@ import ch.qos.logback.classic.Logger; import ch.qos.logback.classic.spi.ILoggingEvent; import ch.qos.logback.core.AppenderBase; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.neo4j.driver.AuthToken; import org.neo4j.driver.AuthTokens; import org.neo4j.driver.Driver; @@ -26,16 +26,13 @@ import static org.assertj.core.api.Assertions.assertThatNoException; import static org.assertj.core.api.Assumptions.assumeThat; -/** - * Tests of functionality special to the Neo4jContainer. - */ -public class Neo4jContainerTest { +class Neo4jContainerTest { // See org.testcontainers.utility.LicenseAcceptance#ACCEPTANCE_FILE_NAME private static final String ACCEPTANCE_FILE_LOCATION = "/container-license-acceptance.txt"; @Test - public void shouldDisableAuthentication() { + void shouldDisableAuthentication() { try ( // spotless:off // withoutAuthentication { @@ -53,7 +50,7 @@ public void shouldDisableAuthentication() { } @Test - public void shouldCopyDatabase() { + void shouldCopyDatabase() { // no aarch64 image available for Neo4j 3.5 assumeThat(DockerClientFactory.instance().getInfo().getArchitecture()).isNotEqualTo("aarch64"); try ( @@ -72,7 +69,7 @@ public void shouldCopyDatabase() { } @Test - public void shouldFailOnCopyDatabaseForDefaultNeo4j4Image() { + void shouldFailOnCopyDatabaseForDefaultNeo4j4Image() { assertThatIllegalArgumentException() .isThrownBy(() -> { new Neo4jContainer("neo4j:4.4.1").withDatabase(MountableFile.forClasspathResource("/test-graph.db")); @@ -81,7 +78,7 @@ public void shouldFailOnCopyDatabaseForDefaultNeo4j4Image() { } @Test - public void shouldFailOnCopyDatabaseForCustomNeo4j4Image() { + void shouldFailOnCopyDatabaseForCustomNeo4j4Image() { assertThatIllegalArgumentException() .isThrownBy(() -> { new Neo4jContainer("neo4j:4.4.1").withDatabase(MountableFile.forClasspathResource("/test-graph.db")); @@ -90,7 +87,7 @@ public void shouldFailOnCopyDatabaseForCustomNeo4j4Image() { } @Test - public void shouldFailOnCopyDatabaseForCustomNonSemverNeo4j4Image() { + void shouldFailOnCopyDatabaseForCustomNonSemverNeo4j4Image() { assertThatIllegalArgumentException() .isThrownBy(() -> { new Neo4jContainer("neo4j:latest").withDatabase(MountableFile.forClasspathResource("/test-graph.db")); @@ -99,7 +96,7 @@ public void shouldFailOnCopyDatabaseForCustomNonSemverNeo4j4Image() { } @Test - public void shouldCopyPlugins() { + void shouldCopyPlugins() { try ( // registerPluginsPath { Neo4jContainer neo4jContainer = new Neo4jContainer("neo4j:4.4") @@ -114,7 +111,7 @@ public void shouldCopyPlugins() { } @Test - public void shouldCopyPlugin() { + void shouldCopyPlugin() { try ( // registerPluginsJar { Neo4jContainer neo4jContainer = new Neo4jContainer("neo4j:4.4") @@ -136,7 +133,7 @@ private static void assertThatCustomPluginWasCopied(Session session) { } @Test - public void shouldCheckEnterpriseLicense() { + void shouldCheckEnterpriseLicense() { assumeThat(Neo4jContainerTest.class.getResource(ACCEPTANCE_FILE_LOCATION)).isNull(); String expectedImageName = "neo4j:4.4-enterprise"; @@ -147,7 +144,7 @@ public void shouldCheckEnterpriseLicense() { } @Test - public void shouldRunEnterprise() { + void shouldRunEnterprise() { assumeThat(Neo4jContainerTest.class.getResource(ACCEPTANCE_FILE_LOCATION)).isNotNull(); try ( @@ -170,7 +167,7 @@ public void shouldRunEnterprise() { } @Test - public void shouldAddConfigToEnvironment() { + void shouldAddConfigToEnvironment() { // neo4jConfiguration { Neo4jContainer neo4jContainer = new Neo4jContainer("neo4j:4.4") .withNeo4jConfig("dbms.security.procedures.unrestricted", "apoc.*,algo.*") @@ -183,7 +180,7 @@ public void shouldAddConfigToEnvironment() { } @Test - public void shouldRespectEnvironmentAuth() { + void shouldRespectEnvironmentAuth() { Neo4jContainer neo4jContainer = new Neo4jContainer("neo4j:4.4").withEnv("NEO4J_AUTH", "neo4j/secret"); neo4jContainer.configure(); @@ -192,7 +189,7 @@ public void shouldRespectEnvironmentAuth() { } @Test - public void shouldSetCustomPasswordCorrectly() { + void shouldSetCustomPasswordCorrectly() { // withAdminPassword { Neo4jContainer neo4jContainer = new Neo4jContainer("neo4j:4.4").withAdminPassword("verySecret"); // } @@ -203,7 +200,7 @@ public void shouldSetCustomPasswordCorrectly() { } @Test - public void containerAdminPasswordOverrulesEnvironmentAuth() { + void containerAdminPasswordOverrulesEnvironmentAuth() { Neo4jContainer neo4jContainer = new Neo4jContainer("neo4j:4.4") .withEnv("NEO4J_AUTH", "neo4j/secret") .withAdminPassword("anotherSecret"); @@ -214,7 +211,7 @@ public void containerAdminPasswordOverrulesEnvironmentAuth() { } @Test - public void containerWithoutAuthenticationOverrulesEnvironmentAuth() { + void containerWithoutAuthenticationOverrulesEnvironmentAuth() { Neo4jContainer neo4jContainer = new Neo4jContainer("neo4j:4.4") .withEnv("NEO4J_AUTH", "neo4j/secret") .withoutAuthentication(); @@ -225,7 +222,7 @@ public void containerWithoutAuthenticationOverrulesEnvironmentAuth() { } @Test - public void shouldRespectAlreadyDefinedPortMappingsBolt() { + void shouldRespectAlreadyDefinedPortMappingsBolt() { Neo4jContainer neo4jContainer = new Neo4jContainer("neo4j:4.4").withExposedPorts(7687); neo4jContainer.configure(); @@ -234,7 +231,7 @@ public void shouldRespectAlreadyDefinedPortMappingsBolt() { } @Test - public void shouldRespectAlreadyDefinedPortMappingsHttp() { + void shouldRespectAlreadyDefinedPortMappingsHttp() { Neo4jContainer neo4jContainer = new Neo4jContainer("neo4j:4.4").withExposedPorts(7474); neo4jContainer.configure(); @@ -243,7 +240,7 @@ public void shouldRespectAlreadyDefinedPortMappingsHttp() { } @Test - public void shouldRespectAlreadyDefinedPortMappingsWithoutHttps() { + void shouldRespectAlreadyDefinedPortMappingsWithoutHttps() { Neo4jContainer neo4jContainer = new Neo4jContainer("neo4j:4.4").withExposedPorts(7687, 7474); neo4jContainer.configure(); @@ -252,7 +249,7 @@ public void shouldRespectAlreadyDefinedPortMappingsWithoutHttps() { } @Test - public void shouldDefaultExportBoltHttpAndHttps() { + void shouldDefaultExportBoltHttpAndHttps() { Neo4jContainer neo4jContainer = new Neo4jContainer("neo4j:4.4"); neo4jContainer.configure(); @@ -261,7 +258,7 @@ public void shouldDefaultExportBoltHttpAndHttps() { } @Test - public void shouldRespectCustomWaitStrategy() { + void shouldRespectCustomWaitStrategy() { Neo4jContainer neo4jContainer = new Neo4jContainer("neo4j:4.4").waitingFor(new CustomDummyWaitStrategy()); neo4jContainer.configure(); @@ -270,7 +267,7 @@ public void shouldRespectCustomWaitStrategy() { } @Test - public void shouldConfigureSinglePluginByName() { + void shouldConfigureSinglePluginByName() { try (Neo4jContainer neo4jContainer = new Neo4jContainer("neo4j:4.4").withPlugins("apoc")) { // needs to get called explicitly for setup neo4jContainer.configure(); @@ -280,7 +277,7 @@ public void shouldConfigureSinglePluginByName() { } @Test - public void shouldConfigureMultiplePluginsByName() { + void shouldConfigureMultiplePluginsByName() { try ( // configureLabsPlugins { Neo4jContainer neo4jContainer = new Neo4jContainer("neo4j:4.4") // @@ -296,7 +293,7 @@ public void shouldConfigureMultiplePluginsByName() { } @Test - public void shouldCreateRandomUuidBasedPasswords() { + void shouldCreateRandomUuidBasedPasswords() { try ( // withRandomPassword { Neo4jContainer neo4jContainer = new Neo4jContainer("neo4j:4.4").withRandomPassword(); @@ -311,7 +308,7 @@ public void shouldCreateRandomUuidBasedPasswords() { } @Test - public void shouldWarnOnPasswordTooShort() { + void shouldWarnOnPasswordTooShort() { try (Neo4jContainer neo4jContainer = new Neo4jContainer("neo4j:4.4");) { Logger logger = (Logger) DockerLoggerFactory.getLogger("neo4j:4.4"); TestLogAppender testLogAppender = new TestLogAppender();