Created
April 14, 2020 11:01
-
-
Save PRASANTHRAJENDRAN/ecd1251fae1cd2e48859177246648924 to your computer and use it in GitHub Desktop.
Test case to validate the configured TTL properties that is set to RedisCacheManager or not
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.demo.spring.data.redis.cache.demo.configuration; | |
| import com.demo.spring.data.redis.cache.demo.SpringBootStarterDataRedisDemoApplication; | |
| import org.junit.jupiter.api.Test; | |
| import org.junit.jupiter.api.extension.ExtendWith; | |
| import org.springframework.beans.factory.annotation.Autowired; | |
| import org.springframework.boot.test.context.SpringBootTest; | |
| import org.springframework.data.redis.cache.RedisCacheConfiguration; | |
| import org.springframework.data.redis.cache.RedisCacheManager; | |
| import org.springframework.test.context.ActiveProfiles; | |
| import org.springframework.test.context.junit.jupiter.SpringExtension; | |
| import java.util.Map; | |
| import static org.junit.jupiter.api.Assertions.assertEquals; | |
| @ActiveProfiles("test") | |
| @ExtendWith(SpringExtension.class) | |
| @SpringBootTest(classes = SpringBootStarterDataRedisDemoApplication.class) | |
| class RedisCacheConfigurationITest { | |
| @Autowired | |
| private RedisCacheManager redisCacheManager = null; | |
| @Autowired | |
| private com.demo.spring.data.redis.cache.demo.configuration.RedisCacheConfiguration.CacheConfigurationProperties cacheConfigurationProperties = null; | |
| @Test | |
| void redisCacheConfigurationPropertiesTest() { | |
| Map<String, String> cacheMap = cacheConfigurationProperties.getCachesTTL(); | |
| Map<String, RedisCacheConfiguration> redisCacheConfiguration = redisCacheManager.getCacheConfigurations(); | |
| cacheMap.forEach((key, value) -> assertEquals(redisCacheConfiguration.get(key).getTtl().getSeconds(), Long.parseLong(value))); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment