From 6184e4154e0683fe5fcce6efc0c7a67bc41a35ea Mon Sep 17 00:00:00 2001 From: Madhura Bhave Date: Wed, 26 Apr 2017 12:21:21 -0700 Subject: [PATCH] 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 --- .../info/EnvironmentInfoContributorTests.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/info/EnvironmentInfoContributorTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/info/EnvironmentInfoContributorTests.java index d1ced85b9b..c363d435ee 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/info/EnvironmentInfoContributorTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/info/EnvironmentInfoContributorTests.java @@ -1,5 +1,5 @@ /* - * 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"); * you may not use this file except in compliance with the License. @@ -16,11 +16,16 @@ package org.springframework.boot.actuate.info; +import java.util.Collections; +import java.util.Map; + import org.junit.Test; import org.springframework.boot.test.util.EnvironmentTestUtils; import org.springframework.core.env.ConfigurableEnvironment; +import org.springframework.core.env.MutablePropertySources; import org.springframework.core.env.StandardEnvironment; +import org.springframework.core.env.SystemEnvironmentPropertySource; import static org.assertj.core.api.Assertions.assertThat; @@ -50,6 +55,16 @@ public class EnvironmentInfoContributorTests { 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) { EnvironmentInfoContributor contributor = new EnvironmentInfoContributor( environment);