Skip to content

Instantly share code, notes, and snippets.

public class SMTPServerRule extends ExternalResource {
private GreenMail smtpServer;
private String hostname;
private int port;
public SMTPServerRule() {
this(25);
}
public class SMTPServerExtension implements BeforeEachCallback, AfterEachCallback {
private GreenMail smtpServer;
private String hostname;
private int port;
public SMTPServerExtension() {
this(25);
}
JUnit 4 Junit 5
org.junit.Before org.junit.jupiter.api.BeforeEach
org.junit.After org.junit.jupiter.api.After
org.junit.BeforeClass org.junit.jupiter.api.BeforeAll
org.junit.AfterClass org.junit.jupiter.api.AfterAll
org.junit.Ignore org.junit.jupiter.api.Disabled
@vgallet
vgallet / TemporaryFolderExtension.java
Last active April 29, 2018 18:06
TemporaryFolderExtension
public class TemporaryFolderExtension implements BeforeEachCallback, AfterEachCallback {
private final File parentFolder;
private File folder;
public TemporaryFolderExtension() {
this(null);
}
public TemporaryFolderExtension(File parentFolder) {
GenericContainer container = new GenericContainer("docker.elastic.co/elasticsearch/elasticsearch:6.1.1")
.withEnv("discovery.type", "single-node")
.withExposedPorts(9200)
.waitingFor(
Wait
.forHttp("/_cat/health?v&pretty")
.forStatusCode(200)
);
@ClassRule
public static GenericContainer redis = new GenericContainer("redis:3.0.2")
.withExposedPorts(6379);
@RunWith(SpringRunner.class)
@DataJpaTest(includeFilters = @ComponentScan.Filter(Service.class))
@TestPropertySource(locations="classpath:application-test.properties")
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
public class ClinicServiceTests {
...
}
@ClassRule
public static GenericContainer mysql = new GenericContainer(
new ImageFromDockerfile("mysql-petclinic")
.withDockerfileFromBuilder(dockerfileBuilder -> {
dockerfileBuilder.from("mysql:5.7.8")
}
);
@ClassRule
public static GenericContainer mysql = new GenericContainer(
new ImageFromDockerfile("mysql-petclinic")
.withDockerfileFromBuilder(dockerfileBuilder -> {
dockerfileBuilder.from("mysql:5.7.8")
// root password is mandatory
.env("MYSQL_ROOT_PASSWORD", "root_password")
.env("MYSQL_DATABASE", "petclinic")
.env("MYSQL_USER", "petclinic")
.env("MYSQL_PASSWORD", "petclinic")
@ClassRule
public static GenericContainer mysql = new GenericContainer(
new ImageFromDockerfile("mysql-petclinic")
.withDockerfileFromBuilder(dockerfileBuilder -> {
dockerfileBuilder.from("mysql:5.7.8")
.env("MYSQL_ROOT_PASSWORD", "root_password")
.env("MYSQL_DATABASE", "petclinic")
.env("MYSQL_USER", "petclinic")
.env("MYSQL_PASSWORD", "petclinic")
.add("a_schema.sql", "/docker-entrypoint-initdb.d")