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..84d364e --- /dev/null +++ b/src/main/java/com/example/coreTest/GeneratedCode.java @@ -0,0 +1,56 @@ +package com.example.coreTest.controller; + +import org.springframework.http.HttpStatus; +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 HealthController { + + @GetMapping("/health") + public ResponseEntity health() { + return new ResponseEntity<>(new HealthStatus("UP"), HttpStatus.OK); + } + + private static class HealthStatus { + private final String status; + + public HealthStatus(String status) { + this.status = status; + } + + public String getStatus() { + return status; + } + } +} + +package com.example.coreTest; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.http.MediaType; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.annotation.Autowired; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; +import org.springframework.test.web.servlet.result.MockMvcResultMatchers; + +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +@WebMvcTest(HealthController.class) +class HealthControllerTest { + + @Autowired + private MockMvc mockMvc; + + @Test + void health_ShouldReturnStatusUp() throws Exception { + mockMvc.perform(MockMvcRequestBuilders.get("/api/health") + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(MockMvcResultMatchers.jsonPath("$.status").value("UP")); + } +} \ No newline at end of file