This is a JUnit Jupiter extension that provides a Neo4j Causal Cluster for JUnit based integration tests.
Warning
|
This software requires the use of the Neo4j Enterprise Edition via the official enterprise Docker Image.
You need to have a valid commercial license in order to use the Enterprise Edition. Using an enterprise Docker image will require you to accept the official Enterprise license agreement. |
Declare the extension as Maven dependency:
<dependency>
<groupId>eu.michael-simons.neo4j</groupId>
<artifactId>junit-jupiter-causal-cluster-testcontainer-extension</artifactId>
<version>2022.1.8</version>
<scope>test</scope>
</dependency>
You also need the Neo4j Java Driver, but I guess you already have that in your application:
<dependency>
<groupId>org.neo4j.driver</groupId>
<artifactId>neo4j-java-driver</artifactId>
<version>${neo4j-java-driver.version}</version>
</dependency>
A test against a causal cluster now looks like this:
import java.net.URI;
import org.junit.jupiter.api.Test;
import org.neo4j.driver.AuthToken;
import org.neo4j.driver.AuthTokens;
import org.neo4j.driver.Driver;
import org.neo4j.driver.GraphDatabase;
import org.neo4j.driver.Session;
import org.neo4j.junit.jupiter.causal_cluster.CausalCluster;import org.neo4j.junit.jupiter.causal_cluster.NeedsCausalCluster;
import org.neo4j.junit.jupiter.causal_cluster.Neo4jUri;
@NeedsCausalCluster(password = PASSWORD) // (1)
public class SimpleTest {
static final String USERNAME = "neo4j";
static final String PASSWORD = "cc";
@CausalCluster // (2)
private static URI neo4jUri;
@Test
void aTest() {
AuthToken authToken = AuthTokens.basic(USERNAME, PASSWORD);
try (
Driver driver = GraphDatabase.driver(neo4jUri, authToken);
Session session = driver.session();
) {
session.run("MATCH (n) RETURN n").list();
}
}
}
-
Register the extension and set a password (Default is
password
) -
Mark a field as
@CausalCluster
. The field can be of typeURI
orString
and will contain aneo4j://
uri into the cluster
For more advanced test, you can also annotate a field of type List<URI>
or List<String>
with @CausalCluster
to get all external entry points into the cluster.
To retrieve the whole cluster, annotate exactly one field of type Neo4jCluster
with @CausalCluster
.
A custom version can be used by setting the appropriate attribute:
@NeedsCausalCluster(neo4jVersion = "3.5.16")
public class SimpleTest {
}