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.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 {

@ -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);
}
}

@ -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<Info> {
@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);
}
}

@ -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<String, Object> 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<String, Object> extractInfoFromEnvironment() throws Exception {

@ -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<String, Object> details = new HashMap<String, Object>();
private final Map<String, Object> details = new HashMap<String, Object>();
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> T get(String infoId) {
return (T) this.details.get(infoId);
}
@Override
public boolean equals(Object obj) {
if (obj == this) {

@ -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();

@ -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<GitInfo> factory = new PropertiesConfigurationFactory<GitInfo>(
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;

@ -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 {

@ -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<InfoEndpoint> {
@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<String, Object> actual = ((Map<String, Object>) getEndpointBean().invoke().get("infoProvider"));
assertThat(actual.get("key1"), equalTo((Object) "value1"));
Info actual = getEndpointBean().invoke().get("environment");
assertThat(actual.get("key1")).isEqualTo("value1");
}
@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;
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);
}
}
}

@ -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);
}
}
}

@ -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);
}
}

@ -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();
}
}
Loading…
Cancel
Save