Package org.neo4j.harness.junit.rule
Class Neo4jRule
java.lang.Object
org.neo4j.harness.junit.rule.Neo4jRule
- All Implemented Interfaces:
org.junit.rules.TestRule
- Direct Known Subclasses:
EnterpriseNeo4jRule
Community Neo4j JUnit
rule
.
Allows easily start neo4j instance for testing purposes with various user-provided options and configurations.
By default it will try to start neo4j with embedded web server on random ports. Therefore it is necessary
for the test code to use httpURI()
and then URI.resolve(String)
to create the URIs to be invoked.
In case if starting embedded web server is not desirable it can be fully disabled by using withDisabledServer()
configuration option.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionorg.junit.runners.model.Statement
apply
(org.junit.runners.model.Statement base, org.junit.runner.Description description) boltURI()
Returns the URI to the Bolt Protocol connector of the instance.config()
Returns the server's configuration.Pre-populate the server with databases copied from the specified source directory.Access theDatabaseManagementService
used by the server.Access default database service.Dump available logs on failure.Dump available logs on failure.httpsURI()
Returns ths URI to the root resource of the instance using the https protocol.httpURI()
Returns the URI to the root resource of the instance.withAggregationFunction
(Class<?> functionClass) Configure the server to load the specified aggregation function definition class.<T> Neo4jRule
withConfig
(Setting<T> key, T value) Configure the Neo4j instance.Disable web server on configured Neo4j instance.withFixture
(String fixtureStatement) Data fixture to inject upon server build.withFixture
(Path cypherFileOrDirectory) Data fixtures to inject upon server build.withFixture
(Function<GraphDatabaseService, Void> fixtureFunction) Data fixture to inject upon server build.withFunction
(Class<?> functionClass) Configure the server to load the specified function definition class.withProcedure
(Class<?> procedureClass) Configure the server to load the specified procedure definition class.withUnmanagedExtension
(String mountPath, Class<?> extension) Shortcut for configuring the server to use an unmanaged extension.withUnmanagedExtension
(String mountPath, String packageName) Shortcut for configuring the server to find and mount all unmanaged extensions in the given package.
-
Constructor Details
-
Neo4jRule
public Neo4jRule() -
Neo4jRule
-
-
Method Details
-
apply
public org.junit.runners.model.Statement apply(org.junit.runners.model.Statement base, org.junit.runner.Description description) -
withConfig
Configure the Neo4j instance. Configuration here can be both configuration aimed at the server as well as the database tuning options. Please refer to the Neo4j Manual for details on available configuration options.- Type Parameters:
T
- the type of the setting- Parameters:
key
- the config keyvalue
- the config value- Returns:
- this configurator instance
-
withUnmanagedExtension
Shortcut for configuring the server to use an unmanaged extension. Please refer to the Neo4j Manual on how to write unmanaged extensions.- Parameters:
mountPath
- the http path, relative to the server base URI, that this extension should be mounted at.extension
- the unmanaged extension class.- Returns:
- this configurator instance
-
withUnmanagedExtension
Shortcut for configuring the server to find and mount all unmanaged extensions in the given package.- Parameters:
mountPath
- the http path, relative to the server base URI, that this extension should be mounted at.packageName
- a java package with extension classes.- Returns:
- this configurator instance
- See Also:
-
withDisabledServer
Disable web server on configured Neo4j instance. For cases where web server is not required to test specific functionality it can be fully disabled using this tuning option.- Returns:
- this configurator instance.
-
withFixture
Data fixtures to inject upon server build. This can be either a file with a plain-text cypher query (for example, myFixture.cyp), or a directory containing such files with the suffix ".cyp".- Parameters:
cypherFileOrDirectory
- file with cypher statement, or directory containing ".cyp"-suffixed files.- Returns:
- this configurator instance
-
withFixture
Data fixture to inject upon server build. This should be a valid Cypher statement.- Parameters:
fixtureStatement
- a cypher statement- Returns:
- this configurator instance
-
withFixture
Data fixture to inject upon server build. This should be a user implemented fixture function operating on aGraphDatabaseService
instance- Parameters:
fixtureFunction
- a fixture function- Returns:
- this configurator instance
-
copyFrom
Pre-populate the server with databases copied from the specified source directory. The source directory needs to have sub-folders `databases/neo4j` in which the source store files are located.- Parameters:
sourceDirectory
- the directory to copy from- Returns:
- this configurator instance
-
withProcedure
Configure the server to load the specified procedure definition class. The class should contain one or more methods annotated withProcedure
, these will become available to call through cypher.- Parameters:
procedureClass
- a class containing one or more procedure definitions- Returns:
- this configurator instance
-
withFunction
Configure the server to load the specified function definition class. The class should contain one or more methods annotated withUserFunction
, these will become available to call through cypher.- Parameters:
functionClass
- a class containing one or more function definitions- Returns:
- this configurator instance
-
withAggregationFunction
Configure the server to load the specified aggregation function definition class. The class should contain one or more methods annotated withUserAggregationFunction
, these will become available to call through cypher.- Parameters:
functionClass
- a class containing one or more function definitions- Returns:
- this configurator instance
-
dumpLogsOnFailure
Dump available logs on failure.- Parameters:
out
- stream used to dump logs into.- Returns:
- this configurator instance
-
dumpLogsOnFailure
Dump available logs on failure.Similar to
dumpLogsOnFailure(PrintStream)
, but permits late-binding the stream, or producing the stream based on some computation.- Parameters:
out
- the supplier of the stream that will be used to dump logs info.- Returns:
- this configurator instance.
-
boltURI
Returns the URI to the Bolt Protocol connector of the instance.- Returns:
- the bolt address.
-
httpURI
Returns the URI to the root resource of the instance. For example, http://localhost:7474/- Returns:
- the http address to the root resource.
-
httpsURI
Returns ths URI to the root resource of the instance using the https protocol. For example, https://localhost:7475/.- Returns:
- the https address to the root resource.
-
databaseManagementService
Access theDatabaseManagementService
used by the server.- Returns:
- the database management service backing this instance.
-
defaultDatabaseService
Access default database service.- Returns:
- default database service.
-
config
Returns the server's configuration.- Returns:
- the current configuration of the instance.
-