diff --git a/src/main/java/org/springframework/samples/petclinic/owner/HelloResource.java b/src/main/java/org/springframework/samples/petclinic/owner/HelloResource.java new file mode 100644 index 000000000..73f5b2fc6 --- /dev/null +++ b/src/main/java/org/springframework/samples/petclinic/owner/HelloResource.java @@ -0,0 +1,21 @@ +package org.springframework.samples.petclinic.owner; + +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 HelloResource { + + @GetMapping("/hello") + public String sayHello() { + return "Hello from Copilot!"; + } + + @GetMapping("/greet") + public String greetUser() { + return "Greetings from Copilot!"; + } + +} diff --git a/src/test/java/org/springframework/samples/petclinic/owner/HelloResourceIT.java b/src/test/java/org/springframework/samples/petclinic/owner/HelloResourceIT.java new file mode 100644 index 000000000..b5577c391 --- /dev/null +++ b/src/test/java/org/springframework/samples/petclinic/owner/HelloResourceIT.java @@ -0,0 +1,28 @@ +package org.springframework.samples.petclinic.owner; + +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.boot.test.context.SpringBootTest; +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 HelloResourceIT { + + @Autowired + private MockMvc mockMvc; + + @Test + public void testSayHello() throws Exception { + mockMvc.perform(get("/api/hello")) + .andExpect(status().isOk()) + .andExpect(content().string("Hello from Copilot!")); + } +} +