Commit 56af3534 authored by Andy Wilkinson's avatar Andy Wilkinson

Merge branch '2.2.x'

Closes gh-20740
parents ed6e5421 e35bf8f4
...@@ -26,11 +26,9 @@ import org.testcontainers.junit.jupiter.Testcontainers; ...@@ -26,11 +26,9 @@ 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.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextInitializer; import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.test.context.DynamicPropertySource;
import org.springframework.test.context.ContextConfiguration;
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;
...@@ -42,7 +40,6 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; ...@@ -42,7 +40,6 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
* @author Stephane Nicoll * @author Stephane Nicoll
* @author Michael Simons * @author Michael Simons
*/ */
@ContextConfiguration(initializers = DataNeo4jTestIntegrationTests.Initializer.class)
@DataNeo4jTest @DataNeo4jTest
@Testcontainers(disabledWithoutDocker = true) @Testcontainers(disabledWithoutDocker = true)
class DataNeo4jTestIntegrationTests { class DataNeo4jTestIntegrationTests {
...@@ -60,6 +57,11 @@ class DataNeo4jTestIntegrationTests { ...@@ -60,6 +57,11 @@ class DataNeo4jTestIntegrationTests {
@Autowired @Autowired
private ApplicationContext applicationContext; private ApplicationContext applicationContext;
@DynamicPropertySource
static void neo4jProperties(DynamicPropertyRegistry registry) {
registry.add("spring.data.neo4j.uri", neo4j::getBoltUrl);
}
@Test @Test
void testRepository() { void testRepository() {
ExampleGraph exampleGraph = new ExampleGraph(); ExampleGraph exampleGraph = new ExampleGraph();
...@@ -76,14 +78,4 @@ class DataNeo4jTestIntegrationTests { ...@@ -76,14 +78,4 @@ class DataNeo4jTestIntegrationTests {
.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.data.neo4j.uri=" + neo4j.getBoltUrl())
.applyTo(configurableApplicationContext.getEnvironment());
}
}
} }
...@@ -24,11 +24,9 @@ import org.testcontainers.junit.jupiter.Container; ...@@ -24,11 +24,9 @@ import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers; import org.testcontainers.junit.jupiter.Testcontainers;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
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;
...@@ -39,7 +37,6 @@ import static org.assertj.core.api.Assertions.assertThat; ...@@ -39,7 +37,6 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Artsiom Yudovin * @author Artsiom Yudovin
*/ */
@Testcontainers(disabledWithoutDocker = true) @Testcontainers(disabledWithoutDocker = true)
@ContextConfiguration(initializers = DataNeo4jTestPropertiesIntegrationTests.Initializer.class)
@DataNeo4jTest(properties = "spring.profiles.active=test") @DataNeo4jTest(properties = "spring.profiles.active=test")
class DataNeo4jTestPropertiesIntegrationTests { class DataNeo4jTestPropertiesIntegrationTests {
...@@ -50,19 +47,14 @@ class DataNeo4jTestPropertiesIntegrationTests { ...@@ -50,19 +47,14 @@ class DataNeo4jTestPropertiesIntegrationTests {
@Autowired @Autowired
private Environment environment; private Environment environment;
@DynamicPropertySource
static void neo4jProperties(DynamicPropertyRegistry registry) {
registry.add("spring.data.neo4j.uri", neo4j::getBoltUrl);
}
@Test @Test
void environmentWithNewProfile() { void environmentWithNewProfile() {
assertThat(this.environment.getActiveProfiles()).containsExactly("test"); assertThat(this.environment.getActiveProfiles()).containsExactly("test");
} }
static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
@Override
public void initialize(ConfigurableApplicationContext configurableApplicationContext) {
TestPropertyValues.of("spring.data.neo4j.uri=" + neo4j.getBoltUrl())
.applyTo(configurableApplicationContext.getEnvironment());
}
}
} }
...@@ -24,12 +24,10 @@ import org.testcontainers.junit.jupiter.Container; ...@@ -24,12 +24,10 @@ import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers; import org.testcontainers.junit.jupiter.Testcontainers;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan.Filter; import org.springframework.context.annotation.ComponentScan.Filter;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
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;
...@@ -40,7 +38,6 @@ import static org.assertj.core.api.Assertions.assertThat; ...@@ -40,7 +38,6 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Michael Simons * @author Michael Simons
*/ */
@Testcontainers(disabledWithoutDocker = true) @Testcontainers(disabledWithoutDocker = true)
@ContextConfiguration(initializers = DataNeo4jTestWithIncludeFilterIntegrationTests.Initializer.class)
@DataNeo4jTest(includeFilters = @Filter(Service.class)) @DataNeo4jTest(includeFilters = @Filter(Service.class))
class DataNeo4jTestWithIncludeFilterIntegrationTests { class DataNeo4jTestWithIncludeFilterIntegrationTests {
...@@ -51,19 +48,14 @@ class DataNeo4jTestWithIncludeFilterIntegrationTests { ...@@ -51,19 +48,14 @@ class DataNeo4jTestWithIncludeFilterIntegrationTests {
@Autowired @Autowired
private ExampleService service; private ExampleService service;
@DynamicPropertySource
static void neo4jProperties(DynamicPropertyRegistry registry) {
registry.add("spring.data.neo4j.uri", neo4j::getBoltUrl);
}
@Test @Test
void testService() { void testService() {
assertThat(this.service.hasNode(ExampleGraph.class)).isFalse(); assertThat(this.service.hasNode(ExampleGraph.class)).isFalse();
} }
static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
@Override
public void initialize(ConfigurableApplicationContext configurableApplicationContext) {
TestPropertyValues.of("spring.data.neo4j.uri=" + neo4j.getBoltUrl())
.applyTo(configurableApplicationContext.getEnvironment());
}
}
} }
/* /*
* 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; ...@@ -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; ...@@ -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 { ...@@ -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 { ...@@ -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());
}
}
} }
/* /*
* 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.
...@@ -21,12 +21,10 @@ import org.testcontainers.junit.jupiter.Container; ...@@ -21,12 +21,10 @@ import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers; import org.testcontainers.junit.jupiter.Testcontainers;
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.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
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;
...@@ -37,7 +35,6 @@ import static org.assertj.core.api.Assertions.assertThat; ...@@ -37,7 +35,6 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Artsiom Yudovin * @author Artsiom Yudovin
*/ */
@Testcontainers(disabledWithoutDocker = true) @Testcontainers(disabledWithoutDocker = true)
@ContextConfiguration(initializers = DataRedisTestPropertiesIntegrationTests.Initializer.class)
@DataRedisTest(properties = "spring.profiles.active=test") @DataRedisTest(properties = "spring.profiles.active=test")
class DataRedisTestPropertiesIntegrationTests { class DataRedisTestPropertiesIntegrationTests {
...@@ -47,19 +44,14 @@ class DataRedisTestPropertiesIntegrationTests { ...@@ -47,19 +44,14 @@ class DataRedisTestPropertiesIntegrationTests {
@Autowired @Autowired
private Environment environment; private Environment environment;
@DynamicPropertySource
static void redisProperties(DynamicPropertyRegistry registry) {
registry.add("spring.redis.port", redis::getFirstMappedPort);
}
@Test @Test
void environmentWithNewProfile() { void environmentWithNewProfile() {
assertThat(this.environment.getActiveProfiles()).containsExactly("test"); assertThat(this.environment.getActiveProfiles()).containsExactly("test");
} }
static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
@Override
public void initialize(ConfigurableApplicationContext configurableApplicationContext) {
TestPropertyValues.of("spring.redis.port=" + redis.getFirstMappedPort())
.applyTo(configurableApplicationContext.getEnvironment());
}
}
} }
/* /*
* 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.
...@@ -21,13 +21,11 @@ import org.testcontainers.junit.jupiter.Container; ...@@ -21,13 +21,11 @@ import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers; import org.testcontainers.junit.jupiter.Testcontainers;
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.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan.Filter; import org.springframework.context.annotation.ComponentScan.Filter;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
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;
...@@ -37,7 +35,6 @@ import static org.assertj.core.api.Assertions.assertThat; ...@@ -37,7 +35,6 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Jayaram Pradhan * @author Jayaram Pradhan
*/ */
@Testcontainers(disabledWithoutDocker = true) @Testcontainers(disabledWithoutDocker = true)
@ContextConfiguration(initializers = DataRedisTestWithIncludeFilterIntegrationTests.Initializer.class)
@DataRedisTest(includeFilters = @Filter(Service.class)) @DataRedisTest(includeFilters = @Filter(Service.class))
class DataRedisTestWithIncludeFilterIntegrationTests { class DataRedisTestWithIncludeFilterIntegrationTests {
...@@ -50,6 +47,11 @@ class DataRedisTestWithIncludeFilterIntegrationTests { ...@@ -50,6 +47,11 @@ class DataRedisTestWithIncludeFilterIntegrationTests {
@Autowired @Autowired
private ExampleService service; private ExampleService service;
@DynamicPropertySource
static void redisProperties(DynamicPropertyRegistry registry) {
registry.add("spring.redis.port", redis::getFirstMappedPort);
}
@Test @Test
void testService() { void testService() {
PersonHash personHash = new PersonHash(); PersonHash personHash = new PersonHash();
...@@ -59,14 +61,4 @@ class DataRedisTestWithIncludeFilterIntegrationTests { ...@@ -59,14 +61,4 @@ class DataRedisTestWithIncludeFilterIntegrationTests {
assertThat(this.service.hasRecord(savedEntity)).isTrue(); assertThat(this.service.hasRecord(savedEntity)).isTrue();
} }
static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
@Override
public void initialize(ConfigurableApplicationContext configurableApplicationContext) {
TestPropertyValues.of("spring.redis.port=" + redis.getFirstMappedPort())
.applyTo(configurableApplicationContext.getEnvironment());
}
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment