Browse Source

Trying to fix tests

pull/284/head
Spencer Gibb 7 years ago
parent
commit
74d9cd3060
No known key found for this signature in database
GPG Key ID: 7788A47380690861
  1. 69
      spring-cloud-context/src/test/java/org/springframework/cloud/context/refresh/ContextRefresherTests.java

69
spring-cloud-context/src/test/java/org/springframework/cloud/context/refresh/ContextRefresherTests.java

@ -1,14 +1,11 @@ @@ -1,14 +1,11 @@
package org.springframework.cloud.context.refresh;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.After;
import org.junit.Test;
import org.mockito.Mockito;
import org.springframework.boot.SpringApplication;
@ -22,53 +19,49 @@ import org.springframework.core.env.MapPropertySource; @@ -22,53 +19,49 @@ import org.springframework.core.env.MapPropertySource;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.PropertySource;
import static org.assertj.core.api.Assertions.assertThat;
public class ContextRefresherTests {
private RefreshScope scope = Mockito.mock(RefreshScope.class);
private ConfigurableApplicationContext context;
@After
public void close() {
if (context != null) {
context.close();
}
}
@Test
public void orderNewPropertiesConsistentWithNewContext() {
context = SpringApplication.run(ContextRefresherTests.class,
try (ConfigurableApplicationContext context = SpringApplication.run(ContextRefresherTests.class,
"--spring.main.webEnvironment=false", "--debug=false",
"--spring.main.bannerMode=OFF");
context.getEnvironment().setActiveProfiles("refresh");
List<String> names = names(context.getEnvironment().getPropertySources());
assertThat(names).doesNotContain(
"applicationConfig: [classpath:/bootstrap-refresh.properties]");
ContextRefresher refresher = new ContextRefresher(context, scope);
refresher.refresh();
names = names(context.getEnvironment().getPropertySources());
assertThat(names)
.contains("applicationConfig: [classpath:/bootstrap-refresh.properties]");
assertThat(names).containsSequence(
"applicationConfig: [classpath:/application.properties]",
"applicationConfig: [classpath:/bootstrap-refresh.properties]");
"--spring.main.bannerMode=OFF")) {
context.getEnvironment().setActiveProfiles("refresh");
List<String> names = names(context.getEnvironment().getPropertySources());
assertThat(names).doesNotContain(
"applicationConfig: [classpath:/bootstrap-refresh.properties]");
ContextRefresher refresher = new ContextRefresher(context, scope);
refresher.refresh();
names = names(context.getEnvironment().getPropertySources());
assertThat(names)
.contains("applicationConfig: [classpath:/bootstrap-refresh.properties]");
assertThat(names).containsSequence(
"applicationConfig: [classpath:/application.properties]",
"applicationConfig: [classpath:/bootstrap-refresh.properties]");
}
}
@Test
public void bootstrapPropertySourceAlwaysFirst() {
// Use spring.cloud.bootstrap.name to switch off the defaults (which would pick up
// a bootstrapProperties immediately
context = SpringApplication.run(ContextRefresherTests.class,
try (ConfigurableApplicationContext context = SpringApplication.run(ContextRefresherTests.class,
"--spring.main.webEnvironment=false", "--debug=false",
"--spring.main.bannerMode=OFF", "--spring.cloud.bootstrap.name=refresh");
List<String> names = names(context.getEnvironment().getPropertySources());
assertThat(names).doesNotContain("bootstrapProperties");
ContextRefresher refresher = new ContextRefresher(context, scope);
TestPropertyValues.of(
"spring.cloud.bootstrap.sources: org.springframework.cloud.context.refresh.ContextRefresherTests.PropertySourceConfiguration")
.applyTo(context);
refresher.refresh();
names = names(context.getEnvironment().getPropertySources());
assertThat(names).first().isEqualTo("bootstrapProperties");
"--spring.main.bannerMode=OFF", "--spring.cloud.bootstrap.name=refresh")) {
List<String> names = names(context.getEnvironment().getPropertySources());
assertThat(names).doesNotContain("bootstrapProperties");
ContextRefresher refresher = new ContextRefresher(context, scope);
TestPropertyValues.of(
"spring.cloud.bootstrap.sources: org.springframework.cloud.context.refresh.ContextRefresherTests.PropertySourceConfiguration")
.applyTo(context);
refresher.refresh();
names = names(context.getEnvironment().getPropertySources());
assertThat(names).first().isEqualTo("bootstrapProperties");
}
}
private List<String> names(MutablePropertySources propertySources) {
@ -83,8 +76,8 @@ public class ContextRefresherTests { @@ -83,8 +76,8 @@ public class ContextRefresherTests {
// This is added to bootstrap context as a source in bootstrap.properties
protected static class PropertySourceConfiguration implements PropertySourceLocator {
public static Map<String, Object> MAP = new HashMap<String, Object>(
Collections.<String, Object>singletonMap("bootstrap.foo", "refresh"));
public static Map<String, Object> MAP = new HashMap<>(
Collections.<String, Object>singletonMap("bootstrap.context-refresh.foo", "refresh"));
@Override
public PropertySource<?> locate(Environment environment) {

Loading…
Cancel
Save