Skip to content

Commit

Permalink
feat: ADORSYS-GIS#63 implement health endpoint (ADORSYS-GIS#79)
Browse files Browse the repository at this point in the history
* feat: configure the health and metrics endpoints

* feat: implement unit test for the health endpoint

* Update pom.xml

* updated: pom.xml file

* fix: remove unneccessary file

* Update PowerPayBackendHealthTest.java

Fix failing test

* Add test case for handling server failures in health endpoint

* fix test

---------

Co-authored-by: mbunwe-victor <[email protected]>
Co-authored-by: chendi <[email protected]>
  • Loading branch information
3 people committed Mar 19, 2024
1 parent 68087a2 commit f67af3c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
5 changes: 5 additions & 0 deletions power-pay-backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@
<artifactId>postgresql</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.adorsys.gis.powerpay.powerpaybackend;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;

@SpringBootTest
@AutoConfigureMockMvc
@ContextConfiguration(classes = { PowerPayBackendApplication.class })
class PowerPayBackendHealthTest {

@Autowired
private MockMvc mockMvc;

@Test
void healthEndpointTest() throws Exception {
mockMvc.perform(MockMvcRequestBuilders.get("/actuator/health"))
.andExpect(result -> {
if (result.getResponse().getStatus() == 200) {
MockMvcResultMatchers.status().isOk().match(result);
MockMvcResultMatchers.jsonPath("$.status").value("UP").match(result);
} else if (result.getResponse().getStatus() >= 500) {
MockMvcResultMatchers.status().is5xxServerError().match(result);
MockMvcResultMatchers.jsonPath("$.status").doesNotExist().match(result);
}
});
}
}

0 comments on commit f67af3c

Please sign in to comment.