From 183f46e28c7960cbd24077c84226ee4a847b85b5 Mon Sep 17 00:00:00 2001 From: Sahil Mansoori Date: Sun, 26 Oct 2025 22:27:14 +0530 Subject: [PATCH 1/3] Added Java 21 setup and run instructions in README --- readme.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/readme.md b/readme.md index 15fcd7c85..0d4b86618 100644 --- a/readme.md +++ b/readme.md @@ -19,6 +19,12 @@ The [spring-petclinic-angular project](https://github.com/spring-petclinic/sprin ## Running Petclinic locally ### With Maven command line +### 🧩 Running PetClinic on Java 21 + +This project also runs smoothly on **Java 21** (tested on JDK 21.0.5). +If you're using Java 21, follow these steps to ensure a clean setup: + +1. **Clone the repository** ```sh git clone https://github.com/spring-petclinic/spring-petclinic-rest.git cd spring-petclinic-rest From 6f3bca2d883541d084ba53256cb2bb3e27c30ef6 Mon Sep 17 00:00:00 2001 From: Sahil Mansoori Date: Sun, 26 Oct 2025 22:27:32 +0530 Subject: [PATCH 2/3] Add HealthController with /api/health endpoint for basic service status --- .../rest/controller/HealthController.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/main/java/org/springframework/samples/petclinic/rest/controller/HealthController.java diff --git a/src/main/java/org/springframework/samples/petclinic/rest/controller/HealthController.java b/src/main/java/org/springframework/samples/petclinic/rest/controller/HealthController.java new file mode 100644 index 000000000..1555709a4 --- /dev/null +++ b/src/main/java/org/springframework/samples/petclinic/rest/controller/HealthController.java @@ -0,0 +1,14 @@ +package org.springframework.samples.petclinic.rest.controller; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; +import java.util.Map; + +@RestController +public class HealthController { + + @GetMapping("/api/health") + public Map healthCheck() { + return Map.of("status", "ok"); + } +} From dea788fc1d3406610bc06ef580904a45eeb2008e Mon Sep 17 00:00:00 2001 From: Sahil Mansoori Date: Sun, 26 Oct 2025 23:25:51 +0530 Subject: [PATCH 3/3] test: add HealthControllerTest to verify /api/health endpoint returns status OK --- .../controller/HealthControllerTests.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/test/java/org/springframework/samples/petclinic/rest/controller/HealthControllerTests.java diff --git a/src/test/java/org/springframework/samples/petclinic/rest/controller/HealthControllerTests.java b/src/test/java/org/springframework/samples/petclinic/rest/controller/HealthControllerTests.java new file mode 100644 index 000000000..45ad9a9a2 --- /dev/null +++ b/src/test/java/org/springframework/samples/petclinic/rest/controller/HealthControllerTests.java @@ -0,0 +1,28 @@ +package org.springframework.samples.petclinic.rest.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.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.security.test.context.support.WithMockUser; +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.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +@WebMvcTest(HealthController.class) +@AutoConfigureMockMvc(addFilters = false) +class HealthControllerTests { + + @Autowired + private MockMvc mockMvc; + + @Test + @WithMockUser + void healthShouldReturnOk() throws Exception { + mockMvc.perform(get("/api/health")) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.status").value("ok")); + } +}