@@ -430,4 +430,66 @@ void testGetOwnersPetsWithPetNotFound() throws Exception {
430430 }
431431
432432
433+ @ Test
434+ @ WithMockUser (roles = "OWNER_ADMIN" )
435+ void testUpdateOwnersPetSuccess () throws Exception {
436+ int ownerId = owners .get (0 ).getId ();
437+ int petId = pets .get (0 ).getId ();
438+ given (this .clinicService .findOwnerById (ownerId )).willReturn (ownerMapper .toOwner (owners .get (0 )));
439+ given (this .clinicService .findPetById (petId )).willReturn (petMapper .toPet (pets .get (0 )));
440+ PetDto updatedPetDto = pets .get (0 );
441+ updatedPetDto .setName ("Rex" );
442+ updatedPetDto .setBirthDate (LocalDate .of (2020 , 1 , 15 ));
443+ ObjectMapper mapper = new ObjectMapper ();
444+ mapper .registerModule (new JavaTimeModule ());
445+ mapper .setDateFormat (new SimpleDateFormat ("yyyy-MM-dd" ));
446+ mapper .disable (SerializationFeature .WRITE_DATES_AS_TIMESTAMPS );
447+ String updatedPetAsJSON = mapper .writeValueAsString (updatedPetDto );
448+ this .mockMvc .perform (put ("/api/owners/" + ownerId + "/pets/" + petId )
449+ .content (updatedPetAsJSON )
450+ .accept (MediaType .APPLICATION_JSON_VALUE )
451+ .contentType (MediaType .APPLICATION_JSON_VALUE ))
452+ .andExpect (status ().isNoContent ());
453+ }
454+
455+ @ Test
456+ @ WithMockUser (roles = "OWNER_ADMIN" )
457+ void testUpdateOwnersPetOwnerNotFound () throws Exception {
458+ int ownerId = 0 ;
459+ int petId = pets .get (0 ).getId ();
460+ given (this .clinicService .findOwnerById (ownerId )).willReturn (null );
461+ PetDto petDto = pets .get (0 );
462+ petDto .setName ("Thor" );
463+ ObjectMapper mapper = new ObjectMapper ();
464+ mapper .registerModule (new JavaTimeModule ());
465+ mapper .setDateFormat (new SimpleDateFormat ("yyyy-MM-dd" ));
466+ mapper .disable (SerializationFeature .WRITE_DATES_AS_TIMESTAMPS );
467+ String updatedPetAsJSON = mapper .writeValueAsString (petDto );
468+ this .mockMvc .perform (put ("/api/owners/" + ownerId + "/pets/" + petId )
469+ .contentType (MediaType .APPLICATION_JSON )
470+ .content (updatedPetAsJSON ))
471+ .andExpect (status ().isNotFound ());
472+ }
473+
474+ @ Test
475+ @ WithMockUser (roles = "OWNER_ADMIN" )
476+ void testUpdateOwnersPetPetNotFound () throws Exception {
477+ int ownerId = owners .get (0 ).getId ();
478+ int petId = 0 ;
479+ given (this .clinicService .findOwnerById (ownerId )).willReturn (ownerMapper .toOwner (owners .get (0 )));
480+ given (this .clinicService .findPetById (petId )).willReturn (null );
481+ PetDto petDto = pets .get (0 );
482+ petDto .setName ("Ghost" );
483+ petDto .setBirthDate (LocalDate .of (2020 , 1 , 1 ));
484+ ObjectMapper mapper = new ObjectMapper ();
485+ mapper .registerModule (new JavaTimeModule ());
486+ mapper .setDateFormat (new SimpleDateFormat ("yyyy-MM-dd" ));
487+ mapper .disable (SerializationFeature .WRITE_DATES_AS_TIMESTAMPS );
488+ String updatedPetAsJSON = mapper .writeValueAsString (petDto );
489+ this .mockMvc .perform (put ("/api/owners/" + ownerId + "/pets/" + petId )
490+ .contentType (MediaType .APPLICATION_JSON )
491+ .content (updatedPetAsJSON ))
492+ .andExpect (status ().isNotFound ());
493+ }
494+
433495}
0 commit comments