Skip to content
Snippets Groups Projects
Commit 5ff6660f authored by Jan Zickermann's avatar Jan Zickermann
Browse files

OZG-4717 Read build number and url from props

parent 419526af
Branches
Tags
No related merge requests found
...@@ -11,4 +11,6 @@ public class BasicAppInfo { ...@@ -11,4 +11,6 @@ public class BasicAppInfo {
private String javaVersion; private String javaVersion;
private String buildVersion; private String buildVersion;
private Instant buildTime; private Instant buildTime;
private String buildNumber;
private String buildUrl;
} }
...@@ -24,6 +24,8 @@ public class BasicAppInfoController { ...@@ -24,6 +24,8 @@ public class BasicAppInfoController {
.javaVersion(basicAppInfoService.getJavaVersion()) .javaVersion(basicAppInfoService.getJavaVersion())
.buildTime(basicAppInfoService.getBuildTime()) .buildTime(basicAppInfoService.getBuildTime())
.buildVersion(basicAppInfoService.getVersion()) .buildVersion(basicAppInfoService.getVersion())
.buildNumber(basicAppInfoService.getBuildNumber())
.buildUrl(basicAppInfoService.getBuildUrl())
.build(); .build();
} }
......
package de.ozgcloud.einstellung; package de.ozgcloud.einstellung;
import java.time.Instant; import java.time.Instant;
import java.util.Objects; import java.util.Optional;
import org.springframework.boot.info.BuildProperties; import org.springframework.boot.info.BuildProperties;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -11,17 +11,25 @@ import lombok.AllArgsConstructor; ...@@ -11,17 +11,25 @@ import lombok.AllArgsConstructor;
@Service @Service
@AllArgsConstructor @AllArgsConstructor
public class BasicAppInfoService { public class BasicAppInfoService {
private BuildProperties buildProperties; private Optional<BuildProperties> buildProperties;
public String getVersion() { public String getVersion() {
return Objects.isNull(buildProperties) ? "--" : buildProperties.getVersion(); return buildProperties.map(BuildProperties::getVersion).orElse("--");
} }
public Instant getBuildTime() { public Instant getBuildTime() {
return Objects.isNull(buildProperties) ? null : buildProperties.getTime(); return buildProperties.map(BuildProperties::getTime).orElse(Instant.now());
} }
public String getJavaVersion() { public String getJavaVersion() {
return System.getProperty("java.version"); return System.getProperty("java.version", "?");
}
public String getBuildNumber() {
return buildProperties.map(p -> p.get("BUILD_NUMBER")).orElse("?");
}
public String getBuildUrl() {
return buildProperties.map(p -> p.get("BUILD_URL")).orElse("?");
} }
} }
...@@ -25,6 +25,9 @@ class BasicAppInfoControllerTest { ...@@ -25,6 +25,9 @@ class BasicAppInfoControllerTest {
final Instant sampleTime = LocalDateTime.parse("2021-04-01T10:30").toInstant(ZoneOffset.UTC); final Instant sampleTime = LocalDateTime.parse("2021-04-01T10:30").toInstant(ZoneOffset.UTC);
final String javaVersion = "1"; final String javaVersion = "1";
final String buildVersion = "2"; final String buildVersion = "2";
final String buildNumber = "3";
final String buildUrl = "url://test";
@Spy @Spy
@InjectMocks @InjectMocks
private BasicAppInfoController basicAppInfoController; private BasicAppInfoController basicAppInfoController;
...@@ -66,10 +69,22 @@ class BasicAppInfoControllerTest { ...@@ -66,10 +69,22 @@ class BasicAppInfoControllerTest {
doRequest() doRequest()
.andExpect(jsonPath("$.buildTime").value(sampleTime.getEpochSecond())); .andExpect(jsonPath("$.buildTime").value(sampleTime.getEpochSecond()));
} }
// ToDo: Implement build number
// @Test @Test
// void shouldHaveBuildNumber() throws Exception { void shouldHaveBuildNumber() throws Exception {
// } when(basicAppInfoService.getBuildNumber()).thenReturn(buildNumber);
doRequest()
.andExpect(jsonPath("$.buildNumber").value(buildNumber));
}
@Test
void shouldHaveBuildUrl() throws Exception {
when(basicAppInfoService.getBuildUrl()).thenReturn(buildUrl);
doRequest()
.andExpect(jsonPath("$.buildUrl").value(buildUrl));
}
private ResultActions doRequest() throws Exception { private ResultActions doRequest() throws Exception {
return mockMvc.perform(get(BasicAppInfoController.PATH)).andExpect(status().isOk()); return mockMvc.perform(get(BasicAppInfoController.PATH)).andExpect(status().isOk());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment