|
|
|
|
@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
|
|
|
|
|
/* |
|
|
|
|
* Copyright 2012-2019 the original author or authors. |
|
|
|
|
* Copyright 2012-2020 the original author or authors. |
|
|
|
|
* |
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
|
@ -25,14 +25,12 @@ import org.testcontainers.junit.jupiter.Testcontainers;
@@ -25,14 +25,12 @@ import org.testcontainers.junit.jupiter.Testcontainers;
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.NoSuchBeanDefinitionException; |
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.boot.test.util.TestPropertyValues; |
|
|
|
|
import org.springframework.boot.testsupport.testcontainers.RedisContainer; |
|
|
|
|
import org.springframework.context.ApplicationContext; |
|
|
|
|
import org.springframework.context.ApplicationContextInitializer; |
|
|
|
|
import org.springframework.context.ConfigurableApplicationContext; |
|
|
|
|
import org.springframework.data.redis.connection.RedisConnection; |
|
|
|
|
import org.springframework.data.redis.core.RedisOperations; |
|
|
|
|
import org.springframework.test.context.ContextConfiguration; |
|
|
|
|
import org.springframework.test.context.DynamicPropertyRegistry; |
|
|
|
|
import org.springframework.test.context.DynamicPropertySource; |
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType; |
|
|
|
|
@ -43,12 +41,13 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
@@ -43,12 +41,13 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
|
|
|
|
* @author Jayaram Pradhan |
|
|
|
|
*/ |
|
|
|
|
@Testcontainers(disabledWithoutDocker = true) |
|
|
|
|
@ContextConfiguration(initializers = DataRedisTestIntegrationTests.Initializer.class) |
|
|
|
|
@DataRedisTest |
|
|
|
|
class DataRedisTestIntegrationTests { |
|
|
|
|
|
|
|
|
|
private static final Charset CHARSET = StandardCharsets.UTF_8; |
|
|
|
|
|
|
|
|
|
@Container |
|
|
|
|
public static RedisContainer redis = new RedisContainer(); |
|
|
|
|
static RedisContainer redis = new RedisContainer(); |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
private RedisOperations<Object, Object> operations; |
|
|
|
|
@ -59,7 +58,10 @@ class DataRedisTestIntegrationTests {
@@ -59,7 +58,10 @@ class DataRedisTestIntegrationTests {
|
|
|
|
|
@Autowired |
|
|
|
|
private ApplicationContext applicationContext; |
|
|
|
|
|
|
|
|
|
private static final Charset CHARSET = StandardCharsets.UTF_8; |
|
|
|
|
@DynamicPropertySource |
|
|
|
|
static void redisProperties(DynamicPropertyRegistry registry) { |
|
|
|
|
registry.add("spring.redis.port", redis::getFirstMappedPort); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void testRepository() { |
|
|
|
|
@ -79,14 +81,4 @@ class DataRedisTestIntegrationTests {
@@ -79,14 +81,4 @@ class DataRedisTestIntegrationTests {
|
|
|
|
|
.isThrownBy(() -> this.applicationContext.getBean(ExampleService.class)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> { |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void initialize(ConfigurableApplicationContext configurableApplicationContext) { |
|
|
|
|
TestPropertyValues.of("spring.redis.port=" + redis.getFirstMappedPort()) |
|
|
|
|
.applyTo(configurableApplicationContext.getEnvironment()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|