@SneakyThrows @Test void createUserTest() { UserDTO request = new UserDTO("testUser", "testPassword"); RestDocumentationResultHandler document = document("user-create-success", requestHeaders(headerWithName("token").description(TOKEN_DESCRIPTION)), requestFields( fieldWithPath("userName").description("Name of user to create "), fieldWithPath("password").description("Password of user") )); mvc.perform(put("/user") .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON) .characterEncoding("UTF-8") .content(getLoginData()) .header("token", token) .content(gson.toJson(request)) ) .andExpect(status().isOk()) .andDo(document); verify(userProfile).registerUsingDefaults(any()); }
@PutMapping @ApiOperation("Creates new user") @ApiResponses(value = { @ApiResponse(code = 200, message = "User successfully created"), @ApiResponse(code = 400, message = "User already exists") }) public void createUser(@Validated @RequestBody UserDTO userDTO) { ReadKeyPassword readKeyPassword = ReadKeyPasswordHelper.getForString(userDTO.getPassword()); UserIDAuth auth = new UserIDAuth(new UserID(userDTO.getUserName()), readKeyPassword); if (dataSafeService.userProfile().userExists(auth.getUserID())) { throw new UserExistsException("user '" + auth.getUserID().getValue() + "' already exists"); } dataSafeService.userProfile().registerUsingDefaults(auth); }
UserController { @PutMapping @ApiOperation("Creates new user") @ApiResponses(value = { @ApiResponse(code = 200, message = "User successfully created"), @ApiResponse(code = 400, message = "User already exists") }) public void createUser(@Validated @RequestBody UserDTO userDTO) { ReadKeyPassword readKeyPassword = ReadKeyPasswordHelper.getForString(userDTO.getPassword()); UserIDAuth auth = new UserIDAuth(new UserID(userDTO.getUserName()), readKeyPassword); if (dataSafeService.userProfile().userExists(auth.getUserID())) { throw new UserExistsException("user '" + auth.getUserID().getValue() + "' already exists"); } dataSafeService.userProfile().registerUsingDefaults(auth); } }
UserController { @PutMapping @ApiOperation("Creates new user") @ApiResponses(value = { @ApiResponse(code = 200, message = "User successfully created"), @ApiResponse(code = 400, message = "User already exists") }) public void createUser(@Validated @RequestBody UserDTO userDTO) { ReadKeyPassword readKeyPassword = ReadKeyPasswordHelper.getForString(userDTO.getPassword()); UserIDAuth auth = new UserIDAuth(new UserID(userDTO.getUserName()), readKeyPassword); if (dataSafeService.userProfile().userExists(auth.getUserID())) { throw new UserExistsException("user '" + auth.getUserID().getValue() + "' already exists"); } dataSafeService.userProfile().registerUsingDefaults(auth); }  }
UserController { @PutMapping @ApiOperation("Creates new user") @ApiResponses(value = { @ApiResponse(code = 200, message = "User successfully created"), @ApiResponse(code = 400, message = "User already exists") }) public void createUser(@Validated @RequestBody UserDTO userDTO) { ReadKeyPassword readKeyPassword = ReadKeyPasswordHelper.getForString(userDTO.getPassword()); UserIDAuth auth = new UserIDAuth(new UserID(userDTO.getUserName()), readKeyPassword); if (dataSafeService.userProfile().userExists(auth.getUserID())) { throw new UserExistsException("user '" + auth.getUserID().getValue() + "' already exists"); } dataSafeService.userProfile().registerUsingDefaults(auth); }  @PutMapping @ApiOperation("Creates new user") @ApiResponses(value = { @ApiResponse(code = 200, message = "User successfully created"), @ApiResponse(code = 400, message = "User already exists") }) void createUser(@Validated @RequestBody UserDTO userDTO); @PostMapping("/password") @ApiOperation("Change users' password") void changePassword(@RequestHeader String user,
                               @RequestHeader String password,
                               @Validated @RequestBody NewPasswordDTO newPassword); @GetMapping("/publicProfile") @ApiOperation("Reads users' profile") UserPublicProfileDTO getPublicProfile(@RequestHeader String user,
                                                 @RequestHeader String password); @GetMapping("/privateProfile") @ApiOperation("Reads users' private profile") UserPrivateProfileDTO getPrivateProfile(@RequestHeader String user,
                                                   @RequestHeader String password); @PostMapping("/publicProfile") @ApiOperation("Modifies users' profile") void updatePublicProfile(@RequestHeader String user,
                                    @RequestHeader String password,
                                    @Validated @RequestBody UserPublicProfileDTO profileDto); @PostMapping("/privateProfile") @ApiOperation("Modifies users' private profile") void updatePrivateProfile(@RequestHeader String user,
                                     @RequestHeader String password,
                                     @Validated @RequestBody UserPrivateProfileDTO profileDto); @PostMapping("/storages") @ApiOperation("Adds users' storage id and credentials") void addStorageCredentials(@RequestHeader String user,
                                      @RequestHeader String password,
                                      @Validated @RequestBody StorageCredsDTO creds); @DeleteMapping("/storages") @ApiOperation("Removes users' storage id and credentials") void removeStorageCredentials(@RequestHeader String user,
                                         @RequestHeader String password,
                                         @RequestHeader String storageId); @DeleteMapping @ApiOperation("Deletes existing user") @ApiResponses(value = { @ApiResponse(code = 200, message = "User successfully deleted"), @ApiResponse(code = 404, message = "User does not exist") }) void deleteUser(@RequestHeader String user,
                           @RequestHeader String password); }
UserController { @PutMapping @ApiOperation("Creates new user") @ApiResponses(value = { @ApiResponse(code = 200, message = "User successfully created"), @ApiResponse(code = 400, message = "User already exists") }) public void createUser(@Validated @RequestBody UserDTO userDTO) { ReadKeyPassword readKeyPassword = ReadKeyPasswordHelper.getForString(userDTO.getPassword()); UserIDAuth auth = new UserIDAuth(new UserID(userDTO.getUserName()), readKeyPassword); if (dataSafeService.userProfile().userExists(auth.getUserID())) { throw new UserExistsException("user '" + auth.getUserID().getValue() + "' already exists"); } dataSafeService.userProfile().registerUsingDefaults(auth); }  @PutMapping @ApiOperation("Creates new user") @ApiResponses(value = { @ApiResponse(code = 200, message = "User successfully created"), @ApiResponse(code = 400, message = "User already exists") }) void createUser(@Validated @RequestBody UserDTO userDTO); @PostMapping("/password") @ApiOperation("Change users' password") void changePassword(@RequestHeader String user,
                               @RequestHeader String password,
                               @Validated @RequestBody NewPasswordDTO newPassword); @GetMapping("/publicProfile") @ApiOperation("Reads users' profile") UserPublicProfileDTO getPublicProfile(@RequestHeader String user,
                                                 @RequestHeader String password); @GetMapping("/privateProfile") @ApiOperation("Reads users' private profile") UserPrivateProfileDTO getPrivateProfile(@RequestHeader String user,
                                                   @RequestHeader String password); @PostMapping("/publicProfile") @ApiOperation("Modifies users' profile") void updatePublicProfile(@RequestHeader String user,
                                    @RequestHeader String password,
                                    @Validated @RequestBody UserPublicProfileDTO profileDto); @PostMapping("/privateProfile") @ApiOperation("Modifies users' private profile") void updatePrivateProfile(@RequestHeader String user,
                                     @RequestHeader String password,
                                     @Validated @RequestBody UserPrivateProfileDTO profileDto); @PostMapping("/storages") @ApiOperation("Adds users' storage id and credentials") void addStorageCredentials(@RequestHeader String user,
                                      @RequestHeader String password,
                                      @Validated @RequestBody StorageCredsDTO creds); @DeleteMapping("/storages") @ApiOperation("Removes users' storage id and credentials") void removeStorageCredentials(@RequestHeader String user,
                                         @RequestHeader String password,
                                         @RequestHeader String storageId); @DeleteMapping @ApiOperation("Deletes existing user") @ApiResponses(value = { @ApiResponse(code = 200, message = "User successfully deleted"), @ApiResponse(code = 404, message = "User does not exist") }) void deleteUser(@RequestHeader String user,
                           @RequestHeader String password);  }