BAEL-15988 : Java file movement

This commit is contained in:
sampada
2020-02-11 10:52:06 +05:30
parent 403da2d4fb
commit e10bf38ad4
13 changed files with 0 additions and 2 deletions

View File

@@ -0,0 +1,23 @@
package com.baeldung.git;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.core.io.ClassPathResource;
@SpringBootApplication(scanBasePackages = { "com.baeldung.git" })
public class CommitIdApplication {
public static void main(String[] args) {
SpringApplication.run(CommitIdApplication.class, args);
}
@Bean
public static PropertySourcesPlaceholderConfigurer placeholderConfigurer() {
PropertySourcesPlaceholderConfigurer c = new PropertySourcesPlaceholderConfigurer();
c.setLocation(new ClassPathResource("git.properties"));
c.setIgnoreResourceNotFound(true);
c.setIgnoreUnresolvablePlaceholders(true);
return c;
}
}

View File

@@ -0,0 +1,30 @@
package com.baeldung.git;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.Map;
@RestController
public class CommitInfoController {
@Value("${git.commit.message.short}")
private String commitMessage;
@Value("${git.branch}")
private String branch;
@Value("${git.commit.id}")
private String commitId;
@GetMapping("/commitId")
public Map<String, String> getCommitId() {
Map<String, String> result = new HashMap<>();
result.put("Commit message", commitMessage);
result.put("Commit branch", branch);
result.put("Commit id", commitId);
return result;
}
}

View File

@@ -0,0 +1,43 @@
package com.baeldung.git;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = CommitIdApplication.class)
@TestPropertySource(properties = { "spring.jmx.default-domain=test" })
public class CommitIdIntegrationTest {
private static final Logger LOG = LoggerFactory.getLogger(CommitIdIntegrationTest.class);
@Value("${git.commit.message.short:UNKNOWN}")
private String commitMessage;
@Value("${git.branch:UNKNOWN}")
private String branch;
@Value("${git.commit.id:UNKNOWN}")
private String commitId;
@Test
public void whenInjecting_shouldDisplay() throws Exception {
LOG.info(commitId);
LOG.info(commitMessage);
LOG.info(branch);
assertThat(commitMessage).isNotEqualTo("UNKNOWN");
assertThat(branch).isNotEqualTo("UNKNOWN");
assertThat(commitId).isNotEqualTo("UNKNOWN");
}
}