diff --git a/core/src/test/java/apoc/cypher/CypherInitializerTest.java b/core/src/test/java/apoc/cypher/CypherInitializerTest.java index 58101d7a3..98fa9acaa 100644 --- a/core/src/test/java/apoc/cypher/CypherInitializerTest.java +++ b/core/src/test/java/apoc/cypher/CypherInitializerTest.java @@ -25,13 +25,16 @@ import apoc.util.TestUtil; import apoc.util.Utils; import apoc.util.collection.Iterators; +import org.hamcrest.Matchers; import org.junit.After; import org.junit.Before; +import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.junit.rules.RuleChain; import java.util.Collections; +import java.util.Map; import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.kernel.availability.AvailabilityListener; @@ -40,6 +43,7 @@ import org.neo4j.test.rule.ImpermanentDbmsRule; import static apoc.ApocConfig.APOC_CONFIG_INITIALIZER; +import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertEquals; import static org.neo4j.configuration.GraphDatabaseSettings.DEFAULT_DATABASE_NAME; import static org.neo4j.configuration.GraphDatabaseSettings.SYSTEM_DATABASE_NAME; @@ -135,6 +139,17 @@ public void multipleInitializersWorks2() { expectNodeCount(1); } + @Ignore // TODO This should work according to the documentation + @Env({ + @EnvSetting(key= APOC_CONFIG_INITIALIZER + "." + SYSTEM_DATABASE_NAME + ".0", value="create database hellohi if not exists") + }) + public void createDbInInitialize() { + GraphDatabaseService systemDb = dbmsRule.getManagementService().database(SYSTEM_DATABASE_NAME); + final var databases = systemDb + .executeTransactionally( "show databases yield name", Map.of(), res -> res.stream().map(r -> r.get("name")).toList()); + assertThat(databases, Matchers.hasItem("hellohi")); + } + @Test @Env({ // this only creates 2 nodes if the statements run in same order @EnvSetting(key= APOC_CONFIG_INITIALIZER + "." + SYSTEM_DATABASE_NAME, value="create user dummy set password 'abcd1234'") diff --git a/it/src/test/java/apoc/it/core/TriggerEnterpriseFeaturesTest.java b/it/src/test/java/apoc/it/core/TriggerEnterpriseFeaturesTest.java index 6a71585c3..d4ca059bc 100644 --- a/it/src/test/java/apoc/it/core/TriggerEnterpriseFeaturesTest.java +++ b/it/src/test/java/apoc/it/core/TriggerEnterpriseFeaturesTest.java @@ -24,6 +24,7 @@ import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; + import org.neo4j.driver.AuthTokens; import org.neo4j.driver.Driver; import org.neo4j.driver.GraphDatabase; @@ -37,7 +38,6 @@ import java.util.concurrent.TimeUnit; import java.util.stream.Stream; -import static apoc.ApocConfig.APOC_CONFIG_INITIALIZER; import static apoc.ApocConfig.APOC_TRIGGER_ENABLED; import static apoc.SystemPropertyKeys.database; import static apoc.trigger.TriggerHandler.TRIGGER_REFRESH; @@ -57,6 +57,7 @@ import static org.neo4j.driver.SessionConfig.forDatabase; import static org.neo4j.test.assertion.Assert.assertEventually; + public class TriggerEnterpriseFeaturesTest { private static final String FOO_DB = "foo"; private static final String INIT_DB = "initdb"; @@ -68,26 +69,25 @@ public class TriggerEnterpriseFeaturesTest { private static Session session; @BeforeClass - public static void beforeAll() { - final String cypherInitializer = String.format("%s.%s.0", - APOC_CONFIG_INITIALIZER, SYSTEM_DATABASE_NAME); - final String createInitDb = String.format("CREATE DATABASE %s IF NOT EXISTS", INIT_DB); + public static void beforeAll() + { + //final String cypherInitializer = String.format("%s.%s.0", APOC_CONFIG_INITIALIZER, SYSTEM_DATABASE_NAME); + //final String createInitDb = String.format("CREATE DATABASE %s IF NOT EXISTS", INIT_DB); // We build the project, the artifact will be placed into ./build/libs neo4jContainer = createEnterpriseDB(List.of(TestContainerUtil.ApocPackage.CORE), true) .withEnv(APOC_TRIGGER_ENABLED, "true") - .withEnv(TRIGGER_REFRESH, String.valueOf(TRIGGER_DEFAULT_REFRESH)) - .withEnv(cypherInitializer, createInitDb); + .withEnv(TRIGGER_REFRESH, String.valueOf(TRIGGER_DEFAULT_REFRESH)); + //.withEnv(cypherInitializer, createInitDb); // TODO Bug in initializer prevents us from doing this neo4jContainer.start(); session = neo4jContainer.getSession(); assertTrue(neo4jContainer.isRunning()); - try (Session sysSession = neo4jContainer.getDriver().session(forDatabase(SYSTEM_DATABASE_NAME))) { - sysSession.writeTransaction(tx -> tx.run(String.format("CREATE DATABASE %s WAIT;", FOO_DB))); - - sysSession.run(String.format("CREATE USER %s SET PASSWORD '%s' SET PASSWORD CHANGE NOT REQUIRED", - NO_ADMIN_USER, NO_ADMIN_PWD)); + try (final var sysSession = neo4jContainer.getDriver().session(forDatabase(SYSTEM_DATABASE_NAME))) { + sysSession.run("CREATE DATABASE %s WAIT".formatted(FOO_DB)).consume(); + sysSession.run("CREATE DATABASE %s WAIT".formatted(INIT_DB)).consume(); + sysSession.run("CREATE USER %s SET PASSWORD '%s' SET PASSWORD CHANGE NOT REQUIRED".formatted(NO_ADMIN_USER, NO_ADMIN_PWD)).consume(); } }