Added HelloResource with /api/hello endpoint

This commit is contained in:
Julia Lassig 2025-04-29 14:23:56 -06:00
parent 0c88f916db
commit 7056330899
2 changed files with 49 additions and 0 deletions

View file

@ -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!";
}
}

View file

@ -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!"));
}
}