@ -19,6 +19,8 @@ package org.springframework.boot.autoconfigure.data.redis;
import org.junit.Test ;
import org.junit.runner.RunWith ;
import org.springframework.beans.BeansException ;
import org.springframework.beans.factory.config.BeanPostProcessor ;
import org.springframework.boot.autoconfigure.AutoConfigurations ;
import org.springframework.boot.test.context.runner.ApplicationContextRunner ;
import org.springframework.boot.testsupport.runner.classpath.ClassPathExclusions ;
@ -160,8 +162,12 @@ public class RedisAutoConfigurationJedisTests {
this . runner
. withPropertyValues ( "spring.redis.sentinel.master:mymaster" ,
"spring.redis.sentinel.nodes:127.0.0.1:26379,127.0.0.1:26380" )
. run ( ( context ) - > assertThat ( context . getBean ( JedisConnectionFactory . class )
. isRedisSentinelAware ( ) ) . isTrue ( ) ) ;
. withUserConfiguration ( JedisConnectionFactoryCaptorConfiguration . class )
. run ( ( context ) - > {
assertThat ( context ) . hasFailed ( ) ;
assertThat ( JedisConnectionFactoryCaptor . connectionFactory
. isRedisSentinelAware ( ) ) . isTrue ( ) ;
} ) ;
}
@Test
@ -170,9 +176,15 @@ public class RedisAutoConfigurationJedisTests {
. withPropertyValues ( "spring.redis.password=password" ,
"spring.redis.sentinel.master:mymaster" ,
"spring.redis.sentinel.nodes:127.0.0.1:26379,127.0.0.1:26380" )
. run ( ( context ) - > assertThat (
context . getBean ( JedisConnectionFactory . class ) . getPassword ( ) )
. isEqualTo ( "password" ) ) ;
. withUserConfiguration ( JedisConnectionFactoryCaptorConfiguration . class )
. run ( ( context ) - > {
assertThat ( context ) . hasFailed ( ) ;
assertThat ( JedisConnectionFactoryCaptor . connectionFactory
. isRedisSentinelAware ( ) ) . isTrue ( ) ;
assertThat (
JedisConnectionFactoryCaptor . connectionFactory . getPassword ( ) )
. isEqualTo ( "password" ) ;
} ) ;
}
@Test
@ -194,4 +206,29 @@ public class RedisAutoConfigurationJedisTests {
}
@Configuration
static class JedisConnectionFactoryCaptorConfiguration {
@Bean
JedisConnectionFactoryCaptor jedisConnectionFactoryCaptor ( ) {
return new JedisConnectionFactoryCaptor ( ) ;
}
}
static class JedisConnectionFactoryCaptor implements BeanPostProcessor {
static JedisConnectionFactory connectionFactory ;
@Override
public Object postProcessBeforeInitialization ( Object bean , String beanName )
throws BeansException {
if ( bean instanceof JedisConnectionFactory ) {
connectionFactory = ( JedisConnectionFactory ) bean ;
}
return bean ;
}
}
}