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

com.jupiter.tools.spring.test.mongo.junit4.BaseMongoIT Maven / Gradle / Ivy

There is a newer version: 0.15
Show newest version
package com.jupiter.tools.spring.test.mongo.junit4;

import com.jupiter.tools.spring.test.mongo.annotation.MongoDataSet;
import org.junit.Rule;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.test.context.junit4.SpringRunner;
import org.testcontainers.containers.GenericContainer;

/**
 * Created by Korovin A. on 19.01.2018.
 * 

* Runs whole application context and start the MongoDB test container. * Also initialize the {@link MongoDbRule} to write integration * tests where you can use the {@link MongoDataSet} annotation. * * @author Korovin Anatoliy * @version 1.0 */ @RunWith(SpringRunner.class) @SpringBootTest public abstract class BaseMongoIT { private static final Integer MONGO_PORT = 27017; static { System.out.println("Start MongoDb testcontainers extension...\n"); GenericContainer mongo = new GenericContainer("mongo:latest") .withExposedPorts(MONGO_PORT); mongo.start(); System.setProperty("spring.data.mongodb.host", mongo.getContainerIpAddress()); System.setProperty("spring.data.mongodb.port", mongo.getMappedPort(MONGO_PORT).toString()); } @Autowired protected MongoTemplate mongoTemplate; @Rule public MongoDbRule mongoDbRule = new MongoDbRule(() -> mongoTemplate); }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy