|
|
@ -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");
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
@ -25,14 +25,12 @@ import org.testcontainers.junit.jupiter.Testcontainers;
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
|
|
|
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.boot.test.util.TestPropertyValues;
|
|
|
|
|
|
|
|
import org.springframework.boot.testsupport.testcontainers.RedisContainer;
|
|
|
|
import org.springframework.boot.testsupport.testcontainers.RedisContainer;
|
|
|
|
import org.springframework.context.ApplicationContext;
|
|
|
|
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.connection.RedisConnection;
|
|
|
|
import org.springframework.data.redis.core.RedisOperations;
|
|
|
|
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.assertThat;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
|
|
@ -43,12 +41,13 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
|
|
|
* @author Jayaram Pradhan
|
|
|
|
* @author Jayaram Pradhan
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Testcontainers(disabledWithoutDocker = true)
|
|
|
|
@Testcontainers(disabledWithoutDocker = true)
|
|
|
|
@ContextConfiguration(initializers = DataRedisTestIntegrationTests.Initializer.class)
|
|
|
|
|
|
|
|
@DataRedisTest
|
|
|
|
@DataRedisTest
|
|
|
|
class DataRedisTestIntegrationTests {
|
|
|
|
class DataRedisTestIntegrationTests {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final Charset CHARSET = StandardCharsets.UTF_8;
|
|
|
|
|
|
|
|
|
|
|
|
@Container
|
|
|
|
@Container
|
|
|
|
public static RedisContainer redis = new RedisContainer();
|
|
|
|
static RedisContainer redis = new RedisContainer();
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private RedisOperations<Object, Object> operations;
|
|
|
|
private RedisOperations<Object, Object> operations;
|
|
|
@ -59,7 +58,10 @@ class DataRedisTestIntegrationTests {
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private ApplicationContext applicationContext;
|
|
|
|
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
|
|
|
|
@Test
|
|
|
|
void testRepository() {
|
|
|
|
void testRepository() {
|
|
|
@ -79,14 +81,4 @@ class DataRedisTestIntegrationTests {
|
|
|
|
.isThrownBy(() -> this.applicationContext.getBean(ExampleService.class));
|
|
|
|
.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());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|