rebase to master

pull/5303/merge
Stephane Nicoll 9 years ago
parent 8bebe6dea9
commit 7618802838

@ -58,15 +58,12 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
import org.springframework.boot.autoconfigure.condition.SearchStrategy; import org.springframework.boot.autoconfigure.condition.SearchStrategy;
import org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration; import org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration;
import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration; import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration;
import org.springframework.boot.bind.PropertiesConfigurationFactory;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.AnnotationAwareOrderComparator; import org.springframework.core.annotation.AnnotationAwareOrderComparator;
import org.springframework.web.servlet.handler.AbstractHandlerMethodMapping; import org.springframework.web.servlet.handler.AbstractHandlerMethodMapping;
import liquibase.integration.spring.SpringLiquibase;
/** /**
* {@link EnableAutoConfiguration Auto-configuration} for common management * {@link EnableAutoConfiguration Auto-configuration} for common management
* {@link Endpoint}s. * {@link Endpoint}s.
@ -81,7 +78,7 @@ import liquibase.integration.spring.SpringLiquibase;
* *
*/ */
@Configuration @Configuration
@AutoConfigureAfter({ FlywayAutoConfiguration.class, LiquibaseAutoConfiguration.class }) @AutoConfigureAfter({FlywayAutoConfiguration.class, LiquibaseAutoConfiguration.class})
@EnableConfigurationProperties(EndpointProperties.class) @EnableConfigurationProperties(EndpointProperties.class)
public class EndpointAutoConfiguration { public class EndpointAutoConfiguration {

@ -37,7 +37,7 @@ import org.springframework.core.io.Resource;
* @since 1.3.0 * @since 1.3.0
*/ */
@Configuration @Configuration
@AutoConfigureBefore({ EndpointAutoConfiguration.class }) @AutoConfigureBefore({EndpointAutoConfiguration.class})
public class InfoProviderAutoConfiguration { public class InfoProviderAutoConfiguration {
@Autowired @Autowired
@ -49,14 +49,13 @@ public class InfoProviderAutoConfiguration {
@Bean @Bean
@ConditionalOnMissingBean(name = "environmentInfoProvider") @ConditionalOnMissingBean(name = "environmentInfoProvider")
public InfoProvider environmentInfoProvider() throws Exception { public InfoProvider environmentInfoProvider() throws Exception {
return new EnvironmentInfoProvider(environment); return new EnvironmentInfoProvider(this.environment);
} }
@Bean @Bean
@ConditionalOnMissingBean(name = "scmInfoProvider") @ConditionalOnMissingBean(name = "scmInfoProvider")
public InfoProvider scmInfoProvider() throws Exception { public InfoProvider scmInfoProvider() throws Exception {
return new ScmGitPropertiesInfoProvider(gitProperties); return new ScmGitPropertiesInfoProvider(this.gitProperties);
} }
} }

@ -26,15 +26,18 @@ import org.springframework.util.Assert;
/** /**
* {@link Endpoint} to expose arbitrary application information. * {@link Endpoint} to expose arbitrary application information.
* *
* The information, which the {@link InfoEndpoint} can provide can be customized to display any informations, * The information, which the {@link InfoEndpoint} can provide can be customized to
* however initially the info endpoint will provide git version information (if available) and environment information, * display any information, however initially the info endpoint will provide git version
* whose entries are prefixed with info. * 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} * In order to add additional information to the endpoint, one has to implement a class,
* interface and register it in the application context. The InfoEndpoint will automatically pick it up, when it is being instantiated. * 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 * The standard InfoProvider for GIT is registered as the scmInfoProvider, and the
* in case standard provider does not meet ones requirements. * 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.ScmGitPropertiesInfoProvider
* @see org.springframework.boot.actuate.info.EnvironmentInfoProvider * @see org.springframework.boot.actuate.info.EnvironmentInfoProvider
@ -61,9 +64,9 @@ public class InfoEndpoint extends AbstractEndpoint<Info> {
@Override @Override
public Info invoke() { public Info invoke() {
Info result = new Info(); Info result = new Info();
for (InfoProvider provider : infoProviders.values()) { for (InfoProvider provider : this.infoProviders.values()) {
Info info = provider.provide(); Info info = provider.provide();
if(info != null) { if (info != null) {
result.put(provider.name(), info); result.put(provider.name(), info);
} }
} }

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.boot.actuate.info; package org.springframework.boot.actuate.info;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
@ -22,9 +23,8 @@ import org.springframework.boot.bind.PropertiesConfigurationFactory;
import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.ConfigurableEnvironment;
/** /**
* A {@link InfoProvider} that provides all environment entries prefixed with info * A {@link InfoProvider} that provides all environment entries prefixed with
* * info.
* See something
* *
* @author Meang Akira Tanaka * @author Meang Akira Tanaka
* @since 1.3.0 * @since 1.3.0
@ -32,13 +32,12 @@ import org.springframework.core.env.ConfigurableEnvironment;
public class EnvironmentInfoProvider implements InfoProvider { public class EnvironmentInfoProvider implements InfoProvider {
private final ConfigurableEnvironment environment; private final ConfigurableEnvironment environment;
private final Map<String, Object> infoMap;
private final Info info; private final Info info;
public EnvironmentInfoProvider(ConfigurableEnvironment environment) throws Exception { public EnvironmentInfoProvider(ConfigurableEnvironment environment) throws Exception {
this.environment = environment; this.environment = environment;
infoMap = extractInfoFromEnvironment(); this.info = new Info(extractInfoFromEnvironment());
this.info = new Info(infoMap);
} }
@Override @Override
@ -48,7 +47,7 @@ public class EnvironmentInfoProvider implements InfoProvider {
@Override @Override
public Info provide() { public Info provide() {
return info; return this.info;
} }
private Map<String, Object> extractInfoFromEnvironment() throws Exception { private Map<String, Object> extractInfoFromEnvironment() throws Exception {

@ -24,12 +24,11 @@ import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonInclude.Include;
/** /**
* Carries information from a specific info provider * Carries information from a specific info provider.
*
* @see org.springframework.boot.actuate.endpoint.InfoEndpoint
* *
* @author Meang Akira Tanaka * @author Meang Akira Tanaka
* @since 1.3.0 * @since 1.3.0
* @see org.springframework.boot.actuate.endpoint.InfoEndpoint
*/ */
@JsonInclude(Include.NON_EMPTY) @JsonInclude(Include.NON_EMPTY)
public final class Info { public final class Info {
@ -44,6 +43,7 @@ public final class Info {
} }
/** /**
* Return the content.
* @return the details of the info or an empty map. * @return the details of the info or an empty map.
*/ */
@JsonAnyGetter @JsonAnyGetter

@ -1,7 +1,23 @@
/*
* 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; package org.springframework.boot.actuate.info;
/** /**
* information provider for the info endpoint * information provider for the info endpoint.
* *
* @author Meang Akira Tanaka * @author Meang Akira Tanaka
*/ */
@ -10,6 +26,7 @@ public interface InfoProvider {
String name(); String name();
/** /**
* Return the {@link Info} instance.
* @return a collection of information * @return a collection of information
*/ */
Info provide(); Info provide();

@ -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; package org.springframework.boot.actuate.info;
import java.util.Properties; import java.util.Properties;
@ -7,7 +23,8 @@ import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PropertiesLoaderUtils; 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. * pl.project13.maven:git-commit-id-plugin.
* *
* @author Meang Akira Tanaka * @author Meang Akira Tanaka
@ -16,11 +33,12 @@ import org.springframework.core.io.support.PropertiesLoaderUtils;
public class ScmGitPropertiesInfoProvider implements InfoProvider { public class ScmGitPropertiesInfoProvider implements InfoProvider {
private final Resource gitPropertiesResource; private final Resource gitPropertiesResource;
private final GitInfo gitInfo; private final GitInfo gitInfo;
public ScmGitPropertiesInfoProvider(Resource gitPropertiesResource) throws Exception { public ScmGitPropertiesInfoProvider(Resource gitPropertiesResource) throws Exception {
this.gitPropertiesResource = gitPropertiesResource; this.gitPropertiesResource = gitPropertiesResource;
gitInfo = extractGitInfo(); this.gitInfo = extractGitInfo();
} }
@Override @Override
@ -30,14 +48,14 @@ public class ScmGitPropertiesInfoProvider implements InfoProvider {
@Override @Override
public Info provide() { public Info provide() {
if(gitInfo == null) { if (this.gitInfo == null) {
return null; return null;
} }
Info result = new Info(); Info result = new Info();
result.put("branch", gitInfo.getBranch()); result.put("branch", this.gitInfo.getBranch());
result.put("commit", gitInfo.getCommit()); result.put("commit", this.gitInfo.getCommit());
return result; return result;
} }
@ -50,7 +68,8 @@ public class ScmGitPropertiesInfoProvider implements InfoProvider {
Properties properties = new Properties(); Properties properties = new Properties();
if (this.gitPropertiesResource.exists()) { if (this.gitPropertiesResource.exists()) {
properties = PropertiesLoaderUtils.loadProperties(this.gitPropertiesResource); properties = PropertiesLoaderUtils.loadProperties(this.gitPropertiesResource);
} else { }
else {
return null; return null;
} }
factory.setProperties(properties); factory.setProperties(properties);
@ -58,6 +77,9 @@ public class ScmGitPropertiesInfoProvider implements InfoProvider {
} }
/**
* Git info.
*/
public static class GitInfo { public static class GitInfo {
private String branch; private String branch;
@ -76,6 +98,9 @@ public class ScmGitPropertiesInfoProvider implements InfoProvider {
return this.commit; return this.commit;
} }
/**
* Commit information.
*/
public static class Commit { public static class Commit {
private String id; private String id;

@ -37,7 +37,6 @@ import org.springframework.boot.actuate.endpoint.RequestMappingEndpoint;
import org.springframework.boot.actuate.endpoint.ShutdownEndpoint; import org.springframework.boot.actuate.endpoint.ShutdownEndpoint;
import org.springframework.boot.actuate.endpoint.TraceEndpoint; import org.springframework.boot.actuate.endpoint.TraceEndpoint;
import org.springframework.boot.actuate.health.Health; 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.actuate.metrics.Metric;
import org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport; import org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport;
import org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration; import org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration;
@ -61,7 +60,6 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Stephane Nicoll * @author Stephane Nicoll
* @author Eddú Meléndez * @author Eddú Meléndez
* @author Meang Akira Tanaka * @author Meang Akira Tanaka
*
*/ */
public class EndpointAutoConfigurationTests { public class EndpointAutoConfigurationTests {

@ -16,12 +16,10 @@
package org.springframework.boot.actuate.endpoint; package org.springframework.boot.actuate.endpoint;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
import java.util.Map; import java.util.Map;
import org.junit.Test; import org.junit.Test;
import org.springframework.boot.actuate.info.Info; import org.springframework.boot.actuate.info.Info;
import org.springframework.boot.actuate.info.InfoProvider; import org.springframework.boot.actuate.info.InfoProvider;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
@ -45,15 +43,8 @@ public class InfoEndpointTests extends AbstractEndpointTests<InfoEndpoint> {
@Test @Test
public void invoke() throws Exception { public void invoke() throws Exception {
Info actual = ((Info) getEndpointBean().invoke().get("environment")); Info actual = getEndpointBean().invoke().get("environment");
assertThat(actual.get("key1"), equalTo((Object) "value1")); assertThat(actual.get("key1")).isEqualTo("value1");
}
@Test
public void invoke_HasProvider_GetProviderInfo() throws Exception {
@SuppressWarnings("unchecked")
Map<String, Object> actual = ((Map<String, Object>) getEndpointBean().invoke().get("infoProvider"));
assertThat(actual.get("key1"), equalTo((Object) "value1"));
} }
@Configuration @Configuration

@ -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; package org.springframework.boot.actuate.endpoint.mvc;
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;
import java.util.Map; import java.util.Map;
@ -11,6 +22,7 @@ import org.elasticsearch.common.collect.Maps;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.autoconfigure.EndpointWebMvcAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.EndpointWebMvcAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.ManagementServerPropertiesAutoConfiguration; 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.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext; 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} * Tests for {@link InfoMvcEndpointTests}
* *
* @author Meang Akira Tanaka * @author Meang Akira Tanaka
*/ */
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = { TestConfiguration.class }) @SpringApplicationConfiguration(classes = {TestConfiguration.class})
@WebAppConfiguration @WebAppConfiguration
@TestPropertySource(properties = {"info.app.name=MyService"}) @TestPropertySource(properties = {"info.app.name=MyService"})
public class InfoMvcEndpointTests { public class InfoMvcEndpointTests {
@ -57,14 +74,16 @@ public class InfoMvcEndpointTests {
@Test @Test
public void home() throws Exception { public void home() throws Exception {
this.mvc.perform(get("/info")).andExpect(status().isOk()) 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, @Import({JacksonAutoConfiguration.class,
HttpMessageConvertersAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class,
EndpointWebMvcAutoConfiguration.class, EndpointWebMvcAutoConfiguration.class,
WebMvcAutoConfiguration.class, WebMvcAutoConfiguration.class,
ManagementServerPropertiesAutoConfiguration.class }) ManagementServerPropertiesAutoConfiguration.class})
@Configuration @Configuration
public static class TestConfiguration { public static class TestConfiguration {
@ -86,7 +105,7 @@ public class InfoMvcEndpointTests {
return "beanName1"; return "beanName1";
} }
}; };
infoProviders.put("beanName1", infoProvider1); this.infoProviders.put("beanName1", infoProvider1);
InfoProvider infoProvider2 = new InfoProvider() { InfoProvider infoProvider2 = new InfoProvider() {
@ -103,12 +122,12 @@ public class InfoMvcEndpointTests {
return "beanName2"; return "beanName2";
} }
}; };
infoProviders.put("beanName2", infoProvider2); this.infoProviders.put("beanName2", infoProvider2);
} }
@Bean @Bean
public InfoEndpoint endpoint() { public InfoEndpoint endpoint() {
return new InfoEndpoint(infoProviders); return new InfoEndpoint(this.infoProviders);
} }
} }

@ -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; package org.springframework.boot.actuate.endpoint.mvc;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.elasticsearch.common.collect.Maps; import org.elasticsearch.common.collect.Maps;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.autoconfigure.EndpointWebMvcAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.EndpointWebMvcAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.ManagementServerPropertiesAutoConfiguration; 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.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext; 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} * Tests for {@link InfoMvcEndpointWithoutAnyInfoProvidersTests}
* *
* @author Meang Akira Tanaka * @author Meang Akira Tanaka
*/ */
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = { TestConfiguration.class }) @SpringApplicationConfiguration(classes = {TestConfiguration.class})
@WebAppConfiguration @WebAppConfiguration
public class InfoMvcEndpointWithoutAnyInfoProvidersTests { public class InfoMvcEndpointWithoutAnyInfoProvidersTests {
@Autowired @Autowired
@ -55,11 +71,11 @@ public class InfoMvcEndpointWithoutAnyInfoProvidersTests {
this.mvc.perform(get("/info")).andExpect(status().isOk()); this.mvc.perform(get("/info")).andExpect(status().isOk());
} }
@Import({ JacksonAutoConfiguration.class, @Import({JacksonAutoConfiguration.class,
HttpMessageConvertersAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class,
EndpointWebMvcAutoConfiguration.class, EndpointWebMvcAutoConfiguration.class,
WebMvcAutoConfiguration.class, WebMvcAutoConfiguration.class,
ManagementServerPropertiesAutoConfiguration.class }) ManagementServerPropertiesAutoConfiguration.class})
@Configuration @Configuration
public static class TestConfiguration { public static class TestConfiguration {
@ -67,7 +83,7 @@ public class InfoMvcEndpointWithoutAnyInfoProvidersTests {
@Bean @Bean
public InfoEndpoint endpoint() { public InfoEndpoint endpoint() {
return new InfoEndpoint(infoProviders); return new InfoEndpoint(this.infoProviders);
} }
} }

@ -1,17 +1,32 @@
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; package org.springframework.boot.actuate.info;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import java.util.Properties; import java.util.Properties;
import org.junit.Test; import org.junit.Test;
import org.springframework.core.env.PropertiesPropertySource; import org.springframework.core.env.PropertiesPropertySource;
import org.springframework.core.env.PropertySource; import org.springframework.core.env.PropertySource;
import org.springframework.core.env.StandardEnvironment; import org.springframework.core.env.StandardEnvironment;
public class EnvironmentInfoProviderTest { import static org.assertj.core.api.Assertions.assertThat;
public class EnvironmentInfoProviderTests {
@Test @Test
public void provide_HasTwoRelevantEntries_ShowOnlyRelevantEntries() throws Exception { public void provide_HasTwoRelevantEntries_ShowOnlyRelevantEntries() throws Exception {
@ -31,9 +46,9 @@ public class EnvironmentInfoProviderTest {
EnvironmentInfoProvider environmentInfoProvider = new EnvironmentInfoProvider(environment); EnvironmentInfoProvider environmentInfoProvider = new EnvironmentInfoProvider(environment);
Info actual = environmentInfoProvider.provide(); Info actual = environmentInfoProvider.provide();
assertThat(actual.getDetails().size(), is(equalTo(2))); assertThat(actual.getDetails().size()).isEqualTo(2);
assertThat((String) actual.get("app"), is(equalTo(expectedAppName))); assertThat((String) actual.get("app")).isEqualTo(expectedAppName);
assertThat((String) actual.get("lang"), is(equalTo(expectedLanguage))); assertThat((String) actual.get("lang")).isEqualTo(expectedLanguage);
} }
@Test @Test
@ -49,7 +64,7 @@ public class EnvironmentInfoProviderTest {
EnvironmentInfoProvider environmentInfoProvider = new EnvironmentInfoProvider(environment); EnvironmentInfoProvider environmentInfoProvider = new EnvironmentInfoProvider(environment);
Info actual = environmentInfoProvider.provide(); Info actual = environmentInfoProvider.provide();
assertThat(actual.getDetails().size(), is(equalTo(0))); assertThat(actual.getDetails().size()).isEqualTo(0);
} }
@ -58,7 +73,7 @@ public class EnvironmentInfoProviderTest {
EnvironmentInfoProvider environmentInfoProvider = new EnvironmentInfoProvider(new StandardEnvironment()); EnvironmentInfoProvider environmentInfoProvider = new EnvironmentInfoProvider(new StandardEnvironment());
Info actual = environmentInfoProvider.provide(); Info actual = environmentInfoProvider.provide();
assertThat(actual.getDetails().size(), is(equalTo(0))); assertThat(actual.getDetails().size()).isEqualTo(0);
} }
} }

@ -1,19 +1,32 @@
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; package org.springframework.boot.actuate.info;
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;
import org.junit.Test; import org.junit.Test;
import org.springframework.boot.actuate.info.ScmGitPropertiesInfoProvider.GitInfo.Commit; import org.springframework.boot.actuate.info.ScmGitPropertiesInfoProvider.GitInfo.Commit;
import org.springframework.core.io.ByteArrayResource; import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.Resource; 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 @Test
@ -22,12 +35,12 @@ public class ScmGitPropertiesInfoProviderTest {
ScmGitPropertiesInfoProvider scmGitPropertiesInfoProvider = new ScmGitPropertiesInfoProvider(resource); ScmGitPropertiesInfoProvider scmGitPropertiesInfoProvider = new ScmGitPropertiesInfoProvider(resource);
Info actual = scmGitPropertiesInfoProvider.provide(); Info actual = scmGitPropertiesInfoProvider.provide();
assertThat(actual, is(not(nullValue()))); assertThat(actual).isNotNull();
assertThat((String) actual.get("branch"), is(nullValue())); assertThat((String) actual.get("branch")).isNull();
Commit actualCommit = (Commit) actual.get("commit"); Commit actualCommit = actual.get("commit");
assertThat(actualCommit, is(not(nullValue()))); assertThat(actualCommit).isNotNull();
assertThat(actualCommit.getId(), is(equalTo(""))); assertThat(actualCommit.getId()).isEqualTo("");
assertThat(actualCommit.getTime(), is(nullValue())); assertThat(actualCommit.getTime()).isNull();
} }
@Test @Test
@ -48,12 +61,12 @@ public class ScmGitPropertiesInfoProviderTest {
ScmGitPropertiesInfoProvider scmGitPropertiesInfoProvider = new ScmGitPropertiesInfoProvider(resource); ScmGitPropertiesInfoProvider scmGitPropertiesInfoProvider = new ScmGitPropertiesInfoProvider(resource);
Info actual = scmGitPropertiesInfoProvider.provide(); Info actual = scmGitPropertiesInfoProvider.provide();
assertThat(actual, is(not(nullValue()))); assertThat(actual).isNotNull();
assertThat((String) actual.get("branch"), is(equalTo("develop"))); assertThat((String) actual.get("branch")).isEqualTo("develop");
Commit actualCommit = (Commit) actual.get("commit"); Commit actualCommit = actual.get("commit");
assertThat(actualCommit, is(not(nullValue()))); assertThat(actualCommit).isNotNull();
assertThat(actualCommit.getId(), is(equalTo("e02a4f3"))); assertThat(actualCommit.getId()).isEqualTo("e02a4f3");
assertThat(actualCommit.getTime(), is(equalTo("2013-04-24T08:42:13+0100"))); assertThat(actualCommit.getTime()).isEqualTo("2013-04-24T08:42:13+0100");
} }
@ -74,25 +87,22 @@ public class ScmGitPropertiesInfoProviderTest {
ScmGitPropertiesInfoProvider scmGitPropertiesInfoProvider = new ScmGitPropertiesInfoProvider(resource); ScmGitPropertiesInfoProvider scmGitPropertiesInfoProvider = new ScmGitPropertiesInfoProvider(resource);
Info actual = scmGitPropertiesInfoProvider.provide(); Info actual = scmGitPropertiesInfoProvider.provide();
assertThat(actual, is(not(nullValue()))); assertThat(actual).isNotNull();
assertThat((String) actual.get("branch"), is(equalTo("develop"))); assertThat((String) actual.get("branch")).isEqualTo("develop");
Commit actualCommit = (Commit) actual.get("commit"); Commit actualCommit = (Commit) actual.get("commit");
assertThat(actualCommit, is(not(nullValue()))); assertThat(actualCommit).isNotNull();
assertThat(actualCommit.getId(), is(equalTo("e02a4f3"))); assertThat(actualCommit.getId()).isEqualTo("e02a4f3");
assertThat(actualCommit.getTime(), is(nullValue())); assertThat(actualCommit.getTime()).isNull();
} }
@Test @Test
public void provide_DoesNotExists_NullReturned() throws Exception { public void provide_DoesNotExists_NullReturned() throws Exception {
Resource resource = mock(Resource.class); Resource resource = mock(Resource.class);
when(resource.exists()) given(resource.exists()).willReturn(false);
.thenReturn(false);
ScmGitPropertiesInfoProvider scmGitPropertiesInfoProvider = new ScmGitPropertiesInfoProvider(resource); ScmGitPropertiesInfoProvider scmGitPropertiesInfoProvider = new ScmGitPropertiesInfoProvider(resource);
Info actual = scmGitPropertiesInfoProvider.provide(); Info actual = scmGitPropertiesInfoProvider.provide();
assertThat(actual, is(nullValue())); assertThat(actual).isNull();
} }
} }
Loading…
Cancel
Save