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
51c9dee8
Commit
51c9dee8
authored
Aug 28, 2020
by
dreis2211
Committed by
Andy Wilkinson
Aug 28, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use DynamicPropertySource in MongoDB tests
See gh-23127
parent
3df58b2d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
30 deletions
+14
-30
DataMongoTestReactiveIntegrationTests.java
...ure/data/mongo/DataMongoTestReactiveIntegrationTests.java
+7
-15
DataMongoTestWithIncludeFilterIntegrationTests.java
...mongo/DataMongoTestWithIncludeFilterIntegrationTests.java
+7
-15
No files found.
spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/mongo/DataMongoTestReactiveIntegrationTests.java
View file @
51c9dee8
...
@@ -24,11 +24,9 @@ import org.testcontainers.junit.jupiter.Container;
...
@@ -24,11 +24,9 @@ import org.testcontainers.junit.jupiter.Container;
import
org.testcontainers.junit.jupiter.Testcontainers
;
import
org.testcontainers.junit.jupiter.Testcontainers
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.util.TestPropertyValues
;
import
org.springframework.context.ApplicationContextInitializer
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.data.mongodb.core.ReactiveMongoTemplate
;
import
org.springframework.data.mongodb.core.ReactiveMongoTemplate
;
import
org.springframework.test.context.ContextConfiguration
;
import
org.springframework.test.context.DynamicPropertyRegistry
;
import
org.springframework.test.context.DynamicPropertySource
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
...
@@ -39,7 +37,6 @@ import static org.assertj.core.api.Assertions.assertThat;
...
@@ -39,7 +37,6 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
*/
@DataMongoTest
@DataMongoTest
@Testcontainers
(
disabledWithoutDocker
=
true
)
@Testcontainers
(
disabledWithoutDocker
=
true
)
@ContextConfiguration
(
initializers
=
DataMongoTestReactiveIntegrationTests
.
Initializer
.
class
)
class
DataMongoTestReactiveIntegrationTests
{
class
DataMongoTestReactiveIntegrationTests
{
@Container
@Container
...
@@ -52,6 +49,11 @@ class DataMongoTestReactiveIntegrationTests {
...
@@ -52,6 +49,11 @@ class DataMongoTestReactiveIntegrationTests {
@Autowired
@Autowired
private
ExampleReactiveRepository
exampleRepository
;
private
ExampleReactiveRepository
exampleRepository
;
@DynamicPropertySource
static
void
mongoProperties
(
DynamicPropertyRegistry
registry
)
{
registry
.
add
(
"spring.data.mongodb.uri"
,
mongoDB:
:
getReplicaSetUrl
);
}
@Test
@Test
void
testRepository
()
{
void
testRepository
()
{
ExampleDocument
exampleDocument
=
new
ExampleDocument
();
ExampleDocument
exampleDocument
=
new
ExampleDocument
();
...
@@ -61,14 +63,4 @@ class DataMongoTestReactiveIntegrationTests {
...
@@ -61,14 +63,4 @@ class DataMongoTestReactiveIntegrationTests {
assertThat
(
this
.
mongoTemplate
.
collectionExists
(
"exampleDocuments"
).
block
(
Duration
.
ofSeconds
(
30
))).
isTrue
();
assertThat
(
this
.
mongoTemplate
.
collectionExists
(
"exampleDocuments"
).
block
(
Duration
.
ofSeconds
(
30
))).
isTrue
();
}
}
static
class
Initializer
implements
ApplicationContextInitializer
<
ConfigurableApplicationContext
>
{
@Override
public
void
initialize
(
ConfigurableApplicationContext
configurableApplicationContext
)
{
TestPropertyValues
.
of
(
"spring.data.mongodb.uri="
+
mongoDB
.
getReplicaSetUrl
())
.
applyTo
(
configurableApplicationContext
.
getEnvironment
());
}
}
}
}
spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/mongo/DataMongoTestWithIncludeFilterIntegrationTests.java
View file @
51c9dee8
...
@@ -24,12 +24,10 @@ import org.testcontainers.junit.jupiter.Container;
...
@@ -24,12 +24,10 @@ import org.testcontainers.junit.jupiter.Container;
import
org.testcontainers.junit.jupiter.Testcontainers
;
import
org.testcontainers.junit.jupiter.Testcontainers
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.util.TestPropertyValues
;
import
org.springframework.context.ApplicationContextInitializer
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.context.annotation.ComponentScan.Filter
;
import
org.springframework.context.annotation.ComponentScan.Filter
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.test.context.ContextConfiguration
;
import
org.springframework.test.context.DynamicPropertyRegistry
;
import
org.springframework.test.context.DynamicPropertySource
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
...
@@ -40,7 +38,6 @@ import static org.assertj.core.api.Assertions.assertThat;
...
@@ -40,7 +38,6 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
*/
@DataMongoTest
(
includeFilters
=
@Filter
(
Service
.
class
))
@DataMongoTest
(
includeFilters
=
@Filter
(
Service
.
class
))
@Testcontainers
(
disabledWithoutDocker
=
true
)
@Testcontainers
(
disabledWithoutDocker
=
true
)
@ContextConfiguration
(
initializers
=
DataMongoTestWithIncludeFilterIntegrationTests
.
Initializer
.
class
)
class
DataMongoTestWithIncludeFilterIntegrationTests
{
class
DataMongoTestWithIncludeFilterIntegrationTests
{
@Container
@Container
...
@@ -50,19 +47,14 @@ class DataMongoTestWithIncludeFilterIntegrationTests {
...
@@ -50,19 +47,14 @@ class DataMongoTestWithIncludeFilterIntegrationTests {
@Autowired
@Autowired
private
ExampleService
service
;
private
ExampleService
service
;
@DynamicPropertySource
static
void
mongoProperties
(
DynamicPropertyRegistry
registry
)
{
registry
.
add
(
"spring.data.mongodb.uri"
,
mongoDB:
:
getReplicaSetUrl
);
}
@Test
@Test
void
testService
()
{
void
testService
()
{
assertThat
(
this
.
service
.
hasCollection
(
"foobar"
)).
isFalse
();
assertThat
(
this
.
service
.
hasCollection
(
"foobar"
)).
isFalse
();
}
}
static
class
Initializer
implements
ApplicationContextInitializer
<
ConfigurableApplicationContext
>
{
@Override
public
void
initialize
(
ConfigurableApplicationContext
configurableApplicationContext
)
{
TestPropertyValues
.
of
(
"spring.data.mongodb.uri="
+
mongoDB
.
getReplicaSetUrl
())
.
applyTo
(
configurableApplicationContext
.
getEnvironment
());
}
}
}
}
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