diff --git a/src/main/java/com/example/demo/controller/HealthController.java b/src/main/java/com/example/demo/controller/HealthController.java new file mode 100644 index 0000000..21fffb7 --- /dev/null +++ b/src/main/java/com/example/demo/controller/HealthController.java @@ -0,0 +1,13 @@ +package com.example.demo.controller; + +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class HealthController { + @GetMapping("/api/health") + public ResponseEntity health() { + return ResponseEntity.ok().body("{\"status\":\"UP\"}"); + } +} \ No newline at end of file diff --git a/src/test/java/com/example/demo/controller/HealthControllerTest.java b/src/test/java/com/example/demo/controller/HealthControllerTest.java new file mode 100644 index 0000000..7a68883 --- /dev/null +++ b/src/test/java/com/example/demo/controller/HealthControllerTest.java @@ -0,0 +1,31 @@ +package com.example.demo.controller; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.web.servlet.MockMvc; + +@SpringBootTest +@AutoConfigureMockMvc +public class HealthControllerTest { + + @Autowired + private MockMvc mockMvc; + + @BeforeEach + public void setUp() throws Exception { + } + + @Test + public void testHealth() throws Exception { + mockMvc.perform(get("/api/health")) + .andExpect(status().isOk()) + .andExpect(content().json("{\"status\":\"UP\"}")); + } +} \ No newline at end of file