diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointAutoConfiguration.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointAutoConfiguration.java index b37d47136e..4f84782bb6 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointAutoConfiguration.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointAutoConfiguration.java @@ -58,15 +58,12 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean import org.springframework.boot.autoconfigure.condition.SearchStrategy; import org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration; import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration; -import org.springframework.boot.bind.PropertiesConfigurationFactory; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.annotation.AnnotationAwareOrderComparator; import org.springframework.web.servlet.handler.AbstractHandlerMethodMapping; -import liquibase.integration.spring.SpringLiquibase; - /** * {@link EnableAutoConfiguration Auto-configuration} for common management * {@link Endpoint}s. @@ -81,7 +78,7 @@ import liquibase.integration.spring.SpringLiquibase; * */ @Configuration -@AutoConfigureAfter({ FlywayAutoConfiguration.class, LiquibaseAutoConfiguration.class }) +@AutoConfigureAfter({FlywayAutoConfiguration.class, LiquibaseAutoConfiguration.class}) @EnableConfigurationProperties(EndpointProperties.class) public class EndpointAutoConfiguration { diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/InfoProviderAutoConfiguration.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/InfoProviderAutoConfiguration.java index aefba43f06..60ed68d302 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/InfoProviderAutoConfiguration.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/InfoProviderAutoConfiguration.java @@ -37,7 +37,7 @@ import org.springframework.core.io.Resource; * @since 1.3.0 */ @Configuration -@AutoConfigureBefore({ EndpointAutoConfiguration.class }) +@AutoConfigureBefore({EndpointAutoConfiguration.class}) public class InfoProviderAutoConfiguration { @Autowired @@ -49,14 +49,13 @@ public class InfoProviderAutoConfiguration { @Bean @ConditionalOnMissingBean(name = "environmentInfoProvider") public InfoProvider environmentInfoProvider() throws Exception { - return new EnvironmentInfoProvider(environment); + return new EnvironmentInfoProvider(this.environment); } - + @Bean @ConditionalOnMissingBean(name = "scmInfoProvider") public InfoProvider scmInfoProvider() throws Exception { - return new ScmGitPropertiesInfoProvider(gitProperties); + return new ScmGitPropertiesInfoProvider(this.gitProperties); } - } diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/InfoEndpoint.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/InfoEndpoint.java index 9632b23ae1..0f8bd3d02f 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/InfoEndpoint.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/InfoEndpoint.java @@ -25,16 +25,19 @@ import org.springframework.util.Assert; /** * {@link Endpoint} to expose arbitrary application information. - * - * The information, which the {@link InfoEndpoint} can provide can be customized to display any informations, - * however initially the info endpoint will provide git version information (if available) and environment information, - * whose entries are prefixed with info. * - * In order to add additional information to the endpoint, one has to implement a class, which implements the {@link org.springframework.boot.actuate.info.InfoProvider} - * interface and register it in the application context. The InfoEndpoint will automatically pick it up, when it is being instantiated. + * The information, which the {@link InfoEndpoint} can provide can be customized to + * display any information, however initially the info endpoint will provide git version + * information (if available) and environment information,whose entries are prefixed with + * info. * - * The standard InfoProvider for GIT is registered as the scmInfoProvider, and the registration can be changed - * in case standard provider does not meet ones requirements. + * In order to add additional information to the endpoint, one has to implement a class, + * which implements the {@link org.springframework.boot.actuate.info.InfoProvider} + * interface and register it in the application context. The InfoEndpoint will + * automatically pick it up, when it is being instantiated. + * + * The standard InfoProvider for GIT is registered as the scmInfoProvider, and the + * registration can be changed in case standard provider does not meet ones requirements. * * @see org.springframework.boot.actuate.info.ScmGitPropertiesInfoProvider * @see org.springframework.boot.actuate.info.EnvironmentInfoProvider @@ -61,9 +64,9 @@ public class InfoEndpoint extends AbstractEndpoint { @Override public Info invoke() { Info result = new Info(); - for (InfoProvider provider : infoProviders.values()) { + for (InfoProvider provider : this.infoProviders.values()) { Info info = provider.provide(); - if(info != null) { + if (info != null) { result.put(provider.name(), info); } } diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/info/EnvironmentInfoProvider.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/info/EnvironmentInfoProvider.java index 573580e7ca..062f8d75eb 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/info/EnvironmentInfoProvider.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/info/EnvironmentInfoProvider.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.boot.actuate.info; import java.util.LinkedHashMap; @@ -22,9 +23,8 @@ import org.springframework.boot.bind.PropertiesConfigurationFactory; import org.springframework.core.env.ConfigurableEnvironment; /** - * A {@link InfoProvider} that provides all environment entries prefixed with info - * - * See something + * A {@link InfoProvider} that provides all environment entries prefixed with + * info. * * @author Meang Akira Tanaka * @since 1.3.0 @@ -32,13 +32,12 @@ import org.springframework.core.env.ConfigurableEnvironment; public class EnvironmentInfoProvider implements InfoProvider { private final ConfigurableEnvironment environment; - private final Map infoMap; + private final Info info; public EnvironmentInfoProvider(ConfigurableEnvironment environment) throws Exception { this.environment = environment; - infoMap = extractInfoFromEnvironment(); - this.info = new Info(infoMap); + this.info = new Info(extractInfoFromEnvironment()); } @Override @@ -48,7 +47,7 @@ public class EnvironmentInfoProvider implements InfoProvider { @Override public Info provide() { - return info; + return this.info; } private Map extractInfoFromEnvironment() throws Exception { diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/info/Info.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/info/Info.java index 1b339b8766..064e966685 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/info/Info.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/info/Info.java @@ -24,17 +24,16 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; /** - * Carries information from a specific info provider - * - * @see org.springframework.boot.actuate.endpoint.InfoEndpoint + * Carries information from a specific info provider. * * @author Meang Akira Tanaka * @since 1.3.0 + * @see org.springframework.boot.actuate.endpoint.InfoEndpoint */ @JsonInclude(Include.NON_EMPTY) public final class Info { - private final Map details = new HashMap(); + private final Map details = new HashMap(); public Info() { } @@ -44,6 +43,7 @@ public final class Info { } /** + * Return the content. * @return the details of the info or an empty map. */ @JsonAnyGetter @@ -54,12 +54,12 @@ public final class Info { public void put(String infoId, Object value) { this.details.put(infoId, value); } - + @SuppressWarnings("unchecked") public T get(String infoId) { return (T) this.details.get(infoId); } - + @Override public boolean equals(Object obj) { if (obj == this) { diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/info/InfoProvider.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/info/InfoProvider.java index ad51181d8c..1a76553676 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/info/InfoProvider.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/info/InfoProvider.java @@ -1,15 +1,32 @@ +/* + * Copyright 2012-2016 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 + * + * http://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.boot.actuate.info; /** - * information provider for the info endpoint + * information provider for the info endpoint. * * @author Meang Akira Tanaka */ public interface InfoProvider { String name(); - + /** + * Return the {@link Info} instance. * @return a collection of information */ Info provide(); diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/info/ScmGitPropertiesInfoProvider.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/info/ScmGitPropertiesInfoProvider.java index 7e6984cef0..8b12488b7b 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/info/ScmGitPropertiesInfoProvider.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/info/ScmGitPropertiesInfoProvider.java @@ -1,3 +1,19 @@ +/* + * Copyright 2012-2016 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 + * + * http://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.boot.actuate.info; import java.util.Properties; @@ -7,20 +23,22 @@ import org.springframework.core.io.Resource; import org.springframework.core.io.support.PropertiesLoaderUtils; /** - * A {@link InfoProvider} that provides git information extracted from the git.properties file generated by the maven plugin + * A {@link InfoProvider} that provides git information extracted from the + * git.properties file generated by the maven plugin * pl.project13.maven:git-commit-id-plugin. - * + * * @author Meang Akira Tanaka * @since 1.3.0 */ public class ScmGitPropertiesInfoProvider implements InfoProvider { private final Resource gitPropertiesResource; + private final GitInfo gitInfo; public ScmGitPropertiesInfoProvider(Resource gitPropertiesResource) throws Exception { this.gitPropertiesResource = gitPropertiesResource; - gitInfo = extractGitInfo(); + this.gitInfo = extractGitInfo(); } @Override @@ -30,19 +48,19 @@ public class ScmGitPropertiesInfoProvider implements InfoProvider { @Override public Info provide() { - if(gitInfo == null) { + if (this.gitInfo == null) { return null; } - + Info result = new Info(); - - result.put("branch", gitInfo.getBranch()); - result.put("commit", gitInfo.getCommit()); - + + result.put("branch", this.gitInfo.getBranch()); + result.put("commit", this.gitInfo.getCommit()); + return result; } - + private GitInfo extractGitInfo() throws Exception { PropertiesConfigurationFactory factory = new PropertiesConfigurationFactory( new GitInfo()); @@ -50,7 +68,8 @@ public class ScmGitPropertiesInfoProvider implements InfoProvider { Properties properties = new Properties(); if (this.gitPropertiesResource.exists()) { properties = PropertiesLoaderUtils.loadProperties(this.gitPropertiesResource); - } else { + } + else { return null; } factory.setProperties(properties); @@ -58,6 +77,9 @@ public class ScmGitPropertiesInfoProvider implements InfoProvider { } + /** + * Git info. + */ public static class GitInfo { private String branch; @@ -76,6 +98,9 @@ public class ScmGitPropertiesInfoProvider implements InfoProvider { return this.commit; } + /** + * Commit information. + */ public static class Commit { private String id; diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointAutoConfigurationTests.java index 4a86b96c53..b42bb062ca 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointAutoConfigurationTests.java @@ -37,7 +37,6 @@ import org.springframework.boot.actuate.endpoint.RequestMappingEndpoint; import org.springframework.boot.actuate.endpoint.ShutdownEndpoint; import org.springframework.boot.actuate.endpoint.TraceEndpoint; import org.springframework.boot.actuate.health.Health; -import org.springframework.boot.actuate.info.Info; import org.springframework.boot.actuate.metrics.Metric; import org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport; import org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration; @@ -61,7 +60,6 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Stephane Nicoll * @author EddĂș MelĂ©ndez * @author Meang Akira Tanaka - * */ public class EndpointAutoConfigurationTests { diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/InfoEndpointTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/InfoEndpointTests.java index 7715fd691a..b88294eb0a 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/InfoEndpointTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/InfoEndpointTests.java @@ -16,12 +16,10 @@ package org.springframework.boot.actuate.endpoint; -import static org.hamcrest.Matchers.equalTo; -import static org.junit.Assert.assertThat; - import java.util.Map; import org.junit.Test; + import org.springframework.boot.actuate.info.Info; import org.springframework.boot.actuate.info.InfoProvider; import org.springframework.boot.context.properties.EnableConfigurationProperties; @@ -45,15 +43,8 @@ public class InfoEndpointTests extends AbstractEndpointTests { @Test public void invoke() throws Exception { - Info actual = ((Info) getEndpointBean().invoke().get("environment")); - assertThat(actual.get("key1"), equalTo((Object) "value1")); - } - - @Test - public void invoke_HasProvider_GetProviderInfo() throws Exception { - @SuppressWarnings("unchecked") - Map actual = ((Map) getEndpointBean().invoke().get("infoProvider")); - assertThat(actual.get("key1"), equalTo((Object) "value1")); + Info actual = getEndpointBean().invoke().get("environment"); + assertThat(actual.get("key1")).isEqualTo("value1"); } @Configuration diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/InfoMvcEndpointTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/InfoMvcEndpointTests.java index 20644b861e..d122c6621c 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/InfoMvcEndpointTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/InfoMvcEndpointTests.java @@ -1,9 +1,20 @@ -package org.springframework.boot.actuate.endpoint.mvc; +/* + * Copyright 2012-2016 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 + * + * http://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. + */ -import static org.hamcrest.Matchers.containsString; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +package org.springframework.boot.actuate.endpoint.mvc; import java.util.Map; @@ -11,6 +22,7 @@ import org.elasticsearch.common.collect.Maps; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.actuate.autoconfigure.EndpointWebMvcAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.ManagementServerPropertiesAutoConfiguration; @@ -32,13 +44,18 @@ import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; +import static org.hamcrest.Matchers.containsString; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + /** * Tests for {@link InfoMvcEndpointTests} * * @author Meang Akira Tanaka */ @RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes = { TestConfiguration.class }) +@SpringApplicationConfiguration(classes = {TestConfiguration.class}) @WebAppConfiguration @TestPropertySource(properties = {"info.app.name=MyService"}) public class InfoMvcEndpointTests { @@ -57,14 +74,16 @@ public class InfoMvcEndpointTests { @Test public void home() throws Exception { this.mvc.perform(get("/info")).andExpect(status().isOk()) - .andExpect(content().string(containsString("\"beanName2\":{\"key22\":\"value22\",\"key21\":\"value21\"},\"beanName1\":{\"key12\":\"value12\",\"key11\":\"value11\"}"))); + .andExpect(content().string( + containsString("\"beanName2\":{\"key22\":\"value22\",\"key21\":\"value21\"}," + + "\"beanName1\":{\"key12\":\"value12\",\"key11\":\"value11\"}"))); } - - @Import({ JacksonAutoConfiguration.class, - HttpMessageConvertersAutoConfiguration.class, - EndpointWebMvcAutoConfiguration.class, - WebMvcAutoConfiguration.class, - ManagementServerPropertiesAutoConfiguration.class }) + + @Import({JacksonAutoConfiguration.class, + HttpMessageConvertersAutoConfiguration.class, + EndpointWebMvcAutoConfiguration.class, + WebMvcAutoConfiguration.class, + ManagementServerPropertiesAutoConfiguration.class}) @Configuration public static class TestConfiguration { @@ -72,7 +91,7 @@ public class InfoMvcEndpointTests { public TestConfiguration() { InfoProvider infoProvider1 = new InfoProvider() { - + @Override public Info provide() { Info result = new Info(); @@ -86,10 +105,10 @@ public class InfoMvcEndpointTests { return "beanName1"; } }; - infoProviders.put("beanName1", infoProvider1); - + this.infoProviders.put("beanName1", infoProvider1); + InfoProvider infoProvider2 = new InfoProvider() { - + @Override public Info provide() { Info result = new Info(); @@ -103,13 +122,13 @@ public class InfoMvcEndpointTests { return "beanName2"; } }; - infoProviders.put("beanName2", infoProvider2); + this.infoProviders.put("beanName2", infoProvider2); } - + @Bean public InfoEndpoint endpoint() { - return new InfoEndpoint(infoProviders); + return new InfoEndpoint(this.infoProviders); } } - + } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/InfoMvcEndpointWithoutAnyInfoProvidersTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/InfoMvcEndpointWithoutAnyInfoProvidersTests.java index 99d07fa5e5..9cb7bc6e9f 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/InfoMvcEndpointWithoutAnyInfoProvidersTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/InfoMvcEndpointWithoutAnyInfoProvidersTests.java @@ -1,15 +1,28 @@ -package org.springframework.boot.actuate.endpoint.mvc; +/* + * Copyright 2012-2016 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 + * + * http://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. + */ -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +package org.springframework.boot.actuate.endpoint.mvc; -import java.util.HashMap; import java.util.Map; import org.elasticsearch.common.collect.Maps; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.actuate.autoconfigure.EndpointWebMvcAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.ManagementServerPropertiesAutoConfiguration; @@ -29,13 +42,16 @@ import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + /** * Tests for {@link InfoMvcEndpointWithoutAnyInfoProvidersTests} * * @author Meang Akira Tanaka */ @RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes = { TestConfiguration.class }) +@SpringApplicationConfiguration(classes = {TestConfiguration.class}) @WebAppConfiguration public class InfoMvcEndpointWithoutAnyInfoProvidersTests { @Autowired @@ -54,12 +70,12 @@ public class InfoMvcEndpointWithoutAnyInfoProvidersTests { public void home() throws Exception { this.mvc.perform(get("/info")).andExpect(status().isOk()); } - - @Import({ JacksonAutoConfiguration.class, - HttpMessageConvertersAutoConfiguration.class, - EndpointWebMvcAutoConfiguration.class, - WebMvcAutoConfiguration.class, - ManagementServerPropertiesAutoConfiguration.class }) + + @Import({JacksonAutoConfiguration.class, + HttpMessageConvertersAutoConfiguration.class, + EndpointWebMvcAutoConfiguration.class, + WebMvcAutoConfiguration.class, + ManagementServerPropertiesAutoConfiguration.class}) @Configuration public static class TestConfiguration { @@ -67,9 +83,9 @@ public class InfoMvcEndpointWithoutAnyInfoProvidersTests { @Bean public InfoEndpoint endpoint() { - return new InfoEndpoint(infoProviders); + return new InfoEndpoint(this.infoProviders); } } - + } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/info/EnvironmentInfoProviderTest.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/info/EnvironmentInfoProviderTests.java similarity index 60% rename from spring-boot-actuator/src/test/java/org/springframework/boot/actuate/info/EnvironmentInfoProviderTest.java rename to spring-boot-actuator/src/test/java/org/springframework/boot/actuate/info/EnvironmentInfoProviderTests.java index 2e0c2c65bd..e9d775ada1 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/info/EnvironmentInfoProviderTest.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/info/EnvironmentInfoProviderTests.java @@ -1,64 +1,79 @@ -package org.springframework.boot.actuate.info; +/* + * Copyright 2012-2016 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 + * + * http://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. + */ -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.is; +package org.springframework.boot.actuate.info; import java.util.Properties; import org.junit.Test; + import org.springframework.core.env.PropertiesPropertySource; import org.springframework.core.env.PropertySource; import org.springframework.core.env.StandardEnvironment; -public class EnvironmentInfoProviderTest { +import static org.assertj.core.api.Assertions.assertThat; + +public class EnvironmentInfoProviderTests { @Test public void provide_HasTwoRelevantEntries_ShowOnlyRelevantEntries() throws Exception { String expectedAppName = "my app name"; String expectedLanguage = "da-DK"; - Properties properties = new Properties(); + Properties properties = new Properties(); properties.setProperty("info.app", expectedAppName); properties.setProperty("info.lang", expectedLanguage); properties.setProperty("logging.path", "notExpected"); - + PropertySource propertySource = new PropertiesPropertySource("mysettings", properties); StandardEnvironment environment = new StandardEnvironment(); environment.getPropertySources().addLast(propertySource); EnvironmentInfoProvider environmentInfoProvider = new EnvironmentInfoProvider(environment); - + Info actual = environmentInfoProvider.provide(); - assertThat(actual.getDetails().size(), is(equalTo(2))); - assertThat((String) actual.get("app"), is(equalTo(expectedAppName))); - assertThat((String) actual.get("lang"), is(equalTo(expectedLanguage))); + assertThat(actual.getDetails().size()).isEqualTo(2); + assertThat((String) actual.get("app")).isEqualTo(expectedAppName); + assertThat((String) actual.get("lang")).isEqualTo(expectedLanguage); } - + @Test public void provide_HasNoRelevantEntries_NoEntries() throws Exception { - Properties properties = new Properties(); + Properties properties = new Properties(); properties.setProperty("logging.path", "notExpected"); - + PropertySource propertySource = new PropertiesPropertySource("mysettings", properties); StandardEnvironment environment = new StandardEnvironment(); environment.getPropertySources().addLast(propertySource); EnvironmentInfoProvider environmentInfoProvider = new EnvironmentInfoProvider(environment); - + Info actual = environmentInfoProvider.provide(); - assertThat(actual.getDetails().size(), is(equalTo(0))); + assertThat(actual.getDetails().size()).isEqualTo(0); } - - + + @Test public void provide_HasNoEntries_NoEntries() throws Exception { EnvironmentInfoProvider environmentInfoProvider = new EnvironmentInfoProvider(new StandardEnvironment()); - + Info actual = environmentInfoProvider.provide(); - assertThat(actual.getDetails().size(), is(equalTo(0))); + assertThat(actual.getDetails().size()).isEqualTo(0); } } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/info/ScmGitPropertiesInfoProviderTest.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/info/ScmGitPropertiesInfoProviderTests.java similarity index 60% rename from spring-boot-actuator/src/test/java/org/springframework/boot/actuate/info/ScmGitPropertiesInfoProviderTest.java rename to spring-boot-actuator/src/test/java/org/springframework/boot/actuate/info/ScmGitPropertiesInfoProviderTests.java index 90eaf0fd55..1a6dba7055 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/info/ScmGitPropertiesInfoProviderTest.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/info/ScmGitPropertiesInfoProviderTests.java @@ -1,33 +1,46 @@ -package org.springframework.boot.actuate.info; +/* + * Copyright 2012-2016 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 + * + * http://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. + */ -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.not; -import static org.hamcrest.Matchers.nullValue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; +package org.springframework.boot.actuate.info; import org.junit.Test; + import org.springframework.boot.actuate.info.ScmGitPropertiesInfoProvider.GitInfo.Commit; import org.springframework.core.io.ByteArrayResource; import org.springframework.core.io.Resource; -public class ScmGitPropertiesInfoProviderTest { +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.mock; + +public class ScmGitPropertiesInfoProviderTests { + - @Test public void provide_HasBadFormatButExists_EmptyInfoReturned() throws Exception { Resource resource = new ByteArrayResource("GARBAGE".getBytes()); ScmGitPropertiesInfoProvider scmGitPropertiesInfoProvider = new ScmGitPropertiesInfoProvider(resource); Info actual = scmGitPropertiesInfoProvider.provide(); - assertThat(actual, is(not(nullValue()))); - assertThat((String) actual.get("branch"), is(nullValue())); - Commit actualCommit = (Commit) actual.get("commit"); - assertThat(actualCommit, is(not(nullValue()))); - assertThat(actualCommit.getId(), is(equalTo(""))); - assertThat(actualCommit.getTime(), is(nullValue())); + assertThat(actual).isNotNull(); + assertThat((String) actual.get("branch")).isNull(); + Commit actualCommit = actual.get("commit"); + assertThat(actualCommit).isNotNull(); + assertThat(actualCommit.getId()).isEqualTo(""); + assertThat(actualCommit.getTime()).isNull(); } @Test @@ -43,17 +56,17 @@ public class ScmGitPropertiesInfoProviderTest { + "git.branch=develop\r\n" + "git.commit.time=2013-04-24T08\\:42\\:13+0100\r\n" + "git.build.time=2013-05-23T09\\:26\\:42+0100\r\n"; - + Resource resource = new ByteArrayResource(gitProperties.getBytes()); ScmGitPropertiesInfoProvider scmGitPropertiesInfoProvider = new ScmGitPropertiesInfoProvider(resource); Info actual = scmGitPropertiesInfoProvider.provide(); - assertThat(actual, is(not(nullValue()))); - assertThat((String) actual.get("branch"), is(equalTo("develop"))); - Commit actualCommit = (Commit) actual.get("commit"); - assertThat(actualCommit, is(not(nullValue()))); - assertThat(actualCommit.getId(), is(equalTo("e02a4f3"))); - assertThat(actualCommit.getTime(), is(equalTo("2013-04-24T08:42:13+0100"))); + assertThat(actual).isNotNull(); + assertThat((String) actual.get("branch")).isEqualTo("develop"); + Commit actualCommit = actual.get("commit"); + assertThat(actualCommit).isNotNull(); + assertThat(actualCommit.getId()).isEqualTo("e02a4f3"); + assertThat(actualCommit.getTime()).isEqualTo("2013-04-24T08:42:13+0100"); } @@ -69,30 +82,27 @@ public class ScmGitPropertiesInfoProviderTest { + "git.build.user.email=dsyer@vmware.com\r\n" + "git.branch=develop\r\n" + "git.build.time=2013-05-23T09\\:26\\:42+0100\r\n"; - + Resource resource = new ByteArrayResource(gitProperties.getBytes()); ScmGitPropertiesInfoProvider scmGitPropertiesInfoProvider = new ScmGitPropertiesInfoProvider(resource); Info actual = scmGitPropertiesInfoProvider.provide(); - assertThat(actual, is(not(nullValue()))); - assertThat((String) actual.get("branch"), is(equalTo("develop"))); - Commit actualCommit = (Commit) actual.get("commit"); - assertThat(actualCommit, is(not(nullValue()))); - assertThat(actualCommit.getId(), is(equalTo("e02a4f3"))); - assertThat(actualCommit.getTime(), is(nullValue())); + assertThat(actual).isNotNull(); + assertThat((String) actual.get("branch")).isEqualTo("develop"); + Commit actualCommit = (Commit) actual.get("commit"); + assertThat(actualCommit).isNotNull(); + assertThat(actualCommit.getId()).isEqualTo("e02a4f3"); + assertThat(actualCommit.getTime()).isNull(); } - @Test public void provide_DoesNotExists_NullReturned() throws Exception { - Resource resource = mock(Resource.class); - when(resource.exists()) - .thenReturn(false); + given(resource.exists()).willReturn(false); ScmGitPropertiesInfoProvider scmGitPropertiesInfoProvider = new ScmGitPropertiesInfoProvider(resource); Info actual = scmGitPropertiesInfoProvider.provide(); - assertThat(actual, is(nullValue())); + assertThat(actual).isNull(); } }