Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String, String> healthCheck() {
return Map.of("status", "ok");
}
}
Original file line number Diff line number Diff line change
@@ -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"));
}
}