Skip to content

Commit 408ecfb

Browse files
Complete DemoController.java with /hello endpoint and add unit tests
Co-authored-by: ffilardi-insight <112668809+ffilardi-insight@users.noreply.github.com>
1 parent 296e4a0 commit 408ecfb

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

copilot-demo/src/main/java/com/microsoft/hackathon/copilotdemo/controller/DemoController.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,14 @@
1010
* If the key is passed, return "hello <key>".
1111
*
1212
*/
13+
@RestController
14+
public class DemoController {
15+
16+
@GetMapping("/hello")
17+
public String hello(@RequestParam(required = false) String key) {
18+
if (key == null) {
19+
return "key not passed";
20+
}
21+
return "hello " + key;
22+
}
23+
}

copilot-demo/src/test/java/com/microsoft/hackathon/copilotdemo/CopilotDemoApplicationTests.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,19 @@ class CopilotDemoApplicationTests {
1616
private MockMvc mockMvc;
1717

1818
// Create a test to check if the /hello GET operation that accepts key as query parameter and returns "hello <key>" is working correctly.
19+
@Test
20+
void testHelloWithKey() throws Exception {
21+
mockMvc.perform(MockMvcRequestBuilders.get("/hello").param("key", "world"))
22+
.andExpect(MockMvcResultMatchers.status().isOk())
23+
.andExpect(MockMvcResultMatchers.content().string("hello world"));
24+
}
25+
26+
// Create a test to check if the /hello GET operation returns "key not passed" when no key is provided
27+
@Test
28+
void testHelloWithoutKey() throws Exception {
29+
mockMvc.perform(MockMvcRequestBuilders.get("/hello"))
30+
.andExpect(MockMvcResultMatchers.status().isOk())
31+
.andExpect(MockMvcResultMatchers.content().string("key not passed"));
32+
}
1933

2034
}

0 commit comments

Comments
 (0)