From bf83f6d1767337a8d77ba4526d553ad729d17cee Mon Sep 17 00:00:00 2001 From: merxgrc Date: Fri, 5 Sep 2025 21:44:13 -0700 Subject: [PATCH] feat(controller): add ItemController class with GET /items endpoint and ItemController test --- .../inventory/InventoryApiApplication.java | 1 + .../com/mrxgrc/inventory/ItemController.java | 13 ++++++++++ .../InventoryApiApplicationTests.java | 1 + .../mrxgrc/inventory/ItemControllerTest.java | 26 +++++++++++++++++++ 4 files changed, 41 insertions(+) create mode 100644 src/main/java/com/mrxgrc/inventory/ItemController.java create mode 100644 src/test/java/com/mrxgrc/inventory/ItemControllerTest.java diff --git a/src/main/java/com/mrxgrc/inventory/InventoryApiApplication.java b/src/main/java/com/mrxgrc/inventory/InventoryApiApplication.java index 1577824..032d629 100644 --- a/src/main/java/com/mrxgrc/inventory/InventoryApiApplication.java +++ b/src/main/java/com/mrxgrc/inventory/InventoryApiApplication.java @@ -1,3 +1,4 @@ +// Main entry point of the application package com.mrxgrc.inventory; import org.springframework.boot.SpringApplication; diff --git a/src/main/java/com/mrxgrc/inventory/ItemController.java b/src/main/java/com/mrxgrc/inventory/ItemController.java new file mode 100644 index 0000000..c1a8af1 --- /dev/null +++ b/src/main/java/com/mrxgrc/inventory/ItemController.java @@ -0,0 +1,13 @@ +package com.mrxgrc.inventory; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class ItemController { + + @GetMapping("/items") + public String getItems() { + return "List of items"; + } +} diff --git a/src/test/java/com/mrxgrc/inventory/InventoryApiApplicationTests.java b/src/test/java/com/mrxgrc/inventory/InventoryApiApplicationTests.java index eac497d..b20ca83 100644 --- a/src/test/java/com/mrxgrc/inventory/InventoryApiApplicationTests.java +++ b/src/test/java/com/mrxgrc/inventory/InventoryApiApplicationTests.java @@ -1,3 +1,4 @@ +// Generated by the protocol buffer compiler to check spring application context starts without errors. package com.mrxgrc.inventory; import org.junit.jupiter.api.Test; diff --git a/src/test/java/com/mrxgrc/inventory/ItemControllerTest.java b/src/test/java/com/mrxgrc/inventory/ItemControllerTest.java new file mode 100644 index 0000000..1ac4b05 --- /dev/null +++ b/src/test/java/com/mrxgrc/inventory/ItemControllerTest.java @@ -0,0 +1,26 @@ +package com.mrxgrc.inventory; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +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.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +@WebMvcTest(ItemController.class) +public class ItemControllerTest { + + @Autowired + private MockMvc mockMvc; + + @Test + void getItemsReturnsListofItems() throws Exception{ + this.mockMvc.perform(get("/items")) + .andExpect(status().isOk()) + .andExpect(content().string("List of items")); + + + } +}