SampleCacheApplicationRedisTests.java (spring-boot-2.7.3) | : | SampleCacheApplicationRedisTests.java (spring-boot-2.7.4) | ||
---|---|---|---|---|
skipping to change at line 48 | skipping to change at line 48 | |||
private static final RedisContainer redis = new RedisContainer(); | private static final RedisContainer redis = new RedisContainer(); | |||
@Autowired | @Autowired | |||
private CacheManager cacheManager; | private CacheManager cacheManager; | |||
@Autowired | @Autowired | |||
private CountryRepository countryRepository; | private CountryRepository countryRepository; | |||
@DynamicPropertySource | @DynamicPropertySource | |||
static void redisProperties(DynamicPropertyRegistry properties) { | static void redisProperties(DynamicPropertyRegistry properties) { | |||
properties.add("spring.redis.url", | properties.add("spring.redis.url", () -> "redis://" + redis.getHo | |||
() -> "redis://" + redis.getContainerIpAddress() | st() + ":" + redis.getFirstMappedPort()); | |||
+ ":" + redis.getFirstMappedPort()); | ||||
} | } | |||
@Test | @Test | |||
void validateCache() { | void validateCache() { | |||
Cache countries = this.cacheManager.getCache("countries"); | Cache countries = this.cacheManager.getCache("countries"); | |||
assertThat(countries).isNotNull(); | assertThat(countries).isNotNull(); | |||
countries.clear(); // Simple test assuming the cache is empty | countries.clear(); // Simple test assuming the cache is empty | |||
assertThat(countries.get("BE")).isNull(); | assertThat(countries.get("BE")).isNull(); | |||
Country be = this.countryRepository.findByCode("BE"); | Country be = this.countryRepository.findByCode("BE"); | |||
assertThat((Country) countries.get("BE").get()).isEqualTo(be); | assertThat((Country) countries.get("BE").get()).isEqualTo(be); | |||
End of changes. 1 change blocks. | ||||
3 lines changed or deleted | 2 lines changed or added |