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
33ef1b6e
Commit
33ef1b6e
authored
Aug 28, 2020
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '2.2.x' into 2.3.x
Closes gh-23124
parents
242a2332
5cd910c7
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
89 additions
and
56 deletions
+89
-56
build.gradle
...-boot-project/spring-boot-test-autoconfigure/build.gradle
+1
-1
DataMongoTestIntegrationTests.java
...toconfigure/data/mongo/DataMongoTestIntegrationTests.java
+18
-1
DataMongoTestReactiveIntegrationTests.java
...ure/data/mongo/DataMongoTestReactiveIntegrationTests.java
+24
-1
DataMongoTestWithIncludeFilterIntegrationTests.java
...mongo/DataMongoTestWithIncludeFilterIntegrationTests.java
+26
-1
TransactionalDataMongoTestIntegrationTests.java
...ata/mongo/TransactionalDataMongoTestIntegrationTests.java
+20
-52
No files found.
spring-boot-project/spring-boot-test-autoconfigure/build.gradle
View file @
33ef1b6e
...
@@ -53,7 +53,6 @@ dependencies {
...
@@ -53,7 +53,6 @@ dependencies {
testImplementation
(
"com.fasterxml.jackson.module:jackson-module-parameter-names"
)
testImplementation
(
"com.fasterxml.jackson.module:jackson-module-parameter-names"
)
testImplementation
(
"com.h2database:h2"
)
testImplementation
(
"com.h2database:h2"
)
testImplementation
(
"com.unboundid:unboundid-ldapsdk"
)
testImplementation
(
"com.unboundid:unboundid-ldapsdk"
)
testImplementation
(
"de.flapdoodle.embed:de.flapdoodle.embed.mongo"
)
testImplementation
(
"io.lettuce:lettuce-core"
)
testImplementation
(
"io.lettuce:lettuce-core"
)
testImplementation
(
"io.projectreactor:reactor-core"
)
testImplementation
(
"io.projectreactor:reactor-core"
)
testImplementation
(
"io.projectreactor:reactor-test"
)
testImplementation
(
"io.projectreactor:reactor-test"
)
...
@@ -76,6 +75,7 @@ dependencies {
...
@@ -76,6 +75,7 @@ dependencies {
testImplementation
(
"org.springframework.hateoas:spring-hateoas"
)
testImplementation
(
"org.springframework.hateoas:spring-hateoas"
)
testImplementation
(
"org.springframework.plugin:spring-plugin-core"
)
testImplementation
(
"org.springframework.plugin:spring-plugin-core"
)
testImplementation
(
"org.testcontainers:junit-jupiter"
)
testImplementation
(
"org.testcontainers:junit-jupiter"
)
testImplementation
(
"org.testcontainers:mongodb"
)
testImplementation
(
"org.testcontainers:neo4j"
)
testImplementation
(
"org.testcontainers:neo4j"
)
testImplementation
(
"org.testcontainers:testcontainers"
)
testImplementation
(
"org.testcontainers:testcontainers"
)
...
...
spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/mongo/DataMongoTestIntegrationTests.java
View file @
33ef1b6e
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -16,12 +16,19 @@
...
@@ -16,12 +16,19 @@
package
org
.
springframework
.
boot
.
test
.
autoconfigure
.
data
.
mongo
;
package
org
.
springframework
.
boot
.
test
.
autoconfigure
.
data
.
mongo
;
import
java.time.Duration
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.testcontainers.containers.MongoDBContainer
;
import
org.testcontainers.junit.jupiter.Container
;
import
org.testcontainers.junit.jupiter.Testcontainers
;
import
org.springframework.beans.factory.NoSuchBeanDefinitionException
;
import
org.springframework.beans.factory.NoSuchBeanDefinitionException
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.data.mongodb.core.MongoTemplate
;
import
org.springframework.data.mongodb.core.MongoTemplate
;
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
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThatExceptionOfType
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThatExceptionOfType
;
...
@@ -32,8 +39,13 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
...
@@ -32,8 +39,13 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
* @author Michael Simons
* @author Michael Simons
*/
*/
@DataMongoTest
@DataMongoTest
@Testcontainers
(
disabledWithoutDocker
=
true
)
class
DataMongoTestIntegrationTests
{
class
DataMongoTestIntegrationTests
{
@Container
static
final
MongoDBContainer
mongoDB
=
new
MongoDBContainer
(
"mongo:4.0.10"
).
withStartupAttempts
(
5
)
.
withStartupTimeout
(
Duration
.
ofMinutes
(
5
));
@Autowired
@Autowired
private
MongoTemplate
mongoTemplate
;
private
MongoTemplate
mongoTemplate
;
...
@@ -58,4 +70,9 @@ class DataMongoTestIntegrationTests {
...
@@ -58,4 +70,9 @@ class DataMongoTestIntegrationTests {
.
isThrownBy
(()
->
this
.
applicationContext
.
getBean
(
ExampleService
.
class
));
.
isThrownBy
(()
->
this
.
applicationContext
.
getBean
(
ExampleService
.
class
));
}
}
@DynamicPropertySource
static
void
mongoProperties
(
DynamicPropertyRegistry
registry
)
{
registry
.
add
(
"spring.data.mongodb.uri"
,
mongoDB:
:
getReplicaSetUrl
);
}
}
}
spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/mongo/DataMongoTestReactiveIntegrationTests.java
View file @
33ef1b6e
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -19,9 +19,16 @@ package org.springframework.boot.test.autoconfigure.data.mongo;
...
@@ -19,9 +19,16 @@ package org.springframework.boot.test.autoconfigure.data.mongo;
import
java.time.Duration
;
import
java.time.Duration
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.testcontainers.containers.MongoDBContainer
;
import
org.testcontainers.junit.jupiter.Container
;
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
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
...
@@ -31,8 +38,14 @@ import static org.assertj.core.api.Assertions.assertThat;
...
@@ -31,8 +38,14 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Stephane Nicoll
* @author Stephane Nicoll
*/
*/
@DataMongoTest
@DataMongoTest
@Testcontainers
(
disabledWithoutDocker
=
true
)
@ContextConfiguration
(
initializers
=
DataMongoTestReactiveIntegrationTests
.
Initializer
.
class
)
class
DataMongoTestReactiveIntegrationTests
{
class
DataMongoTestReactiveIntegrationTests
{
@Container
static
final
MongoDBContainer
mongoDB
=
new
MongoDBContainer
(
"mongo:4.0.10"
).
withStartupAttempts
(
5
)
.
withStartupTimeout
(
Duration
.
ofMinutes
(
5
));
@Autowired
@Autowired
private
ReactiveMongoTemplate
mongoTemplate
;
private
ReactiveMongoTemplate
mongoTemplate
;
...
@@ -48,4 +61,14 @@ class DataMongoTestReactiveIntegrationTests {
...
@@ -48,4 +61,14 @@ 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 @
33ef1b6e
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -16,11 +16,20 @@
...
@@ -16,11 +16,20 @@
package
org
.
springframework
.
boot
.
test
.
autoconfigure
.
data
.
mongo
;
package
org
.
springframework
.
boot
.
test
.
autoconfigure
.
data
.
mongo
;
import
java.time.Duration
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.testcontainers.containers.MongoDBContainer
;
import
org.testcontainers.junit.jupiter.Container
;
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
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
...
@@ -30,8 +39,14 @@ import static org.assertj.core.api.Assertions.assertThat;
...
@@ -30,8 +39,14 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Michael Simons
* @author Michael Simons
*/
*/
@DataMongoTest
(
includeFilters
=
@Filter
(
Service
.
class
))
@DataMongoTest
(
includeFilters
=
@Filter
(
Service
.
class
))
@Testcontainers
(
disabledWithoutDocker
=
true
)
@ContextConfiguration
(
initializers
=
DataMongoTestWithIncludeFilterIntegrationTests
.
Initializer
.
class
)
class
DataMongoTestWithIncludeFilterIntegrationTests
{
class
DataMongoTestWithIncludeFilterIntegrationTests
{
@Container
static
final
MongoDBContainer
mongoDB
=
new
MongoDBContainer
(
"mongo:4.0.10"
).
withStartupAttempts
(
5
)
.
withStartupTimeout
(
Duration
.
ofMinutes
(
5
));
@Autowired
@Autowired
private
ExampleService
service
;
private
ExampleService
service
;
...
@@ -40,4 +55,14 @@ class DataMongoTestWithIncludeFilterIntegrationTests {
...
@@ -40,4 +55,14 @@ class DataMongoTestWithIncludeFilterIntegrationTests {
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
());
}
}
}
}
spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/mongo/TransactionalDataMongoTestIntegrationTests.java
View file @
33ef1b6e
...
@@ -16,34 +16,22 @@
...
@@ -16,34 +16,22 @@
package
org
.
springframework
.
boot
.
test
.
autoconfigure
.
data
.
mongo
;
package
org
.
springframework
.
boot
.
test
.
autoconfigure
.
data
.
mongo
;
import
java.io.IOException
;
import
java.time.Duration
;
import
java.time.Duration
;
import
java.util.List
;
import
com.mongodb.BasicDBList
;
import
com.mongodb.ServerAddress
;
import
com.mongodb.client.ClientSession
;
import
com.mongodb.client.MongoClient
;
import
com.mongodb.client.MongoDatabase
;
import
com.mongodb.connection.ServerDescription
;
import
de.flapdoodle.embed.mongo.config.IMongoCmdOptions
;
import
de.flapdoodle.embed.mongo.config.IMongodConfig
;
import
de.flapdoodle.embed.mongo.config.MongoCmdOptionsBuilder
;
import
de.flapdoodle.embed.mongo.config.MongodConfigBuilder
;
import
de.flapdoodle.embed.mongo.config.Storage
;
import
de.flapdoodle.embed.mongo.distribution.Version
;
import
org.awaitility.Awaitility
;
import
org.bson.Document
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.testcontainers.containers.MongoDBContainer
;
import
org.testcontainers.junit.jupiter.Container
;
import
org.testcontainers.junit.jupiter.Testcontainers
;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.mongo.embedded.EmbeddedMongoProperties
;
import
org.springframework.boot.test.context.TestConfiguration
;
import
org.springframework.boot.test.context.TestConfiguration
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.data.mongodb.MongoDatabaseFactory
;
import
org.springframework.data.mongodb.MongoDatabaseFactory
;
import
org.springframework.data.mongodb.MongoTransactionManager
;
import
org.springframework.data.mongodb.MongoTransactionManager
;
import
org.springframework.data.mongodb.core.MongoTemplate
;
import
org.springframework.data.mongodb.core.MongoTemplate
;
import
org.springframework.test.context.DynamicPropertyRegistry
;
import
org.springframework.test.context.DynamicPropertySource
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
...
@@ -55,8 +43,13 @@ import static org.assertj.core.api.Assertions.assertThat;
...
@@ -55,8 +43,13 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
*/
@DataMongoTest
@DataMongoTest
@Transactional
@Transactional
@Testcontainers
(
disabledWithoutDocker
=
true
)
class
TransactionalDataMongoTestIntegrationTests
{
class
TransactionalDataMongoTestIntegrationTests
{
@Container
static
final
MongoDBContainer
mongoDB
=
new
MongoDBContainer
(
"mongo:4.0.10"
).
withStartupAttempts
(
5
)
.
withStartupTimeout
(
Duration
.
ofMinutes
(
5
));
@Autowired
@Autowired
private
ExampleRepository
exampleRepository
;
private
ExampleRepository
exampleRepository
;
...
@@ -68,6 +61,11 @@ class TransactionalDataMongoTestIntegrationTests {
...
@@ -68,6 +61,11 @@ class TransactionalDataMongoTestIntegrationTests {
assertThat
(
exampleDocument
.
getId
()).
isNotNull
();
assertThat
(
exampleDocument
.
getId
()).
isNotNull
();
}
}
@DynamicPropertySource
static
void
mongoProperties
(
DynamicPropertyRegistry
registry
)
{
registry
.
add
(
"spring.data.mongodb.uri"
,
mongoDB:
:
getReplicaSetUrl
);
}
@TestConfiguration
(
proxyBeanMethods
=
false
)
@TestConfiguration
(
proxyBeanMethods
=
false
)
static
class
TransactionManagerConfiguration
{
static
class
TransactionManagerConfiguration
{
...
@@ -79,53 +77,23 @@ class TransactionalDataMongoTestIntegrationTests {
...
@@ -79,53 +77,23 @@ class TransactionalDataMongoTestIntegrationTests {
}
}
@TestConfiguration
(
proxyBeanMethods
=
false
)
@TestConfiguration
(
proxyBeanMethods
=
false
)
static
class
MongoCustomizationConfiguration
{
static
class
MongoInitializationConfiguration
{
private
static
final
String
REPLICA_SET_NAME
=
"rs1"
;
@Bean
@Bean
IMongodConfig
embeddedMongoConfiguration
(
EmbeddedMongoProperties
embeddedProperties
)
throws
IOException
{
MongoInitializer
mongoInitializer
(
MongoTemplate
template
)
{
IMongoCmdOptions
cmdOptions
=
new
MongoCmdOptionsBuilder
().
useNoJournal
(
false
).
build
();
return
new
MongoInitializer
(
template
);
return
new
MongodConfigBuilder
().
version
(
Version
.
Main
.
PRODUCTION
)
.
replication
(
new
Storage
(
null
,
REPLICA_SET_NAME
,
0
)).
cmdOptions
(
cmdOptions
)
.
stopTimeoutInMillis
(
60000
).
build
();
}
@Bean
MongoInitializer
mongoInitializer
(
MongoClient
client
,
MongoTemplate
template
)
{
return
new
MongoInitializer
(
client
,
template
);
}
}
static
class
MongoInitializer
implements
InitializingBean
{
static
class
MongoInitializer
implements
InitializingBean
{
private
final
MongoClient
client
;
private
final
MongoTemplate
template
;
private
final
MongoTemplate
template
;
MongoInitializer
(
MongoClient
client
,
MongoTemplate
template
)
{
MongoInitializer
(
MongoTemplate
template
)
{
this
.
client
=
client
;
this
.
template
=
template
;
this
.
template
=
template
;
}
}
@Override
@Override
public
void
afterPropertiesSet
()
throws
Exception
{
public
void
afterPropertiesSet
()
throws
Exception
{
List
<
ServerDescription
>
servers
=
this
.
client
.
getClusterDescription
().
getServerDescriptions
();
assertThat
(
servers
).
hasSize
(
1
);
ServerAddress
address
=
servers
.
get
(
0
).
getAddress
();
BasicDBList
members
=
new
BasicDBList
();
members
.
add
(
new
Document
(
"_id"
,
0
).
append
(
"host"
,
address
.
getHost
()
+
":"
+
address
.
getPort
()));
Document
config
=
new
Document
(
"_id"
,
REPLICA_SET_NAME
);
config
.
put
(
"members"
,
members
);
MongoDatabase
admin
=
this
.
client
.
getDatabase
(
"admin"
);
admin
.
runCommand
(
new
Document
(
"replSetInitiate"
,
config
));
Awaitility
.
await
().
atMost
(
Duration
.
ofMinutes
(
1
)).
until
(()
->
{
try
(
ClientSession
session
=
this
.
client
.
startSession
())
{
return
true
;
}
catch
(
Exception
ex
)
{
return
false
;
}
});
this
.
template
.
createCollection
(
"exampleDocuments"
);
this
.
template
.
createCollection
(
"exampleDocuments"
);
}
}
...
...
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