From b00e95377de83a7505f9126d95e824b3f8bff861 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=A4=80=EC=97=B0?= <132131162+GJYeon@users.noreply.github.com> Date: Wed, 8 Jul 2026 11:28:25 +0900 Subject: [PATCH] feat(be): add health check endpoint and unit test --- .../com/example/coreTest/GeneratedCode.java | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/main/java/com/example/coreTest/GeneratedCode.java diff --git a/src/main/java/com/example/coreTest/GeneratedCode.java b/src/main/java/com/example/coreTest/GeneratedCode.java new file mode 100644 index 0000000..2737900 --- /dev/null +++ b/src/main/java/com/example/coreTest/GeneratedCode.java @@ -0,0 +1,61 @@ +package com.example.demo.controller; + +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/api") +public class HealthCheckController { + + @GetMapping("/health") + public ResponseEntity healthCheck() { + return ResponseEntity.ok(new HealthStatus("UP")); + } + + public static class HealthStatus { + private String status; + + public HealthStatus(String status) { + this.status = status; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + } +} + +package com.example.demo.controller; + +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.http.MediaType; +import org.springframework.test.web.servlet.MockMvc; + +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; + +@SpringBootTest +@AutoConfigureMockMvc +public class HealthCheckControllerTest { + + @Autowired + private MockMvc mockMvc; + + @Test + public void healthCheck_ShouldReturnStatusUP() throws Exception { + mockMvc.perform(get("/api/health") + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(content().json("{\"status\":\"UP\"}")); + } +} \ No newline at end of file