Refactor CommitId examples

This commit is contained in:
Grzegorz Piwowarek 2016-08-15 11:33:21 +02:00
parent d7551dd761
commit ad9986874f
3 changed files with 16 additions and 8 deletions

View File

@ -4,7 +4,7 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.PropertySource; import org.springframework.context.annotation.PropertySource;
@PropertySource("classpath:/git.properties") @PropertySource(value = "classpath:/git.properties", ignoreResourceNotFound = true)
@SpringBootApplication(scanBasePackages = { "com.baeldung.git"}) @SpringBootApplication(scanBasePackages = { "com.baeldung.git"})
public class CommitIdApplication { public class CommitIdApplication {
public static void main(String[] args) { public static void main(String[] args) {

View File

@ -27,3 +27,5 @@ info.app.version=1.0.0
security.user.name=admin1 security.user.name=admin1
security.user.password=secret1 security.user.password=secret1
management.security.role=SUPERUSER management.security.role=SUPERUSER
logging.level.org.springframework=INFO

View File

@ -2,6 +2,8 @@ package com.baeldung.git;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
@ -12,27 +14,31 @@ import static org.assertj.core.api.Assertions.assertThat;
@ContextConfiguration(classes = CommitIdApplication.class) @ContextConfiguration(classes = CommitIdApplication.class)
public class CommitIdTest { public class CommitIdTest {
private static final String UNKNOWN_STATUS = "UNKNOWN"; private static final Logger LOG = LoggerFactory.getLogger(CommitIdTest.class);
@Value("${git.commit.message.short:#{'UNKNOWN'}}") @Value("${git.commit.message.short:#{'UNKNOWN'}}")
private String commitMessage; private String commitMessage;
@Value("${git.branch:#{'UNKNOWN'}") @Value("${git.branch:#{'UNKNOWN'}}")
private String branch; private String branch;
@Value("${git.commit.id:#{'UNKNOWN'}") @Value("${git.commit.id:#{'UNKNOWN'}}")
private String commitId; private String commitId;
@Test @Test
public void shouldInjectGitInfoProperties() throws Exception { public void shouldInjectGitInfoProperties() throws Exception {
LOG.info(commitId);
LOG.info(commitMessage);
LOG.info(branch);
assertThat(commitMessage) assertThat(commitMessage)
.isNotEqualTo(UNKNOWN_STATUS); .isNotEqualTo("UNKNOWN");
assertThat(branch) assertThat(branch)
.isNotEqualTo(UNKNOWN_STATUS); .isNotEqualTo("UNKNOWN");
assertThat(commitId) assertThat(commitId)
.isNotEqualTo(UNKNOWN_STATUS); .isNotEqualTo("UNKNOWN");
} }
} }