From ead29dbb7b5623c6136c42a519fb8f3435c75033 Mon Sep 17 00:00:00 2001 From: HeftyB Date: Sat, 19 Sep 2026 10:15:27 -0400 Subject: [PATCH 1/7] Remove isCool debug code from search Drops the isCool request parameter from SearchController, the System.out.println it triggered, and the "Cool Checkbox" in the search form that sent it. [Ticket: #16] Co-Authored-By: Claude Opus 5 --- .../java/com/heftyb/dms/controllers/SearchController.java | 5 ----- src/main/resources/templates/search.html | 4 ---- 2 files changed, 9 deletions(-) diff --git a/src/main/java/com/heftyb/dms/controllers/SearchController.java b/src/main/java/com/heftyb/dms/controllers/SearchController.java index 055a029..a5392ef 100644 --- a/src/main/java/com/heftyb/dms/controllers/SearchController.java +++ b/src/main/java/com/heftyb/dms/controllers/SearchController.java @@ -32,7 +32,6 @@ public SearchController(final VehicleService vehicleService, public String results(Principal principal, ModelMap map, @RequestParam(required = false) long custId, - @RequestParam(required = false) boolean isCool, @RequestParam(required = false) String fname, @RequestParam(required = false) String lname, @RequestParam(required = false) String phone, @@ -53,10 +52,6 @@ public String results(Principal principal, } } - if (isCool) { - System.out.println("You're Cool!"); - } - if (!fname.isEmpty() && !lname.isEmpty()) { List c = customerService.findByName(fname, lname); diff --git a/src/main/resources/templates/search.html b/src/main/resources/templates/search.html index 80e3d95..c096bb7 100644 --- a/src/main/resources/templates/search.html +++ b/src/main/resources/templates/search.html @@ -12,10 +12,6 @@

Search

-
- - -
From a959d9e8f48f6fc2103f79578ddb5e78ae0bea14 Mon Sep 17 00:00:00 2001 From: HeftyB Date: Sat, 19 Sep 2026 10:17:10 -0400 Subject: [PATCH 2/7] Add failing test for GET /search with no parameters custId is a primitive long bound to an optional request parameter, so Spring cannot represent its absence and a bare GET /search fails with IllegalStateException before the handler runs. [Ticket: #16] Co-Authored-By: Claude Opus 5 --- .../dms/controllers/SearchControllerTest.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/test/java/com/heftyb/dms/controllers/SearchControllerTest.java diff --git a/src/test/java/com/heftyb/dms/controllers/SearchControllerTest.java b/src/test/java/com/heftyb/dms/controllers/SearchControllerTest.java new file mode 100644 index 0000000..9c96ec8 --- /dev/null +++ b/src/test/java/com/heftyb/dms/controllers/SearchControllerTest.java @@ -0,0 +1,30 @@ +package com.heftyb.dms.controllers; + +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.context.SpringBootTest; +import org.springframework.security.test.context.support.WithMockUser; +import org.springframework.test.context.ActiveProfiles; +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.view; + +@SpringBootTest +@AutoConfigureMockMvc +@ActiveProfiles("test") +@WithMockUser +class SearchControllerTest { + + @Autowired + private MockMvc mvc; + + @Test + void searchWithNoParametersRendersEmptyResults() throws Exception { + mvc.perform(get("/search")) + .andExpect(status().isOk()) + .andExpect(view().name("results")); + } +} From f40ba967e53582c8dae6db387f836a7f50dc87a1 Mon Sep 17 00:00:00 2001 From: HeftyB Date: Sat, 19 Sep 2026 10:18:34 -0400 Subject: [PATCH 3/7] Fix parameter binding in SearchController Bind custId as a Long and check it for null before comparing, and give the optional String parameters a default of "" so the isEmpty() checks do not throw when a parameter is absent. A bare GET /search now renders the results page with no matches. [Ticket: #16] Co-Authored-By: Claude Opus 5 --- .../heftyb/dms/controllers/SearchController.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/heftyb/dms/controllers/SearchController.java b/src/main/java/com/heftyb/dms/controllers/SearchController.java index a5392ef..4d0e349 100644 --- a/src/main/java/com/heftyb/dms/controllers/SearchController.java +++ b/src/main/java/com/heftyb/dms/controllers/SearchController.java @@ -31,12 +31,12 @@ public SearchController(final VehicleService vehicleService, @GetMapping({"/", ""}) public String results(Principal principal, ModelMap map, - @RequestParam(required = false) long custId, - @RequestParam(required = false) String fname, - @RequestParam(required = false) String lname, - @RequestParam(required = false) String phone, - @RequestParam(required = false) String email, - @RequestParam(required = false) String vin, + @RequestParam(required = false) Long custId, + @RequestParam(required = false, defaultValue = "") String fname, + @RequestParam(required = false, defaultValue = "") String lname, + @RequestParam(required = false, defaultValue = "") String phone, + @RequestParam(required = false, defaultValue = "") String email, + @RequestParam(required = false, defaultValue = "") String vin, @RequestParam(required = false) boolean custSearch, @RequestParam(required = false) boolean vehicleSearch) { map.addAttribute("username", principal.getName()); @@ -44,7 +44,7 @@ public String results(Principal principal, List customers = new ArrayList<>(); List vehicles = new ArrayList<>(); - if (custId != 0) { + if (custId != null && custId != 0) { Customer c = customerService.findById(custId); if (custSearch) customers.add(c); if (vehicleSearch) { From 69cecb97c70f95b637fdc74e0f505345735792bc Mon Sep 17 00:00:00 2001 From: HeftyB Date: Sat, 19 Sep 2026 10:20:17 -0400 Subject: [PATCH 4/7] Remove routes to templates that do not exist - AdminController: remove GET /admin/create_employee, which rendered a missing employee_form template. Nothing links to it; the HR administrator page posts its employee form directly to POST /admin/create_employee, which is unchanged. - VehicleController: GET /vehicles/search works for a non-blank VIN; only its blank-VIN branch rendered a missing add_new_vehicle template. A blank search now redirects to the vehicle list. (The repair orders page's VIN search form targets this route with POST, which it does not accept; that is a separate, unchanged defect.) Every view name returned by a controller now has a template. [Ticket: #17] Co-Authored-By: Claude Opus 5 --- .../java/com/heftyb/dms/controllers/AdminController.java | 8 -------- .../dms/vehicles/controllers/VehicleController.java | 2 +- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/src/main/java/com/heftyb/dms/controllers/AdminController.java b/src/main/java/com/heftyb/dms/controllers/AdminController.java index a949757..2260b6a 100644 --- a/src/main/java/com/heftyb/dms/controllers/AdminController.java +++ b/src/main/java/com/heftyb/dms/controllers/AdminController.java @@ -12,7 +12,6 @@ import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; -import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; @@ -51,13 +50,6 @@ public String adminHome(HttpServletRequest request, Model model, Principal princ return "hr_administrator"; } - @GetMapping({"/create_employee", "/create_employee/"}) - public String create_employee_form(Principal principal, ModelMap map) { - map.addAttribute("username", principal.getName()); - - return "employee_form"; - } - @PostMapping({"/create_employee", "/create_employee/"}) public String create_employee(@Valid Employee employee) { diff --git a/src/main/java/com/heftyb/dms/vehicles/controllers/VehicleController.java b/src/main/java/com/heftyb/dms/vehicles/controllers/VehicleController.java index 0bf40e5..ab4b9f7 100644 --- a/src/main/java/com/heftyb/dms/vehicles/controllers/VehicleController.java +++ b/src/main/java/com/heftyb/dms/vehicles/controllers/VehicleController.java @@ -42,7 +42,7 @@ public String vehicle_details(Principal principal, ModelMap map, @RequestParam l public String vin_search(Principal principal, ModelMap map, @RequestParam String vin) { map.addAttribute("username", principal.getName()); if (vin.isBlank()) { - return "add_new_vehicle"; + return "redirect:/vehicles"; } List vehicles = vehicleService.findByVin(vin); From 9059cdd73dd77c1176ecd3589cd9630af2f61be8 Mon Sep 17 00:00:00 2001 From: HeftyB Date: Sun, 20 Sep 2026 20:20:32 -0400 Subject: [PATCH 5/7] Add failing test for the VIN search POST The shared vin-search fragment submits with POST, but GET /vehicles/search is the only mapping, so the VIN search on the repair orders page returns 405. The second test covers the blank-VIN redirect added earlier in this branch. [Ticket: #17] Co-Authored-By: Claude Opus 5 --- .../controllers/VehicleControllerTest.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/test/java/com/heftyb/dms/vehicles/controllers/VehicleControllerTest.java diff --git a/src/test/java/com/heftyb/dms/vehicles/controllers/VehicleControllerTest.java b/src/test/java/com/heftyb/dms/vehicles/controllers/VehicleControllerTest.java new file mode 100644 index 0000000..29b3a7c --- /dev/null +++ b/src/test/java/com/heftyb/dms/vehicles/controllers/VehicleControllerTest.java @@ -0,0 +1,39 @@ +package com.heftyb.dms.vehicles.controllers; + +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.context.SpringBootTest; +import org.springframework.security.test.context.support.WithMockUser; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.web.servlet.MockMvc; + +import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.redirectedUrl; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view; + +@SpringBootTest +@AutoConfigureMockMvc +@ActiveProfiles("test") +@WithMockUser +class VehicleControllerTest { + + @Autowired + private MockMvc mvc; + + @Test + void vinSearchAcceptsThePostTheFormSends() throws Exception { + mvc.perform(post("/vehicles/search").with(csrf()).param("vin", "JH4TB2H26CC000000")) + .andExpect(status().isOk()) + .andExpect(view().name("vehicles")); + } + + @Test + void blankVinSearchRedirectsToTheVehicleList() throws Exception { + mvc.perform(get("/vehicles/search").param("vin", "")) + .andExpect(redirectedUrl("/vehicles")); + } +} From ea8852b933852a44577c047b00cf2d9db53c81fb Mon Sep 17 00:00:00 2001 From: HeftyB Date: Sun, 20 Sep 2026 20:20:33 -0400 Subject: [PATCH 6/7] Accept POST on the VIN search route The vin-search fragment is shared with the customer page, where the same form posts to a route that creates a record, and its ADD NEW button reuses the form to post elsewhere. Switching the fragment to GET would break that, so the search route accepts both methods. [Ticket: #17] Co-Authored-By: Claude Opus 5 --- .../heftyb/dms/vehicles/controllers/VehicleController.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/heftyb/dms/vehicles/controllers/VehicleController.java b/src/main/java/com/heftyb/dms/vehicles/controllers/VehicleController.java index ab4b9f7..ecc99ea 100644 --- a/src/main/java/com/heftyb/dms/vehicles/controllers/VehicleController.java +++ b/src/main/java/com/heftyb/dms/vehicles/controllers/VehicleController.java @@ -7,6 +7,7 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import java.security.Principal; @@ -38,7 +39,8 @@ public String vehicle_details(Principal principal, ModelMap map, @RequestParam l return "vehicle_details"; } - @GetMapping({"/search", "/search/"}) + // The shared vin-search fragment submits with POST, so this accepts both methods. + @RequestMapping(value = {"/search", "/search/"}, method = {RequestMethod.GET, RequestMethod.POST}) public String vin_search(Principal principal, ModelMap map, @RequestParam String vin) { map.addAttribute("username", principal.getName()); if (vin.isBlank()) { From 47c09203411ece9090e9a409626bca69e49e539a Mon Sep 17 00:00:00 2001 From: HeftyB Date: Sun, 20 Sep 2026 20:48:23 -0400 Subject: [PATCH 7/7] Delete commented-out code in SearchController Five earlier versions of loops that the live code beside them replaced. [Ticket: #16] Co-Authored-By: Claude Opus 5 --- .../java/com/heftyb/dms/controllers/SearchController.java | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/main/java/com/heftyb/dms/controllers/SearchController.java b/src/main/java/com/heftyb/dms/controllers/SearchController.java index 4d0e349..661c448 100644 --- a/src/main/java/com/heftyb/dms/controllers/SearchController.java +++ b/src/main/java/com/heftyb/dms/controllers/SearchController.java @@ -57,7 +57,6 @@ public String results(Principal principal, if (custSearch) c.iterator().forEachRemaining(customers::add); if (vehicleSearch) { -// c.stream().map(cust -> cust.getVehicles().iterator().forEachRemaining(vehicles::add)); final List finalVehicles = vehicles; c.stream().forEach(cust -> { cust.getVehicles().iterator().forEachRemaining(finalVehicles::add); @@ -65,9 +64,6 @@ public String results(Principal principal, finalVehicles.iterator().forEachRemaining(vehicles::add); } } else if (!lname.isEmpty()) { -// customerService.findByLastName(lname) -// .iterator().forEachRemaining(customers::add); -// List c = customerService.findByLastName(lname); if (custSearch) c.iterator().forEachRemaining(customers::add); @@ -77,10 +73,8 @@ public String results(Principal principal, cust.getVehicles().iterator().forEachRemaining(finalVehicles::add); }); vehicles = finalVehicles; -// finalVehicles.iterator().forEachRemaining(vehicles::add); } } else if (!fname.isEmpty()) { -// customerService.findByFirstName(fname).iterator().forEachRemaining(customers::add); List c = customerService.findByFirstName(fname); if (custSearch) c.iterator().forEachRemaining(customers::add); @@ -88,7 +82,6 @@ public String results(Principal principal, c.stream().forEach(cust -> { cust.getVehicles().iterator().forEachRemaining(finalVehicles::add); }); -// finalVehicles.iterator().forEachRemaining(vehicles::add); vehicles = finalVehicles; }