Adds support for property origin tracking in config server/client

Adds a new format if requested using v2 Accept header, otherwise the
format is backwards compatible so older clients will work with new
servers.

fixes gh-866
This commit is contained in:
Spencer Gibb
2019-08-02 15:00:47 -04:00
committed by GitHub
parent cbcdcde9c2
commit 7f547f8ec1
42 changed files with 479 additions and 167 deletions

View File

@@ -27,7 +27,11 @@ import java.util.Map.Entry;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.boot.env.OriginTrackedMapPropertySource;
import org.springframework.boot.origin.Origin;
import org.springframework.boot.origin.OriginTrackedValue;
import org.springframework.cloud.bootstrap.config.PropertySourceLocator;
import org.springframework.cloud.bootstrap.support.OriginTrackedCompositePropertySource;
import org.springframework.cloud.config.client.ConfigClientProperties.Credentials;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.config.environment.PropertySource;
@@ -46,6 +50,7 @@ import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.retry.annotation.Retryable;
import org.springframework.util.Assert;
import org.springframework.util.Base64Utils;
import org.springframework.util.StringUtils;
import org.springframework.web.client.HttpClientErrorException;
@@ -56,6 +61,7 @@ import org.springframework.web.client.RestTemplate;
import static org.springframework.cloud.config.client.ConfigClientProperties.AUTHORIZATION;
import static org.springframework.cloud.config.client.ConfigClientProperties.STATE_HEADER;
import static org.springframework.cloud.config.client.ConfigClientProperties.TOKEN_HEADER;
import static org.springframework.cloud.config.environment.EnvironmentMediaType.V2_JSON;
/**
* @author Dave Syer
@@ -81,7 +87,8 @@ public class ConfigServicePropertySourceLocator implements PropertySourceLocator
public org.springframework.core.env.PropertySource<?> locate(
org.springframework.core.env.Environment environment) {
ConfigClientProperties properties = this.defaultProperties.override(environment);
CompositePropertySource composite = new CompositePropertySource("configService");
CompositePropertySource composite = new OriginTrackedCompositePropertySource(
"configService");
RestTemplate restTemplate = this.restTemplate == null
? getSecureRestTemplate(properties) : this.restTemplate;
Exception error = null;
@@ -100,15 +107,15 @@ public class ConfigServicePropertySourceLocator implements PropertySourceLocator
if (result != null) {
log(result);
if (result.getPropertySources() != null) { // result.getPropertySources()
// can be null if using
// xml
// result.getPropertySources() can be null if using xml
if (result.getPropertySources() != null) {
for (PropertySource source : result.getPropertySources()) {
@SuppressWarnings("unchecked")
Map<String, Object> map = (Map<String, Object>) source
.getSource();
Map<String, Object> map = translateOrigins(source.getName(),
(Map<String, Object>) source.getSource());
composite.addPropertySource(
new MapPropertySource(source.getName(), map));
new OriginTrackedMapPropertySource(source.getName(),
map));
}
}
@@ -171,6 +178,32 @@ public class ConfigServicePropertySourceLocator implements PropertySourceLocator
}
}
private Map<String, Object> translateOrigins(String name,
Map<String, Object> source) {
Map<String, Object> withOrigins = new HashMap<>();
for (Map.Entry<String, Object> entry : source.entrySet()) {
boolean hasOrigin = false;
if (entry.getValue() instanceof Map) {
@SuppressWarnings("unchecked")
Map<String, Object> value = (Map<String, Object>) entry.getValue();
if (value.size() == 2 && value.containsKey("origin")
&& value.containsKey("value")) {
Origin origin = new ConfigServiceOrigin(name, value.get("origin"));
OriginTrackedValue trackedValue = OriginTrackedValue
.of(value.get("value"), origin);
withOrigins.put(entry.getKey(), trackedValue);
hasOrigin = true;
}
}
if (!hasOrigin) {
withOrigins.put(entry.getKey(), entry.getValue());
}
}
return withOrigins;
}
private void putValue(HashMap<String, Object> map, String key, String value) {
if (StringUtils.hasText(value)) {
map.put(key, value);
@@ -208,6 +241,8 @@ public class ConfigServicePropertySourceLocator implements PropertySourceLocator
try {
HttpHeaders headers = new HttpHeaders();
headers.setAccept(
Collections.singletonList(MediaType.parseMediaType(V2_JSON)));
addAuthorizationToken(properties, headers, username, password);
if (StringUtils.hasText(token)) {
headers.add(TOKEN_HEADER, token);
@@ -215,7 +250,6 @@ public class ConfigServicePropertySourceLocator implements PropertySourceLocator
if (StringUtils.hasText(state) && properties.isSendState()) {
headers.add(STATE_HEADER, state);
}
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
final HttpEntity<Void> entity = new HttpEntity<>((Void) null, headers);
response = restTemplate.exchange(uri + path, HttpMethod.GET, entity,
@@ -321,4 +355,25 @@ public class ConfigServicePropertySourceLocator implements PropertySourceLocator
}
static class ConfigServiceOrigin implements Origin {
private final String remotePropertySource;
private final Object origin;
ConfigServiceOrigin(String remotePropertySource, Object origin) {
this.remotePropertySource = remotePropertySource;
Assert.notNull(origin, "origin may not be null");
this.origin = origin;
}
@Override
public String toString() {
return "Config Server " + this.remotePropertySource + ":"
+ this.origin.toString();
}
}
}

View File

@@ -0,0 +1,40 @@
/*
* Copyright 2012-2017 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.config.environment;
/**
* Media types that can be consumed and produced by Environment endpoints.
*
* @author Spencer Gibb
* @since 2.0.0
*/
public final class EnvironmentMediaType {
/**
* Constant for the Config Server V1 media type.
*/
public static final String V1_JSON = "application/vnd.spring-cloud.config-server.v1+json";
/**
* Constant for the Config Server V2 media type.
*/
public static final String V2_JSON = "application/vnd.spring-cloud.config-server.v2+json";
private EnvironmentMediaType() {
}
}

View File

@@ -0,0 +1,52 @@
/*
* Copyright 2013-2019 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.config.environment;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* A description of a property's value, including its origin if available.
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
public final class PropertyValueDescriptor {
private final Object value;
private String origin;
@JsonCreator
public PropertyValueDescriptor(@JsonProperty("value") Object value,
@JsonProperty("origin") String origin) {
this.value = value;
this.origin = origin;
}
public Object getValue() {
return this.value;
}
public String getOrigin() {
return this.origin;
}
public void setOrigin(String origin) {
this.origin = origin;
}
}

View File

@@ -54,6 +54,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.springframework.cloud.config.client.ConfigClientProperties.AUTHORIZATION;
import static org.springframework.cloud.config.environment.EnvironmentMediaType.V2_JSON;
public class ConfigServicePropertySourceLocatorTests {
@@ -83,7 +84,7 @@ public class ConfigServicePropertySourceLocatorTests {
HttpEntity httpEntity = argumentCaptor.getValue();
assertThat(httpEntity.getHeaders().getAccept())
.containsExactly(MediaType.APPLICATION_JSON);
.containsExactly(MediaType.parseMediaType(V2_JSON));
}
@Test

View File

@@ -35,6 +35,13 @@
<artifactId>spring-cloud-config-server</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
<type>test-jar</type>
<scope>test</scope>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>

View File

@@ -123,5 +123,20 @@
<start-class>org.springframework.cloud.config.server.ConfigServerApplication
</start-class>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.2</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@@ -71,7 +71,7 @@ public class ConfigServerHealthIndicator extends AbstractHealthIndicator {
try {
Environment environment = this.environmentRepository.findOne(application,
profiles, repository.getLabel());
profiles, repository.getLabel(), false);
HashMap<String, Object> detail = new HashMap<>();
detail.put("name", environment.getName());

View File

@@ -46,11 +46,17 @@ public abstract class AbstractScmEnvironmentRepository extends AbstractScmAccess
@Override
public synchronized Environment findOne(String application, String profile,
String label) {
return findOne(application, profile, label, false);
}
@Override
public synchronized Environment findOne(String application, String profile,
String label, boolean includeOrigin) {
NativeEnvironmentRepository delegate = new NativeEnvironmentRepository(
getEnvironment(), new NativeEnvironmentProperties());
Locations locations = getLocations(application, profile, label);
delegate.setSearchLocations(locations.getLocations());
Environment result = delegate.findOne(application, profile, "");
Environment result = delegate.findOne(application, profile, "", includeOrigin);
result.setVersion(locations.getVersion());
result.setLabel(label);
return this.cleaner.clean(result, getWorkingDirectory().toURI().toString(),

View File

@@ -46,19 +46,25 @@ public class CompositeEnvironmentRepository implements EnvironmentRepository {
@Override
public Environment findOne(String application, String profile, String label) {
return findOne(application, profile, label, false);
}
@Override
public Environment findOne(String application, String profile, String label,
boolean includeOrigin) {
Environment env = new Environment(application, new String[] { profile }, label,
null, null);
if (this.environmentRepositories.size() == 1) {
Environment envRepo = this.environmentRepositories.get(0).findOne(application,
profile, label);
profile, label, includeOrigin);
env.addAll(envRepo.getPropertySources());
env.setVersion(envRepo.getVersion());
env.setState(envRepo.getState());
}
else {
for (EnvironmentRepository repo : this.environmentRepositories) {
env.addAll(
repo.findOne(application, profile, label).getPropertySources());
for (EnvironmentRepository repo : environmentRepositories) {
env.addAll(repo.findOne(application, profile, label, includeOrigin)
.getPropertySources());
}
}
return env;

View File

@@ -16,8 +16,11 @@
package org.springframework.cloud.config.server.environment;
import java.util.Map;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.config.environment.PropertySource;
import org.springframework.cloud.config.environment.PropertyValueDescriptor;
/**
* @author Dave Syer
@@ -31,9 +34,24 @@ public class EnvironmentCleaner {
String name = source.getName().replace(workingDir, "");
name = name.replace("applicationConfig: [", "");
name = uri + "/" + name.replace("]", "");
result.add(new PropertySource(name, source.getSource()));
result.add(new PropertySource(name, clean(source.getSource(), uri)));
}
return result;
}
protected Map<?, ?> clean(Map<?, ?> source, String uri) {
for (Map.Entry<?, ?> entry : source.entrySet()) {
if (entry.getValue() instanceof PropertyValueDescriptor) {
PropertyValueDescriptor descriptor = (PropertyValueDescriptor) entry
.getValue();
if (!uri.endsWith("/")) {
uri = uri + "/";
}
String updated = descriptor.getOrigin().replace("[", "[" + uri);
descriptor.setOrigin(updated);
}
}
return source;
}
}

View File

@@ -35,6 +35,7 @@ import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.nodes.Tag;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.config.environment.EnvironmentMediaType;
import org.springframework.cloud.config.environment.PropertySource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
@@ -104,12 +105,31 @@ public class EnvironmentController {
@RequestMapping("/{name}/{profiles:.*[^-].*}")
public Environment defaultLabel(@PathVariable String name,
@PathVariable String profiles) {
return labelled(name, profiles, null);
return getEnvironment(name, profiles, null, false);
}
@RequestMapping(path = "/{name}/{profiles:.*[^-].*}",
produces = EnvironmentMediaType.V2_JSON)
public Environment defaultLabelIncludeOrigin(@PathVariable String name,
@PathVariable String profiles) {
return getEnvironment(name, profiles, null, true);
}
@RequestMapping("/{name}/{profiles}/{label:.*}")
public Environment labelled(@PathVariable String name, @PathVariable String profiles,
@PathVariable String label) {
return getEnvironment(name, profiles, label, false);
}
@RequestMapping(path = "/{name}/{profiles}/{label:.*}",
produces = EnvironmentMediaType.V2_JSON)
public Environment labelledIncludeOrigin(@PathVariable String name,
@PathVariable String profiles, @PathVariable String label) {
return getEnvironment(name, profiles, label, true);
}
public Environment getEnvironment(String name, String profiles, String label,
boolean includeOrigin) {
if (name != null && name.contains("(_)")) {
// "(_)" is uncommon in a git repo name, but "/" cannot be matched
// by Spring MVC
@@ -120,7 +140,8 @@ public class EnvironmentController {
// by Spring MVC
label = label.replace("(_)", "/");
}
Environment environment = this.repository.findOne(name, profiles, label);
Environment environment = this.repository.findOne(name, profiles, label,
includeOrigin);
if (!this.acceptEmpty
&& (environment == null || environment.getPropertySources().isEmpty())) {
throw new EnvironmentNotFoundException("Profile Not found");

View File

@@ -22,6 +22,7 @@ import java.util.Map;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.config.environment.PropertySource;
import org.springframework.cloud.config.environment.PropertyValueDescriptor;
import org.springframework.cloud.config.server.encryption.EnvironmentEncryptor;
/**
@@ -51,16 +52,36 @@ public class EnvironmentEncryptorEnvironmentRepository implements EnvironmentRep
@Override
public Environment findOne(String name, String profiles, String label) {
Environment environment = this.delegate.findOne(name, profiles, label);
return findOne(name, profiles, label, false);
}
@Override
public Environment findOne(String name, String profiles, String label,
boolean includeOrigin) {
Environment environment = this.delegate.findOne(name, profiles, label,
includeOrigin);
if (this.environmentEncryptor != null) {
environment = this.environmentEncryptor.decrypt(environment);
}
if (!this.overrides.isEmpty()) {
environment.addFirst(new PropertySource("overrides", this.overrides));
environment.addFirst(
new PropertySource("overrides", getOverridesMap(includeOrigin)));
}
return environment;
}
private Map<?, ?> getOverridesMap(boolean includeOrigin) {
if (!includeOrigin) {
return this.overrides;
}
Map<Object, Object> map = new LinkedHashMap<>();
for (Map.Entry entry : this.overrides.entrySet()) {
map.put(entry.getKey(), new PropertyValueDescriptor(entry.getValue(),
"Config server overrides"));
}
return map;
}
/**
* @param overrides the overrides to set
*/

View File

@@ -26,4 +26,9 @@ public interface EnvironmentRepository {
Environment findOne(String application, String profile, String label);
default Environment findOne(String application, String profile, String label,
boolean includeOrigin) {
return findOne(application, profile, label);
}
}

View File

@@ -52,7 +52,8 @@ public class EnvironmentRepositoryPropertySourceLocator implements PropertySourc
Environment environment) {
CompositePropertySource composite = new CompositePropertySource("configService");
for (PropertySource source : this.repository
.findOne(this.name, this.profiles, this.label).getPropertySources()) {
.findOne(this.name, this.profiles, this.label, false)
.getPropertySources()) {
@SuppressWarnings("unchecked")
Map<String, Object> map = (Map<String, Object>) source.getSource();
composite.addPropertySource(new MapPropertySource(source.getName(), map));

View File

@@ -123,7 +123,7 @@ public class MultipleJGitEnvironmentRepository extends JGitEnvironmentRepository
application, profile, label)) {
try {
Environment source = candidate.findOne(application, profile,
label);
label, false);
if (source != null) {
return candidate.getLocations(application, profile, label);
}
@@ -149,7 +149,8 @@ public class MultipleJGitEnvironmentRepository extends JGitEnvironmentRepository
}
@Override
public Environment findOne(String application, String profile, String label) {
public Environment findOne(String application, String profile, String label,
boolean includeOrigin) {
for (PatternMatchingJGitEnvironmentRepository repository : this.repos.values()) {
if (repository.matches(application, profile, label)) {
for (JGitEnvironmentRepository candidate : getRepositories(repository,
@@ -159,7 +160,7 @@ public class MultipleJGitEnvironmentRepository extends JGitEnvironmentRepository
label = candidate.getDefaultLabel();
}
Environment source = candidate.findOne(application, profile,
label);
label, includeOrigin);
if (source != null) {
return source;
}
@@ -183,9 +184,9 @@ public class MultipleJGitEnvironmentRepository extends JGitEnvironmentRepository
label = candidate.getDefaultLabel();
}
if (candidate == this) {
return super.findOne(application, profile, label);
return super.findOne(application, profile, label, includeOrigin);
}
return candidate.findOne(application, profile, label);
return candidate.findOne(application, profile, label, includeOrigin);
}
private List<JGitEnvironmentRepository> getRepositories(
@@ -286,7 +287,8 @@ public class MultipleJGitEnvironmentRepository extends JGitEnvironmentRepository
}
@Override
public Environment findOne(String application, String profile, String label) {
public Environment findOne(String application, String profile, String label,
boolean includeOrigin) {
if (this.pattern == null || this.pattern.length == 0) {
return null;
@@ -294,7 +296,7 @@ public class MultipleJGitEnvironmentRepository extends JGitEnvironmentRepository
if (PatternMatchUtils.simpleMatch(this.pattern,
application + "/" + profile)) {
return super.findOne(application, profile, label);
return super.findOne(application, profile, label, includeOrigin);
}
return null;

View File

@@ -125,6 +125,12 @@ public class NativeEnvironmentRepository
@Override
public Environment findOne(String config, String profile, String label) {
return findOne(config, profile, label, false);
}
@Override
public Environment findOne(String config, String profile, String label,
boolean includeOrigin) {
SpringApplicationBuilder builder = new SpringApplicationBuilder(
PropertyPlaceholderAutoConfiguration.class);
ConfigurableEnvironment environment = getEnvironment(profile);
@@ -143,7 +149,7 @@ public class NativeEnvironmentRepository
environment.getPropertySources().remove("profiles");
try {
return clean(new PassthruEnvironmentRepository(environment).findOne(config,
profile, label));
profile, label, includeOrigin));
}
finally {
context.close();

View File

@@ -22,8 +22,12 @@ import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import org.springframework.boot.origin.Origin;
import org.springframework.boot.origin.OriginLookup;
import org.springframework.boot.origin.TextResourceOrigin;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.config.environment.PropertySource;
import org.springframework.cloud.config.environment.PropertyValueDescriptor;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MapPropertySource;
import org.springframework.core.env.StandardEnvironment;
@@ -60,6 +64,12 @@ public class PassthruEnvironmentRepository implements EnvironmentRepository {
@Override
public Environment findOne(String application, String env, String label) {
return findOne(application, env, label, false);
}
@Override
public Environment findOne(String application, String env, String label,
boolean includeOrigin) {
Environment result = new Environment(application,
StringUtils.commaDelimitedListToStringArray(env), label, null, null);
for (org.springframework.core.env.PropertySource<?> source : this.environment
@@ -67,20 +77,40 @@ public class PassthruEnvironmentRepository implements EnvironmentRepository {
String name = source.getName();
if (!this.standardSources.contains(name)
&& source instanceof MapPropertySource) {
result.add(new PropertySource(name, getMap(source)));
result.add(new PropertySource(name, getMap(source, includeOrigin)));
}
}
return result;
}
private Map<?, ?> getMap(org.springframework.core.env.PropertySource<?> source) {
private Map<?, ?> getMap(org.springframework.core.env.PropertySource<?> source,
boolean includeOrigin) {
Map<Object, Object> map = new LinkedHashMap<>();
Map<?, ?> input = (Map<?, ?>) source.getSource();
for (Object key : input.keySet()) {
// Spring Boot wraps the property values in an "origin" detector, so we need
// to extract the string values
map.put(key, source.getProperty(key.toString()));
if (includeOrigin && source instanceof OriginLookup) {
OriginLookup<String> originLookup = (OriginLookup<String>) source;
for (Object key : input.keySet()) {
Origin origin = originLookup.getOrigin(key.toString());
String originDesc;
if (origin instanceof TextResourceOrigin) {
TextResourceOrigin tro = (TextResourceOrigin) origin;
originDesc = tro.getLocation().toString();
}
else {
originDesc = origin.toString();
}
Object value = source.getProperty(key.toString());
map.put(key, new PropertyValueDescriptor(value, originDesc));
}
}
else {
for (Object key : input.keySet()) {
// Spring Boot wraps the property values in an "origin" detector, so we
// need
// to extract the string values
map.put(key, source.getProperty(key.toString()));
}
}
return map;
}

View File

@@ -115,7 +115,7 @@ public class ResourceController {
String text = StreamUtils.copyToString(is, Charset.forName("UTF-8"));
if (resolvePlaceholders) {
Environment environment = this.environmentRepository.findOne(name,
profile, label);
profile, label, false);
text = resolvePlaceholders(prepareEnvironment(environment), text);
}
return text;

View File

@@ -34,6 +34,7 @@ import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.cloud.config.server.test.ConfigServerTestUtils.assertOriginTrackedValue;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = ConfigServerApplication.class,
@@ -65,10 +66,8 @@ public class BootstrapConfigServerIntegrationTests {
Environment environment = new TestRestTemplate().getForObject(
"http://localhost:" + this.port + "/foo/development/", Environment.class);
assertThat(environment.getPropertySources()).hasSize(2);
assertThat(environment.getPropertySources().get(0).getSource().get("bar"))
.isEqualTo("foo");
assertThat(environment.getPropertySources().get(1).getSource().get("info.foo"))
.isEqualTo("bar");
assertOriginTrackedValue(environment, 0, "bar", "foo");
assertOriginTrackedValue(environment, 1, "info.foo", "bar");
}
@Test

View File

@@ -76,8 +76,7 @@ public class CompositeIntegrationTests {
.contains("svn-config-repo")).isTrue();
assertThat(environment.getPropertySources().get(2).getName()
.contains("svn-config-repo")).isTrue();
assertThat("{spring.cloud.config.enabled=true}").isEqualTo(
environment.getPropertySources().get(0).getSource().toString());
ConfigServerTestUtils.assertConfigEnabled(environment);
}
@Test
@@ -138,8 +137,7 @@ public class CompositeIntegrationTests {
.contains("svn-config-repo")).isTrue();
assertThat(environment.getPropertySources().get(2).getName()
.contains("svn-config-repo")).isTrue();
assertThat("{spring.cloud.config.enabled=true}").isEqualTo(
environment.getPropertySources().get(0).getSource().toString());
ConfigServerTestUtils.assertConfigEnabled(environment);
}
@Test

View File

@@ -45,6 +45,7 @@ import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.anyString;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
@@ -88,7 +89,7 @@ public class ConfigClientOffIntegrationTests {
@Bean
public EnvironmentRepository environmentRepository() {
EnvironmentRepository repository = Mockito.mock(EnvironmentRepository.class);
given(repository.findOne(anyString(), anyString(), anyString()))
given(repository.findOne(anyString(), anyString(), anyString(), anyBoolean()))
.willReturn(new Environment("", ""));
return repository;
}

View File

@@ -48,6 +48,7 @@ import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.anyString;
@@ -101,7 +102,7 @@ public class ConfigClientOnIntegrationTests {
@Bean
public EnvironmentRepository environmentRepository() {
EnvironmentRepository repository = Mockito.mock(EnvironmentRepository.class);
given(repository.findOne(anyString(), anyString(), anyString()))
given(repository.findOne(anyString(), anyString(), anyString(), anyBoolean()))
.willReturn(new Environment("", ""));
return repository;
}

View File

@@ -61,8 +61,7 @@ public class NativeConfigServerIntegrationTests {
assertThat(environment.getPropertySources().isEmpty()).isFalse();
assertThat(environment.getPropertySources().get(0).getName())
.isEqualTo("overrides");
assertThat(environment.getPropertySources().get(0).getSource().toString())
.isEqualTo("{spring.cloud.config.enabled=true}");
ConfigServerTestUtils.assertConfigEnabled(environment);
}
@Test

View File

@@ -51,11 +51,13 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.BDDMockito.given;
import static org.springframework.cloud.config.server.test.ConfigServerTestUtils.assertOriginTrackedValue;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = TestConfiguration.class, properties = {
"spring.cloud.config.enabled=true",
"management.endpoints.web.exposure.include=env, refresh" }, webEnvironment = WebEnvironment.RANDOM_PORT)
@SpringBootTest(classes = TestConfiguration.class,
properties = { "spring.cloud.config.enabled=true",
"management.endpoints.web.exposure.include=env, refresh" },
webEnvironment = WebEnvironment.RANDOM_PORT)
@ActiveProfiles("test")
@DirtiesContext
public class RefreshableConfigServerIntegrationTests {
@@ -79,9 +81,9 @@ public class RefreshableConfigServerIntegrationTests {
}
/*
* We're emulating an application "foo" which is running with the "development" profile
* and is asking for its properties using the REST endpoint. We're also calling the
* /env & /refresh actuator endpoints to change the
* We're emulating an application "foo" which is running with the "development"
* profile and is asking for its properties using the REST endpoint. We're also
* calling the /env & /refresh actuator endpoints to change the
* `spring.cloud.config.server.overrides.foo` property. Since we see that we only get
* the overridden "foo" property after the context refresh we are sure that the
* properties have been set and the EnvironmentController bean has successfully been
@@ -110,8 +112,7 @@ public class RefreshableConfigServerIntegrationTests {
environment = new TestRestTemplate().getForObject(
"http://localhost:" + this.port + "/foo/development/", Environment.class);
assertThat(environment.getPropertySources()).isNotEmpty();
assertThat(environment.getPropertySources().get(0).getSource().get("foo"))
.isEqualTo("bar");
assertOriginTrackedValue(environment, 0, "foo", "bar");
}
@Configuration
@@ -124,7 +125,7 @@ public class RefreshableConfigServerIntegrationTests {
EnvironmentRepository repository = Mockito.mock(EnvironmentRepository.class);
Environment environment = new Environment("", "");
given(repository.findOne(isA(String.class), isA(String.class),
nullable(String.class))).willReturn(environment);
nullable(String.class), isA(Boolean.class))).willReturn(environment);
return repository;
}

View File

@@ -70,8 +70,7 @@ public class SubversionConfigServerIntegrationTests {
assertThat(environment.getPropertySources().isEmpty()).isFalse();
assertThat(environment.getPropertySources().get(0).getName())
.isEqualTo("overrides");
assertThat(environment.getPropertySources().get(0).getSource().toString())
.isEqualTo("{spring.cloud.config.enabled=true}");
ConfigServerTestUtils.assertConfigEnabled(environment);
}
@Test

View File

@@ -67,8 +67,7 @@ public class VanillaConfigServerIntegrationTests {
assertThat(environment.getPropertySources().isEmpty()).isFalse();
assertThat(environment.getPropertySources().get(0).getName())
.isEqualTo("overrides");
assertThat(environment.getPropertySources().get(0).getSource().toString())
.isEqualTo("{spring.cloud.config.enabled=true}");
ConfigServerTestUtils.assertConfigEnabled(environment);
}
@Test

View File

@@ -30,6 +30,7 @@ import org.springframework.cloud.config.server.config.ConfigServerHealthIndicato
import org.springframework.cloud.config.server.environment.EnvironmentRepository;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
@@ -56,16 +57,16 @@ public class ConfigServerHealthIndicatorTests {
@Test
public void defaultStatusWorks() {
when(this.repository.findOne(anyString(), anyString(), Mockito.<String>isNull()))
.thenReturn(this.environment);
when(this.repository.findOne(anyString(), anyString(), Mockito.<String>isNull(),
anyBoolean())).thenReturn(this.environment);
assertThat(this.indicator.health().getStatus()).as("wrong default status")
.isEqualTo(Status.UP);
}
@Test
public void exceptionStatusIsDown() {
when(this.repository.findOne(anyString(), anyString(), Mockito.<String>isNull()))
.thenThrow(new RuntimeException());
when(this.repository.findOne(anyString(), anyString(), Mockito.<String>isNull(),
anyBoolean())).thenThrow(new RuntimeException());
assertThat(this.indicator.health().getStatus()).as("wrong exception status")
.isEqualTo(Status.DOWN);
}
@@ -77,7 +78,7 @@ public class ConfigServerHealthIndicatorTests {
repo.setProfiles("myprofile");
repo.setLabel("mylabel");
this.indicator.setRepositories(Collections.singletonMap("myname", repo));
when(this.repository.findOne("myname", "myprofile", "mylabel"))
when(this.repository.findOne("myname", "myprofile", "mylabel", false))
.thenReturn(this.environment);
assertThat(this.indicator.health().getStatus()).as("wrong default status")
.isEqualTo(Status.UP);

View File

@@ -209,6 +209,12 @@ public class CustomCompositeEnvironmentRepositoryTests {
@Override
public Environment findOne(String application, String profile, String label) {
return findOne(application, profile, label, false);
}
@Override
public Environment findOne(String application, String profile, String label,
boolean includeOrigin) {
Environment e = new Environment("test", new String[0], "label", "version",
"state");
PropertySource p = new PropertySource(this.properties.getPropertySourceName(),

View File

@@ -76,6 +76,12 @@ public class CustomEnvironmentRepositoryTests {
@Override
public Environment findOne(String application, String profile,
String label) {
return findOne(application, profile, label, false);
}
@Override
public Environment findOne(String application, String profile,
String label, boolean includeOrigin) {
return new Environment("test", new String[0], "label", "version",
"state");
}

View File

@@ -78,7 +78,7 @@ public class CompositeEnvironmentRepositoryTests {
repos.add(new TestOrderedEnvironmentRepository(1, e2, loc3));
SearchPathCompositeEnvironmentRepository compositeRepo = new SearchPathCompositeEnvironmentRepository(
repos);
Environment compositeEnv = compositeRepo.findOne("foo", "bar", "world");
Environment compositeEnv = compositeRepo.findOne("foo", "bar", "world", false);
List<PropertySource> propertySources = compositeEnv.getPropertySources();
assertThat(propertySources.size()).isEqualTo(5);
assertThat(propertySources.get(0).getName()).isEqualTo("p2");
@@ -127,10 +127,10 @@ public class CompositeEnvironmentRepositoryTests {
repos);
SearchPathCompositeEnvironmentRepository multiCompositeRepo = new SearchPathCompositeEnvironmentRepository(
repos2);
Environment env = compositeRepo.findOne("app", "dev", "label");
Environment env = compositeRepo.findOne("app", "dev", "label", false);
assertThat(env.getVersion()).isEqualTo("1");
assertThat(env.getState()).isEqualTo("state");
Environment multiEnv = multiCompositeRepo.findOne("app", "dev", "label");
Environment multiEnv = multiCompositeRepo.findOne("app", "dev", "label", false);
assertThat(multiEnv.getVersion()).isEqualTo(null);
assertThat(multiEnv.getState()).isEqualTo(null);
@@ -163,7 +163,13 @@ public class CompositeEnvironmentRepositoryTests {
@Override
public Environment findOne(String application, String profile, String label) {
return this.env;
return findOne(application, profile, label, false);
}
@Override
public Environment findOne(String application, String profile, String label,
boolean includeOrigin) {
return env;
}
@Override

View File

@@ -41,6 +41,9 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
/**
* @author Dave Syer
* @author Roy Clarkson
@@ -69,56 +72,56 @@ public class EnvironmentControllerIntegrationTests {
@Test
public void environmentNoLabel() throws Exception {
Mockito.when(this.repository.findOne("foo", "default", null))
when(this.repository.findOne("foo", "default", null, false))
.thenReturn(this.environment);
this.mvc.perform(MockMvcRequestBuilders.get("/foo/default"))
.andExpect(MockMvcResultMatchers.status().isOk());
Mockito.verify(this.repository).findOne("foo", "default", null);
verify(this.repository).findOne("foo", "default", null, false);
}
@Test
public void propertiesNoLabel() throws Exception {
Mockito.when(this.repository.findOne("foo", "default", null))
when(this.repository.findOne("foo", "default", null, false))
.thenReturn(this.environment);
this.mvc.perform(MockMvcRequestBuilders.get("/foo-default.properties"))
.andExpect(MockMvcResultMatchers.status().isOk());
Mockito.verify(this.repository).findOne("foo", "default", null);
verify(this.repository).findOne("foo", "default", null, false);
}
@Test
public void propertiesLabel() throws Exception {
Mockito.when(this.repository.findOne("foo", "default", "label"))
when(this.repository.findOne("foo", "default", "label", false))
.thenReturn(this.environment);
this.mvc.perform(MockMvcRequestBuilders.get("/label/foo-default.properties"))
.andExpect(MockMvcResultMatchers.status().isOk());
Mockito.verify(this.repository).findOne("foo", "default", "label");
verify(this.repository).findOne("foo", "default", "label", false);
}
@Test
public void propertiesLabelWhenApplicationNameContainsHyphen() throws Exception {
Environment environment = new Environment("foo-bar", "default");
environment.add(new PropertySource("foo", new HashMap<>()));
Mockito.when(this.repository.findOne("foo-bar", "default", "label"))
when(this.repository.findOne("foo-bar", "default", "label", false))
.thenReturn(this.environment);
this.mvc.perform(MockMvcRequestBuilders.get("/label/foo-bar-default.properties"))
.andExpect(MockMvcResultMatchers.status().isOk());
Mockito.verify(this.repository).findOne("foo-bar", "default", "label");
verify(this.repository).findOne("foo-bar", "default", "label", false);
}
@Test
public void propertiesLabelWithSlash() throws Exception {
Mockito.when(this.repository.findOne("foo", "default", "label/spam"))
when(this.repository.findOne("foo", "default", "label/spam", false))
.thenReturn(this.environment);
this.mvc.perform(
MockMvcRequestBuilders.get("/label(_)spam/foo-default.properties"))
.andExpect(MockMvcResultMatchers.status().isOk());
Mockito.verify(this.repository).findOne("foo", "default", "label/spam");
verify(this.repository).findOne("foo", "default", "label/spam", false);
}
@Test
public void environmentWithLabel() throws Exception {
Mockito.when(this.repository.findOne("foo", "default", "awesome"))
when(this.repository.findOne("foo", "default", "awesome", false))
.thenReturn(this.environment);
this.mvc.perform(MockMvcRequestBuilders.get("/foo/default/awesome"))
.andExpect(MockMvcResultMatchers.status().isOk());
@@ -126,7 +129,7 @@ public class EnvironmentControllerIntegrationTests {
@Test
public void environmentWithMissingLabel() throws Exception {
Mockito.when(this.repository.findOne("foo", "default", "missing"))
when(this.repository.findOne("foo", "default", "missing", false))
.thenThrow(new NoSuchLabelException("Planned"));
this.mvc.perform(MockMvcRequestBuilders.get("/foo/default/missing"))
.andExpect(MockMvcResultMatchers.status().isNotFound());
@@ -134,7 +137,7 @@ public class EnvironmentControllerIntegrationTests {
@Test
public void environmentWithMissingRepo() throws Exception {
Mockito.when(this.repository.findOne("foo", "default", "missing"))
when(this.repository.findOne("foo", "default", "missing", false))
.thenThrow(new NoSuchRepositoryException("Planned"));
this.mvc.perform(MockMvcRequestBuilders.get("/foo/default/missing"))
.andExpect(MockMvcResultMatchers.status().isNotFound());
@@ -142,7 +145,7 @@ public class EnvironmentControllerIntegrationTests {
@Test
public void environmentWithLabelContainingPeriod() throws Exception {
Mockito.when(this.repository.findOne("foo", "default", "1.0.0"))
when(this.repository.findOne("foo", "default", "1.0.0", false))
.thenReturn(this.environment);
this.mvc.perform(MockMvcRequestBuilders.get("/foo/default/1.0.0"))
.andExpect(MockMvcResultMatchers.status().isOk());
@@ -150,7 +153,7 @@ public class EnvironmentControllerIntegrationTests {
@Test
public void environmentWithLabelContainingSlash() throws Exception {
Mockito.when(this.repository.findOne("foo", "default", "feature/puff"))
when(this.repository.findOne("foo", "default", "feature/puff", false))
.thenReturn(this.environment);
this.mvc.perform(MockMvcRequestBuilders.get("/foo/default/feature(_)puff"))
.andExpect(MockMvcResultMatchers.status().isOk())
@@ -162,7 +165,7 @@ public class EnvironmentControllerIntegrationTests {
public void environmentWithApplicationContainingSlash() throws Exception {
Environment environment = new Environment("foo/app", "default");
environment.add(new PropertySource("foo", new HashMap<>()));
Mockito.when(this.repository.findOne("foo/app", "default", null))
when(this.repository.findOne("foo/app", "default", null, false))
.thenReturn(environment);
this.mvc.perform(MockMvcRequestBuilders.get("/foo(_)app/default"))
.andExpect(MockMvcResultMatchers.status().isOk())

View File

@@ -26,7 +26,6 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.Mockito;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.config.environment.PropertySource;
@@ -37,6 +36,8 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
/**
* @author Dave Syer
@@ -50,7 +51,7 @@ public class EnvironmentControllerTests {
@Rule
public ExpectedException expected = ExpectedException.none();
private EnvironmentRepository repository = Mockito.mock(EnvironmentRepository.class);
private EnvironmentRepository repository = mock(EnvironmentRepository.class);
private EnvironmentController controller;
@@ -72,7 +73,7 @@ public class EnvironmentControllerTests {
Map<String, Object> map = new HashMap<String, Object>();
map.put("a.b.c", "d");
this.environment.add(new PropertySource("one", map));
Mockito.when(this.repository.findOne("foo", "bar", null))
when(this.repository.findOne("foo", "bar", null, false))
.thenReturn(this.environment);
String yaml = this.controller.yaml("foo", "bar", false).getBody();
assertThat(yaml).isEqualTo("a:\n b:\n c: d\n");
@@ -85,7 +86,7 @@ public class EnvironmentControllerTests {
this.environment.add(new PropertySource("one", map));
this.environment.addFirst(
new PropertySource("two", Collections.singletonMap("a.b.c", "e")));
Mockito.when(this.repository.findOne("foo", "bar", null))
when(this.repository.findOne("foo", "bar", null, false))
.thenReturn(this.environment);
String yaml = this.controller.yaml("foo", "bar", false).getBody();
assertThat(yaml).isEqualTo("a:\n b:\n c: e\n");
@@ -102,7 +103,7 @@ public class EnvironmentControllerTests {
map.put("A", "Z");
map.put("S", 3);
this.environment.addFirst(new PropertySource("two", map));
Mockito.when(this.repository.findOne("foo", "bar", null))
when(this.repository.findOne("foo", "bar", null, false))
.thenReturn(this.environment);
String yaml = this.controller.yaml("foo", "bar", false).getBody();
assertThat(yaml).isEqualTo("A: Z\nS: 3\nY: 0\n");
@@ -161,7 +162,7 @@ public class EnvironmentControllerTests {
map.put("a.b[0]", "c");
map.put("a.b[1]", "d");
this.environment.add(new PropertySource("one", map));
Mockito.when(this.repository.findOne("foo", "bar", null))
when(this.repository.findOne("foo", "bar", null, false))
.thenReturn(this.environment);
String yaml = this.controller.yaml("foo", "bar", false).getBody();
assertThat(yaml).isEqualTo("a:\n b:\n - c\n - d\n");
@@ -182,7 +183,7 @@ public class EnvironmentControllerTests {
twoMap.put("a.b[1]", "h");
this.environment.addFirst(new PropertySource("two", twoMap));
Mockito.when(this.repository.findOne("foo", "bar", "two"))
when(this.repository.findOne("foo", "bar", "two", false))
.thenReturn(this.environment);
Environment environment = this.controller.labelled("foo", "bar", "two");
assertThat(environment).isNotNull();
@@ -201,7 +202,7 @@ public class EnvironmentControllerTests {
@Test
public void testNameWithSlash() {
Mockito.when(this.repository.findOne("foo/spam", "bar", "two"))
when(this.repository.findOne("foo/spam", "bar", "two", false))
.thenReturn(this.environment);
Environment returnedEnvironment = this.controller.labelled("foo(_)spam", "bar",
@@ -220,7 +221,7 @@ public class EnvironmentControllerTests {
@Test
public void testwithValidEnvironment() {
Mockito.when(this.repository.findOne("foo", "bar", null))
when(this.repository.findOne("foo", "bar", null, false))
.thenReturn(this.environment);
Environment environment = this.controller.labelled("foo", "bar", null);
assertThat(environment).isNotNull();
@@ -230,7 +231,7 @@ public class EnvironmentControllerTests {
@Test
public void testLabelWithSlash() {
Mockito.when(this.repository.findOne("foo", "bar", "two/spam"))
when(this.repository.findOne("foo", "bar", "two/spam", false))
.thenReturn(this.environment);
Environment returnedEnvironment = this.controller.labelled("foo", "bar",
@@ -255,7 +256,7 @@ public class EnvironmentControllerTests {
twoMap.put("a.b[1]", "h");
this.environment.addFirst(new PropertySource("two", twoMap));
Mockito.when(this.repository.findOne("foo", "bar", null))
when(this.repository.findOne("foo", "bar", null, false))
.thenReturn(this.environment);
String yaml = this.controller.yaml("foo", "bar", false).getBody();
@@ -268,7 +269,7 @@ public class EnvironmentControllerTests {
Map<String, Object> map = new LinkedHashMap<String, Object>();
map.put("document", "blah");
this.environment.add(new PropertySource("one", map));
Mockito.when(this.repository.findOne("foo", "bar", null))
when(this.repository.findOne("foo", "bar", null, false))
.thenReturn(this.environment);
String yaml = this.controller.yaml("foo", "bar", false).getBody();
assertThat(yaml).isEqualTo("blah\n");
@@ -280,7 +281,7 @@ public class EnvironmentControllerTests {
map.put("document[0]", "c");
map.put("document[1]", "d");
this.environment.add(new PropertySource("one", map));
Mockito.when(this.repository.findOne("foo", "bar", null))
when(this.repository.findOne("foo", "bar", null, false))
.thenReturn(this.environment);
String yaml = this.controller.yaml("foo", "bar", false).getBody();
assertThat(yaml).isEqualTo("- c\n- d\n");
@@ -292,7 +293,7 @@ public class EnvironmentControllerTests {
map.put("document[0].a", "c");
map.put("document[1].a", "d");
this.environment.add(new PropertySource("one", map));
Mockito.when(this.repository.findOne("foo", "bar", null))
when(this.repository.findOne("foo", "bar", null, false))
.thenReturn(this.environment);
String yaml = this.controller.yaml("foo", "bar", false).getBody();
assertThat(yaml).isEqualTo("- a: c\n- a: d\n");
@@ -305,7 +306,7 @@ public class EnvironmentControllerTests {
map.put("a.b[0].d", "e");
map.put("a.b[1].c", "d");
this.environment.add(new PropertySource("one", map));
Mockito.when(this.repository.findOne("foo", "bar", null))
when(this.repository.findOne("foo", "bar", null, false))
.thenReturn(this.environment);
String yaml = this.controller.yaml("foo", "bar", false).getBody();
assertThat("a:\n b:\n - d: e\n c: d\n - c: d\n".equals(yaml)
@@ -324,7 +325,7 @@ public class EnvironmentControllerTests {
map.put("a.b[3][0]", "r");
map.put("a.b[3][1]", "s");
this.environment.add(new PropertySource("one", map));
Mockito.when(this.repository.findOne("foo", "bar", null))
when(this.repository.findOne("foo", "bar", null, false))
.thenReturn(this.environment);
String yaml = this.controller.yaml("foo", "bar", false).getBody();
String expected = // @formatter:off
@@ -354,7 +355,7 @@ public class EnvironmentControllerTests {
map.put("a.b[1].c", "y");
map.put("a.b[1].e[0].d", "z");
this.environment.add(new PropertySource("one", map));
Mockito.when(this.repository.findOne("foo", "bar", null))
when(this.repository.findOne("foo", "bar", null, false))
.thenReturn(this.environment);
String json = this.controller.jsonProperties("foo", "bar", false).getBody();
assertThat(json).as("Wrong output: " + json).isEqualTo(
@@ -367,7 +368,7 @@ public class EnvironmentControllerTests {
map.put("b[0].c", "d");
map.put("b[1].c", "d");
this.environment.add(new PropertySource("one", map));
Mockito.when(this.repository.findOne("foo", "bar", null))
when(this.repository.findOne("foo", "bar", null, false))
.thenReturn(this.environment);
String yaml = this.controller.yaml("foo", "bar", false).getBody();
assertThat(yaml).isEqualTo("b:\n- c: d\n- c: d\n");
@@ -379,7 +380,7 @@ public class EnvironmentControllerTests {
map.put("x.a.b[0].c", "d");
map.put("x.a.b[1].c", "d");
this.environment.add(new PropertySource("one", map));
Mockito.when(this.repository.findOne("foo", "bar", null))
when(this.repository.findOne("foo", "bar", null, false))
.thenReturn(this.environment);
String yaml = this.controller.yaml("foo", "bar", false).getBody();
assertThat(yaml).isEqualTo("x:\n a:\n b:\n - c: d\n - c: d\n");
@@ -476,7 +477,7 @@ public class EnvironmentControllerTests {
this.environment.add(new PropertySource("one", map));
this.environment.addFirst(
new PropertySource("two", Collections.singletonMap("a.b.c", "${foo}")));
Mockito.when(this.repository.findOne("foo", "bar", null))
when(this.repository.findOne("foo", "bar", null, false))
.thenReturn(this.environment);
}
@@ -484,7 +485,7 @@ public class EnvironmentControllerTests {
System.setProperty("foo", "bar");
this.environment.addFirst(
new PropertySource("two", Collections.singletonMap("a.b.c", "${foo}")));
Mockito.when(this.repository.findOne("foo", "bar", null))
when(this.repository.findOne("foo", "bar", null, false))
.thenReturn(this.environment);
}
@@ -492,13 +493,13 @@ public class EnvironmentControllerTests {
System.setProperty("foo", "bar");
this.environment.addFirst(new PropertySource("two",
Collections.singletonMap("a.b.c", "${foo:spam}")));
Mockito.when(this.repository.findOne("foo", "bar", null))
when(this.repository.findOne("foo", "bar", null, false))
.thenReturn(this.environment);
}
@Test
public void mappingForEnvironment() throws Exception {
Mockito.when(this.repository.findOne("foo", "bar", null))
when(this.repository.findOne("foo", "bar", null, false))
.thenReturn(this.environment);
MockMvc mvc = MockMvcBuilders.standaloneSetup(this.controller).build();
mvc.perform(MockMvcRequestBuilders.get("/foo/bar"))
@@ -507,7 +508,7 @@ public class EnvironmentControllerTests {
@Test
public void mappingForLabelledEnvironment() throws Exception {
Mockito.when(this.repository.findOne("foo", "bar", "other"))
when(this.repository.findOne("foo", "bar", "other", false))
.thenReturn(this.environment);
MockMvc mvc = MockMvcBuilders.standaloneSetup(this.controller).build();
mvc.perform(MockMvcRequestBuilders.get("/foo/bar/other"))
@@ -516,7 +517,7 @@ public class EnvironmentControllerTests {
@Test
public void environmentMissing() throws Exception {
Mockito.when(this.repository.findOne("foo1", "notfound", null))
when(this.repository.findOne("foo1", "notfound", null, false))
.thenThrow(new EnvironmentNotFoundException("Missing Environment"));
MockMvc mvc = MockMvcBuilders.standaloneSetup(this.controller).build();
mvc.perform(MockMvcRequestBuilders.get("/foo1/notfound"))
@@ -525,7 +526,7 @@ public class EnvironmentControllerTests {
@Test
public void mappingForYaml() throws Exception {
Mockito.when(this.repository.findOne("foo", "bar", null))
when(this.repository.findOne("foo", "bar", null, false))
.thenReturn(this.environment);
MockMvc mvc = MockMvcBuilders.standaloneSetup(this.controller).build();
mvc.perform(MockMvcRequestBuilders.get("/foo-bar.yml"))
@@ -536,7 +537,7 @@ public class EnvironmentControllerTests {
@Test
public void mappingForJson() throws Exception {
Mockito.when(this.repository.findOne("foo", "bar", null))
when(this.repository.findOne("foo", "bar", null, false))
.thenReturn(this.environment);
MockMvc mvc = MockMvcBuilders.standaloneSetup(this.controller).build();
mvc.perform(MockMvcRequestBuilders.get("/foo-bar.json"))
@@ -547,7 +548,7 @@ public class EnvironmentControllerTests {
@Test
public void mappingForLabelledYaml() throws Exception {
Mockito.when(this.repository.findOne("foo", "bar", "other"))
when(this.repository.findOne("foo", "bar", "other", false))
.thenReturn(this.environment);
MockMvc mvc = MockMvcBuilders.standaloneSetup(this.controller).build();
mvc.perform(MockMvcRequestBuilders.get("/other/foo-bar.yml")).andExpect(
@@ -556,7 +557,7 @@ public class EnvironmentControllerTests {
@Test
public void mappingForLabelledProperties() throws Exception {
Mockito.when(this.repository.findOne("foo", "bar", "other"))
when(this.repository.findOne("foo", "bar", "other", false))
.thenReturn(this.environment);
MockMvc mvc = MockMvcBuilders.standaloneSetup(this.controller).build();
mvc.perform(MockMvcRequestBuilders.get("/other/foo-bar.properties")).andExpect(
@@ -565,7 +566,7 @@ public class EnvironmentControllerTests {
@Test
public void mappingForProperties() throws Exception {
Mockito.when(this.repository.findOne("foo", "bar", null))
when(this.repository.findOne("foo", "bar", null, false))
.thenReturn(this.environment);
MockMvc mvc = MockMvcBuilders.standaloneSetup(this.controller).build();
mvc.perform(MockMvcRequestBuilders.get("/foo-bar.properties")).andExpect(
@@ -574,7 +575,7 @@ public class EnvironmentControllerTests {
@Test
public void mappingForLabelledYamlWithHyphen() throws Exception {
Mockito.when(this.repository.findOne("foo-bar-foo2-bar2", "spam", "other"))
when(this.repository.findOne("foo-bar-foo2-bar2", "spam", "other", false))
.thenReturn(this.environment);
MockMvc mvc = MockMvcBuilders.standaloneSetup(this.controller).build();
mvc.perform(MockMvcRequestBuilders.get("/other/foo-bar-foo2-bar2-spam.yml"))
@@ -584,7 +585,7 @@ public class EnvironmentControllerTests {
@Test
public void mappingforLabelledJsonProperties() throws Exception {
Mockito.when(this.repository.findOne("foo", "bar", "other"))
when(this.repository.findOne("foo", "bar", "other", false))
.thenReturn(this.environment);
MockMvc mvc = MockMvcBuilders.standaloneSetup(this.controller).build();
mvc.perform(MockMvcRequestBuilders.get("/other/foo-bar.json")).andExpect(
@@ -593,7 +594,7 @@ public class EnvironmentControllerTests {
@Test
public void mappingforJsonProperties() throws Exception {
Mockito.when(this.repository.findOne("foo", "bar", null))
when(this.repository.findOne("foo", "bar", null, false))
.thenReturn(this.environment);
MockMvc mvc = MockMvcBuilders.standaloneSetup(this.controller).build();
mvc.perform(MockMvcRequestBuilders.get("/foo-bar.json")).andExpect(
@@ -602,7 +603,7 @@ public class EnvironmentControllerTests {
@Test
public void mappingForLabelledJsonPropertiesWithHyphen() throws Exception {
Mockito.when(this.repository.findOne("foo-bar-foo2-bar2", "spam", "other"))
when(this.repository.findOne("foo-bar-foo2-bar2", "spam", "other", false))
.thenReturn(this.environment);
MockMvc mvc = MockMvcBuilders.standaloneSetup(this.controller).build();
mvc.perform(MockMvcRequestBuilders.get("/other/foo-bar-foo2-bar2-spam.json"))

View File

@@ -30,6 +30,7 @@ import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.config.environment.PropertySource;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.when;
/**
* @author Dave Syer
@@ -57,10 +58,11 @@ public class EnvironmentEncryptorEnvironmentRepositoryTests {
Map<String, Object> map = new HashMap<String, Object>();
map.put("a.b.c", "d");
this.environment.add(new PropertySource("one", map));
Mockito.when(this.repository.findOne("foo", "bar", "master"))
when(this.repository.findOne("foo", "bar", "master", false))
.thenReturn(this.environment);
assertThat(this.controller.findOne("foo", "bar", "master").getPropertySources()
.get(0).getSource().toString()).isEqualTo("{foo=bar}");
assertThat(this.controller.findOne("foo", "bar", "master", false)
.getPropertySources().get(0).getSource().toString())
.isEqualTo("{foo=bar}");
}
@Test
@@ -69,10 +71,11 @@ public class EnvironmentEncryptorEnvironmentRepositoryTests {
Map<String, Object> map = new HashMap<String, Object>();
map.put("bar", "foo");
this.environment.add(new PropertySource("one", map));
Mockito.when(this.repository.findOne("foo", "bar", "master"))
when(this.repository.findOne("foo", "bar", "master", false))
.thenReturn(this.environment);
assertThat(this.controller.findOne("foo", "bar", "master").getPropertySources()
.get(0).getSource().toString()).isEqualTo("{foo=${bar}}");
assertThat(this.controller.findOne("foo", "bar", "master", false)
.getPropertySources().get(0).getSource().toString())
.isEqualTo("{foo=${bar}}");
}
}

View File

@@ -104,7 +104,6 @@ public class JGitEnvironmentRepositoryIntegrationTests {
.properties("spring.cloud.config.server.git.uri:" + uri).run();
EnvironmentRepository repository = this.context
.getBean(EnvironmentRepository.class);
repository.findOne("bar", "staging", "master");
Environment environment = repository.findOne("bar", "staging", "master");
assertThat(environment.getPropertySources().size()).isEqualTo(2);
assertThat(environment.getName()).isEqualTo("bar");
@@ -121,7 +120,6 @@ public class JGitEnvironmentRepositoryIntegrationTests {
.run("--spring.cloud.config.server.git.uri=" + uri);
EnvironmentRepository repository = this.context
.getBean(EnvironmentRepository.class);
repository.findOne("bar", "staging", "master");
Environment environment = repository.findOne("bar", "staging", "master");
assertThat(environment.getPropertySources().get(0).getSource().get("foo"))
.isEqualTo("bar");
@@ -212,7 +210,6 @@ public class JGitEnvironmentRepositoryIntegrationTests {
.getBean(JGitEnvironmentRepository.class);
new File(repository.getUri().replaceAll("file:", ""), ".git/index.lock")
.createNewFile();
repository.findOne("bar", "staging", "master");
Environment environment = repository.findOne("bar", "staging", "master");
assertThat(environment.getPropertySources().get(0).getSource().get("foo"))
.isEqualTo("foo");
@@ -228,7 +225,6 @@ public class JGitEnvironmentRepositoryIntegrationTests {
"--spring.cloud.config.server.git.searchPaths=sub");
EnvironmentRepository repository = this.context
.getBean(EnvironmentRepository.class);
repository.findOne("bar", "staging", "master");
Environment environment = repository.findOne("bar", "staging", "master");
assertThat(environment.getPropertySources().size()).isEqualTo(2);
}
@@ -243,7 +239,6 @@ public class JGitEnvironmentRepositoryIntegrationTests {
"--spring.cloud.config.server.git.searchPaths={application}");
EnvironmentRepository repository = this.context
.getBean(EnvironmentRepository.class);
repository.findOne("foo,bar", "staging", "master");
Environment environment = repository.findOne("foo,bar", "staging", "master");
assertThat(environment.getPropertySources().size()).isEqualTo(3);
}
@@ -258,7 +253,6 @@ public class JGitEnvironmentRepositoryIntegrationTests {
"--spring.cloud.config.server.git.searchPaths={profile}");
EnvironmentRepository repository = this.context
.getBean(EnvironmentRepository.class);
repository.findOne("foo,bar", "staging", "master");
Environment environment = repository.findOne("staging", "foo,bar", "master");
assertThat(environment.getPropertySources().size()).isEqualTo(3);
}
@@ -330,7 +324,6 @@ public class JGitEnvironmentRepositoryIntegrationTests {
"--spring.cloud.config.server.git.cloneOnStart=true");
EnvironmentRepository repository = this.context
.getBean(EnvironmentRepository.class);
repository.findOne("bar", "staging", "master");
Environment environment = repository.findOne("bar", "staging", "master");
assertThat(environment.getPropertySources().get(0).getSource().get("foo"))
.isEqualTo("bar");
@@ -356,7 +349,6 @@ public class JGitEnvironmentRepositoryIntegrationTests {
"--spring.cloud.config.server.git.cloneOnStart=true");
EnvironmentRepository repository = this.context
.getBean(EnvironmentRepository.class);
repository.findOne("bar", "staging", "master");
Environment environment = repository.findOne("bar", "staging", "master");
assertThat(environment.getPropertySources().size()).isEqualTo(2);
}

View File

@@ -122,7 +122,6 @@ public class JGitEnvironmentRepositoryTests {
@Test
public void vanilla() {
this.repository.findOne("bar", "staging", "master");
Environment environment = this.repository.findOne("bar", "staging", "master");
assertThat(environment.getPropertySources().size()).isEqualTo(2);
assertThat(environment.getPropertySources().get(0).getName())
@@ -135,7 +134,6 @@ public class JGitEnvironmentRepositoryTests {
String uri = ConfigServerTestUtils.prepareLocalRepo("another-config-repo");
this.repository.setUri(uri);
this.repository.setSearchPaths(new String[] { "sub" });
this.repository.findOne("bar", "staging", "master");
Environment environment = this.repository.findOne("bar", "staging", "master");
assertThat(environment.getPropertySources().size()).isEqualTo(2);
assertThat(environment.getPropertySources().get(0).getName())
@@ -148,7 +146,6 @@ public class JGitEnvironmentRepositoryTests {
String uri = ConfigServerTestUtils.prepareLocalRepo("another-config-repo");
this.repository.setUri(uri);
this.repository.setSearchPaths(new String[] { "{application}" });
this.repository.findOne("sub", "staging", "master");
Environment environment = this.repository.findOne("sub", "staging", "master");
assertThat(environment.getPropertySources().size()).isEqualTo(1);
assertThat(environment.getPropertySources().get(0).getName())
@@ -168,7 +165,6 @@ public class JGitEnvironmentRepositoryTests {
String uri = ConfigServerTestUtils.prepareLocalRepo("another-config-repo");
this.repository.setUri(uri);
this.repository.setSearchPaths(new String[] { "sub*" });
this.repository.findOne("bar", "staging", "master");
Environment environment = this.repository.findOne("bar", "staging", "master");
assertThat(environment.getPropertySources().size()).isEqualTo(2);
assertThat(environment.getPropertySources().get(0).getName())
@@ -199,7 +195,6 @@ public class JGitEnvironmentRepositoryTests {
@Test
public void basedir() {
this.repository.setBasedir(this.basedir);
this.repository.findOne("bar", "staging", "master");
Environment environment = this.repository.findOne("bar", "staging", "master");
assertThat(environment.getPropertySources().size()).isEqualTo(2);
assertThat(environment.getPropertySources().get(0).getName())
@@ -212,7 +207,6 @@ public class JGitEnvironmentRepositoryTests {
assertThat(this.basedir.mkdirs()).isTrue();
assertThat(new File(this.basedir, ".nothing").createNewFile()).isTrue();
this.repository.setBasedir(this.basedir);
this.repository.findOne("bar", "staging", "master");
Environment environment = this.repository.findOne("bar", "staging", "master");
assertThat(environment.getPropertySources().size()).isEqualTo(2);
assertThat(environment.getPropertySources().get(0).getName())

View File

@@ -91,7 +91,6 @@ public class MultipleJGitEnvironmentRepositoryIntegrationTests {
.properties("spring.cloud.config.server.git.uri:" + defaultRepoUri).run();
EnvironmentRepository repository = this.context
.getBean(EnvironmentRepository.class);
repository.findOne("bar", "staging", "master");
Environment environment = repository.findOne("bar", "staging", "master");
assertThat(environment.getPropertySources().size()).isEqualTo(2);
}
@@ -110,7 +109,6 @@ public class MultipleJGitEnvironmentRepositoryIntegrationTests {
.properties(repoMapping).run();
EnvironmentRepository repository = this.context
.getBean(EnvironmentRepository.class);
repository.findOne("test1-svc", "staging", "master");
Environment environment = repository.findOne("test1-svc", "staging", "master");
assertThat(environment.getPropertySources().size()).isEqualTo(2);
}
@@ -130,7 +128,6 @@ public class MultipleJGitEnvironmentRepositoryIntegrationTests {
.properties(repoMapping).run();
EnvironmentRepository repository = this.context
.getBean(EnvironmentRepository.class);
repository.findOne("test1-svc", "staging", "master");
Environment environment = repository.findOne("test1-svc", "staging", "master");
assertThat(environment.getPropertySources().size()).isEqualTo(2);
assertThat(30).isEqualTo(((MultipleJGitEnvironmentRepository) repository)
@@ -152,7 +149,6 @@ public class MultipleJGitEnvironmentRepositoryIntegrationTests {
.properties(repoMapping).run();
EnvironmentRepository repository = this.context
.getBean(EnvironmentRepository.class);
repository.findOne("test1-svc", "staging", "master");
Environment environment = repository.findOne("test1-svc", "staging", "master");
assertThat(environment.getPropertySources().size()).isEqualTo(2);
}
@@ -172,7 +168,6 @@ public class MultipleJGitEnvironmentRepositoryIntegrationTests {
.properties(repoMapping).run();
EnvironmentRepository repository = this.context
.getBean(EnvironmentRepository.class);
repository.findOne("test1-svc", "staging", "master");
Environment environment = repository.findOne("test1-svc", "staging,cloud",
"master");
assertThat(environment.getPropertySources().size()).isEqualTo(2);
@@ -197,7 +192,6 @@ public class MultipleJGitEnvironmentRepositoryIntegrationTests {
.properties(repoMapping).run();
EnvironmentRepository repository = this.context
.getBean(EnvironmentRepository.class);
repository.findOne("test1-svc", "staging", "master");
Environment environment = repository.findOne("test1-svc", "cloud,staging",
"master");
assertThat(environment.getPropertySources().size()).isEqualTo(2);
@@ -219,7 +213,6 @@ public class MultipleJGitEnvironmentRepositoryIntegrationTests {
.properties(repoMapping).run();
EnvironmentRepository repository = this.context
.getBean(EnvironmentRepository.class);
repository.findOne("test1-svc", "staging", "master");
Environment environment = repository.findOne("test1-svc", "staging", "master");
assertThat(environment.getPropertySources().size()).isEqualTo(2);
}

View File

@@ -124,7 +124,6 @@ public class MultipleJGitEnvironmentRepositoryTests {
String uri = ConfigServerTestUtils.prepareLocalRepo("another-config-repo");
this.repository.setUri(uri);
this.repository.setSearchPaths(new String[] { "sub" });
this.repository.findOne("bar", "staging", "master");
Environment environment = this.repository.findOne("bar", "staging", "master");
assertThat(environment.getPropertySources().size()).isEqualTo(2);
assertThat(environment.getPropertySources().get(0).getName())
@@ -152,7 +151,6 @@ public class MultipleJGitEnvironmentRepositoryTests {
@Test
public void defaultRepoTwice() {
this.repository.findOne("bar", "staging", "master");
Environment environment = this.repository.findOne("bar", "staging", "master");
assertThat(environment.getPropertySources().size()).isEqualTo(2);
assertThat(environment.getPropertySources().get(0).getName())

View File

@@ -94,7 +94,8 @@ public class NativeEnvironmentRepositoryTests {
@Test
public void labelled() {
this.repository.setSearchLocations("classpath:/test");
Environment environment = this.repository.findOne("foo", "development", "dev");
Environment environment = this.repository.findOne("foo", "development", "dev",
false);
assertThat(environment.getPropertySources().size()).isEqualTo(3);
// position 1 because it has higher precedence than anything except the
// foo-development.properties

View File

@@ -82,7 +82,6 @@ public class SVNKitEnvironmentRepositoryIntegrationTests {
.run("--spring.cloud.config.server.svn.uri=" + uri);
EnvironmentRepository repository = this.context
.getBean(EnvironmentRepository.class);
repository.findOne("bar", "staging", "trunk");
Environment environment = repository.findOne("bar", "staging", "trunk");
assertThat(environment.getPropertySources().size()).isEqualTo(2);
}
@@ -96,7 +95,6 @@ public class SVNKitEnvironmentRepositoryIntegrationTests {
.run("--spring.cloud.config.server.svn.uri=" + uri);
EnvironmentRepository repository = this.context
.getBean(EnvironmentRepository.class);
repository.findOne("bar", "staging", "trunk");
Environment environment = repository.findOne("bar", "staging", "trunk");
assertThat(environment.getPropertySources().get(0).getSource().get("foo"))
.isEqualTo("bar");
@@ -146,7 +144,6 @@ public class SVNKitEnvironmentRepositoryIntegrationTests {
.run("--spring.cloud.config.server.svn.uri=" + uri);
EnvironmentRepository repository = this.context
.getBean(EnvironmentRepository.class);
repository.findOne("bar", "staging", "unknownlabel");
Environment environment = repository.findOne("bar", "staging", "unknownlabel");
assertThat(environment.getPropertySources().size()).isEqualTo(0);
}

View File

@@ -108,7 +108,8 @@ public class SVNKitEnvironmentRepositoryTests {
@Test
public void branch_no_folder() {
Environment environment = this.repository.findOne("bar", "staging", "demobranch");
Environment environment = this.repository.findOne("bar", "staging", "demobranch",
false);
assertThat(environment.getPropertySources().size()).isEqualTo(1);
assertThat(environment.getPropertySources().get(0).getName()
.contains("bar.properties")).isTrue();

View File

@@ -43,6 +43,9 @@ import org.springframework.util.MimeTypeUtils;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
/**
* @author Dave Syer
* @author Daniel Lavoie
@@ -72,41 +75,41 @@ public class ResourceControllerIntegrationTests {
@Test
public void environmentNoLabel() throws Exception {
Mockito.when(this.repository.findOne("foo", "default", "master"))
when(this.repository.findOne("foo", "default", "master", false))
.thenReturn(new Environment("foo", "default"));
Mockito.when(this.resources.findOne("foo", "default", "master", "foo.txt"))
when(this.resources.findOne("foo", "default", "master", "foo.txt"))
.thenReturn(new ByteArrayResource("hello".getBytes()));
this.mvc.perform(MockMvcRequestBuilders.get("/foo/default/master/foo.txt"))
.andExpect(MockMvcResultMatchers.status().isOk());
Mockito.verify(this.repository).findOne("foo", "default", "master");
Mockito.verify(this.resources).findOne("foo", "default", "master", "foo.txt");
verify(this.repository).findOne("foo", "default", "master", false);
verify(this.resources).findOne("foo", "default", "master", "foo.txt");
}
@Test
public void resourceNoLabel() throws Exception {
Mockito.when(this.repository.findOne("foo", "default", null))
when(this.repository.findOne("foo", "default", null, false))
.thenReturn(new Environment("foo", "default", "master"));
Mockito.when(this.resources.findOne("foo", "default", null, "foo.txt"))
when(this.resources.findOne("foo", "default", null, "foo.txt"))
.thenReturn(new ByteArrayResource("hello".getBytes()));
this.mvc.perform(MockMvcRequestBuilders.get("/foo/default/foo.txt")
.param("useDefaultLabel", ""))
.andExpect(MockMvcResultMatchers.status().isOk());
Mockito.verify(this.repository).findOne("foo", "default", null);
Mockito.verify(this.resources).findOne("foo", "default", null, "foo.txt");
verify(this.repository).findOne("foo", "default", null, false);
verify(this.resources).findOne("foo", "default", null, "foo.txt");
}
@Test
public void binaryResourceNoLabel() throws Exception {
Mockito.when(this.repository.findOne("foo", "default", null))
when(this.repository.findOne("foo", "default", null, false))
.thenReturn(new Environment("foo", "default", "master"));
Mockito.when(this.resources.findOne("foo", "default", null, "foo.txt"))
when(this.resources.findOne("foo", "default", null, "foo.txt"))
.thenReturn(new ByteArrayResource("hello".getBytes()));
this.mvc.perform(MockMvcRequestBuilders.get("/foo/default/foo.txt")
.param("useDefaultLabel", "")
.header(HttpHeaders.ACCEPT, MimeTypeUtils.APPLICATION_OCTET_STREAM_VALUE))
.andExpect(MockMvcResultMatchers.status().isOk());
Mockito.verify(this.repository).findOne("foo", "default", null);
Mockito.verify(this.resources).findOne("foo", "default", null, "foo.txt");
verify(this.repository).findOne("foo", "default", null, false);
verify(this.resources).findOne("foo", "default", null, "foo.txt");
}
@Configuration

View File

@@ -18,6 +18,7 @@ package org.springframework.cloud.config.server.test;
import java.io.File;
import java.io.IOException;
import java.util.Map;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.RepositoryCache.FileKey;
@@ -29,6 +30,8 @@ import org.springframework.cloud.config.environment.PropertySource;
import org.springframework.util.FileSystemUtils;
import org.springframework.util.StringUtils;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Dave Syer
* @author Daniel Lavoie
@@ -139,4 +142,25 @@ public final class ConfigServerTestUtils {
return null;
}
@SuppressWarnings("unchecked")
public static void assertConfigEnabled(Environment environment) {
Object source = environment.getPropertySources().get(0).getSource();
assertThat(source).isNotNull().isInstanceOf(Map.class);
Map map = Map.class.cast(source);
assertThat(map).containsKeys("spring.cloud.config.enabled");
Object value = map.get("spring.cloud.config.enabled");
assertThat(value).isInstanceOf(Map.class);
map = Map.class.cast(value);
assertThat(map).containsEntry("value", "true");
}
@SuppressWarnings("unchecked")
public static void assertOriginTrackedValue(Environment environment, int index,
String key, String expectedValue) {
Object value = environment.getPropertySources().get(index).getSource().get(key);
assertThat(value).isNotNull().isInstanceOf(Map.class);
Map map = (Map) value;
assertThat(map).containsEntry("value", expectedValue);
}
}