@Test @WithAnonymousUser public void create_test() throws Exception { ProfileCreateForm userCreateForm = new ProfileCreateForm(); userCreateForm.setUserHandle("ORZClsZpTvWrYGl7mXL5Wg"); userCreateForm.setFirstName("John"); userCreateForm.setLastName("Doe"); userCreateForm.setEmailAddress("john.doe@example.com"); userCreateForm.setPassword("password"); userCreateForm.setAuthenticators(Collections.emptyList()); userCreateForm.setSingleFactorAuthenticationAllowed(true); UserEntity userEntity = new UserEntity(); userEntity.setId(1); userEntity.setUserHandle(Base64UrlUtil.decode("ORZClsZpTvWrYGl7mXL5Wg")); userEntity.setFirstName("John"); userEntity.setLastName("Doe"); userEntity.setEmailAddress("john.doe@example.com"); userEntity.setAuthenticators(Collections.emptyList()); userEntity.setAuthorities(Collections.singletonList(new AuthorityEntity(0, "SINGLE_FACTOR_AUTHN_ALLOWED"))); when(profileAppService.create(any())).thenReturn(userEntity); mvc.perform( post("/api/profile") .contentType(MediaType.APPLICATION_JSON) .content(objectMapper.writeValueAsString(userCreateForm)) .with(SecurityMockMvcRequestPostProcessors.csrf()) ) .andExpect(status().isOk()) .andExpect(jsonPath("$.id", is(1))) .andExpect(jsonPath("$.userHandle", is("ORZClsZpTvWrYGl7mXL5Wg"))) .andExpect(jsonPath("$.firstName", is("John"))) .andExpect(jsonPath("$.lastName", is("Doe"))) .andExpect(jsonPath("$.emailAddress", is("john.doe@example.com"))) .andExpect(jsonPath("$.authenticators", is(empty()))) .andExpect(jsonPath("$.singleFactorAuthenticationAllowed", is(true))) ; verify(profileAppService).create(any()); }
@PostMapping public ProfileForm create(@Valid @RequestBody ProfileCreateForm profileCreateForm) { UserEntity userEntity = mapper.mapForCreate(profileCreateForm); UserEntity createdUserEntity = profileAppService.create(userEntity); return mapper.mapToProfileForm(createdUserEntity); }
ProfileController { @PostMapping public ProfileForm create(@Valid @RequestBody ProfileCreateForm profileCreateForm) { UserEntity userEntity = mapper.mapForCreate(profileCreateForm); UserEntity createdUserEntity = profileAppService.create(userEntity); return mapper.mapToProfileForm(createdUserEntity); } }
ProfileController { @PostMapping public ProfileForm create(@Valid @RequestBody ProfileCreateForm profileCreateForm) { UserEntity userEntity = mapper.mapForCreate(profileCreateForm); UserEntity createdUserEntity = profileAppService.create(userEntity); return mapper.mapToProfileForm(createdUserEntity); } @Autowired  ProfileController(ProfileAppService profileAppService, AppSpecificMapper mapper); }
ProfileController { @PostMapping public ProfileForm create(@Valid @RequestBody ProfileCreateForm profileCreateForm) { UserEntity userEntity = mapper.mapForCreate(profileCreateForm); UserEntity createdUserEntity = profileAppService.create(userEntity); return mapper.mapToProfileForm(createdUserEntity); } @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); }
ProfileController { @PostMapping public ProfileForm create(@Valid @RequestBody ProfileCreateForm profileCreateForm) { UserEntity userEntity = mapper.mapForCreate(profileCreateForm); UserEntity createdUserEntity = profileAppService.create(userEntity); return mapper.mapToProfileForm(createdUserEntity); } @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);  }