mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-22 07:15:49 +00:00
solver @ModelAttributes in OwnerController
Implement CommonAttribute for owner attributes names constants
This commit is contained in:
parent
da3666f1aa
commit
a564611681
4 changed files with 5 additions and 5 deletions
|
@ -46,7 +46,6 @@ class OwnerController {
|
|||
private final OwnerService ownerService;
|
||||
private final VisitService visitService;
|
||||
|
||||
@Autowired
|
||||
OwnerController(OwnerService ownerService, VisitService visitService) {
|
||||
this.ownerService = ownerService;
|
||||
this.visitService = visitService;
|
||||
|
|
|
@ -82,7 +82,7 @@ class VisitController {
|
|||
|
||||
// Spring MVC calls method loadPetWithVisit(...) before processNewVisitForm is called
|
||||
@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()) {
|
||||
return "pets/createOrUpdateVisitForm";
|
||||
}
|
||||
|
|
|
@ -71,9 +71,9 @@ class PetControllerTests {
|
|||
cat.setId(3);
|
||||
cat.setName("hamster");
|
||||
|
||||
given(this.petTypeService.findPetTypes()).willReturn(Lists.newArrayList(cat));
|
||||
given(this.ownerService.findById(TEST_OWNER_ID)).willReturn(new OwnerDTO());
|
||||
given(this.petService.findById(TEST_PET_ID)).willReturn(new PetDTO());
|
||||
given(this.petTypeService.findPetTypes()).willReturn(Lists.newArrayList(cat));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -59,8 +59,9 @@ class VisitControllerTests {
|
|||
|
||||
@Test
|
||||
void testInitNewVisitForm() throws Exception {
|
||||
mockMvc.perform(get("/owners/*/pets/{petId}/visits/new", TEST_PET_ID)).andExpect(status().isOk())
|
||||
.andExpect(view().name("pets/createOrUpdateVisitForm"));
|
||||
mockMvc.perform(get("/owners/*/pets/{petId}/visits/new", TEST_PET_ID))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(view().name("pets/createOrUpdateVisitForm"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in a new issue