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
dd53ed0a
Commit
dd53ed0a
authored
Jun 05, 2017
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish "Add Slice test annotation for Redis"
Closes gh-9224
parent
2d36d2a7
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
44 additions
and
35 deletions
+44
-35
spring-boot-features.adoc
spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc
+6
-1
pom.xml
spring-boot-test-autoconfigure/pom.xml
+15
-15
AutoConfigureDataRedis.java
...test/autoconfigure/data/redis/AutoConfigureDataRedis.java
+1
-1
DataRedisTest.java
...ork/boot/test/autoconfigure/data/redis/DataRedisTest.java
+3
-6
DataRedisTypeExcludeFilter.java
.../autoconfigure/data/redis/DataRedisTypeExcludeFilter.java
+1
-2
spring.factories
...utoconfigure/src/main/resources/META-INF/spring.factories
+1
-2
DataRedisTestIntegrationTests.java
...toconfigure/data/redis/DataRedisTestIntegrationTests.java
+6
-3
DataRedisTestWithIncludeFilterIntegrationTests.java
...redis/DataRedisTestWithIncludeFilterIntegrationTests.java
+5
-1
ExampleService.java
...rk/boot/test/autoconfigure/data/redis/ExampleService.java
+4
-4
PersonHash.java
...mework/boot/test/autoconfigure/data/redis/PersonHash.java
+2
-0
No files found.
spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc
View file @
dd53ed0a
...
@@ -6010,9 +6010,13 @@ disable transaction management for a test or for the whole class as follows:
...
@@ -6010,9 +6010,13 @@ disable transaction management for a test or for the whole class as follows:
A list of the auto-configuration that is enabled by `@DataNeo4jTest` can be
A list of the auto-configuration that is enabled by `@DataNeo4jTest` can be
<<appendix-test-auto-configuration#test-auto-configuration,found in the appendix>>.
<<appendix-test-auto-configuration#test-auto-configuration,found in the appendix>>.
[[boot-features-testing-spring-boot-applications-testing-autoconfigured-redis-test]]
[[boot-features-testing-spring-boot-applications-testing-autoconfigured-redis-test]]
==== Auto-configured Data Redis tests
==== Auto-configured Data Redis tests
`@DataRedisTest` can be used if you want to test Redis applications.
`@DataRedisTest` can be used if you want to test Redis applications. By default, it will
scan for `@RedisHash` classes and configure Spring Data Redis repositories. Regular
`@Component` beans will not be loaded into the `ApplicationContext`:
[source,java,indent=0]
[source,java,indent=0]
----
----
...
@@ -6036,6 +6040,7 @@ A list of the auto-configuration that is enabled by `@DataRedisTest` can be
...
@@ -6036,6 +6040,7 @@ A list of the auto-configuration that is enabled by `@DataRedisTest` can be
<<appendix-test-auto-configuration#test-auto-configuration,found in the appendix>>.
<<appendix-test-auto-configuration#test-auto-configuration,found in the appendix>>.
[[boot-features-testing-spring-boot-applications-testing-autoconfigured-ldap-test]]
[[boot-features-testing-spring-boot-applications-testing-autoconfigured-ldap-test]]
==== Auto-configured Data LDAP tests
==== Auto-configured Data LDAP tests
`@DataLdapTest` can be used if you want to test LDAP applications. By default, it will
`@DataLdapTest` can be used if you want to test LDAP applications. By default, it will
...
...
spring-boot-test-autoconfigure/pom.xml
View file @
dd53ed0a
...
@@ -59,11 +59,6 @@
...
@@ -59,11 +59,6 @@
<artifactId>
htmlunit
</artifactId>
<artifactId>
htmlunit
</artifactId>
<optional>
true
</optional>
<optional>
true
</optional>
</dependency>
</dependency>
<dependency>
<groupId>
org.apache.commons
</groupId>
<artifactId>
commons-pool2
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<dependency>
<groupId>
org.hibernate
</groupId>
<groupId>
org.hibernate
</groupId>
<artifactId>
hibernate-core
</artifactId>
<artifactId>
hibernate-core
</artifactId>
...
@@ -136,6 +131,11 @@
...
@@ -136,6 +131,11 @@
<artifactId>
spring-data-neo4j
</artifactId>
<artifactId>
spring-data-neo4j
</artifactId>
<optional>
true
</optional>
<optional>
true
</optional>
</dependency>
</dependency>
<dependency>
<groupId>
org.springframework.data
</groupId>
<artifactId>
spring-data-redis
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<dependency>
<groupId>
org.springframework.restdocs
</groupId>
<groupId>
org.springframework.restdocs
</groupId>
<artifactId>
spring-restdocs-mockmvc
</artifactId>
<artifactId>
spring-restdocs-mockmvc
</artifactId>
...
@@ -151,16 +151,6 @@
...
@@ -151,16 +151,6 @@
<artifactId>
spring-security-test
</artifactId>
<artifactId>
spring-security-test
</artifactId>
<optional>
true
</optional>
<optional>
true
</optional>
</dependency>
</dependency>
<dependency>
<groupId>
org.springframework.data
</groupId>
<artifactId>
spring-data-redis
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
redis.clients
</groupId>
<artifactId>
jedis
</artifactId>
<optional>
true
</optional>
</dependency>
<!-- Test -->
<!-- Test -->
<dependency>
<dependency>
...
@@ -188,6 +178,11 @@
...
@@ -188,6 +178,11 @@
<artifactId>
reactor-core
</artifactId>
<artifactId>
reactor-core
</artifactId>
<scope>
test
</scope>
<scope>
test
</scope>
</dependency>
</dependency>
<dependency>
<groupId>
org.apache.commons
</groupId>
<artifactId>
commons-pool2
</artifactId>
<scope>
test
</scope>
</dependency>
<dependency>
<dependency>
<groupId>
org.aspectj
</groupId>
<groupId>
org.aspectj
</groupId>
<artifactId>
aspectjrt
</artifactId>
<artifactId>
aspectjrt
</artifactId>
...
@@ -248,6 +243,11 @@
...
@@ -248,6 +243,11 @@
<artifactId>
tomcat-embed-el
</artifactId>
<artifactId>
tomcat-embed-el
</artifactId>
<scope>
test
</scope>
<scope>
test
</scope>
</dependency>
</dependency>
<dependency>
<groupId>
redis.clients
</groupId>
<artifactId>
jedis
</artifactId>
<scope>
test
</scope>
</dependency>
<dependency>
<dependency>
<groupId>
de.flapdoodle.embed
</groupId>
<groupId>
de.flapdoodle.embed
</groupId>
<artifactId>
de.flapdoodle.embed.mongo
</artifactId>
<artifactId>
de.flapdoodle.embed.mongo
</artifactId>
...
...
spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/redis/AutoConfigureDataRedis.java
View file @
dd53ed0a
...
@@ -31,7 +31,7 @@ import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
...
@@ -31,7 +31,7 @@ import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
* than using this annotation directly.
* than using this annotation directly.
*
*
* @author Jayaram Pradhan
* @author Jayaram Pradhan
*
*
@since 2.0.0
*/
*/
@Target
(
ElementType
.
TYPE
)
@Target
(
ElementType
.
TYPE
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
...
...
spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/redis/DataRedisTest.java
View file @
dd53ed0a
...
@@ -33,21 +33,18 @@ import org.springframework.context.annotation.ComponentScan.Filter;
...
@@ -33,21 +33,18 @@ import org.springframework.context.annotation.ComponentScan.Filter;
import
org.springframework.core.annotation.AliasFor
;
import
org.springframework.core.annotation.AliasFor
;
import
org.springframework.test.context.BootstrapWith
;
import
org.springframework.test.context.BootstrapWith
;
/**
/**
* Annotation that can be used in combination with {@code @RunWith(SpringRunner.class)}
* Annotation that can be used in combination with {@code @RunWith(SpringRunner.class)}
* for a typical Data Redis test. Can be used when a test focuses <strong>only</strong> on
* for a typical Data Redis test. Can be used when a test focuses <strong>only</strong> on
* Redis
DB
components.
* Redis components.
* <p>
* <p>
* Using this annotation will disable full auto-configuration and instead apply only
* Using this annotation will disable full auto-configuration and instead apply only
* configuration relevant to Redis
DB
tests.
* configuration relevant to Redis tests.
* <p>
* <p>
*
*
* @author Jayaram Pradhan
* @author Jayaram Pradhan
*
*
@since 2.0.0
*/
*/
@Target
(
ElementType
.
TYPE
)
@Target
(
ElementType
.
TYPE
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Documented
@Documented
...
...
spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/redis/DataRedisTypeExcludeFilter.java
View file @
dd53ed0a
...
@@ -24,8 +24,6 @@ import org.springframework.boot.test.autoconfigure.filter.AnnotationCustomizable
...
@@ -24,8 +24,6 @@ import org.springframework.boot.test.autoconfigure.filter.AnnotationCustomizable
import
org.springframework.context.annotation.ComponentScan.Filter
;
import
org.springframework.context.annotation.ComponentScan.Filter
;
import
org.springframework.core.annotation.AnnotatedElementUtils
;
import
org.springframework.core.annotation.AnnotatedElementUtils
;
/**
/**
* {@link TypeExcludeFilter} for {@link DataRedisTest @DataRedisTest}.
* {@link TypeExcludeFilter} for {@link DataRedisTest @DataRedisTest}.
*
*
...
@@ -71,4 +69,5 @@ class DataRedisTypeExcludeFilter extends AnnotationCustomizableTypeExcludeFilter
...
@@ -71,4 +69,5 @@ class DataRedisTypeExcludeFilter extends AnnotationCustomizableTypeExcludeFilter
protected
Set
<
Class
<?>>
getComponentIncludes
()
{
protected
Set
<
Class
<?>>
getComponentIncludes
()
{
return
Collections
.
emptySet
();
return
Collections
.
emptySet
();
}
}
}
}
spring-boot-test-autoconfigure/src/main/resources/META-INF/spring.factories
View file @
dd53ed0a
...
@@ -39,8 +39,7 @@ org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration
...
@@ -39,8 +39,7 @@ org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration
# AutoConfigureDataRedis auto-configuration imports
# AutoConfigureDataRedis auto-configuration imports
org.springframework.boot.test.autoconfigure.data.redis.AutoConfigureDataRedis=\
org.springframework.boot.test.autoconfigure.data.redis.AutoConfigureDataRedis=\
org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration,\
org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration,\
org.springframework.boot.autoconfigure.data.redis.RedisRepositoriesAutoConfiguration,\
org.springframework.boot.autoconfigure.data.redis.RedisRepositoriesAutoConfiguration
org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration
# AutoConfigureJdbc auto-configuration imports
# AutoConfigureJdbc auto-configuration imports
org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureJdbc=\
org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureJdbc=\
...
...
spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/redis/DataRedisTestIntegrationTests.java
View file @
dd53ed0a
...
@@ -25,6 +25,7 @@ import org.junit.runner.RunWith;
...
@@ -25,6 +25,7 @@ import org.junit.runner.RunWith;
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.testsupport.rule.RedisTestServer
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContext
;
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
;
...
@@ -32,7 +33,6 @@ import org.springframework.test.context.junit4.SpringRunner;
...
@@ -32,7 +33,6 @@ import org.springframework.test.context.junit4.SpringRunner;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
/**
* Integration test for {@link DataRedisTest}.
* Integration test for {@link DataRedisTest}.
*
*
...
@@ -42,12 +42,15 @@ import static org.assertj.core.api.Assertions.assertThat;
...
@@ -42,12 +42,15 @@ import static org.assertj.core.api.Assertions.assertThat;
@DataRedisTest
@DataRedisTest
public
class
DataRedisTestIntegrationTests
{
public
class
DataRedisTestIntegrationTests
{
@
Autowired
@
Rule
p
rivate
RedisOperations
<
Object
,
Object
>
operations
;
p
ublic
RedisTestServer
redis
=
new
RedisTestServer
()
;
@Rule
@Rule
public
ExpectedException
thrown
=
ExpectedException
.
none
();
public
ExpectedException
thrown
=
ExpectedException
.
none
();
@Autowired
private
RedisOperations
<
Object
,
Object
>
operations
;
@Autowired
@Autowired
private
ExampleRepository
exampleRepository
;
private
ExampleRepository
exampleRepository
;
...
...
spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/redis/DataRedisTestWithIncludeFilterIntegrationTests.java
View file @
dd53ed0a
...
@@ -16,10 +16,12 @@
...
@@ -16,10 +16,12 @@
package
org
.
springframework
.
boot
.
test
.
autoconfigure
.
data
.
redis
;
package
org
.
springframework
.
boot
.
test
.
autoconfigure
.
data
.
redis
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.testsupport.rule.RedisTestServer
;
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.junit4.SpringRunner
;
import
org.springframework.test.context.junit4.SpringRunner
;
...
@@ -35,6 +37,9 @@ import static org.assertj.core.api.Assertions.assertThat;
...
@@ -35,6 +37,9 @@ import static org.assertj.core.api.Assertions.assertThat;
@DataRedisTest
(
includeFilters
=
@Filter
(
Service
.
class
))
@DataRedisTest
(
includeFilters
=
@Filter
(
Service
.
class
))
public
class
DataRedisTestWithIncludeFilterIntegrationTests
{
public
class
DataRedisTestWithIncludeFilterIntegrationTests
{
@Rule
public
RedisTestServer
redis
=
new
RedisTestServer
();
@Autowired
@Autowired
private
ExampleRepository
exampleRepository
;
private
ExampleRepository
exampleRepository
;
...
@@ -48,7 +53,6 @@ public class DataRedisTestWithIncludeFilterIntegrationTests {
...
@@ -48,7 +53,6 @@ public class DataRedisTestWithIncludeFilterIntegrationTests {
assertThat
(
personHash
.
getId
()).
isNull
();
assertThat
(
personHash
.
getId
()).
isNull
();
PersonHash
savedEntity
=
this
.
exampleRepository
.
save
(
personHash
);
PersonHash
savedEntity
=
this
.
exampleRepository
.
save
(
personHash
);
assertThat
(
this
.
service
.
hasRecord
(
savedEntity
)).
isTrue
();
assertThat
(
this
.
service
.
hasRecord
(
savedEntity
)).
isTrue
();
this
.
exampleRepository
.
deleteAll
();
}
}
}
}
spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/redis/ExampleService.java
View file @
dd53ed0a
...
@@ -22,7 +22,6 @@ import org.springframework.data.redis.connection.RedisConnection;
...
@@ -22,7 +22,6 @@ import org.springframework.data.redis.connection.RedisConnection;
import
org.springframework.data.redis.core.RedisOperations
;
import
org.springframework.data.redis.core.RedisOperations
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
/**
/**
* Example service used with {@link DataRedisTest} tests.
* Example service used with {@link DataRedisTest} tests.
*
*
...
@@ -31,16 +30,17 @@ import org.springframework.stereotype.Service;
...
@@ -31,16 +30,17 @@ import org.springframework.stereotype.Service;
@Service
@Service
public
class
ExampleService
{
public
class
ExampleService
{
private
RedisOperations
<
Object
,
Object
>
operations
;
private
static
final
Charset
CHARSET
=
Charset
.
forName
(
"UTF-8"
);
private
static
final
Charset
CHARSET
=
Charset
.
forName
(
"UTF-8"
);
private
RedisOperations
<
Object
,
Object
>
operations
;
public
ExampleService
(
RedisOperations
<
Object
,
Object
>
operations
)
{
public
ExampleService
(
RedisOperations
<
Object
,
Object
>
operations
)
{
this
.
operations
=
operations
;
this
.
operations
=
operations
;
}
}
public
boolean
hasRecord
(
PersonHash
personHash
)
{
public
boolean
hasRecord
(
PersonHash
personHash
)
{
return
this
.
operations
.
execute
(
return
this
.
operations
.
execute
(
(
RedisConnection
connection
)
->
(
RedisConnection
connection
)
->
connection
.
exists
((
"persons:"
+
personHash
.
getId
()).
getBytes
(
CHARSET
)));
connection
.
exists
((
"persons:"
+
personHash
.
getId
()).
getBytes
(
CHARSET
)));
}
}
}
}
spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/redis/PersonHash.java
View file @
dd53ed0a
...
@@ -29,6 +29,7 @@ public class PersonHash {
...
@@ -29,6 +29,7 @@ public class PersonHash {
@Id
@Id
private
String
id
;
private
String
id
;
private
String
description
;
private
String
description
;
public
String
getId
()
{
public
String
getId
()
{
...
@@ -46,4 +47,5 @@ public class PersonHash {
...
@@ -46,4 +47,5 @@ public class PersonHash {
public
void
setDescription
(
String
description
)
{
public
void
setDescription
(
String
description
)
{
this
.
description
=
description
;
this
.
description
=
description
;
}
}
}
}
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