View Javadoc
1   package org.oxerr.spring.cache.redis.scored.spring.boot.autoconfigure;
2   
3   import static org.assertj.core.api.Assertions.assertThat;
4   import static org.junit.jupiter.api.Assertions.assertTrue;
5   
6   import org.junit.jupiter.api.Test;
7   import org.oxerr.spring.cache.redis.scored.ScoreHolder;
8   import org.oxerr.spring.cache.redis.scored.ScoredRedisCacheInterceptor;
9   import org.oxerr.spring.cache.redis.scored.ScoredRedisCacheWriter;
10  import org.springframework.boot.autoconfigure.AutoConfigurations;
11  import org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration;
12  import org.springframework.boot.autoconfigure.cache.RedisCacheManagerBuilderCustomizer;
13  import org.springframework.boot.test.context.runner.ApplicationContextRunner;
14  import org.springframework.cache.CacheManager;
15  import org.springframework.cache.annotation.ProxyCachingConfiguration;
16  import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
17  
18  class ScoredRedisCacheAutoConfigurationTest {
19  
20  	private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
21  		.withConfiguration(
22  			AutoConfigurations.of(
23  				ProxyCachingConfiguration.class,
24  				CacheAutoConfiguration.class,
25  				ScoredRedisCacheAutoConfiguration.class
26  			)
27  		);
28  
29  	@Test
30  	void test() {
31  		this.contextRunner
32  			.withBean(LettuceConnectionFactory.class)
33  			.run(context -> {
34  				assertThat(context)
35  					.hasSingleBean(RedisCacheManagerBuilderCustomizer.class)
36  					.hasSingleBean(ScoredRedisCacheInterceptor.class)
37  					.hasSingleBean(ScoreHolder.class);
38  
39  				Object cacheWriter = context.getBean(CacheManager.class).getCache("hello").getNativeCache();
40  				assertTrue(cacheWriter instanceof ScoredRedisCacheWriter);
41  			});
42  	}
43  
44  }