Migrate tests to JUnit5 testcontainer extensions
Closes gh-15456
This commit is contained in:
parent
1db1c8b03c
commit
684a1c7a3c
|
|
@ -926,6 +926,11 @@
|
|||
<artifactId>cassandra</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>testcontainers</artifactId>
|
||||
|
|
|
|||
|
|
@ -18,11 +18,12 @@ package org.springframework.boot.autoconfigure.data.cassandra;
|
|||
|
||||
import com.datastax.driver.core.Cluster;
|
||||
import com.datastax.driver.core.Session;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.testcontainers.containers.CassandraContainer;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurationPackages;
|
||||
import org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration;
|
||||
|
|
@ -41,15 +42,16 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
* @author Mark Paluch
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@Testcontainers
|
||||
public class CassandraDataAutoConfigurationIntegrationTests {
|
||||
|
||||
@ClassRule
|
||||
@Container
|
||||
public static SkippableContainer<CassandraContainer<?>> cassandra = new SkippableContainer<>(
|
||||
CassandraContainer::new);
|
||||
|
||||
private AnnotationConfigApplicationContext context;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
TestPropertyValues
|
||||
|
|
@ -60,7 +62,7 @@ public class CassandraDataAutoConfigurationIntegrationTests {
|
|||
.applyTo(this.context.getEnvironment());
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void close() {
|
||||
if (this.context != null) {
|
||||
this.context.close();
|
||||
|
|
|
|||
|
|
@ -20,9 +20,10 @@ import java.util.List;
|
|||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.client.transport.TransportClient;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||
import org.junit.After;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
|
||||
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
||||
import org.springframework.boot.test.util.TestPropertyValues;
|
||||
|
|
@ -41,14 +42,15 @@ import static org.mockito.Mockito.mock;
|
|||
* @author Andy Wilkinson
|
||||
*/
|
||||
@Deprecated
|
||||
@Testcontainers
|
||||
public class ElasticsearchAutoConfigurationTests {
|
||||
|
||||
@ClassRule
|
||||
@Container
|
||||
public static ElasticsearchContainer elasticsearch = new ElasticsearchContainer();
|
||||
|
||||
private AnnotationConfigApplicationContext context;
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void close() {
|
||||
if (this.context != null) {
|
||||
this.context.close();
|
||||
|
|
|
|||
|
|
@ -16,9 +16,10 @@
|
|||
|
||||
package org.springframework.boot.autoconfigure.data.elasticsearch;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
|
||||
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
||||
import org.springframework.boot.test.util.TestPropertyValues;
|
||||
|
|
@ -37,14 +38,15 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
* @author Artur Konczak
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
@Testcontainers
|
||||
public class ElasticsearchDataAutoConfigurationTests {
|
||||
|
||||
@ClassRule
|
||||
@Container
|
||||
public static ElasticsearchContainer elasticsearch = new ElasticsearchContainer();
|
||||
|
||||
private AnnotationConfigApplicationContext context;
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void close() {
|
||||
if (this.context != null) {
|
||||
this.context.close();
|
||||
|
|
|
|||
|
|
@ -17,9 +17,10 @@
|
|||
package org.springframework.boot.autoconfigure.data.elasticsearch;
|
||||
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.junit.After;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
|
||||
import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage;
|
||||
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
||||
|
|
@ -41,14 +42,15 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
* @author Phillip Webb
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
@Testcontainers
|
||||
public class ElasticsearchRepositoriesAutoConfigurationTests {
|
||||
|
||||
@ClassRule
|
||||
@Container
|
||||
public static ElasticsearchContainer elasticsearch = new ElasticsearchContainer();
|
||||
|
||||
private AnnotationConfigApplicationContext context;
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void close() {
|
||||
this.context.close();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,10 +16,11 @@
|
|||
|
||||
package org.springframework.boot.autoconfigure.data.redis;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
|
||||
import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage;
|
||||
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
||||
|
|
@ -40,20 +41,21 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
*
|
||||
* @author Eddú Meléndez
|
||||
*/
|
||||
@Testcontainers
|
||||
public class RedisRepositoriesAutoConfigurationTests {
|
||||
|
||||
@ClassRule
|
||||
@Container
|
||||
public static RedisContainer redis = new RedisContainer();
|
||||
|
||||
private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
TestPropertyValues.of("spring.redis.port=" + redis.getMappedPort())
|
||||
.applyTo(this.context.getEnvironment());
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void close() {
|
||||
this.context.close();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,8 +27,9 @@ import io.searchbox.client.JestResult;
|
|||
import io.searchbox.client.http.JestHttpClient;
|
||||
import io.searchbox.core.Get;
|
||||
import io.searchbox.core.Index;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
|
|
@ -49,9 +50,10 @@ import static org.mockito.Mockito.mock;
|
|||
* @author Andy Wilkinson
|
||||
*/
|
||||
@Deprecated
|
||||
@Testcontainers
|
||||
public class JestAutoConfigurationTests {
|
||||
|
||||
@ClassRule
|
||||
@Container
|
||||
public static ElasticsearchContainer elasticsearch = new ElasticsearchContainer();
|
||||
|
||||
private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
|
|
|
|||
|
|
@ -26,8 +26,9 @@ import org.elasticsearch.client.RequestOptions;
|
|||
import org.elasticsearch.client.RestClient;
|
||||
import org.elasticsearch.client.RestClientBuilder;
|
||||
import org.elasticsearch.client.RestHighLevelClient;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
|
|
@ -44,9 +45,10 @@ import static org.mockito.Mockito.mock;
|
|||
*
|
||||
* @author Brian Clozel
|
||||
*/
|
||||
@Testcontainers
|
||||
public class RestClientAutoConfigurationTests {
|
||||
|
||||
@ClassRule
|
||||
@Container
|
||||
public static ElasticsearchContainer elasticsearch = new ElasticsearchContainer();
|
||||
|
||||
private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -16,8 +16,9 @@
|
|||
|
||||
package org.springframework.boot.autoconfigure.session;
|
||||
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
|
||||
|
|
@ -41,10 +42,11 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
* @author Stephane Nicoll
|
||||
* @author Vedran Pavic
|
||||
*/
|
||||
@Testcontainers
|
||||
public class SessionAutoConfigurationRedisTests
|
||||
extends AbstractSessionAutoConfigurationTests {
|
||||
|
||||
@ClassRule
|
||||
@Container
|
||||
public static RedisContainer redis = new RedisContainer();
|
||||
|
||||
protected final WebApplicationContextRunner contextRunner = new WebApplicationContextRunner()
|
||||
|
|
|
|||
|
|
@ -344,6 +344,11 @@
|
|||
<artifactId>spring-plugin-core</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>neo4j</artifactId>
|
||||
|
|
|
|||
|
|
@ -16,11 +16,11 @@
|
|||
|
||||
package org.springframework.boot.test.autoconfigure.data.neo4j;
|
||||
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.neo4j.ogm.session.Session;
|
||||
import org.testcontainers.containers.Neo4jContainer;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
|
@ -30,7 +30,6 @@ import org.springframework.context.ApplicationContext;
|
|||
import org.springframework.context.ApplicationContextInitializer;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
|
@ -42,12 +41,12 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
|||
* @author Stephane Nicoll
|
||||
* @author Michael Simons
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration(initializers = DataNeo4jTestIntegrationTests.Initializer.class)
|
||||
@DataNeo4jTest
|
||||
@Testcontainers
|
||||
public class DataNeo4jTestIntegrationTests {
|
||||
|
||||
@ClassRule
|
||||
@Container
|
||||
public static SkippableContainer<Neo4jContainer<?>> neo4j = new SkippableContainer<>(
|
||||
() -> new Neo4jContainer<>().withAdminPassword(null));
|
||||
|
||||
|
|
|
|||
|
|
@ -16,10 +16,10 @@
|
|||
|
||||
package org.springframework.boot.test.autoconfigure.data.neo4j;
|
||||
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.testcontainers.containers.Neo4jContainer;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.util.TestPropertyValues;
|
||||
|
|
@ -28,7 +28,6 @@ import org.springframework.context.ApplicationContextInitializer;
|
|||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
|
@ -38,13 +37,13 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
*
|
||||
* @author Artsiom Yudovin
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@Testcontainers
|
||||
@ContextConfiguration(
|
||||
initializers = DataNeo4jTestPropertiesIntegrationTests.Initializer.class)
|
||||
@DataNeo4jTest(properties = "spring.profiles.active=test")
|
||||
public class DataNeo4jTestPropertiesIntegrationTests {
|
||||
|
||||
@ClassRule
|
||||
@Container
|
||||
public static SkippableContainer<Neo4jContainer<?>> neo4j = new SkippableContainer<>(
|
||||
() -> new Neo4jContainer<>().withAdminPassword(null));
|
||||
|
||||
|
|
|
|||
|
|
@ -16,10 +16,10 @@
|
|||
|
||||
package org.springframework.boot.test.autoconfigure.data.neo4j;
|
||||
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.testcontainers.containers.Neo4jContainer;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.util.TestPropertyValues;
|
||||
|
|
@ -29,7 +29,6 @@ import org.springframework.context.ConfigurableApplicationContext;
|
|||
import org.springframework.context.annotation.ComponentScan.Filter;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
|
@ -39,13 +38,13 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
* @author Eddú Meléndez
|
||||
* @author Michael Simons
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@Testcontainers
|
||||
@ContextConfiguration(
|
||||
initializers = DataNeo4jTestWithIncludeFilterIntegrationTests.Initializer.class)
|
||||
@DataNeo4jTest(includeFilters = @Filter(Service.class))
|
||||
public class DataNeo4jTestWithIncludeFilterIntegrationTests {
|
||||
|
||||
@ClassRule
|
||||
@Container
|
||||
public static SkippableContainer<Neo4jContainer<?>> neo4j = new SkippableContainer<>(
|
||||
() -> new Neo4jContainer<>().withAdminPassword(null));
|
||||
|
||||
|
|
|
|||
|
|
@ -19,9 +19,9 @@ package org.springframework.boot.test.autoconfigure.data.redis;
|
|||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
|
@ -33,7 +33,6 @@ import org.springframework.context.ConfigurableApplicationContext;
|
|||
import org.springframework.data.redis.connection.RedisConnection;
|
||||
import org.springframework.data.redis.core.RedisOperations;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
|
@ -43,12 +42,12 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
|||
*
|
||||
* @author Jayaram Pradhan
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@Testcontainers
|
||||
@ContextConfiguration(initializers = DataRedisTestIntegrationTests.Initializer.class)
|
||||
@DataRedisTest
|
||||
public class DataRedisTestIntegrationTests {
|
||||
|
||||
@ClassRule
|
||||
@Container
|
||||
public static RedisContainer redis = new RedisContainer();
|
||||
|
||||
@Autowired
|
||||
|
|
|
|||
|
|
@ -16,9 +16,9 @@
|
|||
|
||||
package org.springframework.boot.test.autoconfigure.data.redis;
|
||||
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.util.TestPropertyValues;
|
||||
|
|
@ -27,7 +27,6 @@ import org.springframework.context.ApplicationContextInitializer;
|
|||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
|
@ -37,13 +36,13 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
*
|
||||
* @author Artsiom Yudovin
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@Testcontainers
|
||||
@ContextConfiguration(
|
||||
initializers = DataRedisTestPropertiesIntegrationTests.Initializer.class)
|
||||
@DataRedisTest(properties = "spring.profiles.active=test")
|
||||
public class DataRedisTestPropertiesIntegrationTests {
|
||||
|
||||
@ClassRule
|
||||
@Container
|
||||
public static RedisContainer redis = new RedisContainer();
|
||||
|
||||
@Autowired
|
||||
|
|
|
|||
|
|
@ -16,9 +16,9 @@
|
|||
|
||||
package org.springframework.boot.test.autoconfigure.data.redis;
|
||||
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.util.TestPropertyValues;
|
||||
|
|
@ -28,7 +28,6 @@ import org.springframework.context.ConfigurableApplicationContext;
|
|||
import org.springframework.context.annotation.ComponentScan.Filter;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
|
@ -37,13 +36,13 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
*
|
||||
* @author Jayaram Pradhan
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@Testcontainers
|
||||
@ContextConfiguration(
|
||||
initializers = DataRedisTestWithIncludeFilterIntegrationTests.Initializer.class)
|
||||
@DataRedisTest(includeFilters = @Filter(Service.class))
|
||||
public class DataRedisTestWithIncludeFilterIntegrationTests {
|
||||
|
||||
@ClassRule
|
||||
@Container
|
||||
public static RedisContainer redis = new RedisContainer();
|
||||
|
||||
@Autowired
|
||||
|
|
|
|||
|
|
@ -70,6 +70,10 @@
|
|||
<artifactId>jakarta.servlet-api</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -19,13 +19,11 @@ package org.springframework.boot.testsupport.testcontainers;
|
|||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.junit.AssumptionViolatedException;
|
||||
import org.junit.jupiter.api.Assumptions;
|
||||
import org.junit.rules.TestRule;
|
||||
import org.junit.runner.Description;
|
||||
import org.junit.runners.model.Statement;
|
||||
import org.testcontainers.DockerClientFactory;
|
||||
import org.testcontainers.containers.FailureDetectingExternalResource;
|
||||
import org.testcontainers.containers.GenericContainer;
|
||||
import org.testcontainers.lifecycle.Startable;
|
||||
|
||||
/**
|
||||
* {@link TestRule} for working with an optional Docker environment. Spins up a
|
||||
|
|
@ -34,7 +32,7 @@ import org.testcontainers.containers.GenericContainer;
|
|||
* @author Madhura Bhave
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
class Container implements TestRule {
|
||||
class Container implements Startable {
|
||||
|
||||
private final int port;
|
||||
|
||||
|
|
@ -60,19 +58,6 @@ class Container implements TestRule {
|
|||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public Statement apply(Statement base, Description description) {
|
||||
try {
|
||||
DockerClientFactory.instance().client();
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
return new SkipStatement();
|
||||
}
|
||||
this.container = this.containerFactory.get();
|
||||
return ((FailureDetectingExternalResource) this.container).apply(base,
|
||||
description);
|
||||
}
|
||||
|
||||
public int getMappedPort() {
|
||||
return this.container.getMappedPort(this.port);
|
||||
}
|
||||
|
|
@ -81,14 +66,29 @@ class Container implements TestRule {
|
|||
return this.container;
|
||||
}
|
||||
|
||||
private static class SkipStatement extends Statement {
|
||||
@Override
|
||||
public void start() {
|
||||
Assumptions.assumeTrue(isDockerRunning(),
|
||||
"Could not find valid docker environment.");
|
||||
this.container = this.containerFactory.get();
|
||||
this.container.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void evaluate() {
|
||||
throw new AssumptionViolatedException(
|
||||
"Could not find a valid Docker environment.");
|
||||
private boolean isDockerRunning() {
|
||||
try {
|
||||
DockerClientFactory.instance().client();
|
||||
return true;
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
if (this.container != null) {
|
||||
this.container.stop();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -18,9 +18,6 @@ package org.springframework.boot.testsupport.testcontainers;
|
|||
|
||||
import java.time.Duration;
|
||||
|
||||
import org.junit.runner.Description;
|
||||
import org.junit.runners.model.Statement;
|
||||
|
||||
/**
|
||||
* A {@link Container} for Elasticsearch.
|
||||
*
|
||||
|
|
@ -40,23 +37,15 @@ public class ElasticsearchContainer extends Container {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Statement apply(Statement base, Description description) {
|
||||
Statement wrapped = super.apply(base, description);
|
||||
return new Statement() {
|
||||
|
||||
@Override
|
||||
public void evaluate() throws Throwable {
|
||||
System.setProperty("es.set.netty.runtime.available.processors", "false");
|
||||
try {
|
||||
wrapped.evaluate();
|
||||
}
|
||||
finally {
|
||||
System.clearProperty("es.set.netty.runtime.available.processors");
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
public void start() {
|
||||
System.setProperty("es.set.netty.runtime.available.processors", "false");
|
||||
super.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
System.clearProperty("es.set.netty.runtime.available.processors");
|
||||
super.stop();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,13 +18,10 @@ package org.springframework.boot.testsupport.testcontainers;
|
|||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.junit.AssumptionViolatedException;
|
||||
import org.junit.rules.TestRule;
|
||||
import org.junit.runner.Description;
|
||||
import org.junit.runners.model.Statement;
|
||||
import org.junit.jupiter.api.Assumptions;
|
||||
import org.testcontainers.DockerClientFactory;
|
||||
import org.testcontainers.containers.FailureDetectingExternalResource;
|
||||
import org.testcontainers.containers.GenericContainer;
|
||||
import org.testcontainers.lifecycle.Startable;
|
||||
|
||||
/**
|
||||
* A {@link GenericContainer} decorator that skips test execution when Docker is not
|
||||
|
|
@ -32,8 +29,9 @@ import org.testcontainers.containers.GenericContainer;
|
|||
*
|
||||
* @param <T> type of the underlying container
|
||||
* @author Andy Wilkinson
|
||||
* @author Madhura Bhave
|
||||
*/
|
||||
public class SkippableContainer<T> implements TestRule {
|
||||
public class SkippableContainer<T extends GenericContainer> implements Startable {
|
||||
|
||||
private final Supplier<T> containerFactory;
|
||||
|
||||
|
|
@ -43,19 +41,6 @@ public class SkippableContainer<T> implements TestRule {
|
|||
this.containerFactory = containerFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Statement apply(Statement base, Description description) {
|
||||
try {
|
||||
DockerClientFactory.instance().client();
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
return new SkipStatement();
|
||||
}
|
||||
this.container = this.containerFactory.get();
|
||||
return ((FailureDetectingExternalResource) this.container).apply(base,
|
||||
description);
|
||||
}
|
||||
|
||||
public T getContainer() {
|
||||
if (this.container == null) {
|
||||
throw new IllegalStateException(
|
||||
|
|
@ -64,14 +49,29 @@ public class SkippableContainer<T> implements TestRule {
|
|||
return this.container;
|
||||
}
|
||||
|
||||
private static class SkipStatement extends Statement {
|
||||
@Override
|
||||
public void start() {
|
||||
Assumptions.assumeTrue(isDockerRunning(),
|
||||
"Could not find valid docker environment.");
|
||||
this.container = this.containerFactory.get();
|
||||
this.container.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void evaluate() {
|
||||
throw new AssumptionViolatedException(
|
||||
"Could not find a valid Docker environment.");
|
||||
private boolean isDockerRunning() {
|
||||
try {
|
||||
DockerClientFactory.instance().client();
|
||||
return true;
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
if (this.container != null) {
|
||||
this.container.stop();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue