Commit 6184e415 authored by Madhura Bhave's avatar Madhura Bhave Committed by Phillip Webb

Test correct binding in '/info' endpoint

Add a test to ensure that the updated configuration properties work
correctly binds environment sources in the `/info` endpoint.

Closes gh-7388
parent e3ea7a7d
/* /*
* Copyright 2012-2016 the original author or authors. * Copyright 2012-2017 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.
...@@ -16,11 +16,16 @@ ...@@ -16,11 +16,16 @@
package org.springframework.boot.actuate.info; package org.springframework.boot.actuate.info;
import java.util.Collections;
import java.util.Map;
import org.junit.Test; import org.junit.Test;
import org.springframework.boot.test.util.EnvironmentTestUtils; import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.StandardEnvironment; import org.springframework.core.env.StandardEnvironment;
import org.springframework.core.env.SystemEnvironmentPropertySource;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
...@@ -50,6 +55,16 @@ public class EnvironmentInfoContributorTests { ...@@ -50,6 +55,16 @@ public class EnvironmentInfoContributorTests {
assertThat(actual.getDetails().size()).isEqualTo(0); assertThat(actual.getDetails().size()).isEqualTo(0);
} }
@Test
@SuppressWarnings("unchecked")
public void propertiesFromEnvironmentShouldBindCorrectly() throws Exception {
MutablePropertySources propertySources = this.environment.getPropertySources();
propertySources.addFirst(new SystemEnvironmentPropertySource("system",
Collections.singletonMap("INFO_ENVIRONMENT_FOO", "green")));
Info actual = contributeFrom(this.environment);
assertThat(actual.get("environment", Map.class)).containsEntry("foo", "green");
}
private static Info contributeFrom(ConfigurableEnvironment environment) { private static Info contributeFrom(ConfigurableEnvironment environment) {
EnvironmentInfoContributor contributor = new EnvironmentInfoContributor( EnvironmentInfoContributor contributor = new EnvironmentInfoContributor(
environment); environment);
......
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