ProfileController { @PutMapping public ProfileForm update(@AuthenticationPrincipal UserEntity loginUserEntity, @Valid @RequestBody ProfileUpdateForm profileUpdateForm) { int id = loginUserEntity.getId(); UserEntity updatedUserEntity = profileAppService.update(id, profileUpdateForm); return mapper.mapToProfileForm(updatedUserEntity); } @Autowired  ProfileController(ProfileAppService profileAppService, AppSpecificMapper mapper); @InitBinder("profileCreateForm") void initProfileCreateFormBinder(WebDataBinder binder); @InitBinder("profileUpdateForm") void initProfileUpdateFormBinder(WebDataBinder binder); @GetMapping ProfileForm show(@AuthenticationPrincipal UserEntity loginUserEntity); @PostMapping ProfileForm create(@Valid @RequestBody ProfileCreateForm profileCreateForm); @PutMapping ProfileForm update(@AuthenticationPrincipal UserEntity loginUserEntity, @Valid @RequestBody ProfileUpdateForm profileUpdateForm); @DeleteMapping void delete(@AuthenticationPrincipal UserEntity loginUserEntity);  }
@Test @WithMockWebAuthnUser(id = 1, firstName = "John", lastName = "Doe", emailAddress = "john.doe@example.com", authorities = {"ROLE_USER"}, authenticators = {}) public void update_test() throws Exception { int userId = 1; byte[] userHandle = UUIDUtil.convertUUIDToBytes(UUID.randomUUID()); ProfileUpdateForm userUpdateForm = new ProfileUpdateForm(); userUpdateForm.setUserHandle(Base64UrlUtil.encodeToString(userHandle)); userUpdateForm.setFirstName("John"); userUpdateForm.setLastName("Smith"); userUpdateForm.setEmailAddress("john.smith@example.com"); userUpdateForm.setAuthenticators(Collections.emptyList()); userUpdateForm.setSingleFactorAuthenticationAllowed(true); UserEntity userEntity = new UserEntity(); userEntity.setId(userId); userEntity.setUserHandle(userHandle); userEntity.setId(userId); userEntity.setFirstName("John"); userEntity.setLastName("Smith"); userEntity.setEmailAddress("john.smith@example.com"); userEntity.setAuthenticators(Collections.emptyList()); userEntity.setAuthorities(Collections.singletonList(new AuthorityEntity(0, "SINGLE_FACTOR_AUTHN_ALLOWED"))); when(profileAppService.update(anyInt(), any())).thenReturn(userEntity); mvc.perform( put("/api/profile") .contentType(MediaType.APPLICATION_JSON) .content(objectMapper.writeValueAsString(userUpdateForm)) .with(SecurityMockMvcRequestPostProcessors.csrf()) ) .andExpect(status().isOk()) .andExpect(jsonPath("$.id", is(1))) .andExpect(jsonPath("$.userHandle", is(Base64UrlUtil.encodeToString(userHandle)))) .andExpect(jsonPath("$.firstName", is("John"))) .andExpect(jsonPath("$.lastName", is("Smith"))) .andExpect(jsonPath("$.emailAddress", is("john.smith@example.com"))) .andExpect(jsonPath("$.authenticators", is(empty()))) .andExpect(jsonPath("$.singleFactorAuthenticationAllowed", is(true))) ; verify(profileAppService).update(anyInt(), any()); }