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
9a6c3392
Commit
9a6c3392
authored
Jan 08, 2018
by
Madhura Bhave
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use TestContainers util from spring-boot-test-support
See gh-10516
parent
996b3ef7
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
108 additions
and
109 deletions
+108
-109
CassandraDataAutoConfigurationIntegrationTests.java
...andra/CassandraDataAutoConfigurationIntegrationTests.java
+15
-45
RedisRepositoriesAutoConfigurationTests.java
...e/data/redis/RedisRepositoriesAutoConfigurationTests.java
+10
-1
ReactiveSessionAutoConfigurationRedisTests.java
...e/session/ReactiveSessionAutoConfigurationRedisTests.java
+0
-8
SessionAutoConfigurationRedisTests.java
...configure/session/SessionAutoConfigurationRedisTests.java
+1
-1
DataNeo4jTestIntegrationTests.java
...toconfigure/data/neo4j/DataNeo4jTestIntegrationTests.java
+16
-39
DataNeo4jTestWithIncludeFilterIntegrationTests.java
...neo4j/DataNeo4jTestWithIncludeFilterIntegrationTests.java
+22
-7
DataRedisTestIntegrationTests.java
...toconfigure/data/redis/DataRedisTestIntegrationTests.java
+22
-4
DataRedisTestWithIncludeFilterIntegrationTests.java
...redis/DataRedisTestWithIncludeFilterIntegrationTests.java
+22
-4
No files found.
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfigurationIntegrationTests.java
View file @
9a6c3392
...
@@ -16,25 +16,20 @@
...
@@ -16,25 +16,20 @@
package
org
.
springframework
.
boot
.
autoconfigure
.
data
.
cassandra
;
package
org
.
springframework
.
boot
.
autoconfigure
.
data
.
cassandra
;
import
java.util.concurrent.Callable
;
import
java.util.concurrent.TimeUnit
;
import
com.datastax.driver.core.Cluster
;
import
com.datastax.driver.core.Cluster
;
import
com.datastax.driver.core.Session
;
import
com.datastax.driver.core.Session
;
import
com.datastax.driver.core.exceptions.NoHostAvailableException
;
import
org.junit.After
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.ClassRule
;
import
org.junit.ClassRule
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.rnorth.ducttape.TimeoutException
;
import
org.testcontainers.containers.GenericContainer
;
import
org.rnorth.ducttape.unreliables.Unreliables
;
import
org.testcontainers.containers.FixedHostPortGenericContainer
;
import
org.testcontainers.containers.wait.HostPortWaitStrategy
;
import
org.springframework.boot.autoconfigure.AutoConfigurationPackages
;
import
org.springframework.boot.autoconfigure.AutoConfigurationPackages
;
import
org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration
;
import
org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration
;
import
org.springframework.boot.autoconfigure.data.cassandra.city.City
;
import
org.springframework.boot.autoconfigure.data.cassandra.city.City
;
import
org.springframework.boot.test.util.TestPropertyValues
;
import
org.springframework.boot.test.util.TestPropertyValues
;
import
org.springframework.boot.testsupport.testcontainers.DockerTestContainer
;
import
org.springframework.boot.testsupport.testcontainers.DockerTestContainer
;
import
org.springframework.boot.testsupport.testcontainers.TestContainers
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.data.cassandra.config.CassandraSessionFactoryBean
;
import
org.springframework.data.cassandra.config.CassandraSessionFactoryBean
;
import
org.springframework.data.cassandra.config.SchemaAction
;
import
org.springframework.data.cassandra.config.SchemaAction
;
...
@@ -50,13 +45,19 @@ import static org.assertj.core.api.Assertions.assertThat;
...
@@ -50,13 +45,19 @@ import static org.assertj.core.api.Assertions.assertThat;
public
class
CassandraDataAutoConfigurationIntegrationTests
{
public
class
CassandraDataAutoConfigurationIntegrationTests
{
@ClassRule
@ClassRule
public
static
DockerTestContainer
<
FixedHostPortGenericContainer
<?>>
cassandra
=
new
DockerTestContainer
<>(
public
static
DockerTestContainer
<
GenericContainer
<?>>
cassandra
=
new
DockerTestContainer
<>(
()
->
new
FixedHostPortGenericContainer
<>(
"cassandra:latest"
)
TestContainers:
:
cassandra
);
.
withFixedExposedPort
(
9042
,
9042
)
.
waitingFor
(
new
ConnectionVerifyingWaitStrategy
()));
private
AnnotationConfigApplicationContext
context
;
private
AnnotationConfigApplicationContext
context
;
@Before
public
void
setUp
()
{
this
.
context
=
new
AnnotationConfigApplicationContext
();
TestPropertyValues
.
of
(
"spring.data.cassandra.port="
+
cassandra
.
getMappedPort
(
9042
))
.
applyTo
(
this
.
context
.
getEnvironment
());
}
@After
@After
public
void
close
()
{
public
void
close
()
{
if
(
this
.
context
!=
null
)
{
if
(
this
.
context
!=
null
)
{
...
@@ -66,7 +67,6 @@ public class CassandraDataAutoConfigurationIntegrationTests {
...
@@ -66,7 +67,6 @@ public class CassandraDataAutoConfigurationIntegrationTests {
@Test
@Test
public
void
hasDefaultSchemaActionSet
()
{
public
void
hasDefaultSchemaActionSet
()
{
this
.
context
=
new
AnnotationConfigApplicationContext
();
String
cityPackage
=
City
.
class
.
getPackage
().
getName
();
String
cityPackage
=
City
.
class
.
getPackage
().
getName
();
AutoConfigurationPackages
.
register
(
this
.
context
,
cityPackage
);
AutoConfigurationPackages
.
register
(
this
.
context
,
cityPackage
);
this
.
context
.
register
(
CassandraAutoConfiguration
.
class
,
this
.
context
.
register
(
CassandraAutoConfiguration
.
class
,
...
@@ -81,7 +81,6 @@ public class CassandraDataAutoConfigurationIntegrationTests {
...
@@ -81,7 +81,6 @@ public class CassandraDataAutoConfigurationIntegrationTests {
@Test
@Test
public
void
hasRecreateSchemaActionSet
()
{
public
void
hasRecreateSchemaActionSet
()
{
createTestKeyspaceIfNotExists
();
createTestKeyspaceIfNotExists
();
this
.
context
=
new
AnnotationConfigApplicationContext
();
String
cityPackage
=
City
.
class
.
getPackage
().
getName
();
String
cityPackage
=
City
.
class
.
getPackage
().
getName
();
AutoConfigurationPackages
.
register
(
this
.
context
,
cityPackage
);
AutoConfigurationPackages
.
register
(
this
.
context
,
cityPackage
);
TestPropertyValues
TestPropertyValues
...
@@ -97,41 +96,12 @@ public class CassandraDataAutoConfigurationIntegrationTests {
...
@@ -97,41 +96,12 @@ public class CassandraDataAutoConfigurationIntegrationTests {
}
}
private
void
createTestKeyspaceIfNotExists
()
{
private
void
createTestKeyspaceIfNotExists
()
{
Cluster
cluster
=
Cluster
.
builder
().
addContactPoint
(
"localhost"
).
build
();
Cluster
cluster
=
Cluster
.
builder
().
withPort
(
cassandra
.
getMappedPort
(
9042
))
.
addContactPoint
(
"localhost"
).
build
();
try
(
Session
session
=
cluster
.
connect
())
{
try
(
Session
session
=
cluster
.
connect
())
{
session
.
execute
(
"CREATE KEYSPACE IF NOT EXISTS boot_test"
session
.
execute
(
"CREATE KEYSPACE IF NOT EXISTS boot_test"
+
" WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };"
);
+
" WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };"
);
}
}
}
}
static
class
ConnectionVerifyingWaitStrategy
extends
HostPortWaitStrategy
{
@Override
protected
void
waitUntilReady
()
{
super
.
waitUntilReady
();
try
{
Unreliables
.
retryUntilTrue
((
int
)
this
.
startupTimeout
.
getSeconds
(),
TimeUnit
.
SECONDS
,
checkConnection
());
}
catch
(
TimeoutException
ex
)
{
throw
new
IllegalStateException
(
ex
);
}
}
private
Callable
<
Boolean
>
checkConnection
()
{
return
()
->
{
try
(
Cluster
cluster
=
Cluster
.
builder
().
addContactPoint
(
"localhost"
)
.
build
())
{
cluster
.
connect
();
return
true
;
}
catch
(
NoHostAvailableException
ex
)
{
return
false
;
}
};
}
}
}
}
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisRepositoriesAutoConfigurationTests.java
View file @
9a6c3392
...
@@ -17,6 +17,7 @@
...
@@ -17,6 +17,7 @@
package
org
.
springframework
.
boot
.
autoconfigure
.
data
.
redis
;
package
org
.
springframework
.
boot
.
autoconfigure
.
data
.
redis
;
import
org.junit.After
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.ClassRule
;
import
org.junit.ClassRule
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.testcontainers.containers.GenericContainer
;
import
org.testcontainers.containers.GenericContainer
;
...
@@ -27,6 +28,7 @@ import org.springframework.boot.autoconfigure.data.alt.redis.CityRedisRepository
...
@@ -27,6 +28,7 @@ import org.springframework.boot.autoconfigure.data.alt.redis.CityRedisRepository
import
org.springframework.boot.autoconfigure.data.empty.EmptyDataPackage
;
import
org.springframework.boot.autoconfigure.data.empty.EmptyDataPackage
;
import
org.springframework.boot.autoconfigure.data.redis.city.City
;
import
org.springframework.boot.autoconfigure.data.redis.city.City
;
import
org.springframework.boot.autoconfigure.data.redis.city.CityRepository
;
import
org.springframework.boot.autoconfigure.data.redis.city.CityRepository
;
import
org.springframework.boot.test.util.TestPropertyValues
;
import
org.springframework.boot.testsupport.testcontainers.DockerTestContainer
;
import
org.springframework.boot.testsupport.testcontainers.DockerTestContainer
;
import
org.springframework.boot.testsupport.testcontainers.TestContainers
;
import
org.springframework.boot.testsupport.testcontainers.TestContainers
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
...
@@ -44,10 +46,17 @@ public class RedisRepositoriesAutoConfigurationTests {
...
@@ -44,10 +46,17 @@ public class RedisRepositoriesAutoConfigurationTests {
@ClassRule
@ClassRule
public
static
DockerTestContainer
<
GenericContainer
<?>>
redis
=
new
DockerTestContainer
<>(
public
static
DockerTestContainer
<
GenericContainer
<?>>
redis
=
new
DockerTestContainer
<>(
()
->
TestContainers
.
redis
()
);
TestContainers:
:
redis
);
private
AnnotationConfigApplicationContext
context
=
new
AnnotationConfigApplicationContext
();
private
AnnotationConfigApplicationContext
context
=
new
AnnotationConfigApplicationContext
();
@Before
public
void
setUp
()
{
TestPropertyValues
.
of
(
"spring.redis.port="
+
redis
.
getMappedPort
(
6379
))
.
applyTo
(
this
.
context
.
getEnvironment
());
}
@After
@After
public
void
close
()
{
public
void
close
()
{
this
.
context
.
close
();
this
.
context
.
close
();
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/ReactiveSessionAutoConfigurationRedisTests.java
View file @
9a6c3392
...
@@ -16,9 +16,7 @@
...
@@ -16,9 +16,7 @@
package
org
.
springframework
.
boot
.
autoconfigure
.
session
;
package
org
.
springframework
.
boot
.
autoconfigure
.
session
;
import
org.junit.ClassRule
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.testcontainers.containers.FixedHostPortGenericContainer
;
import
org.springframework.beans.DirectFieldAccessor
;
import
org.springframework.beans.DirectFieldAccessor
;
import
org.springframework.boot.autoconfigure.AutoConfigurations
;
import
org.springframework.boot.autoconfigure.AutoConfigurations
;
...
@@ -28,7 +26,6 @@ import org.springframework.boot.test.context.FilteredClassLoader;
...
@@ -28,7 +26,6 @@ import org.springframework.boot.test.context.FilteredClassLoader;
import
org.springframework.boot.test.context.assertj.AssertableReactiveWebApplicationContext
;
import
org.springframework.boot.test.context.assertj.AssertableReactiveWebApplicationContext
;
import
org.springframework.boot.test.context.runner.ContextConsumer
;
import
org.springframework.boot.test.context.runner.ContextConsumer
;
import
org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner
;
import
org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner
;
import
org.springframework.boot.testsupport.testcontainers.DockerTestContainer
;
import
org.springframework.session.data.mongo.ReactiveMongoOperationsSessionRepository
;
import
org.springframework.session.data.mongo.ReactiveMongoOperationsSessionRepository
;
import
org.springframework.session.data.redis.ReactiveRedisOperationsSessionRepository
;
import
org.springframework.session.data.redis.ReactiveRedisOperationsSessionRepository
;
import
org.springframework.session.data.redis.RedisFlushMode
;
import
org.springframework.session.data.redis.RedisFlushMode
;
...
@@ -45,11 +42,6 @@ import static org.assertj.core.api.Assertions.assertThat;
...
@@ -45,11 +42,6 @@ import static org.assertj.core.api.Assertions.assertThat;
public
class
ReactiveSessionAutoConfigurationRedisTests
public
class
ReactiveSessionAutoConfigurationRedisTests
extends
AbstractSessionAutoConfigurationTests
{
extends
AbstractSessionAutoConfigurationTests
{
@ClassRule
public
static
DockerTestContainer
<
FixedHostPortGenericContainer
<?>>
redis
=
new
DockerTestContainer
<>(
()
->
new
FixedHostPortGenericContainer
<>(
"redis:latest"
)
.
withFixedExposedPort
(
6379
,
6379
));
protected
final
ReactiveWebApplicationContextRunner
contextRunner
=
new
ReactiveWebApplicationContextRunner
()
protected
final
ReactiveWebApplicationContextRunner
contextRunner
=
new
ReactiveWebApplicationContextRunner
()
.
withConfiguration
(
AutoConfigurations
.
of
(
SessionAutoConfiguration
.
class
));
.
withConfiguration
(
AutoConfigurations
.
of
(
SessionAutoConfiguration
.
class
));
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationRedisTests.java
View file @
9a6c3392
...
@@ -49,7 +49,7 @@ public class SessionAutoConfigurationRedisTests
...
@@ -49,7 +49,7 @@ public class SessionAutoConfigurationRedisTests
@ClassRule
@ClassRule
public
static
DockerTestContainer
<
GenericContainer
<?>>
redis
=
new
DockerTestContainer
<>(
public
static
DockerTestContainer
<
GenericContainer
<?>>
redis
=
new
DockerTestContainer
<>(
()
->
TestContainers
.
redis
()
);
TestContainers:
:
redis
);
protected
final
WebApplicationContextRunner
contextRunner
=
new
WebApplicationContextRunner
()
protected
final
WebApplicationContextRunner
contextRunner
=
new
WebApplicationContextRunner
()
.
withConfiguration
(
AutoConfigurations
.
of
(
SessionAutoConfiguration
.
class
));
.
withConfiguration
(
AutoConfigurations
.
of
(
SessionAutoConfiguration
.
class
));
...
...
spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/neo4j/DataNeo4jTestIntegrationTests.java
View file @
9a6c3392
...
@@ -16,26 +16,23 @@
...
@@ -16,26 +16,23 @@
package
org
.
springframework
.
boot
.
test
.
autoconfigure
.
data
.
neo4j
;
package
org
.
springframework
.
boot
.
test
.
autoconfigure
.
data
.
neo4j
;
import
java.util.concurrent.Callable
;
import
java.util.concurrent.TimeUnit
;
import
org.junit.ClassRule
;
import
org.junit.ClassRule
;
import
org.junit.Rule
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.junit.rules.ExpectedException
;
import
org.junit.rules.ExpectedException
;
import
org.junit.runner.RunWith
;
import
org.junit.runner.RunWith
;
import
org.neo4j.ogm.config.Configuration
;
import
org.neo4j.ogm.session.Session
;
import
org.neo4j.ogm.session.Session
;
import
org.neo4j.ogm.session.SessionFactory
;
import
org.testcontainers.containers.GenericContainer
;
import
org.rnorth.ducttape.TimeoutException
;
import
org.rnorth.ducttape.unreliables.Unreliables
;
import
org.testcontainers.containers.FixedHostPortGenericContainer
;
import
org.testcontainers.containers.wait.HostPortWaitStrategy
;
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.boot.test.util.TestPropertyValues
;
import
org.springframework.boot.testsupport.testcontainers.DockerTestContainer
;
import
org.springframework.boot.testsupport.testcontainers.DockerTestContainer
;
import
org.springframework.boot.testsupport.testcontainers.TestContainers
;
import
org.springframework.context.ApplicationContext
;
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
org.springframework.test.context.junit4.SpringRunner
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
...
@@ -47,15 +44,13 @@ import static org.assertj.core.api.Assertions.assertThat;
...
@@ -47,15 +44,13 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Stephane Nicoll
* @author Stephane Nicoll
*/
*/
@RunWith
(
SpringRunner
.
class
)
@RunWith
(
SpringRunner
.
class
)
@ContextConfiguration
(
initializers
=
DataNeo4jTestIntegrationTests
.
Initializer
.
class
)
@DataNeo4jTest
@DataNeo4jTest
public
class
DataNeo4jTestIntegrationTests
{
public
class
DataNeo4jTestIntegrationTests
{
@ClassRule
@ClassRule
public
static
DockerTestContainer
<
FixedHostPortGenericContainer
<?>>
neo4j
=
new
DockerTestContainer
<>(
public
static
DockerTestContainer
<
GenericContainer
<?>>
neo4j
=
new
DockerTestContainer
<>(
()
->
new
FixedHostPortGenericContainer
<>(
"neo4j:latest"
)
TestContainers:
:
neo4j
);
.
withFixedExposedPort
(
7687
,
7687
)
.
waitingFor
(
new
ConnectionVerifyingWaitStrategy
())
.
withEnv
(
"NEO4J_AUTH"
,
"none"
));
@Rule
@Rule
public
ExpectedException
thrown
=
ExpectedException
.
none
();
public
ExpectedException
thrown
=
ExpectedException
.
none
();
...
@@ -85,35 +80,17 @@ public class DataNeo4jTestIntegrationTests {
...
@@ -85,35 +80,17 @@ public class DataNeo4jTestIntegrationTests {
this
.
applicationContext
.
getBean
(
ExampleService
.
class
);
this
.
applicationContext
.
getBean
(
ExampleService
.
class
);
}
}
static
class
ConnectionVerifyingWaitStrategy
extends
HostPortWaitStrategy
{
static
class
Initializer
implements
ApplicationContextInitializer
<
ConfigurableApplicationContext
>
{
@Override
@Override
protected
void
waitUntilReady
()
{
public
void
initialize
(
super
.
waitUntilReady
();
ConfigurableApplicationContext
configurableApplicationContext
)
{
Configuration
configuration
=
new
Configuration
.
Builder
()
TestPropertyValues
.
uri
(
"bolt://localhost:7687"
).
build
();
.
of
(
"spring.data.neo4j.uri=bolt://localhost:"
+
neo4j
.
getMappedPort
(
7687
))
SessionFactory
sessionFactory
=
new
SessionFactory
(
configuration
,
.
applyTo
(
configurableApplicationContext
.
getEnvironment
());
"org.springframework.boot.test.autoconfigure.data.neo4j"
);
try
{
Unreliables
.
retryUntilTrue
((
int
)
this
.
startupTimeout
.
getSeconds
(),
TimeUnit
.
SECONDS
,
checkConnection
(
sessionFactory
));
}
catch
(
TimeoutException
e
)
{
throw
new
IllegalStateException
();
}
}
}
private
Callable
<
Boolean
>
checkConnection
(
SessionFactory
sessionFactory
)
{
return
()
->
{
try
{
sessionFactory
.
openSession
().
beginTransaction
().
close
();
return
true
;
}
catch
(
Exception
ex
)
{
return
false
;
}
};
}
}
}
}
}
spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/neo4j/DataNeo4jTestWithIncludeFilterIntegrationTests.java
View file @
9a6c3392
...
@@ -19,12 +19,17 @@ package org.springframework.boot.test.autoconfigure.data.neo4j;
...
@@ -19,12 +19,17 @@ package org.springframework.boot.test.autoconfigure.data.neo4j;
import
org.junit.ClassRule
;
import
org.junit.ClassRule
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.junit.runner.RunWith
;
import
org.testcontainers.containers.
FixedHostPort
GenericContainer
;
import
org.testcontainers.containers.GenericContainer
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.util.TestPropertyValues
;
import
org.springframework.boot.testsupport.testcontainers.DockerTestContainer
;
import
org.springframework.boot.testsupport.testcontainers.DockerTestContainer
;
import
org.springframework.boot.testsupport.testcontainers.TestContainers
;
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.junit4.SpringRunner
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
...
@@ -35,16 +40,13 @@ import static org.assertj.core.api.Assertions.assertThat;
...
@@ -35,16 +40,13 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Eddú Meléndez
* @author Eddú Meléndez
*/
*/
@RunWith
(
SpringRunner
.
class
)
@RunWith
(
SpringRunner
.
class
)
@ContextConfiguration
(
initializers
=
DataNeo4jTestWithIncludeFilterIntegrationTests
.
Initializer
.
class
)
@DataNeo4jTest
(
includeFilters
=
@Filter
(
Service
.
class
))
@DataNeo4jTest
(
includeFilters
=
@Filter
(
Service
.
class
))
public
class
DataNeo4jTestWithIncludeFilterIntegrationTests
{
public
class
DataNeo4jTestWithIncludeFilterIntegrationTests
{
@ClassRule
@ClassRule
public
static
DockerTestContainer
<
FixedHostPortGenericContainer
<?>>
neo4j
=
new
DockerTestContainer
<>(
public
static
DockerTestContainer
<
GenericContainer
<?>>
neo4j
=
new
DockerTestContainer
<>(
()
->
new
FixedHostPortGenericContainer
<>(
"neo4j:latest"
)
TestContainers:
:
neo4j
);
.
withFixedExposedPort
(
7687
,
7687
)
.
waitingFor
(
new
DataNeo4jTestIntegrationTests
.
ConnectionVerifyingWaitStrategy
())
.
withEnv
(
"NEO4J_AUTH"
,
"none"
));
@Autowired
@Autowired
private
ExampleService
service
;
private
ExampleService
service
;
...
@@ -54,4 +56,17 @@ public class DataNeo4jTestWithIncludeFilterIntegrationTests {
...
@@ -54,4 +56,17 @@ public class DataNeo4jTestWithIncludeFilterIntegrationTests {
assertThat
(
this
.
service
.
hasNode
(
ExampleGraph
.
class
)).
isFalse
();
assertThat
(
this
.
service
.
hasNode
(
ExampleGraph
.
class
)).
isFalse
();
}
}
static
class
Initializer
implements
ApplicationContextInitializer
<
ConfigurableApplicationContext
>
{
@Override
public
void
initialize
(
ConfigurableApplicationContext
configurableApplicationContext
)
{
TestPropertyValues
.
of
(
"spring.data.neo4j.uri=bolt://localhost:"
+
neo4j
.
getMappedPort
(
7687
))
.
applyTo
(
configurableApplicationContext
.
getEnvironment
());
}
}
}
}
spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/redis/DataRedisTestIntegrationTests.java
View file @
9a6c3392
...
@@ -24,14 +24,19 @@ import org.junit.Rule;
...
@@ -24,14 +24,19 @@ import org.junit.Rule;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.junit.rules.ExpectedException
;
import
org.junit.rules.ExpectedException
;
import
org.junit.runner.RunWith
;
import
org.junit.runner.RunWith
;
import
org.testcontainers.containers.
FixedHostPort
GenericContainer
;
import
org.testcontainers.containers.GenericContainer
;
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.boot.test.util.TestPropertyValues
;
import
org.springframework.boot.testsupport.testcontainers.DockerTestContainer
;
import
org.springframework.boot.testsupport.testcontainers.DockerTestContainer
;
import
org.springframework.boot.testsupport.testcontainers.TestContainers
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContextInitializer
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.data.redis.connection.RedisConnection
;
import
org.springframework.data.redis.connection.RedisConnection
;
import
org.springframework.data.redis.core.RedisOperations
;
import
org.springframework.data.redis.core.RedisOperations
;
import
org.springframework.test.context.ContextConfiguration
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
...
@@ -42,13 +47,13 @@ import static org.assertj.core.api.Assertions.assertThat;
...
@@ -42,13 +47,13 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Jayaram Pradhan
* @author Jayaram Pradhan
*/
*/
@RunWith
(
SpringRunner
.
class
)
@RunWith
(
SpringRunner
.
class
)
@ContextConfiguration
(
initializers
=
DataRedisTestIntegrationTests
.
Initializer
.
class
)
@DataRedisTest
@DataRedisTest
public
class
DataRedisTestIntegrationTests
{
public
class
DataRedisTestIntegrationTests
{
@ClassRule
@ClassRule
public
static
DockerTestContainer
<
FixedHostPortGenericContainer
<?>>
redis
=
new
DockerTestContainer
<>(
public
static
DockerTestContainer
<
GenericContainer
<?>>
redis
=
new
DockerTestContainer
<>(
()
->
new
FixedHostPortGenericContainer
<>(
"redis:latest"
)
TestContainers:
:
redis
);
.
withFixedExposedPort
(
6379
,
6379
));
@Rule
@Rule
public
ExpectedException
thrown
=
ExpectedException
.
none
();
public
ExpectedException
thrown
=
ExpectedException
.
none
();
...
@@ -82,4 +87,17 @@ public class DataRedisTestIntegrationTests {
...
@@ -82,4 +87,17 @@ public class DataRedisTestIntegrationTests {
this
.
applicationContext
.
getBean
(
ExampleService
.
class
);
this
.
applicationContext
.
getBean
(
ExampleService
.
class
);
}
}
static
class
Initializer
implements
ApplicationContextInitializer
<
ConfigurableApplicationContext
>
{
@Override
public
void
initialize
(
ConfigurableApplicationContext
configurableApplicationContext
)
{
TestPropertyValues
.
of
(
"spring.redis.port="
+
redis
.
getMappedPort
(
6379
))
.
applyTo
(
configurableApplicationContext
.
getEnvironment
());
}
}
}
}
spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/redis/DataRedisTestWithIncludeFilterIntegrationTests.java
View file @
9a6c3392
...
@@ -19,12 +19,17 @@ package org.springframework.boot.test.autoconfigure.data.redis;
...
@@ -19,12 +19,17 @@ package org.springframework.boot.test.autoconfigure.data.redis;
import
org.junit.ClassRule
;
import
org.junit.ClassRule
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.junit.runner.RunWith
;
import
org.testcontainers.containers.
FixedHostPort
GenericContainer
;
import
org.testcontainers.containers.GenericContainer
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.util.TestPropertyValues
;
import
org.springframework.boot.testsupport.testcontainers.DockerTestContainer
;
import
org.springframework.boot.testsupport.testcontainers.DockerTestContainer
;
import
org.springframework.boot.testsupport.testcontainers.TestContainers
;
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.junit4.SpringRunner
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
...
@@ -35,13 +40,13 @@ import static org.assertj.core.api.Assertions.assertThat;
...
@@ -35,13 +40,13 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Jayaram Pradhan
* @author Jayaram Pradhan
*/
*/
@RunWith
(
SpringRunner
.
class
)
@RunWith
(
SpringRunner
.
class
)
@ContextConfiguration
(
initializers
=
DataRedisTestWithIncludeFilterIntegrationTests
.
Initializer
.
class
)
@DataRedisTest
(
includeFilters
=
@Filter
(
Service
.
class
))
@DataRedisTest
(
includeFilters
=
@Filter
(
Service
.
class
))
public
class
DataRedisTestWithIncludeFilterIntegrationTests
{
public
class
DataRedisTestWithIncludeFilterIntegrationTests
{
@ClassRule
@ClassRule
public
static
DockerTestContainer
<
FixedHostPortGenericContainer
<?>>
redis
=
new
DockerTestContainer
<>(
public
static
DockerTestContainer
<
GenericContainer
<?>>
redis
=
new
DockerTestContainer
<>(
()
->
new
FixedHostPortGenericContainer
<>(
"redis:latest"
)
TestContainers:
:
redis
);
.
withFixedExposedPort
(
6379
,
6379
));
@Autowired
@Autowired
private
ExampleRepository
exampleRepository
;
private
ExampleRepository
exampleRepository
;
...
@@ -58,4 +63,17 @@ public class DataRedisTestWithIncludeFilterIntegrationTests {
...
@@ -58,4 +63,17 @@ public class DataRedisTestWithIncludeFilterIntegrationTests {
assertThat
(
this
.
service
.
hasRecord
(
savedEntity
)).
isTrue
();
assertThat
(
this
.
service
.
hasRecord
(
savedEntity
)).
isTrue
();
}
}
static
class
Initializer
implements
ApplicationContextInitializer
<
ConfigurableApplicationContext
>
{
@Override
public
void
initialize
(
ConfigurableApplicationContext
configurableApplicationContext
)
{
TestPropertyValues
.
of
(
"spring.redis.port="
+
redis
.
getMappedPort
(
6379
))
.
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