Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
684a1c7a
Commit
684a1c7a
authored
May 08, 2019
by
Madhura Bhave
Committed by
Stephane Nicoll
May 08, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate tests to JUnit5 testcontainer extensions
Closes gh-15456
parent
1db1c8b0
Changes
20
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
155 additions
and
142 deletions
+155
-142
pom.xml
spring-boot-project/spring-boot-autoconfigure/pom.xml
+5
-0
CassandraDataAutoConfigurationIntegrationTests.java
...andra/CassandraDataAutoConfigurationIntegrationTests.java
+9
-7
ElasticsearchAutoConfigurationTests.java
...ta/elasticsearch/ElasticsearchAutoConfigurationTests.java
+7
-5
ElasticsearchDataAutoConfigurationTests.java
...lasticsearch/ElasticsearchDataAutoConfigurationTests.java
+7
-5
ElasticsearchRepositoriesAutoConfigurationTests.java
...arch/ElasticsearchRepositoriesAutoConfigurationTests.java
+7
-5
RedisRepositoriesAutoConfigurationTests.java
...e/data/redis/RedisRepositoriesAutoConfigurationTests.java
+8
-6
JestAutoConfigurationTests.java
...figure/elasticsearch/jest/JestAutoConfigurationTests.java
+5
-3
RestClientAutoConfigurationTests.java
.../elasticsearch/rest/RestClientAutoConfigurationTests.java
+5
-3
SessionAutoConfigurationRedisTests.java
...configure/session/SessionAutoConfigurationRedisTests.java
+6
-4
pom.xml
spring-boot-project/spring-boot-test-autoconfigure/pom.xml
+5
-0
DataNeo4jTestIntegrationTests.java
...toconfigure/data/neo4j/DataNeo4jTestIntegrationTests.java
+5
-6
DataNeo4jTestPropertiesIntegrationTests.java
...e/data/neo4j/DataNeo4jTestPropertiesIntegrationTests.java
+5
-6
DataNeo4jTestWithIncludeFilterIntegrationTests.java
...neo4j/DataNeo4jTestWithIncludeFilterIntegrationTests.java
+5
-6
DataRedisTestIntegrationTests.java
...toconfigure/data/redis/DataRedisTestIntegrationTests.java
+5
-6
DataRedisTestPropertiesIntegrationTests.java
...e/data/redis/DataRedisTestPropertiesIntegrationTests.java
+5
-6
DataRedisTestWithIncludeFilterIntegrationTests.java
...redis/DataRedisTestWithIncludeFilterIntegrationTests.java
+5
-6
pom.xml
...roject/spring-boot-tools/spring-boot-test-support/pom.xml
+4
-0
Container.java
...gframework/boot/testsupport/testcontainers/Container.java
+24
-24
ElasticsearchContainer.java
...ot/testsupport/testcontainers/ElasticsearchContainer.java
+9
-20
SkippableContainer.java
...k/boot/testsupport/testcontainers/SkippableContainer.java
+24
-24
No files found.
spring-boot-project/spring-boot-autoconfigure/pom.xml
View file @
684a1c7a
...
...
@@ -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>
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfigurationIntegrationTests.java
View file @
684a1c7a
...
...
@@ -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
{
@C
lassRule
@C
ontainer
public
static
SkippableContainer
<
CassandraContainer
<?>>
cassandra
=
new
SkippableContainer
<>(
CassandraContainer:
:
new
);
private
AnnotationConfigApplicationContext
context
;
@Before
@Before
Each
public
void
setUp
()
{
this
.
context
=
new
AnnotationConfigApplicationContext
();
TestPropertyValues
...
...
@@ -60,7 +62,7 @@ public class CassandraDataAutoConfigurationIntegrationTests {
.
applyTo
(
this
.
context
.
getEnvironment
());
}
@After
@After
Each
public
void
close
()
{
if
(
this
.
context
!=
null
)
{
this
.
context
.
close
();
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchAutoConfigurationTests.java
View file @
684a1c7a
...
...
@@ -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
{
@C
lassRule
@C
ontainer
public
static
ElasticsearchContainer
elasticsearch
=
new
ElasticsearchContainer
();
private
AnnotationConfigApplicationContext
context
;
@After
@After
Each
public
void
close
()
{
if
(
this
.
context
!=
null
)
{
this
.
context
.
close
();
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchDataAutoConfigurationTests.java
View file @
684a1c7a
...
...
@@ -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
{
@C
lassRule
@C
ontainer
public
static
ElasticsearchContainer
elasticsearch
=
new
ElasticsearchContainer
();
private
AnnotationConfigApplicationContext
context
;
@After
@After
Each
public
void
close
()
{
if
(
this
.
context
!=
null
)
{
this
.
context
.
close
();
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchRepositoriesAutoConfigurationTests.java
View file @
684a1c7a
...
...
@@ -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
{
@C
lassRule
@C
ontainer
public
static
ElasticsearchContainer
elasticsearch
=
new
ElasticsearchContainer
();
private
AnnotationConfigApplicationContext
context
;
@After
@After
Each
public
void
close
()
{
this
.
context
.
close
();
}
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisRepositoriesAutoConfigurationTests.java
View file @
684a1c7a
...
...
@@ -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
{
@C
lassRule
@C
ontainer
public
static
RedisContainer
redis
=
new
RedisContainer
();
private
AnnotationConfigApplicationContext
context
=
new
AnnotationConfigApplicationContext
();
@Before
@Before
Each
public
void
setUp
()
{
TestPropertyValues
.
of
(
"spring.redis.port="
+
redis
.
getMappedPort
())
.
applyTo
(
this
.
context
.
getEnvironment
());
}
@After
@After
Each
public
void
close
()
{
this
.
context
.
close
();
}
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/elasticsearch/jest/JestAutoConfigurationTests.java
View file @
684a1c7a
...
...
@@ -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
{
@C
lassRule
@C
ontainer
public
static
ElasticsearchContainer
elasticsearch
=
new
ElasticsearchContainer
();
private
ApplicationContextRunner
contextRunner
=
new
ApplicationContextRunner
()
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/elasticsearch/rest/RestClientAutoConfigurationTests.java
View file @
684a1c7a
...
...
@@ -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
{
@C
lassRule
@C
ontainer
public
static
ElasticsearchContainer
elasticsearch
=
new
ElasticsearchContainer
();
private
ApplicationContextRunner
contextRunner
=
new
ApplicationContextRunner
()
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationRedisTests.java
View file @
684a1c7a
/*
* Copyright 2012-201
8
the original author or authors.
* Copyright 2012-201
9
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
{
@C
lassRule
@C
ontainer
public
static
RedisContainer
redis
=
new
RedisContainer
();
protected
final
WebApplicationContextRunner
contextRunner
=
new
WebApplicationContextRunner
()
...
...
spring-boot-project/spring-boot-test-autoconfigure/pom.xml
View file @
684a1c7a
...
...
@@ -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>
...
...
spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/neo4j/DataNeo4jTestIntegrationTests.java
View file @
684a1c7a
...
...
@@ -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
{
@C
lassRule
@C
ontainer
public
static
SkippableContainer
<
Neo4jContainer
<?>>
neo4j
=
new
SkippableContainer
<>(
()
->
new
Neo4jContainer
<>().
withAdminPassword
(
null
));
...
...
spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/neo4j/DataNeo4jTestPropertiesIntegrationTests.java
View file @
684a1c7a
...
...
@@ -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
{
@C
lassRule
@C
ontainer
public
static
SkippableContainer
<
Neo4jContainer
<?>>
neo4j
=
new
SkippableContainer
<>(
()
->
new
Neo4jContainer
<>().
withAdminPassword
(
null
));
...
...
spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/neo4j/DataNeo4jTestWithIncludeFilterIntegrationTests.java
View file @
684a1c7a
...
...
@@ -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
{
@C
lassRule
@C
ontainer
public
static
SkippableContainer
<
Neo4jContainer
<?>>
neo4j
=
new
SkippableContainer
<>(
()
->
new
Neo4jContainer
<>().
withAdminPassword
(
null
));
...
...
spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/redis/DataRedisTestIntegrationTests.java
View file @
684a1c7a
...
...
@@ -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
{
@C
lassRule
@C
ontainer
public
static
RedisContainer
redis
=
new
RedisContainer
();
@Autowired
...
...
spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/redis/DataRedisTestPropertiesIntegrationTests.java
View file @
684a1c7a
...
...
@@ -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
{
@C
lassRule
@C
ontainer
public
static
RedisContainer
redis
=
new
RedisContainer
();
@Autowired
...
...
spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/redis/DataRedisTestWithIncludeFilterIntegrationTests.java
View file @
684a1c7a
...
...
@@ -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
{
@C
lassRule
@C
ontainer
public
static
RedisContainer
redis
=
new
RedisContainer
();
@Autowired
...
...
spring-boot-project/spring-boot-tools/spring-boot-test-support/pom.xml
View file @
684a1c7a
...
...
@@ -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>
...
...
spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/testcontainers/Container.java
View file @
684a1c7a
/*
* Copyright 2012-201
8
the original author or authors.
* Copyright 2012-201
9
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
TestRu
le
{
class
Container
implements
Startab
le
{
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
();
}
}
}
spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/testcontainers/ElasticsearchContainer.java
View file @
684a1c7a
/*
* Copyright 2012-201
8
the original author or authors.
* Copyright 2012-201
9
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
();
}
}
spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/testcontainers/SkippableContainer.java
View file @
684a1c7a
...
...
@@ -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
TestRu
le
{
public
class
SkippableContainer
<
T
extends
GenericContainer
>
implements
Startab
le
{
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
();
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment