From 19a3094e38174c0971d151c8967ae2abcb7fa2a2 Mon Sep 17 00:00:00 2001 From: Tobias Ericsson Date: Sun, 22 Sep 2024 13:33:11 +0200 Subject: [PATCH] wip --- .../neo4j/docker/TestDeprecationWarning.java | 10 +- .../docker/TestDockerComposeSecrets.java | 3 +- .../neo4j/docker/coredb/TestAdminReport.java | 32 +- .../docker/coredb/TestAuthentication.java | 55 ++-- .../com/neo4j/docker/coredb/TestBasic.java | 285 +++++++----------- .../docker/coredb/TestCausalCluster.java | 2 +- .../com/neo4j/docker/coredb/TestMounting.java | 2 +- .../java/com/neo4j/docker/coredb/TestSSL.java | 2 +- .../com/neo4j/docker/coredb/TestUpgrade.java | 6 +- .../configurations/TestConfSettings.java | 2 +- .../configurations/TestExtendedConf.java | 2 +- .../TestJVMAdditionalConfig.java | 2 +- .../TestBundledPluginInstallation.java | 25 +- .../plugins/TestPluginInstallation.java | 8 +- .../docker/neo4jadmin/TestAdminBasic.java | 4 +- .../docker/neo4jadmin/TestBackupRestore.java | 4 +- .../neo4jadmin/TestBackupRestore44.java | 4 +- .../neo4j/docker/neo4jadmin/TestDumpLoad.java | 4 +- .../docker/neo4jadmin/TestDumpLoad44.java | 4 +- .../neo4j/docker/neo4jadmin/TestReport.java | 2 +- .../neo4j/docker/utils/HelperContainers.java | 22 ++ .../com/neo4j/docker/utils/TestSettings.java | 6 +- 22 files changed, 201 insertions(+), 285 deletions(-) diff --git a/src/test/java/com/neo4j/docker/TestDeprecationWarning.java b/src/test/java/com/neo4j/docker/TestDeprecationWarning.java index 1d3987d9..dff3413b 100644 --- a/src/test/java/com/neo4j/docker/TestDeprecationWarning.java +++ b/src/test/java/com/neo4j/docker/TestDeprecationWarning.java @@ -26,7 +26,7 @@ void shouldWarnIfUsingDeprecatedBaseOS_coreDB() throws Exception { Assumptions.assumeTrue( TestSettings.BASE_OS == TestSettings.BaseOS.UBI8, "Deprecation warning should only exist in UBI8 images"); - try(GenericContainer container = new GenericContainer(TestSettings.IMAGE_ID)) + try(GenericContainer container = new GenericContainer(TestSettings.NEO4J_IMAGE_ID)) { container.withEnv( "NEO4J_ACCEPT_LICENSE_AGREEMENT", "yes" ) .withExposedPorts( 7474, 7687 ) @@ -45,7 +45,7 @@ void shouldWarnIfUsingDeprecatedBaseOS_admin() { Assumptions.assumeTrue( TestSettings.BASE_OS == TestSettings.BaseOS.UBI8, "Deprecation warning should only exist in UBI8 images"); - try(GenericContainer container = new GenericContainer(TestSettings.ADMIN_IMAGE_ID)) + try(GenericContainer container = new GenericContainer(TestSettings.NEO4J_ADMIN_IMAGE_ID)) { container.withEnv( "NEO4J_ACCEPT_LICENSE_AGREEMENT", "yes" ) .withExposedPorts( 7474, 7687 ) @@ -66,7 +66,7 @@ void shouldOnlyWarnWhenRunningNeo4jCommands() throws Exception { Assumptions.assumeTrue( TestSettings.BASE_OS == TestSettings.BaseOS.UBI8, "Deprecation warning should only exist in UBI8 images"); - try(GenericContainer container = new GenericContainer(TestSettings.IMAGE_ID)) + try(GenericContainer container = new GenericContainer(TestSettings.NEO4J_IMAGE_ID)) { container.withEnv( "NEO4J_ACCEPT_LICENSE_AGREEMENT", "yes" ) .withExposedPorts( 7474, 7687 ) @@ -86,7 +86,7 @@ void shouldIgnoreDeprecationSuppression_coreDB() throws Exception { Assumptions.assumeTrue( TestSettings.BASE_OS == TestSettings.BaseOS.UBI8, "Deprecation warning should only exist in UBI8 images"); - try(GenericContainer container = new GenericContainer(TestSettings.IMAGE_ID)) + try(GenericContainer container = new GenericContainer(TestSettings.NEO4J_IMAGE_ID)) { container.withEnv( "NEO4J_ACCEPT_LICENSE_AGREEMENT", "yes" ) .withEnv( DEPRECATION_WARN_SUPPRESS_FLAG, "suppress" ) @@ -106,7 +106,7 @@ void shouldIgnoreDeprecationSuppressed_admin() { Assumptions.assumeTrue( TestSettings.BASE_OS == TestSettings.BaseOS.UBI8, "Deprecation warning should only exist in UBI8 images"); - try(GenericContainer container = new GenericContainer(TestSettings.ADMIN_IMAGE_ID)) + try(GenericContainer container = new GenericContainer(TestSettings.NEO4J_ADMIN_IMAGE_ID)) { container.withEnv( "NEO4J_ACCEPT_LICENSE_AGREEMENT", "yes" ) .withEnv( DEPRECATION_WARN_SUPPRESS_FLAG, "suppress" ) diff --git a/src/test/java/com/neo4j/docker/TestDockerComposeSecrets.java b/src/test/java/com/neo4j/docker/TestDockerComposeSecrets.java index 7963d1f7..50c88c94 100644 --- a/src/test/java/com/neo4j/docker/TestDockerComposeSecrets.java +++ b/src/test/java/com/neo4j/docker/TestDockerComposeSecrets.java @@ -22,7 +22,6 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.attribute.PosixFilePermissions; -import java.time.Duration; import static com.neo4j.docker.utils.WaitStrategies.waitForBoltReady; @@ -50,7 +49,7 @@ private DockerComposeContainer createContainer( File composeFile, Path container container.withExposedService( serviceName, DEFAULT_BOLT_PORT ) .withExposedService( serviceName, DEFAULT_HTTP_PORT ) - .withEnv( "NEO4J_IMAGE", TestSettings.IMAGE_ID.asCanonicalNameString() ) + .withEnv( "NEO4J_IMAGE", TestSettings.NEO4J_IMAGE_ID.asCanonicalNameString() ) .withEnv( "HOST_ROOT", containerRootDir.toAbsolutePath().toString() ) .waitingFor( serviceName, waitForBoltReady() ) .withLogConsumer( serviceName, new Slf4jLogConsumer( log ) ); diff --git a/src/test/java/com/neo4j/docker/coredb/TestAdminReport.java b/src/test/java/com/neo4j/docker/coredb/TestAdminReport.java index 9309d8f1..41145ab7 100644 --- a/src/test/java/com/neo4j/docker/coredb/TestAdminReport.java +++ b/src/test/java/com/neo4j/docker/coredb/TestAdminReport.java @@ -1,11 +1,6 @@ package com.neo4j.docker.coredb; -import com.neo4j.docker.utils.DatabaseIO; -import com.neo4j.docker.utils.Neo4jVersion; -import com.neo4j.docker.utils.SetContainerUser; -import com.neo4j.docker.utils.WaitStrategies; -import com.neo4j.docker.utils.TemporaryFolderManager; -import com.neo4j.docker.utils.TestSettings; +import com.neo4j.docker.utils.*; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -47,27 +42,12 @@ static void setCorrectPathFlagForVersion() reportDestinationFlag = "--to-path"; } } - - private GenericContainer createNeo4jContainer( boolean asCurrentUser) - { - GenericContainer container = new GenericContainer( TestSettings.IMAGE_ID ) - .withEnv( "NEO4J_ACCEPT_LICENSE_AGREEMENT", "yes" ) - .withEnv( "NEO4J_AUTH", "neo4j/"+PASSWORD ) - .withExposedPorts( 7474, 7687 ) - .withLogConsumer( new Slf4jLogConsumer( log ) ) - .waitingFor(WaitStrategies.waitForNeo4jReady( PASSWORD )); - if(asCurrentUser) - { - SetContainerUser.nonRootUser( container ); - } - return container; - } - + @ParameterizedTest(name = "ascurrentuser_{0}") @ValueSource(booleans = {true, false}) void testMountToTmpReports(boolean asCurrentUser) throws Exception { - try(GenericContainer container = createNeo4jContainer(asCurrentUser)) + try(GenericContainer container = HelperContainers.createNeo4jContainer(asCurrentUser)) { temporaryFolderManager.createFolderAndMountAsVolume(container, "/logs"); Path reportFolder = temporaryFolderManager.createFolderAndMountAsVolume(container, "/tmp/reports"); @@ -102,7 +82,7 @@ void testCanWriteReportToAnyMountedLocation_toPathWithSpace(boolean asCurrentUse private void verifyCanWriteToMountedLocation(boolean asCurrentUser, String testFolderPrefix, String[] execArgs) throws Exception { - try(GenericContainer container = createNeo4jContainer(asCurrentUser)) + try(GenericContainer container = HelperContainers.createNeo4jContainer(asCurrentUser)) { temporaryFolderManager.createFolderAndMountAsVolume(container, "/logs"); Path reportFolder = temporaryFolderManager.createFolderAndMountAsVolume(container, "/reports"); @@ -120,7 +100,7 @@ private void verifyCanWriteToMountedLocation(boolean asCurrentUser, String testF @Test void shouldShowNeo4jAdminHelpText_whenCMD() throws Exception { - try(GenericContainer container = createNeo4jContainer(false)) + try(GenericContainer container = HelperContainers.createNeo4jContainer(false)) { container.withCommand( "neo4j-admin-report", "--help" ); WaitStrategies.waitUntilContainerFinished( container, Duration.ofSeconds( 20 ) ); @@ -142,7 +122,7 @@ void shouldShowNeo4jAdminHelpText_whenCMD() throws Exception @Test void shouldShowNeo4jAdminHelpText_whenEXEC() throws Exception { - try(GenericContainer container = createNeo4jContainer(false)) + try(GenericContainer container = HelperContainers.createNeo4jContainer(false)) { temporaryFolderManager.createFolderAndMountAsVolume(container, "/logs"); container.start(); diff --git a/src/test/java/com/neo4j/docker/coredb/TestAuthentication.java b/src/test/java/com/neo4j/docker/coredb/TestAuthentication.java index a10074e5..7f44ff3d 100644 --- a/src/test/java/com/neo4j/docker/coredb/TestAuthentication.java +++ b/src/test/java/com/neo4j/docker/coredb/TestAuthentication.java @@ -2,12 +2,7 @@ import com.neo4j.docker.coredb.configurations.Configuration; import com.neo4j.docker.coredb.configurations.Setting; -import com.neo4j.docker.utils.DatabaseIO; -import com.neo4j.docker.utils.Neo4jVersion; -import com.neo4j.docker.utils.SetContainerUser; -import com.neo4j.docker.utils.WaitStrategies; -import com.neo4j.docker.utils.TemporaryFolderManager; -import com.neo4j.docker.utils.TestSettings; +import com.neo4j.docker.utils.*; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.Test; @@ -35,21 +30,7 @@ public class TestAuthentication @RegisterExtension public static TemporaryFolderManager temporaryFolderManager = new TemporaryFolderManager(); - - private GenericContainer createContainer( boolean asCurrentUser ) - { - GenericContainer container = new GenericContainer( TestSettings.IMAGE_ID ); - container.withEnv( "NEO4J_ACCEPT_LICENSE_AGREEMENT", "yes" ) - .withExposedPorts( 7474, 7687 ) - .withLogConsumer( new Slf4jLogConsumer( log ) ) - .waitingFor(WaitStrategies.waitForBoltReady()); - if(asCurrentUser) - { - SetContainerUser.nonRootUser( container ); - } - return container; - } - + private Path setInitialPasswordWithSecretsFile(GenericContainer container, String password) throws IOException { Path secretsFolder = temporaryFolderManager.createFolderAndMountAsVolume( container, "/secrets" ); @@ -63,7 +44,7 @@ void testNoPassword() { // we test that setting NEO4J_AUTH to "none" lets the database start in TestBasic.java, // but that does not test that we can read/write the database - try(GenericContainer container = createContainer( false )) + try(GenericContainer container = HelperContainers.createNeo4jContainer( false )) { container.withEnv( "NEO4J_AUTH", "none"); container.start(); @@ -76,7 +57,7 @@ void testNoPassword() @Test void testPasswordCantBeNeo4j() throws Exception { - try(GenericContainer failContainer = new GenericContainer( TestSettings.IMAGE_ID ).withLogConsumer( new Slf4jLogConsumer( log ) )) + try(GenericContainer failContainer = new GenericContainer( TestSettings.NEO4J_IMAGE_ID ).withLogConsumer( new Slf4jLogConsumer( log ) )) { if ( TestSettings.EDITION == TestSettings.Edition.ENTERPRISE ) { @@ -97,7 +78,7 @@ void testPasswordCantBeNeo4j() throws Exception @Test void testDefaultPasswordAndPasswordResetIfNoNeo4jAuthSet() { - try(GenericContainer container = createContainer( true )) + try(GenericContainer container = HelperContainers.createNeo4jContainer( true )) { log.info( "Starting first container as current user and not specifying NEO4J_AUTH" ); container.waitingFor( WaitStrategies.waitForNeo4jReady( "neo4j" ) ); @@ -123,7 +104,7 @@ void testCanSetPassword( boolean asCurrentUser ) throws Exception String password = "some_valid_password"; Path dataMount; - try(GenericContainer firstContainer = createContainer( asCurrentUser )) + try(GenericContainer firstContainer = HelperContainers.createNeo4jContainer( asCurrentUser )) { firstContainer.withEnv( "NEO4J_AUTH", "neo4j/"+password ) .waitingFor(WaitStrategies.waitForNeo4jReady(password)); @@ -137,7 +118,7 @@ void testCanSetPassword( boolean asCurrentUser ) throws Exception } // with a new container, check the database data. - try(GenericContainer secondContainer = createContainer( asCurrentUser ) + try(GenericContainer secondContainer = HelperContainers.createNeo4jContainer( asCurrentUser ) .waitingFor(WaitStrategies.waitForNeo4jReady(password))) { temporaryFolderManager.mountHostFolderAsVolume( secondContainer, dataMount, "/data" ); @@ -154,7 +135,7 @@ void testCanSetPasswordFromSecretsFile( boolean asCurrentUser ) throws Exception { String password = "some_valid_password"; - try(GenericContainer container = createContainer( asCurrentUser ) + try(GenericContainer container = HelperContainers.createNeo4jContainer( asCurrentUser ) .waitingFor(WaitStrategies.waitForNeo4jReady(password))) { setInitialPasswordWithSecretsFile( container, password ); @@ -173,7 +154,7 @@ void testSecretsFileTakesPriorityOverEnvAuthentication() throws Exception String password = "some_valid_password"; String wrongPassword = "not_the_password"; - try(GenericContainer container = createContainer(false ) + try(GenericContainer container = HelperContainers.createNeo4jContainer(false ) .waitingFor(WaitStrategies.waitForNeo4jReady(password))) { container.withEnv( "NEO4J_AUTH", "neo4j/" + wrongPassword ); @@ -192,7 +173,7 @@ void testSecretsFileTakesPriorityOverEnvAuthentication() throws Exception @Test void testFailsIfSecretsFileSetButMissing() { - try(GenericContainer failContainer = createContainer( false )) + try(GenericContainer failContainer = HelperContainers.createNeo4jContainer( false )) { WaitStrategies.waitUntilContainerFinished( failContainer, Duration.ofSeconds( 30 ) ); failContainer.withEnv( NEO4J_AUTH_FILE_ENV, "/secrets/doesnotexist.secret" ); @@ -211,7 +192,7 @@ void testCanSetPasswordWithDebugging() throws Exception { String password = "some_valid_password"; - try ( GenericContainer container = createContainer( false ) ) + try ( GenericContainer container = HelperContainers.createNeo4jContainer( false ) ) { container.withEnv( "NEO4J_AUTH", "neo4j/" + password ) .withEnv( "NEO4J_DEBUG", "yes" ) @@ -230,7 +211,7 @@ void testSettingNeo4jAuthDoesntOverrideExistingPassword( boolean asCurrentUser ) String password = "some_valid_password"; Path dataMount; - try(GenericContainer firstContainer = createContainer( asCurrentUser )) + try(GenericContainer firstContainer = HelperContainers.createNeo4jContainer( asCurrentUser )) { firstContainer.withEnv( "NEO4J_AUTH", "neo4j/"+password ) .waitingFor(WaitStrategies.waitForNeo4jReady( password)); @@ -245,7 +226,7 @@ void testSettingNeo4jAuthDoesntOverrideExistingPassword( boolean asCurrentUser ) } // with a new container, check the database data. - try(GenericContainer secondContainer = createContainer( asCurrentUser )) + try(GenericContainer secondContainer = HelperContainers.createNeo4jContainer( asCurrentUser )) { String wrongPassword = "not_the_password"; secondContainer.withEnv( "NEO4J_AUTH", "neo4j/"+wrongPassword ); @@ -264,7 +245,7 @@ void testPromptsForPasswordReset() { Assumptions.assumeTrue( TestSettings.NEO4J_VERSION.isAtLeastVersion( new Neo4jVersion( 3,6,0 ) ), "Require password reset is only a feature in 3.6 onwards"); - try(GenericContainer container = createContainer( false )) + try(GenericContainer container = HelperContainers.createNeo4jContainer( false )) { String user = "neo4j"; String intialPass = "apassword"; @@ -290,7 +271,7 @@ void testWarnAndFailIfPasswordLessThan8Chars(boolean usePasswordFile) throws Exc Assumptions.assumeTrue( TestSettings.NEO4J_VERSION.isAtLeastVersion( new Neo4jVersion( 5,2,0 ) ), "Minimum password length introduced in 5.2.0"); String shortPassword = "123"; - try(GenericContainer failContainer = createContainer( false )) + try(GenericContainer failContainer = HelperContainers.createNeo4jContainer( false )) { if(usePasswordFile) { @@ -318,7 +299,7 @@ void testWarnAndFailIfPasswordLessThanOverride(boolean usePasswordFile) throws E Assumptions.assumeTrue( TestSettings.NEO4J_VERSION.isAtLeastVersion( new Neo4jVersion( 5,2,0 ) ), "Minimum password length introduced in 5.2.0"); String shortPassword = "123"; - try(GenericContainer failContainer = createContainer( false )) + try(GenericContainer failContainer = HelperContainers.createNeo4jContainer( false )) { if(usePasswordFile) { @@ -348,7 +329,7 @@ void shouldNotWarnAboutMinimumPasswordLengthIfSettingOverridden_env(boolean useP Assumptions.assumeTrue( TestSettings.NEO4J_VERSION.isAtLeastVersion( new Neo4jVersion( 5,2,0 ) ), "Minimum password length introduced in 5.2.0"); String shortPassword = "123"; - try(GenericContainer container = createContainer( false )) + try(GenericContainer container = HelperContainers.createNeo4jContainer( false ).waitingFor(WaitStrategies.waitForBoltReady())) { if(usePasswordFile) { @@ -370,7 +351,7 @@ void shouldNotWarnAboutMinimumPasswordLengthIfSettingOverridden_conf(boolean use Assumptions.assumeTrue( TestSettings.NEO4J_VERSION.isAtLeastVersion( new Neo4jVersion( 5,2,0 ) ), "Minimum password length introduced in 5.2.0"); String shortPassword = "123"; - try(GenericContainer container = createContainer( false )) + try(GenericContainer container = HelperContainers.createNeo4jContainer( false )) { if(usePasswordFile) { diff --git a/src/test/java/com/neo4j/docker/coredb/TestBasic.java b/src/test/java/com/neo4j/docker/coredb/TestBasic.java index bb5b4932..5b225032 100644 --- a/src/test/java/com/neo4j/docker/coredb/TestBasic.java +++ b/src/test/java/com/neo4j/docker/coredb/TestBasic.java @@ -2,14 +2,8 @@ import com.github.dockerjava.api.command.KillContainerCmd; import com.github.dockerjava.api.command.StopContainerCmd; -import com.neo4j.docker.utils.DatabaseIO; -import com.neo4j.docker.utils.Neo4jVersion; -import com.neo4j.docker.utils.TemporaryFolderManager; -import com.neo4j.docker.utils.TestSettings; -import com.neo4j.docker.utils.WaitStrategies; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Assumptions; -import org.junit.jupiter.api.Test; +import com.neo4j.docker.utils.*; +import org.junit.jupiter.api.*; import org.junit.jupiter.api.extension.RegisterExtension; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; @@ -32,201 +26,160 @@ import static com.neo4j.docker.utils.WaitStrategies.waitForBoltReady; import static com.neo4j.docker.utils.WaitStrategies.waitForNeo4jReady; -public class TestBasic -{ - private static Logger log = LoggerFactory.getLogger( TestBasic.class ); +class TestBasic { + private static Logger log = LoggerFactory.getLogger(TestBasic.class); @RegisterExtension public static TemporaryFolderManager temporaryFolderManager = new TemporaryFolderManager(); + public final static GenericContainer NEO4J_CONTAINER = HelperContainers.createNeo4jContainer(false); - private GenericContainer createBasicContainer() - { - GenericContainer container = new GenericContainer( TestSettings.IMAGE_ID ); - container.withEnv( "NEO4J_ACCEPT_LICENSE_AGREEMENT", "yes" ) - .withExposedPorts( 7474, 7687 ) - .withLogConsumer( new Slf4jLogConsumer( log ) ); - return container; + @BeforeAll + public static void before() { + NEO4J_CONTAINER.start(); + Assertions.assertTrue( NEO4J_CONTAINER.isRunning() ); } - @Test - void testListensOn7687() - { - try ( GenericContainer container = createBasicContainer() ) - { - container.waitingFor( waitForNeo4jReady( "neo4j" ) ); - container.start(); - Assertions.assertTrue( container.isRunning() ); - String stdout = container.getLogs(); - Assertions.assertFalse( stdout.contains( "DEBUGGING ENABLED" ), - "Debugging was enabled even though we did not set debugging" ); - } + @AfterAll + public static void after() { + NEO4J_CONTAINER.stop(); + Assertions.assertFalse( NEO4J_CONTAINER.isRunning() ); } @Test - void testNoUnexpectedErrors() - { - Assumptions.assumeFalse( TestSettings.BASE_OS == TestSettings.BaseOS.UBI8, - "UBI8 based images are expected to have a warning in stderr" ); - try ( GenericContainer container = createBasicContainer() ) - { - container.waitingFor( waitForNeo4jReady( "neo4j" ) ); - container.start(); - Assertions.assertTrue( container.isRunning() ); + void testListensOn7687() { + String stdout = NEO4J_CONTAINER.getLogs(); + Assertions.assertFalse(stdout.contains("DEBUGGING ENABLED"), + "Debugging was enabled even though we did not set debugging"); + } - String stderr = container.getLogs( OutputFrame.OutputType.STDERR ); - Assertions.assertEquals( "", stderr, - "Unexpected errors in stderr from container!\n" + - stderr ); - } + @Test + void testNoUnexpectedErrors() { + Assumptions.assumeFalse(TestSettings.BASE_OS == TestSettings.BaseOS.UBI8, + "UBI8 based images are expected to have a warning in stderr"); + + String stderr = NEO4J_CONTAINER.getLogs(OutputFrame.OutputType.STDERR); + Assertions.assertEquals("", stderr, + "Unexpected errors in stderr from container!\n" + + stderr); } @Test - void testLicenseAcceptanceRequired_Neo4jServer() - { - Assumptions.assumeTrue( TestSettings.NEO4J_VERSION.isAtLeastVersion( new Neo4jVersion( 3, 3, 0 ) ), - "No license checks before version 3.3.0" ); - Assumptions.assumeTrue( TestSettings.EDITION == TestSettings.Edition.ENTERPRISE, - "No license checks for community edition" ); + void testLicenseAcceptanceRequired_Neo4jServer() { + Assumptions.assumeTrue(TestSettings.NEO4J_VERSION.isAtLeastVersion(new Neo4jVersion(3, 3, 0)), + "No license checks before version 3.3.0"); + Assumptions.assumeTrue(TestSettings.EDITION == TestSettings.Edition.ENTERPRISE, + "No license checks for community edition"); String logsOut; - try ( GenericContainer container = new GenericContainer( TestSettings.IMAGE_ID ) - .withLogConsumer( new Slf4jLogConsumer( log ) ) ) - { - WaitStrategies.waitUntilContainerFinished( container, Duration.ofSeconds( 30 ) ); + try (GenericContainer container = new GenericContainer(TestSettings.NEO4J_IMAGE_ID) + .withLogConsumer(new Slf4jLogConsumer(log))) { + WaitStrategies.waitUntilContainerFinished(container, Duration.ofSeconds(30)); // container start should fail due to licensing. - Assertions.assertThrows( ContainerLaunchException.class, () -> container.start(), - "Neo4j did not notify about accepting the license agreement" ); + Assertions.assertThrows(ContainerLaunchException.class, () -> container.start(), + "Neo4j did not notify about accepting the license agreement"); logsOut = container.getLogs(); } // double check the container didn't warn and start neo4j anyway - Assertions.assertTrue( logsOut.contains( "must accept the license" ), - "Neo4j did not notify about accepting the license agreement" ); - Assertions.assertFalse( logsOut.contains( "Remote interface available" ), - "Neo4j was started even though the license was not accepted" ); + Assertions.assertTrue(logsOut.contains("must accept the license"), + "Neo4j did not notify about accepting the license agreement"); + Assertions.assertFalse(logsOut.contains("Remote interface available"), + "Neo4j was started even though the license was not accepted"); } @Test - void testLicenseAcceptanceAvoidsWarning() - { - Assumptions.assumeTrue( TestSettings.EDITION == TestSettings.Edition.ENTERPRISE, - "No license checks for community edition" ); - Assumptions.assumeTrue( TestSettings.NEO4J_VERSION.isAtLeastVersion( new Neo4jVersion( 5, 0, 0 ) ), - "No unified license acceptance method before 5.0.0" ); - try ( GenericContainer container = createBasicContainer() ) - { - container.waitingFor( waitForNeo4jReady( "neo4j" ) ); - container.start(); - Assertions.assertTrue( container.isRunning() ); - - String stdout = container.getLogs( OutputFrame.OutputType.STDOUT ); - Assertions.assertTrue( stdout.contains( "The license agreement was accepted with environment variable " + - "NEO4J_ACCEPT_LICENSE_AGREEMENT=yes when the Software was started." ), - "Neo4j did not register that the license was agreed to." ); - } + void testLicenseAcceptanceAvoidsWarning() { + Assumptions.assumeTrue(TestSettings.EDITION == TestSettings.Edition.ENTERPRISE, + "No license checks for community edition"); + Assumptions.assumeTrue(TestSettings.NEO4J_VERSION.isAtLeastVersion(new Neo4jVersion(5, 0, 0)), + "No unified license acceptance method before 5.0.0"); + + String stdout = NEO4J_CONTAINER.getLogs(OutputFrame.OutputType.STDOUT); + Assertions.assertTrue(stdout.contains("The license agreement was accepted with environment variable " + + "NEO4J_ACCEPT_LICENSE_AGREEMENT=yes when the Software was started."), + "Neo4j did not register that the license was agreed to."); } @Test - void testLicenseAcceptanceAvoidsWarning_evaluation() - { - Assumptions.assumeTrue( TestSettings.EDITION == TestSettings.Edition.ENTERPRISE, - "No license checks for community edition" ); - Assumptions.assumeTrue( TestSettings.NEO4J_VERSION.isAtLeastVersion( new Neo4jVersion( 5, 0, 0 ) ), - "No unified license acceptance method before 5.0.0" ); - try ( GenericContainer container = createBasicContainer() ) - { - container.withEnv( "NEO4J_ACCEPT_LICENSE_AGREEMENT", "eval" ) - .waitingFor( waitForNeo4jReady( "neo4j" ) ); + void testLicenseAcceptanceAvoidsWarning_evaluation() { + Assumptions.assumeTrue(TestSettings.EDITION == TestSettings.Edition.ENTERPRISE, + "No license checks for community edition"); + Assumptions.assumeTrue(TestSettings.NEO4J_VERSION.isAtLeastVersion(new Neo4jVersion(5, 0, 0)), + "No unified license acceptance method before 5.0.0"); + try (GenericContainer container = HelperContainers.createNeo4jContainer( false)) { + container.withEnv("NEO4J_ACCEPT_LICENSE_AGREEMENT", "eval"); container.start(); - Assertions.assertTrue( container.isRunning() ); + Assertions.assertTrue(container.isRunning()); - String stdout = container.getLogs( OutputFrame.OutputType.STDOUT ); - Assertions.assertTrue( stdout.contains( "The license agreement was accepted with environment variable " + - "NEO4J_ACCEPT_LICENSE_AGREEMENT=eval when the Software was started." ), - "Neo4j did not register that the evaluation license was agreed to." ); + String stdout = container.getLogs(OutputFrame.OutputType.STDOUT); + Assertions.assertTrue(stdout.contains("The license agreement was accepted with environment variable " + + "NEO4J_ACCEPT_LICENSE_AGREEMENT=eval when the Software was started."), + "Neo4j did not register that the evaluation license was agreed to."); } } @Test - void testCypherShellOnPath() throws Exception - { + void testCypherShellOnPath() throws Exception { String expectedCypherShellPath = "/var/lib/neo4j/bin/cypher-shell"; - try ( GenericContainer container = createBasicContainer() ) - { - container.waitingFor( waitForNeo4jReady( "neo4j" ) ); - container.start(); - - Container.ExecResult whichResult = container.execInContainer( "which", "cypher-shell" ); - Assertions.assertTrue( whichResult.getStdout().contains( expectedCypherShellPath ), - "cypher-shell not on path" ); - } + Container.ExecResult whichResult = NEO4J_CONTAINER.execInContainer("which", "cypher-shell"); + Assertions.assertTrue(whichResult.getStdout().contains(expectedCypherShellPath), + "cypher-shell not on path"); } @Test - void testCanChangeWorkDir() - { - try ( GenericContainer container = createBasicContainer() ) - { - container.waitingFor( waitForNeo4jReady( "neo4j" ) ); - container.setWorkingDirectory( "/tmp" ); - Assertions.assertDoesNotThrow( container::start, - "Could not start neo4j from workdir other than NEO4J_HOME" ); + void testCanChangeWorkDir() { + try (GenericContainer container = HelperContainers.createNeo4jContainer( false)) { + container.waitingFor(waitForNeo4jReady("neo4j")); + container.setWorkingDirectory("/tmp"); + Assertions.assertDoesNotThrow(container::start, + "Could not start neo4j from workdir other than NEO4J_HOME"); } } @Test - void testPackagingInfoContainsDocker() throws Exception - { - Assumptions.assumeTrue( TestSettings.NEO4J_VERSION.isAtLeastVersion( new Neo4jVersion( 5, 0, 0 ) ), - "No packaging_info file before 5.0.0" ); - try ( GenericContainer container = createBasicContainer() ) - { - container.waitingFor( waitForNeo4jReady( "neo4j" ) ); - container.start(); - String packagingInfo = container.execInContainer("cat", "/var/lib/neo4j/packaging_info").getStdout(); - List actualPackageType = Stream.of(packagingInfo.split( "\n" )) - .filter(line -> line.startsWith("Package Type:")) - .toList(); - Assertions.assertEquals(1, actualPackageType.size(), - "There should only be 1 Package Type declarations in the packaging_info:\n"+actualPackageType); - Assertions.assertEquals("Package Type: docker " + TestSettings.BASE_OS.name().toLowerCase(), - actualPackageType.get(0), "Docker packaging type is missing from packaging info file"); - } + void testPackagingInfoContainsDocker() throws Exception { + Assumptions.assumeTrue(TestSettings.NEO4J_VERSION.isAtLeastVersion(new Neo4jVersion(5, 0, 0)), + "No packaging_info file before 5.0.0"); + + String packagingInfo = NEO4J_CONTAINER.execInContainer("cat", "/var/lib/neo4j/packaging_info").getStdout(); + List actualPackageType = Stream.of(packagingInfo.split("\n")) + .filter(line -> line.startsWith("Package Type:")) + .toList(); + Assertions.assertEquals(1, actualPackageType.size(), + "There should only be 1 Package Type declarations in the packaging_info:\n" + actualPackageType); + Assertions.assertEquals("Package Type: docker " + TestSettings.BASE_OS.name().toLowerCase(), + actualPackageType.get(0), "Docker packaging type is missing from packaging info file"); + } - @ParameterizedTest( name = "ShutsDownCorrectly_{0}" ) - @ValueSource( strings = {"SIGTERM", "SIGINT"} ) - void testShutsDownCleanly( String signal ) - { - try ( GenericContainer container = createBasicContainer() ) - { - container.withEnv( "NEO4J_AUTH", "none" ) - .waitingFor( waitForNeo4jReady( "none" ) ); + @ParameterizedTest(name = "ShutsDownCorrectly_{0}") + @ValueSource(strings = {"SIGTERM", "SIGINT"}) + void testShutsDownCleanly(String signal) { + try (GenericContainer container = HelperContainers.createNeo4jContainer( false)) { + container.withEnv("NEO4J_AUTH", "none") + .waitingFor(waitForNeo4jReady("none")); container.start(); - DatabaseIO dbio = new DatabaseIO( container ); - dbio.putInitialDataIntoContainer( "neo4j", "none" ); - try(KillContainerCmd kill = container.getDockerClient().killContainerCmd(container.getContainerId()); - StopContainerCmd stop = container.getDockerClient().stopContainerCmd(container.getContainerId())) - { - log.info( "issuing container stop command " + signal ); + DatabaseIO dbio = new DatabaseIO(container); + dbio.putInitialDataIntoContainer("neo4j", "none"); + try (KillContainerCmd kill = container.getDockerClient().killContainerCmd(container.getContainerId()); + StopContainerCmd stop = container.getDockerClient().stopContainerCmd(container.getContainerId())) { + log.info("issuing container stop command " + signal); kill.withSignal(signal).exec(); log.info("waiting for container to shut down."); stop.withTimeout(30).exec(); } String stdout = container.getLogs(); - Assertions.assertTrue( stdout.contains( "Neo4j Server shutdown initiated by request" ), - "clean shutdown not initiated by " + signal + "\n" + stdout); - Assertions.assertTrue( stdout.contains( "Stopped." ), - "clean shutdown not initiated by " + signal + "\n" + stdout); + Assertions.assertTrue(stdout.contains("Neo4j Server shutdown initiated by request"), + "clean shutdown not initiated by " + signal + "\n" + stdout); + Assertions.assertTrue(stdout.contains("Stopped."), + "clean shutdown not initiated by " + signal + "\n" + stdout); } } @Test - void testStartsWhenDebuggingEnabled() - { - try ( GenericContainer container = createBasicContainer() ) - { - container.withEnv( "NEO4J_DEBUG", "true" ); + void testStartsWhenDebuggingEnabled() { + try (GenericContainer container = HelperContainers.createNeo4jContainer( false)) { + container.withEnv("NEO4J_DEBUG", "true"); container.start(); - Assertions.assertTrue( container.isRunning() ); + Assertions.assertTrue(container.isRunning()); } } @@ -236,45 +189,41 @@ void testStartsWhenDebuggingEnabled() file. In turn this causes the container to not be re-startable. */ @Test - void testContainerCanBeRestartedAfterUnexpectedTermination() throws IOException - { - try ( GenericContainer container = createBasicContainer() ) - { + void testContainerCanBeRestartedAfterUnexpectedTermination() throws IOException { + try (GenericContainer container = HelperContainers.createNeo4jContainer( false)) { int boltHostPort = getUniqueHostPort(); int browserHostPort = getUniqueHostPort(); - container.waitingFor( waitForBoltReady() ); - container.withEnv( "NEO4J_AUTH", "none" ); + container.waitingFor(waitForBoltReady()); + container.withEnv("NEO4J_AUTH", "none"); // Ensuring host ports are constant with container restarts - container.setPortBindings( List.of( browserHostPort + ":7474", boltHostPort + ":7687" ) ); + container.setPortBindings(List.of(browserHostPort + ":7474", boltHostPort + ":7687")); container.start(); // Terminating container with a SIGKILL signal to emulate docker engine (docker desktop) being terminated by user. // This also keeps around the container unlike GenericContainer::stop(), which cleans up everything - log.info( "Terminating container with SIGKILL signal" ); - container.getDockerClient().killContainerCmd( container.getContainerId() ).withSignal( "SIGKILL" ).exec(); + log.info("Terminating container with SIGKILL signal"); + container.getDockerClient().killContainerCmd(container.getContainerId()).withSignal("SIGKILL").exec(); // Restarting the container with DockerClient because the GenericContainer was not terminates and GenericContainer::start() // does not work - log.info( "Starting container" ); - container.getDockerClient().startContainerCmd( container.getContainerId() ).exec(); + log.info("Starting container"); + container.getDockerClient().startContainerCmd(container.getContainerId()).exec(); // Applying the Waiting strategy to ensure container is correctly running, because DockerClient does not check - waitForBoltReady().waitUntilReady( container ); + waitForBoltReady().waitUntilReady(container); } } @Test - void testExtensionScriptIsExecuted() throws IOException - { + void testExtensionScriptIsExecuted() throws IOException { Path scriptFolder = temporaryFolderManager.createFolder("extension_script"); Path script = scriptFolder.resolve("startscript.sh"); Files.writeString(script, "#!/bin/bash\n\necho \"SCRIPT EXECUTED!\""); - try ( GenericContainer container = createBasicContainer() ) - { + try (GenericContainer container = HelperContainers.createNeo4jContainer( false)) { temporaryFolderManager.mountHostFolderAsVolume(container, scriptFolder, "/extension"); container.waitingFor(waitForBoltReady()) .withEnv("EXTENSION_SCRIPT", "/extension/startscript.sh"); diff --git a/src/test/java/com/neo4j/docker/coredb/TestCausalCluster.java b/src/test/java/com/neo4j/docker/coredb/TestCausalCluster.java index a847431c..76e6b955 100644 --- a/src/test/java/com/neo4j/docker/coredb/TestCausalCluster.java +++ b/src/test/java/com/neo4j/docker/coredb/TestCausalCluster.java @@ -52,7 +52,7 @@ void testCausalClusteringBasic() throws Exception int i = 0; for (String line : contentLines) { - editedLines[i] = line.replaceAll("%%IMAGE%%", TestSettings.IMAGE_ID.asCanonicalNameString()); + editedLines[i] = line.replaceAll("%%IMAGE%%", TestSettings.NEO4J_IMAGE_ID.asCanonicalNameString()); editedLines[i] = editedLines[i].replaceAll("%%LOGS_DIR%%", tmpDir.toAbsolutePath().toString()); editedLines[i] = editedLines[i].replaceAll("%%USERIDGROUPID%%", SetContainerUser.getNonRootUserString()); i++; diff --git a/src/test/java/com/neo4j/docker/coredb/TestMounting.java b/src/test/java/com/neo4j/docker/coredb/TestMounting.java index 97ad1b4d..57c29c21 100644 --- a/src/test/java/com/neo4j/docker/coredb/TestMounting.java +++ b/src/test/java/com/neo4j/docker/coredb/TestMounting.java @@ -66,7 +66,7 @@ private GenericContainer setupBasicContainer( boolean asCurrentUser, boolean isS asCurrentUser ? "non-root" : "root", isSecurityFlagSet ? "with secure file permissions" : "with unsecured file permissions" ); - GenericContainer container = new GenericContainer( TestSettings.IMAGE_ID ); + GenericContainer container = new GenericContainer( TestSettings.NEO4J_IMAGE_ID); container.withExposedPorts( 7474, 7687 ) .withLogConsumer( new Slf4jLogConsumer( log ) ) .withEnv( "NEO4J_ACCEPT_LICENSE_AGREEMENT", "yes" ) diff --git a/src/test/java/com/neo4j/docker/coredb/TestSSL.java b/src/test/java/com/neo4j/docker/coredb/TestSSL.java index 59c16d26..6f220015 100644 --- a/src/test/java/com/neo4j/docker/coredb/TestSSL.java +++ b/src/test/java/com/neo4j/docker/coredb/TestSSL.java @@ -55,7 +55,7 @@ private void assumeFIPSCompatible() private GenericContainer createContainer() { - GenericContainer container = new GenericContainer<>(TestSettings.IMAGE_ID) + GenericContainer container = new GenericContainer<>(TestSettings.NEO4J_IMAGE_ID) .withEnv("NEO4J_ACCEPT_LICENSE_AGREEMENT", "yes") .withEnv("NEO4J_AUTH", "neo4j/"+PASSWORD) .withEnv("NEO4J_DEBUG", "yes") diff --git a/src/test/java/com/neo4j/docker/coredb/TestUpgrade.java b/src/test/java/com/neo4j/docker/coredb/TestUpgrade.java index 81432bee..5634e31a 100644 --- a/src/test/java/com/neo4j/docker/coredb/TestUpgrade.java +++ b/src/test/java/com/neo4j/docker/coredb/TestUpgrade.java @@ -11,13 +11,11 @@ import com.neo4j.docker.utils.TestSettings; import java.io.IOException; import java.nio.file.Path; -import java.time.Duration; import java.util.Arrays; import java.util.List; import java.util.Random; import java.util.function.Consumer; -import com.neo4j.docker.utils.WaitStrategies; import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.extension.RegisterExtension; import org.junit.jupiter.params.ParameterizedTest; @@ -148,7 +146,7 @@ private void testUpgradeFileMounts( Neo4jVersion upgradeFrom ) throws IOExceptio container.getDockerClient().stopContainerCmd( container.getContainerId() ).exec(); } - try(GenericContainer container = makeContainer( TestSettings.IMAGE_ID )) + try(GenericContainer container = makeContainer( TestSettings.NEO4J_IMAGE_ID)) { temporaryFolderManager.mountHostFolderAsVolume( container, data, "/data" ); temporaryFolderManager.mountHostFolderAsVolume( container, logs, "/logs" ); @@ -185,7 +183,7 @@ private void testUpgradeNamedVolumes( Neo4jVersion upgradeFrom ) container.getDockerClient().stopContainerCmd( container.getContainerId() ).exec(); } - try(GenericContainer container = makeContainer( TestSettings.IMAGE_ID )) + try(GenericContainer container = makeContainer( TestSettings.NEO4J_IMAGE_ID)) { container.withCreateContainerCmdModifier( (Consumer) cmd -> cmd.getHostConfig().withBinds( diff --git a/src/test/java/com/neo4j/docker/coredb/configurations/TestConfSettings.java b/src/test/java/com/neo4j/docker/coredb/configurations/TestConfSettings.java index 77a3cac0..3174911f 100644 --- a/src/test/java/com/neo4j/docker/coredb/configurations/TestConfSettings.java +++ b/src/test/java/com/neo4j/docker/coredb/configurations/TestConfSettings.java @@ -54,7 +54,7 @@ static void getVersionSpecificConfigurationSettings() private GenericContainer createContainer() { - return new GenericContainer(TestSettings.IMAGE_ID) + return new GenericContainer(TestSettings.NEO4J_IMAGE_ID) .withEnv("NEO4J_AUTH", AUTH) .withEnv("NEO4J_ACCEPT_LICENSE_AGREEMENT", "yes") .withExposedPorts(7474, 7687) diff --git a/src/test/java/com/neo4j/docker/coredb/configurations/TestExtendedConf.java b/src/test/java/com/neo4j/docker/coredb/configurations/TestExtendedConf.java index b853cc14..191d134d 100644 --- a/src/test/java/com/neo4j/docker/coredb/configurations/TestExtendedConf.java +++ b/src/test/java/com/neo4j/docker/coredb/configurations/TestExtendedConf.java @@ -56,7 +56,7 @@ static void createVersionSpecificConfigurationSettings() { protected GenericContainer createContainer(String password) { - GenericContainer container = new GenericContainer( TestSettings.IMAGE_ID ) + GenericContainer container = new GenericContainer( TestSettings.NEO4J_IMAGE_ID) .withEnv( "NEO4J_AUTH", password == null || password.isEmpty() ? "none" : "neo4j/" + password ) .withEnv( "NEO4J_ACCEPT_LICENSE_AGREEMENT", "yes" ) .withEnv( "EXTENDED_CONF", "true" ) diff --git a/src/test/java/com/neo4j/docker/coredb/configurations/TestJVMAdditionalConfig.java b/src/test/java/com/neo4j/docker/coredb/configurations/TestJVMAdditionalConfig.java index ec28e198..68348722 100644 --- a/src/test/java/com/neo4j/docker/coredb/configurations/TestJVMAdditionalConfig.java +++ b/src/test/java/com/neo4j/docker/coredb/configurations/TestJVMAdditionalConfig.java @@ -41,7 +41,7 @@ static void getVersionSpecificConfigurationSettings() private GenericContainer createContainer() { - return new GenericContainer(TestSettings.IMAGE_ID) + return new GenericContainer(TestSettings.NEO4J_IMAGE_ID) .withEnv("NEO4J_AUTH", AUTH) .withEnv("NEO4J_DEBUG", AUTH) .withEnv("NEO4J_ACCEPT_LICENSE_AGREEMENT", "yes") diff --git a/src/test/java/com/neo4j/docker/coredb/plugins/TestBundledPluginInstallation.java b/src/test/java/com/neo4j/docker/coredb/plugins/TestBundledPluginInstallation.java index 1d2c8b40..e937e4dc 100644 --- a/src/test/java/com/neo4j/docker/coredb/plugins/TestBundledPluginInstallation.java +++ b/src/test/java/com/neo4j/docker/coredb/plugins/TestBundledPluginInstallation.java @@ -1,10 +1,6 @@ package com.neo4j.docker.coredb.plugins; -import com.neo4j.docker.utils.DatabaseIO; -import com.neo4j.docker.utils.Neo4jVersion; -import com.neo4j.docker.utils.WaitStrategies; -import com.neo4j.docker.utils.TemporaryFolderManager; -import com.neo4j.docker.utils.TestSettings; +import com.neo4j.docker.utils.*; import org.jetbrains.annotations.Nullable; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assumptions; @@ -91,21 +87,12 @@ static Stream bundledPluginsArgs() { ); } - private GenericContainer createContainer() - { - GenericContainer container = new GenericContainer( TestSettings.IMAGE_ID ); - container.withEnv( "NEO4J_AUTH", "none" ) - .withEnv( "NEO4J_ACCEPT_LICENSE_AGREEMENT", "yes" ) - .withEnv("NEO4J_DEBUG", "yes") - .withExposedPorts( 7474, 7687 ) - .withLogConsumer( new Slf4jLogConsumer( log ) ) - .waitingFor( WaitStrategies.waitForBoltReady() ); - return container; - } - private GenericContainer createContainerWithBundledPlugin(BundledPlugin plugin) { - return createContainer().withEnv( Neo4jPluginEnv.get(), "[\"" +plugin.name+ "\"]" ); + return HelperContainers.createNeo4jContainer( false ) + .withEnv( Neo4jPluginEnv.get(), "[\"" +plugin.name+ "\"]" ) + .withEnv( "NEO4J_AUTH", "none" ) + .waitingFor(WaitStrategies.waitForBoltReady()); } @ParameterizedTest(name = "testBundledPlugin_{0}") @@ -253,7 +240,7 @@ void testPluginLoadsWithAuthentication() throws Exception @Test void testBrowserListensOn7474() { - try(GenericContainer container = createContainer()) + try(GenericContainer container = HelperContainers.createNeo4jContainer( false )) { container.waitingFor( new HttpWaitStrategy() .forPort(7474) diff --git a/src/test/java/com/neo4j/docker/coredb/plugins/TestPluginInstallation.java b/src/test/java/com/neo4j/docker/coredb/plugins/TestPluginInstallation.java index 4272acbd..15938b31 100644 --- a/src/test/java/com/neo4j/docker/coredb/plugins/TestPluginInstallation.java +++ b/src/test/java/com/neo4j/docker/coredb/plugins/TestPluginInstallation.java @@ -80,7 +80,7 @@ private class VersionsJsonEntry private GenericContainer createContainerWithTestingPlugin() { Testcontainers.exposeHostPorts( httpServer.PORT ); - GenericContainer container = new GenericContainer( TestSettings.IMAGE_ID ); + GenericContainer container = new GenericContainer( TestSettings.NEO4J_IMAGE_ID); container.withEnv( "NEO4J_AUTH", DB_USER + "/" + DB_PASSWORD ) .withEnv( "NEO4J_ACCEPT_LICENSE_AGREEMENT", "yes" ) @@ -98,7 +98,7 @@ private GenericContainer setupContainerWithUser( boolean asCurrentUser ) log.info( "Running as user {}, {}", asCurrentUser ? "non-root" : "root" ); - GenericContainer container = new GenericContainer( TestSettings.IMAGE_ID ); + GenericContainer container = new GenericContainer( TestSettings.NEO4J_IMAGE_ID); container.withExposedPorts( 7474, 7687 ) .withLogConsumer( new Slf4jLogConsumer( log ) ) .withEnv( "NEO4J_ACCEPT_LICENSE_AGREEMENT", "yes" ) @@ -257,7 +257,7 @@ public void testPluginConfigurationDoesNotOverrideUserSetValues() throws Excepti void invalidPluginNameShouldGiveOptionsAndError() { Assumptions.assumeTrue( NEO4J_VERSION.isAtLeastVersion( Neo4jVersion.NEO4J_VERSION_440 ) ); - try ( GenericContainer container = new GenericContainer( TestSettings.IMAGE_ID ) ) + try ( GenericContainer container = new GenericContainer( TestSettings.NEO4J_IMAGE_ID) ) { // if we try to set a plugin that doesn't exist container.withEnv( Neo4jPluginEnv.get(), "[\"notarealplugin\"]" ) @@ -276,7 +276,7 @@ void invalidPluginNameShouldGiveOptionsAndError() void invalidPluginNameShouldGiveOptionsAndError_mulitpleplugins() { Assumptions.assumeTrue( NEO4J_VERSION.isAtLeastVersion( Neo4jVersion.NEO4J_VERSION_440 ) ); - try ( GenericContainer container = new GenericContainer( TestSettings.IMAGE_ID ) ) + try ( GenericContainer container = new GenericContainer( TestSettings.NEO4J_IMAGE_ID) ) { // if we try to set a plugin that doesn't exist container.withEnv( Neo4jPluginEnv.get(), "[\"apoc\", \"notarealplugin\"]" ) diff --git a/src/test/java/com/neo4j/docker/neo4jadmin/TestAdminBasic.java b/src/test/java/com/neo4j/docker/neo4jadmin/TestAdminBasic.java index 3e697e72..4404bdfd 100644 --- a/src/test/java/com/neo4j/docker/neo4jadmin/TestAdminBasic.java +++ b/src/test/java/com/neo4j/docker/neo4jadmin/TestAdminBasic.java @@ -20,7 +20,7 @@ public class TestAdminBasic @Test void testCannotRunNeo4j() { - GenericContainer admin = new GenericContainer( TestSettings.ADMIN_IMAGE_ID ); + GenericContainer admin = new GenericContainer( TestSettings.NEO4J_ADMIN_IMAGE_ID); admin.withEnv( "NEO4J_ACCEPT_LICENSE_AGREEMENT", "yes" ) .withExposedPorts( 7474, 7687 ) .withLogConsumer( new Slf4jLogConsumer( log ) ) @@ -37,7 +37,7 @@ void testLicenseAcceptanceRequired_Neo4jAdmin() "No license checks for community edition"); String logsOut; - try(GenericContainer container = new GenericContainer( TestSettings.ADMIN_IMAGE_ID ) + try(GenericContainer container = new GenericContainer( TestSettings.NEO4J_ADMIN_IMAGE_ID) .withLogConsumer( new Slf4jLogConsumer( log ) ) ) { WaitStrategies.waitUntilContainerFinished( container, Duration.ofSeconds( 30) ); diff --git a/src/test/java/com/neo4j/docker/neo4jadmin/TestBackupRestore.java b/src/test/java/com/neo4j/docker/neo4jadmin/TestBackupRestore.java index 03492172..d56df8e6 100644 --- a/src/test/java/com/neo4j/docker/neo4jadmin/TestBackupRestore.java +++ b/src/test/java/com/neo4j/docker/neo4jadmin/TestBackupRestore.java @@ -52,7 +52,7 @@ private GenericContainer createDBContainer( boolean asDefaultUser, String passwo auth = "neo4j/"+password; } Map confNames = Configuration.getConfigurationNameMap(); - GenericContainer container = new GenericContainer( TestSettings.IMAGE_ID ); + GenericContainer container = new GenericContainer( TestSettings.NEO4J_IMAGE_ID); container.withEnv( "NEO4J_AUTH", auth ) .withEnv( "NEO4J_ACCEPT_LICENSE_AGREEMENT", "yes" ) .withEnv( confNames.get( Setting.BACKUP_ENABLED ).envName, "true" ) @@ -69,7 +69,7 @@ private GenericContainer createDBContainer( boolean asDefaultUser, String passwo private GenericContainer createAdminContainer( boolean asDefaultUser ) { - GenericContainer container = new GenericContainer( TestSettings.ADMIN_IMAGE_ID ); + GenericContainer container = new GenericContainer( TestSettings.NEO4J_ADMIN_IMAGE_ID); container.withEnv( "NEO4J_ACCEPT_LICENSE_AGREEMENT", "yes" ) .withLogConsumer( new Slf4jLogConsumer( log ) ); WaitStrategies.waitUntilContainerFinished( container, Duration.ofSeconds( 180) ); diff --git a/src/test/java/com/neo4j/docker/neo4jadmin/TestBackupRestore44.java b/src/test/java/com/neo4j/docker/neo4jadmin/TestBackupRestore44.java index 28abdae6..679d9401 100644 --- a/src/test/java/com/neo4j/docker/neo4jadmin/TestBackupRestore44.java +++ b/src/test/java/com/neo4j/docker/neo4jadmin/TestBackupRestore44.java @@ -50,7 +50,7 @@ private GenericContainer createDBContainer( boolean asDefaultUser, String passwo auth = "neo4j/"+password; } Map confNames = Configuration.getConfigurationNameMap(); - GenericContainer container = new GenericContainer( TestSettings.IMAGE_ID ); + GenericContainer container = new GenericContainer( TestSettings.NEO4J_IMAGE_ID); container.withEnv( "NEO4J_AUTH", auth ) .withEnv( "NEO4J_ACCEPT_LICENSE_AGREEMENT", "yes" ) .withEnv( confNames.get( Setting.BACKUP_ENABLED ).envName, "true" ) @@ -67,7 +67,7 @@ private GenericContainer createDBContainer( boolean asDefaultUser, String passwo private GenericContainer createAdminContainer( boolean asDefaultUser ) { - GenericContainer container = new GenericContainer( TestSettings.ADMIN_IMAGE_ID ); + GenericContainer container = new GenericContainer( TestSettings.NEO4J_ADMIN_IMAGE_ID); container.withEnv( "NEO4J_ACCEPT_LICENSE_AGREEMENT", "yes" ) .withLogConsumer( new Slf4jLogConsumer( log ) ); WaitStrategies.waitUntilContainerFinished( container, Duration.ofSeconds( 180) ); diff --git a/src/test/java/com/neo4j/docker/neo4jadmin/TestDumpLoad.java b/src/test/java/com/neo4j/docker/neo4jadmin/TestDumpLoad.java index 70bccd33..c6a582b1 100644 --- a/src/test/java/com/neo4j/docker/neo4jadmin/TestDumpLoad.java +++ b/src/test/java/com/neo4j/docker/neo4jadmin/TestDumpLoad.java @@ -42,7 +42,7 @@ private GenericContainer createDBContainer( boolean asDefaultUser, String passwo auth = "neo4j/"+password; } - GenericContainer container = new GenericContainer( TestSettings.IMAGE_ID ); + GenericContainer container = new GenericContainer( TestSettings.NEO4J_IMAGE_ID); container.withEnv( "NEO4J_AUTH", auth ) .withEnv( "NEO4J_ACCEPT_LICENSE_AGREEMENT", "yes" ) .withExposedPorts( 7474, 7687 ) @@ -57,7 +57,7 @@ private GenericContainer createDBContainer( boolean asDefaultUser, String passwo private GenericContainer createAdminContainer( boolean asDefaultUser ) { - GenericContainer container = new GenericContainer( TestSettings.ADMIN_IMAGE_ID ); + GenericContainer container = new GenericContainer( TestSettings.NEO4J_ADMIN_IMAGE_ID); container.withEnv( "NEO4J_ACCEPT_LICENSE_AGREEMENT", "yes" ) .withExposedPorts( 7474, 7687 ) .withLogConsumer( new Slf4jLogConsumer( log ) ) diff --git a/src/test/java/com/neo4j/docker/neo4jadmin/TestDumpLoad44.java b/src/test/java/com/neo4j/docker/neo4jadmin/TestDumpLoad44.java index 3cbd106d..0e7646c9 100644 --- a/src/test/java/com/neo4j/docker/neo4jadmin/TestDumpLoad44.java +++ b/src/test/java/com/neo4j/docker/neo4jadmin/TestDumpLoad44.java @@ -46,7 +46,7 @@ private GenericContainer createDBContainer( boolean asDefaultUser, String passwo auth = "neo4j/"+password; } - GenericContainer container = new GenericContainer( TestSettings.IMAGE_ID ); + GenericContainer container = new GenericContainer( TestSettings.NEO4J_IMAGE_ID); container.withEnv( "NEO4J_AUTH", auth ) .withEnv( "NEO4J_ACCEPT_LICENSE_AGREEMENT", "yes" ) .withExposedPorts( 7474, 7687 ) @@ -66,7 +66,7 @@ private GenericContainer createDBContainer( boolean asDefaultUser, String passwo private GenericContainer createAdminContainer( boolean asDefaultUser ) { - GenericContainer container = new GenericContainer( TestSettings.ADMIN_IMAGE_ID ); + GenericContainer container = new GenericContainer( TestSettings.NEO4J_ADMIN_IMAGE_ID); container.withEnv( "NEO4J_ACCEPT_LICENSE_AGREEMENT", "yes" ) .withExposedPorts( 7474, 7687 ) .withLogConsumer( new Slf4jLogConsumer( log ) ) diff --git a/src/test/java/com/neo4j/docker/neo4jadmin/TestReport.java b/src/test/java/com/neo4j/docker/neo4jadmin/TestReport.java index 66f1b609..3bb1af69 100644 --- a/src/test/java/com/neo4j/docker/neo4jadmin/TestReport.java +++ b/src/test/java/com/neo4j/docker/neo4jadmin/TestReport.java @@ -18,7 +18,7 @@ public class TestReport private GenericContainer createAdminContainer() { - GenericContainer container = new GenericContainer( TestSettings.ADMIN_IMAGE_ID ) + GenericContainer container = new GenericContainer( TestSettings.NEO4J_ADMIN_IMAGE_ID) .withEnv( "NEO4J_ACCEPT_LICENSE_AGREEMENT", "yes" ).withEnv( "NEO4J_DEBUG", "yes" ) .withCommand( "neo4j-admin", "server", "report" ) .withLogConsumer( new Slf4jLogConsumer( log ) ); diff --git a/src/test/java/com/neo4j/docker/utils/HelperContainers.java b/src/test/java/com/neo4j/docker/utils/HelperContainers.java index e7a3ab95..93dc02d6 100644 --- a/src/test/java/com/neo4j/docker/utils/HelperContainers.java +++ b/src/test/java/com/neo4j/docker/utils/HelperContainers.java @@ -1,13 +1,21 @@ package com.neo4j.docker.utils; +import org.junit.jupiter.api.Assertions; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.testcontainers.containers.GenericContainer; +import org.testcontainers.containers.output.Slf4jLogConsumer; import org.testcontainers.containers.wait.strategy.Wait; import org.testcontainers.utility.DockerImageName; import java.time.Duration; +import static com.neo4j.docker.utils.WaitStrategies.waitForNeo4jReady; + public class HelperContainers { + private static Logger log = LoggerFactory.getLogger( HelperContainers.class ); + public static GenericContainer nginx() { return new GenericContainer(DockerImageName.parse("nginx:latest")) @@ -15,4 +23,18 @@ public static GenericContainer nginx() .waitingFor(Wait.forHttp("/") .withStartupTimeout(Duration.ofSeconds(20))); } + + public static GenericContainer createNeo4jContainer( boolean asCurrentUser ) + { + GenericContainer container = new GenericContainer( TestSettings.NEO4J_IMAGE_ID); + container.withEnv( "NEO4J_ACCEPT_LICENSE_AGREEMENT", "yes" ) + .withExposedPorts( 7474, 7687 ) + .withLogConsumer( new Slf4jLogConsumer( log ) ) + .waitingFor( waitForNeo4jReady( "neo4j" ) ); + if(asCurrentUser) + { + SetContainerUser.nonRootUser( container ); + } + return container; + } } diff --git a/src/test/java/com/neo4j/docker/utils/TestSettings.java b/src/test/java/com/neo4j/docker/utils/TestSettings.java index 7741b870..31497245 100644 --- a/src/test/java/com/neo4j/docker/utils/TestSettings.java +++ b/src/test/java/com/neo4j/docker/utils/TestSettings.java @@ -9,8 +9,8 @@ public class TestSettings { public static final Neo4jVersion NEO4J_VERSION = getVersion(); - public static final DockerImageName IMAGE_ID = getImage(); - public static final DockerImageName ADMIN_IMAGE_ID = getNeo4jAdminImage(); + public static final DockerImageName NEO4J_IMAGE_ID = getNeo4jImage(); + public static final DockerImageName NEO4J_ADMIN_IMAGE_ID = getNeo4jAdminImage(); public static final Path TEST_TMP_FOLDER = Paths.get("local-mounts" ); public static final Edition EDITION = getEdition(); public static final BaseOS BASE_OS = getBaseOS(); @@ -47,7 +47,7 @@ private static Neo4jVersion getVersion() return Neo4jVersion.fromVersionString( getValueFromPropertyOrEnv( "version", "NEO4JVERSION" )); } - private static DockerImageName getImage() + private static DockerImageName getNeo4jImage() { return DockerImageName.parse(getValueFromPropertyOrEnv("image", "NEO4J_IMAGE")); }