From 583af60854ca26e878ee3f47405fe37f228b04e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=98=B8=EC=84=B1?= <68679792+HoSeong0731@users.noreply.github.com> Date: Wed, 8 Jul 2026 10:50:13 +0900 Subject: [PATCH] feat(be): add health check endpoint --- .../demo/controller/HealthController.java | 13 ++++++++ .../demo/controller/HealthControllerTest.java | 31 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 src/main/java/com/example/demo/controller/HealthController.java create mode 100644 src/test/java/com/example/demo/controller/HealthControllerTest.java 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