Skip to content

Commit

Permalink
[Fb3ZFQbn] Adds cypher initializer test
Browse files Browse the repository at this point in the history
  • Loading branch information
ncordon committed Apr 28, 2023
1 parent 4d0e647 commit f0a4aea
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions it/src/test/java/apoc/it/core/StartupTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
import org.neo4j.driver.Session;

import java.util.List;
import java.util.stream.Collectors;
import java.util.concurrent.TimeUnit;import java.util.stream.Collectors;

import static apoc.util.TestContainerUtil.createDB;
import static apoc.util.TestContainerUtil.dockerImageForNeo4j;
import static apoc.util.TestContainerUtil.createEnterpriseDB;import static apoc.util.TestContainerUtil.dockerImageForNeo4j;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assert.fail;import static org.neo4j.test.assertion.Assert.assertEventually;

/*
This test is just to verify if the APOC procedures and functions are correctly deployed into a Neo4j instance without any startup issue.
Expand Down Expand Up @@ -61,6 +61,36 @@ public void check_basic_deployment() {
}
}

@Test
public void check_cypherInitializer_waits_for_systemDb_to_be_available() {
// we check that with apoc-core jar and all extra-dependencies jars every procedure/function is detected
var version = Neo4jVersion.ENTERPRISE;
try {
Neo4jContainerExtension neo4jContainer = createDB(version, List.of(ApocPackage.CORE), !TestUtil.isRunningInCI())
.withEnv("apoc.initializer.system.0", "CREATE USER dummy IF NOT EXISTS SET PASSWORD \"pass12345\" CHANGE NOT REQUIRED")
.withEnv("apoc.initializer.system.1", "GRANT ROLE reader TO dummy");
neo4jContainer.start();

try (Session session = neo4jContainer.getSession()) {
assertEventually(() ->
session.run( "SHOW USERS YIELD roles, user WHERE user = 'dummy' RETURN roles" ).stream()
.collect( Collectors.toList() ), (result) ->
result.size() > 0 && result.get(0).get( "roles" ).asList().contains("reader" ),
30, TimeUnit.SECONDS
);
}

neo4jContainer.close();
} catch (Exception ex) {
if (TestContainerUtil.isDockerImageAvailable(ex)) {
ex.printStackTrace();
fail("Should not have thrown exception when trying to start Neo4j: " + ex);
} else {
fail( "The docker image " + dockerImageForNeo4j(version) + " could not be loaded. Check whether it's available locally / in the CI. Exception:" + ex);
}
}
}

@Test
public void compare_with_sources() {
for (var version: Neo4jVersion.values()) {
Expand Down

0 comments on commit f0a4aea

Please sign in to comment.