Skip to content
Snippets Groups Projects
Commit 9fbd2d19 authored by OZGCloud's avatar OZGCloud
Browse files

OZG-4717 Cleanup

parent 294a4d74
No related branches found
No related tags found
No related merge requests found
...@@ -14,13 +14,6 @@ ...@@ -14,13 +14,6 @@
<version>1.0.0-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
<name>Administration</name> <name>Administration</name>
<description>Administration Backend Project</description> <description>Administration Backend Project</description>
<properties>
<java.version>21</java.version>
<!--<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>-->
<build.number>x</build.number>
<build.url>no-url</build.url>
</properties>
<dependencies> <dependencies>
<!-- Spring --> <!-- Spring -->
<dependency> <dependency>
......
...@@ -7,10 +7,9 @@ import lombok.Getter; ...@@ -7,10 +7,9 @@ import lombok.Getter;
@Builder @Builder
@Getter @Getter
public class BasicAppInfo { class Root {
private String javaVersion; private String javaVersion;
private String buildVersion; private String buildVersion;
private Instant buildTime; private Instant buildTime;
private String buildNumber; private String buildNumber;
private String buildUrl;
} }
...@@ -4,28 +4,27 @@ import org.springframework.web.bind.annotation.GetMapping; ...@@ -4,28 +4,27 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import lombok.AllArgsConstructor; import lombok.RequiredArgsConstructor;
@RestController @RestController
@AllArgsConstructor @RequiredArgsConstructor
@RequestMapping(BasicAppInfoController.PATH) @RequestMapping(RootController.PATH)
public class BasicAppInfoController { public class RootController {
static final String PATH = "/api"; // NOSONAR static final String PATH = "/api"; // NOSONAR
private BasicAppInfoService basicAppInfoService; private final RootService rootService;
@GetMapping @GetMapping
public BasicAppInfo getInfo() { public Root getRoot() {
return buildInfo(); return buildRoot();
} }
private BasicAppInfo buildInfo() { private Root buildRoot() {
return BasicAppInfo.builder() return Root.builder()
.javaVersion(basicAppInfoService.getJavaVersion()) .javaVersion(rootService.getJavaVersion())
.buildTime(basicAppInfoService.getBuildTime()) .buildTime(rootService.getBuildTime())
.buildVersion(basicAppInfoService.getVersion()) .buildVersion(rootService.getVersion())
.buildNumber(basicAppInfoService.getBuildNumber()) .buildNumber(rootService.getBuildNumber())
.buildUrl(basicAppInfoService.getBuildUrl())
.build(); .build();
} }
......
...@@ -6,12 +6,12 @@ import java.util.Optional; ...@@ -6,12 +6,12 @@ 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;
import lombok.AllArgsConstructor; import lombok.RequiredArgsConstructor;
@Service @Service
@AllArgsConstructor @RequiredArgsConstructor
public class BasicAppInfoService { class RootService {
private Optional<BuildProperties> buildProperties; private final Optional<BuildProperties> buildProperties;
public String getVersion() { public String getVersion() {
return buildProperties.map(BuildProperties::getVersion).orElse("--"); return buildProperties.map(BuildProperties::getVersion).orElse("--");
......
...@@ -12,16 +12,19 @@ import org.junit.jupiter.api.BeforeEach; ...@@ -12,16 +12,19 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.Spy; import org.mockito.Spy;
import org.springframework.boot.test.context.SpringBootTest; import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.ResultActions; import org.springframework.test.web.servlet.ResultActions;
import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.test.web.servlet.setup.MockMvcBuilders;
@SpringBootTest import lombok.SneakyThrows;
class BasicAppInfoControllerTest {
@ExtendWith(MockitoExtension.class)
class RootControllerTest {
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";
...@@ -30,64 +33,65 @@ class BasicAppInfoControllerTest { ...@@ -30,64 +33,65 @@ class BasicAppInfoControllerTest {
@Spy @Spy
@InjectMocks @InjectMocks
private BasicAppInfoController basicAppInfoController; private RootController rootController;
@Mock @Mock
private BasicAppInfoService basicAppInfoService; private RootService rootService;
private MockMvc mockMvc; private MockMvc mockMvc;
@BeforeEach @BeforeEach
void mock() { void mock() {
mockMvc = MockMvcBuilders.standaloneSetup(basicAppInfoController).build(); mockMvc = MockMvcBuilders.standaloneSetup(rootController).build();
} }
@DisplayName("Basic info") @DisplayName("Root")
@Nested @Nested
class TestInfo { class TestInfo {
@Test @Test
void shouldHaveJavaVersion() throws Exception { @SneakyThrows
when(basicAppInfoService.getJavaVersion()).thenReturn(javaVersion); void shouldHaveJavaVersion() {
when(rootService.getJavaVersion()).thenReturn(javaVersion);
doRequest()
.andExpect(jsonPath("$.javaVersion").value(javaVersion));
}
@Test ResultActions result = doRequest();
void shouldHaveVersion() throws Exception {
when(basicAppInfoService.getVersion()).thenReturn(buildVersion);
doRequest() result.andExpect(jsonPath("$.javaVersion").value(javaVersion));
.andExpect(jsonPath("$.buildVersion").value(buildVersion));
} }
@Test @Test
void shouldHaveBuildTime() throws Exception { @SneakyThrows
when(basicAppInfoService.getBuildTime()).thenReturn(sampleTime); void shouldHaveVersion() {
when(rootService.getVersion()).thenReturn(buildVersion);
doRequest() ResultActions result = doRequest();
.andExpect(jsonPath("$.buildTime").value(sampleTime.getEpochSecond()));
result.andExpect(jsonPath("$.buildVersion").value(buildVersion));
} }
@Test @Test
void shouldHaveBuildNumber() throws Exception { @SneakyThrows
when(basicAppInfoService.getBuildNumber()).thenReturn(buildNumber); void shouldHaveBuildTime() {
when(rootService.getBuildTime()).thenReturn(sampleTime);
ResultActions result = doRequest();
doRequest() result.andExpect(jsonPath("$.buildTime").value(sampleTime.getEpochSecond()));
.andExpect(jsonPath("$.buildNumber").value(buildNumber));
} }
@Test @Test
void shouldHaveBuildUrl() throws Exception { @SneakyThrows
when(basicAppInfoService.getBuildUrl()).thenReturn(buildUrl); void shouldHaveBuildNumber() {
when(rootService.getBuildNumber()).thenReturn(buildNumber);
ResultActions result = doRequest();
doRequest() result.andExpect(jsonPath("$.buildNumber").value(buildNumber));
.andExpect(jsonPath("$.buildUrl").value(buildUrl));
} }
private ResultActions doRequest() throws Exception { @SneakyThrows
return mockMvc.perform(get(BasicAppInfoController.PATH)).andExpect(status().isOk()); private ResultActions doRequest() {
return mockMvc.perform(get(RootController.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