test/src/main/java/eu/internetofus/common/test/MongoContainer.java
/**
   * Start the MongoDB container if it is not started yet.
   *
   * @return this containers instance.
   */
Start the MongoDB container if it is not started yet.
@return this containers instance.
Start the MongoDB container if it is not started yet . @return this containers instance .
@SuppressWarnings({ "resource", "unchecked" })
  public SELF startMongoContainer() {
    if (this.mongoContainer == null) {
      Logger.trace("Starting MongoDB container");
      this.mongoContainer = new GenericContainer<>(DockerImageName.parse(MONGO_DOCKER_NAME)).withStartupAttempts(1)
          .withEnv("MONGO_INITDB_ROOT_USERNAME", "root").withEnv("MONGO_INITDB_ROOT_PASSWORD", "password")
          .withEnv("MONGO_INITDB_DATABASE", MONGODB_NAME)
          .withCopyFileToContainer(
              MountableFile.forClasspathResource(
                  MongoContainer.class.getPackageName().replaceAll("\\.", "/") + "/initialize-wenetDB.js"),
              "/docker-entrypoint-initdb.d/init-mongo.js")
          .withExposedPorts(EXPORT_MONGODB_PORT).withNetwork(this.network).withNetworkAliases(MONGODB_NAME)
          .waitingFor(Wait.forListeningPort());
      this.mongoContainer.start();
      Logger.trace("Started MongoDB container");
    }
    return (SELF) this;
  }
@ SuppressWarnings ( { "resource" , "unchecked" } ) public SELF startMongoContainer ( ) { if ( this . mongoContainer == null ) { Logger . trace ( "Starting MongoDB container" ) ; this . mongoContainer = new GenericContainer < > ( DockerImageName . parse ( MONGO_DOCKER_NAME ) ) . withStartupAttempts ( 1 ) . withEnv ( "MONGO_INITDB_ROOT_USERNAME" , "root" ) . withEnv ( "MONGO_INITDB_ROOT_PASSWORD" , "password" ) . withEnv ( "MONGO_INITDB_DATABASE" , MONGODB_NAME ) . withCopyFileToContainer ( MountableFile . forClasspathResource ( MongoContainer . class . getPackageName ( ) . replaceAll ( "\\." , "/" ) + "/initialize-wenetDB.js" ) , "/docker-entrypoint-initdb.d/init-mongo.js" ) . withExposedPorts ( EXPORT_MONGODB_PORT ) . withNetwork ( this . network ) . withNetworkAliases ( MONGODB_NAME ) . waitingFor ( Wait . forListeningPort ( ) ) ; this . mongoContainer . start ( ) ; Logger . trace ( "Started MongoDB container" ) ; } return ( SELF ) this ; }
Start the MongoDB container if it is not started yet.
Start the MongoDB container if it is not started yet .