Class Neo4jContainer

java.lang.Object
org.testcontainers.containers.GenericContainer<Neo4jContainer>
org.testcontainers.neo4j.Neo4jContainer
All Implemented Interfaces:
AutoCloseable, org.testcontainers.containers.Container<Neo4jContainer>, org.testcontainers.containers.ContainerState, org.testcontainers.containers.traits.LinkableContainer, org.testcontainers.containers.wait.strategy.WaitStrategyTarget, org.testcontainers.lifecycle.Startable

public class Neo4jContainer extends org.testcontainers.containers.GenericContainer<Neo4jContainer>
Testcontainers implementation for Neo4j.

Supported image: neo4j

Exposed ports:

  • Bolt: 7687
  • HTTP: 7474
  • HTTPS: 7473
  • Nested Class Summary

    Nested classes/interfaces inherited from interface org.testcontainers.containers.Container

    org.testcontainers.containers.Container.ExecResult
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final org.testcontainers.containers.wait.strategy.WaitStrategy
    Default wait strategies

    Fields inherited from class org.testcontainers.containers.GenericContainer

    CONTAINER_RUNNING_TIMEOUT_SEC, dependencies, dockerClient, INTERNAL_HOST_HOSTNAME, waitStrategy

    Fields inherited from interface org.testcontainers.containers.ContainerState

    STATE_HEALTHY
  • Constructor Summary

    Constructors
    Constructor
    Description
    Neo4jContainer(String dockerImageName)
    Creates a Neo4jContainer using a specific docker image.
    Neo4jContainer(org.testcontainers.utility.DockerImageName dockerImageName)
    Creates a Neo4jContainer using a specific docker image.
  • Method Summary

    Modifier and Type
    Method
    Description
    Accepts the license agreement of the container.
    protected void
     
     
     
     
     
     
    withAdminPassword(String adminPassword)
    Sets the admin password for the default account (which is
    withDatabase(org.testcontainers.utility.MountableFile graphDb)
    Copies an existing graph.db folder into the container.
    Adds Neo4j configuration properties to the container.
    Disables authentication.
    withPlugins(String... plugins)
    Registers one or more Neo4j plugins for server startup.
    withPlugins(org.testcontainers.utility.MountableFile plugins)
    Adds plugins to the given directory to the container.
     

    Methods inherited from class org.testcontainers.containers.GenericContainer

    addEnv, addExposedPort, addExposedPorts, addFileSystemBind, addFixedExposedPort, addFixedExposedPort, addLink, canBeReused, containerIsCreated, containerIsStarted, containerIsStarted, containerIsStarting, containerIsStarting, containerIsStopped, containerIsStopping, copyFileFromContainer, createVolumeDirectory, dependsOn, dependsOn, dependsOn, doStart, equals, getBinds, getCommandParts, getContainerId, getContainerInfo, getContainerName, getCopyToFileContainerPathMap, getCreateContainerCmdModifiers, getDependencies, getDockerClient, getDockerImageName, getEnv, getEnvMap, getExposedPorts, getExtraHosts, getImage, getIpAddress, getLabels, getLinkedContainers, getLivenessCheckPort, getLivenessCheckPorts, getLogConsumers, getNetwork, getNetworkAliases, getNetworkMode, getPortBindings, getShmSize, getStartupAttempts, getStartupCheckStrategy, getTestHostIpAddress, getTmpFsMapping, getVolumesFroms, getWaitStrategy, getWorkingDirectory, hashCode, isHostAccessible, isPrivilegedMode, isShouldBeReused, logger, setBinds, setCommand, setCommand, setCommandParts, setContainerDef, setCopyToFileContainerPathMap, setDockerImageName, setEnv, setExposedPorts, setExtraHosts, setHostAccessible, setImage, setLabels, setLinkedContainers, setLogConsumers, setNetwork, setNetworkAliases, setNetworkMode, setPortBindings, setPrivilegedMode, setShmSize, setStartupAttempts, setStartupCheckStrategy, setTmpFsMapping, setVolumesFroms, setWaitStrategy, setWorkingDirectory, start, stop, toString, waitingFor, waitUntilContainerStarted, withAccessToHost, withClasspathResourceMapping, withClasspathResourceMapping, withCommand, withCommand, withCopyFileToContainer, withCopyToContainer, withCreateContainerCmdModifier, withEnv, withEnv, withExposedPorts, withExtraHost, withFileSystemBind, withImagePullPolicy, withLabel, withLabels, withLogConsumer, withMinimumRunningDuration, withNetwork, withNetworkAliases, withNetworkMode, withPrivilegedMode, withReuse, withSharedMemorySize, withStartupAttempts, withStartupCheckStrategy, withStartupTimeout, withTmpFs, withVolumesFrom, withWorkingDirectory

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.testcontainers.containers.Container

    addFileSystemBind, followOutput, followOutput, self, withEnv, withFileSystemBind

    Methods inherited from interface org.testcontainers.containers.ContainerState

    copyFileFromContainer, copyFileToContainer, copyFileToContainer, execInContainer, execInContainer, execInContainer, execInContainer, execInContainerWithUser, execInContainerWithUser, getBoundPortNumbers, getContainerIpAddress, getCurrentContainerInfo, getFirstMappedPort, getHost, getLogs, getLogs, getMappedPort, isCreated, isHealthy, isRunning

    Methods inherited from interface org.testcontainers.lifecycle.Startable

    close
  • Field Details

    • WAIT_FOR_BOLT

      public static final org.testcontainers.containers.wait.strategy.WaitStrategy WAIT_FOR_BOLT
      Default wait strategies
  • Constructor Details

    • Neo4jContainer

      public Neo4jContainer(String dockerImageName)
      Creates a Neo4jContainer using a specific docker image.
      Parameters:
      dockerImageName - The docker image to use.
    • Neo4jContainer

      public Neo4jContainer(org.testcontainers.utility.DockerImageName dockerImageName)
      Creates a Neo4jContainer using a specific docker image.
      Parameters:
      dockerImageName - The docker image to use.
  • Method Details

    • getLivenessCheckPortNumbers

      public Set<Integer> getLivenessCheckPortNumbers()
      Specified by:
      getLivenessCheckPortNumbers in interface org.testcontainers.containers.wait.strategy.WaitStrategyTarget
      Overrides:
      getLivenessCheckPortNumbers in class org.testcontainers.containers.GenericContainer<Neo4jContainer>
    • configure

      protected void configure()
      Overrides:
      configure in class org.testcontainers.containers.GenericContainer<Neo4jContainer>
    • getBoltUrl

      public String getBoltUrl()
      Returns:
      Bolt URL for use with Neo4j's Java-Driver.
    • getHttpUrl

      public String getHttpUrl()
      Returns:
      URL of the transactional HTTP endpoint.
    • getHttpsUrl

      public String getHttpsUrl()
      Returns:
      URL of the transactional HTTPS endpoint.
    • acceptLicense

      public Neo4jContainer acceptLicense()
      Accepts the license agreement of the container.
      Returns:
      this
    • withAdminPassword

      public Neo4jContainer withAdminPassword(String adminPassword)
      Sets the admin password for the default account (which is
      neo4j
      ). A null value or an empty string disables authentication.
      Parameters:
      adminPassword - The admin password for the default database account.
      Returns:
      This container.
    • withoutAuthentication

      public Neo4jContainer withoutAuthentication()
      Disables authentication.
      Returns:
      This container.
    • withDatabase

      public Neo4jContainer withDatabase(org.testcontainers.utility.MountableFile graphDb)
      Copies an existing graph.db folder into the container. This can either be a classpath resource or a host resource. Please have a look at the factory methods in MountableFile.
      If you want to map your database into the container instead of copying them, please use #withClasspathResourceMapping, but this will only work when your test does not run in a container itself.
      Note: This method only works with Neo4j 3.5.
      Mapping would work like this:
            @Container
            private static final Neo4jContainer databaseServer = new Neo4jContainer<>()
                .withClasspathResourceMapping("/test-graph.db", "/data/databases/graph.db", BindMode.READ_WRITE);
       
      Parameters:
      graphDb - The graph.db folder to copy into the container
      Returns:
      This container.
      Throws:
      IllegalArgumentException - If the database version is not 3.5.
    • withPlugins

      public Neo4jContainer withPlugins(org.testcontainers.utility.MountableFile plugins)
      Adds plugins to the given directory to the container. If plugins denotes a directory, than all of that directory is mapped to Neo4j's plugins. Otherwise, single resources are copied over.
      If you want to map your plugins into the container instead of copying them, please use #withClasspathResourceMapping, but this will only work when your test does not run in a container itself.
      Parameters:
      plugins -
      Returns:
      This container.
    • withNeo4jConfig

      public Neo4jContainer withNeo4jConfig(String key, String value)
      Adds Neo4j configuration properties to the container. The properties can be added as in the official Neo4j configuration, the method automatically translate them into the format required by the Neo4j container.
      Parameters:
      key - The key to configure, i.e. dbms.security.procedures.unrestricted
      value - The value to set
      Returns:
      This container.
    • getAdminPassword

      public String getAdminPassword()
      Returns:
      The admin password for the neo4j account or literal null if auth is disabled.
    • withPlugins

      public Neo4jContainer withPlugins(String... plugins)
      Registers one or more Neo4j plugins for server startup. The plugins are listed here
      Parameters:
      plugins - The Neo4j plugins that should get started with the server.
      Returns:
      This container.
    • withRandomPassword

      public Neo4jContainer withRandomPassword()