All Downloads are FREE. Search and download functionalities are using the official Maven repository.

generator.server.springboot.database.neo4j.TestNeo4jManager.mustache Maven / Gradle / Ivy

There is a newer version: 1.22.0
Show newest version
package {{packageName}};

import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
import org.springframework.context.ApplicationListener;
import org.testcontainers.containers.Neo4jContainer;
import org.testcontainers.utility.DockerImageName;

class TestNeo4jManager implements ApplicationListener {

  private static Neo4jContainer neo4jContainer;

  @Override
  @SuppressWarnings("resource")
  public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
    if (neo4jContainer != null) {
      return;
    }

    neo4jContainer = new Neo4jContainer<>(DockerImageName.parse("{{neo4jDockerImage}}")).withoutAuthentication();

    neo4jContainer.start();

    System.setProperty("TEST_NEO4J_URI", neo4jContainer.getBoltUrl());
    Runtime.getRuntime().addShutdownHook(new Thread(stopContainer()));
  }

  private Runnable stopContainer() {
    return neo4jContainer::stop;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy