Polish "Add Slice test annotation for Redis"

Closes gh-9224
pull/9443/merge
Stephane Nicoll 8 years ago
parent 2d36d2a7e4
commit dd53ed0aec

@ -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
<<appendix-test-auto-configuration#test-auto-configuration,found in the appendix>>.
[[boot-features-testing-spring-boot-applications-testing-autoconfigured-redis-test]]
==== 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]
----
@ -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>>.
[[boot-features-testing-spring-boot-applications-testing-autoconfigured-ldap-test]]
==== Auto-configured Data LDAP tests
`@DataLdapTest` can be used if you want to test LDAP applications. By default, it will

@ -59,11 +59,6 @@
<artifactId>htmlunit</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
@ -136,6 +131,11 @@
<artifactId>spring-data-neo4j</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.restdocs</groupId>
<artifactId>spring-restdocs-mockmvc</artifactId>
@ -151,16 +151,6 @@
<artifactId>spring-security-test</artifactId>
<optional>true</optional>
</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 -->
<dependency>
@ -188,6 +178,11 @@
<artifactId>reactor-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
@ -248,6 +243,11 @@
<artifactId>tomcat-embed-el</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.mongo</artifactId>

@ -31,7 +31,7 @@ import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
* than using this annotation directly.
*
* @author Jayaram Pradhan
*
* @since 2.0.0
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)

@ -33,21 +33,18 @@ import org.springframework.context.annotation.ComponentScan.Filter;
import org.springframework.core.annotation.AliasFor;
import org.springframework.test.context.BootstrapWith;
/**
* 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
* RedisDB components.
* Redis components.
* <p>
* Using this annotation will disable full auto-configuration and instead apply only
* configuration relevant to RedisDB tests.
* configuration relevant to Redis tests.
* <p>
*
* @author Jayaram Pradhan
*
* @since 2.0.0
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented

@ -24,8 +24,6 @@ import org.springframework.boot.test.autoconfigure.filter.AnnotationCustomizable
import org.springframework.context.annotation.ComponentScan.Filter;
import org.springframework.core.annotation.AnnotatedElementUtils;
/**
* {@link TypeExcludeFilter} for {@link DataRedisTest @DataRedisTest}.
*
@ -71,4 +69,5 @@ class DataRedisTypeExcludeFilter extends AnnotationCustomizableTypeExcludeFilter
protected Set<Class<?>> getComponentIncludes() {
return Collections.emptySet();
}
}

@ -39,8 +39,7 @@ org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration
# AutoConfigureDataRedis auto-configuration imports
org.springframework.boot.test.autoconfigure.data.redis.AutoConfigureDataRedis=\
org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration,\
org.springframework.boot.autoconfigure.data.redis.RedisRepositoriesAutoConfiguration,\
org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration
org.springframework.boot.autoconfigure.data.redis.RedisRepositoriesAutoConfiguration
# AutoConfigureJdbc auto-configuration imports
org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureJdbc=\

@ -25,6 +25,7 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.testsupport.rule.RedisTestServer;
import org.springframework.context.ApplicationContext;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.core.RedisOperations;
@ -32,7 +33,6 @@ import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Integration test for {@link DataRedisTest}.
*
@ -42,12 +42,15 @@ import static org.assertj.core.api.Assertions.assertThat;
@DataRedisTest
public class DataRedisTestIntegrationTests {
@Autowired
private RedisOperations<Object, Object> operations;
@Rule
public RedisTestServer redis = new RedisTestServer();
@Rule
public ExpectedException thrown = ExpectedException.none();
@Autowired
private RedisOperations<Object, Object> operations;
@Autowired
private ExampleRepository exampleRepository;

@ -16,10 +16,12 @@
package org.springframework.boot.test.autoconfigure.data.redis;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.testsupport.rule.RedisTestServer;
import org.springframework.context.annotation.ComponentScan.Filter;
import org.springframework.stereotype.Service;
import org.springframework.test.context.junit4.SpringRunner;
@ -35,6 +37,9 @@ import static org.assertj.core.api.Assertions.assertThat;
@DataRedisTest(includeFilters = @Filter(Service.class))
public class DataRedisTestWithIncludeFilterIntegrationTests {
@Rule
public RedisTestServer redis = new RedisTestServer();
@Autowired
private ExampleRepository exampleRepository;
@ -48,7 +53,6 @@ public class DataRedisTestWithIncludeFilterIntegrationTests {
assertThat(personHash.getId()).isNull();
PersonHash savedEntity = this.exampleRepository.save(personHash);
assertThat(this.service.hasRecord(savedEntity)).isTrue();
this.exampleRepository.deleteAll();
}
}

@ -22,7 +22,6 @@ import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.core.RedisOperations;
import org.springframework.stereotype.Service;
/**
* Example service used with {@link DataRedisTest} tests.
*
@ -31,16 +30,17 @@ import org.springframework.stereotype.Service;
@Service
public class ExampleService {
private RedisOperations<Object, Object> operations;
private static final Charset CHARSET = Charset.forName("UTF-8");
private RedisOperations<Object, Object> operations;
public ExampleService(RedisOperations<Object, Object> operations) {
this.operations = operations;
}
public boolean hasRecord(PersonHash personHash) {
return this.operations.execute(
(RedisConnection connection) -> connection.exists(("persons:" + personHash.getId()).getBytes(CHARSET)));
return this.operations.execute((RedisConnection connection) ->
connection.exists(("persons:" + personHash.getId()).getBytes(CHARSET)));
}
}

@ -29,6 +29,7 @@ public class PersonHash {
@Id
private String id;
private String description;
public String getId() {
@ -46,4 +47,5 @@ public class PersonHash {
public void setDescription(String description) {
this.description = description;
}
}

Loading…
Cancel
Save