mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-18 05:25:50 +00:00
Added HelloResource with /api/hello endpoint
This commit is contained in:
parent
0c88f916db
commit
7056330899
2 changed files with 49 additions and 0 deletions
|
@ -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!";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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!"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue