solver @ModelAttributes in OwnerController

Implement CommonAttribute for owner attributes names constants
This commit is contained in:
PEDSF 2020-10-10 17:24:50 +02:00
parent da3666f1aa
commit a564611681
4 changed files with 5 additions and 5 deletions

View file

@ -46,7 +46,6 @@ class OwnerController {
private final OwnerService ownerService; private final OwnerService ownerService;
private final VisitService visitService; private final VisitService visitService;
@Autowired
OwnerController(OwnerService ownerService, VisitService visitService) { OwnerController(OwnerService ownerService, VisitService visitService) {
this.ownerService = ownerService; this.ownerService = ownerService;
this.visitService = visitService; this.visitService = visitService;

View file

@ -82,7 +82,7 @@ class VisitController {
// Spring MVC calls method loadPetWithVisit(...) before processNewVisitForm is called // Spring MVC calls method loadPetWithVisit(...) before processNewVisitForm is called
@PostMapping("/owners/{ownerId}/pets/{petId}/visits/new") @PostMapping("/owners/{ownerId}/pets/{petId}/visits/new")
public String processNewVisitForm(@Valid VisitDTO visit, BindingResult result) { public String processNewVisitForm(@ModelAttribute("visit") @Valid VisitDTO visit, BindingResult result) {
if (result.hasErrors()) { if (result.hasErrors()) {
return "pets/createOrUpdateVisitForm"; return "pets/createOrUpdateVisitForm";
} }

View file

@ -71,9 +71,9 @@ class PetControllerTests {
cat.setId(3); cat.setId(3);
cat.setName("hamster"); cat.setName("hamster");
given(this.petTypeService.findPetTypes()).willReturn(Lists.newArrayList(cat));
given(this.ownerService.findById(TEST_OWNER_ID)).willReturn(new OwnerDTO()); given(this.ownerService.findById(TEST_OWNER_ID)).willReturn(new OwnerDTO());
given(this.petService.findById(TEST_PET_ID)).willReturn(new PetDTO()); given(this.petService.findById(TEST_PET_ID)).willReturn(new PetDTO());
given(this.petTypeService.findPetTypes()).willReturn(Lists.newArrayList(cat));
} }
@Test @Test

View file

@ -59,7 +59,8 @@ class VisitControllerTests {
@Test @Test
void testInitNewVisitForm() throws Exception { void testInitNewVisitForm() throws Exception {
mockMvc.perform(get("/owners/*/pets/{petId}/visits/new", TEST_PET_ID)).andExpect(status().isOk()) mockMvc.perform(get("/owners/*/pets/{petId}/visits/new", TEST_PET_ID))
.andExpect(status().isOk())
.andExpect(view().name("pets/createOrUpdateVisitForm")); .andExpect(view().name("pets/createOrUpdateVisitForm"));
} }