@Test public void testResetPasswordWithToken() throws Exception { final String token = "token"; final String ip = "ip"; final String password = "password"; final String confirmedPassword = "password"; final Date date = currentTime(); UserService userService = mockUserService(); UserService userService2 = mock(UserService.class); CommandGateway gateway = mock(CommandGateway.class); ResetPasswordCommand command = new ResetPasswordCommand(token, password, confirmedPassword, ip, date); UserServiceFacadeImpl service = new UserServiceFacadeImpl(); service.setUserService(userService); service.setCommandGateway(gateway); service.resetPasswordWithToken(token, password, confirmedPassword, ip, date); service.setUserService(userService2); service.resetPasswordWithToken(token, password, confirmedPassword, ip, date); verify(userService).getCurrentUser(); verify(userService2).getCurrentUser(); verify(gateway).sendAndWait(eq(command)); }
@Override public UserAccount resetPasswordWithToken(String token, String password, String confirmedPassword, String operatingIp, Date resetTime) { UserAccount userAccount = currentUser(); if (userAccount != null) { logger.warn("user has already logged on"); return null; } ResetPasswordCommand command = new ResetPasswordCommand(token, password, confirmedPassword, operatingIp, resetTime); final String username = commandGateway.sendAndWait(command); if (!Strings.hasText(username)) { return null; } AuthenticateUserCommand authenticateUserCommand = new AuthenticateUserCommand(username, password, operatingIp, resetTime); return commandGateway.sendAndWait(authenticateUserCommand); }
UserServiceFacadeImpl implements UserServiceFacade { @Override public UserAccount resetPasswordWithToken(String token, String password, String confirmedPassword, String operatingIp, Date resetTime) { UserAccount userAccount = currentUser(); if (userAccount != null) { logger.warn("user has already logged on"); return null; } ResetPasswordCommand command = new ResetPasswordCommand(token, password, confirmedPassword, operatingIp, resetTime); final String username = commandGateway.sendAndWait(command); if (!Strings.hasText(username)) { return null; } AuthenticateUserCommand authenticateUserCommand = new AuthenticateUserCommand(username, password, operatingIp, resetTime); return commandGateway.sendAndWait(authenticateUserCommand); } }
UserServiceFacadeImpl implements UserServiceFacade { @Override public UserAccount resetPasswordWithToken(String token, String password, String confirmedPassword, String operatingIp, Date resetTime) { UserAccount userAccount = currentUser(); if (userAccount != null) { logger.warn("user has already logged on"); return null; } ResetPasswordCommand command = new ResetPasswordCommand(token, password, confirmedPassword, operatingIp, resetTime); final String username = commandGateway.sendAndWait(command); if (!Strings.hasText(username)) { return null; } AuthenticateUserCommand authenticateUserCommand = new AuthenticateUserCommand(username, password, operatingIp, resetTime); return commandGateway.sendAndWait(authenticateUserCommand); }  }
UserServiceFacadeImpl implements UserServiceFacade { @Override public UserAccount resetPasswordWithToken(String token, String password, String confirmedPassword, String operatingIp, Date resetTime) { UserAccount userAccount = currentUser(); if (userAccount != null) { logger.warn("user has already logged on"); return null; } ResetPasswordCommand command = new ResetPasswordCommand(token, password, confirmedPassword, operatingIp, resetTime); final String username = commandGateway.sendAndWait(command); if (!Strings.hasText(username)) { return null; } AuthenticateUserCommand authenticateUserCommand = new AuthenticateUserCommand(username, password, operatingIp, resetTime); return commandGateway.sendAndWait(authenticateUserCommand); }  @Override UserAccount currentUser(); @Override UserEntry currentDetailUser(); @Override boolean isWithdrawPasswordSet(); @Override boolean isWithdrawPasswordMatched(String withdrawPassword); @Override boolean canAuthWithNewPassword(String username, String newPassword); @Override UserPasswordReset getToken(String token); PortfolioEntry obtainPortfolioForUser(); @Override boolean matchPreviousPassword(String previousPassword); @Override void editDetails(String username, String email, String cellPhoneNumber, String firstName, String lastName); @Override void editAdminDetails(String username,
                                 String email,
                                 Identifier identifier,
                                 String cellPhoneNumber,
                                 String firstName,
                                 String lastName,
                                 List<String> roles); @Override void updateNotificationSettings(boolean logonAlert, boolean withdrawMoneyAlert, boolean withdrawItemAlert, boolean executedAlert); @Override void changePassword(String previousPassword,
                               String newPassword,
                               String confirmedNewPassword,
                               String operatingIp,
                               Date changedTime); @Override boolean createWithdrawPassword(String withdrawPassword, String confirmedWithdrawPassword, String operatingIp, Date changedTime); @Override boolean matchPreviousWithdrawPassword(String previousPassword); boolean generateForgetPasswordToken(String email, String operatingIp, Date currentTime); @Override UserAccount resetPasswordWithToken(String token,
                                              String password,
                                              String confirmedPassword,
                                              String operatingIp,
                                              Date resetTime); @Override void changeWithdrawPassword(String previousPassword,
                                       String withdrawPassword,
                                       String confirmedWithdrawPassword,
                                       String operatingIp,
                                       Date changedTime); @Override UserEntry findByEmail(String email); @Override int findPasswordResetCount(String email, String ip, Date currentDate); @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired void setPasswordEncoder(PasswordEncoder passwordEncoder); @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired void setCommandGateway(CommandGateway commandGateway); @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired void setUserService(UserService userService); @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired void setUserRepository(UserQueryRepository userRepository); @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired void setPortfolioQueryRepository(PortfolioQueryRepository portfolioQueryRepository); @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired void setUserPasswordResetRepository(UserPasswordResetRepository userPasswordResetRepository); @Autowired void setEmailSender(ForgetPasswordEmailSender emailSender); }
UserServiceFacadeImpl implements UserServiceFacade { @Override public UserAccount resetPasswordWithToken(String token, String password, String confirmedPassword, String operatingIp, Date resetTime) { UserAccount userAccount = currentUser(); if (userAccount != null) { logger.warn("user has already logged on"); return null; } ResetPasswordCommand command = new ResetPasswordCommand(token, password, confirmedPassword, operatingIp, resetTime); final String username = commandGateway.sendAndWait(command); if (!Strings.hasText(username)) { return null; } AuthenticateUserCommand authenticateUserCommand = new AuthenticateUserCommand(username, password, operatingIp, resetTime); return commandGateway.sendAndWait(authenticateUserCommand); }  @Override UserAccount currentUser(); @Override UserEntry currentDetailUser(); @Override boolean isWithdrawPasswordSet(); @Override boolean isWithdrawPasswordMatched(String withdrawPassword); @Override boolean canAuthWithNewPassword(String username, String newPassword); @Override UserPasswordReset getToken(String token); PortfolioEntry obtainPortfolioForUser(); @Override boolean matchPreviousPassword(String previousPassword); @Override void editDetails(String username, String email, String cellPhoneNumber, String firstName, String lastName); @Override void editAdminDetails(String username,
                                 String email,
                                 Identifier identifier,
                                 String cellPhoneNumber,
                                 String firstName,
                                 String lastName,
                                 List<String> roles); @Override void updateNotificationSettings(boolean logonAlert, boolean withdrawMoneyAlert, boolean withdrawItemAlert, boolean executedAlert); @Override void changePassword(String previousPassword,
                               String newPassword,
                               String confirmedNewPassword,
                               String operatingIp,
                               Date changedTime); @Override boolean createWithdrawPassword(String withdrawPassword, String confirmedWithdrawPassword, String operatingIp, Date changedTime); @Override boolean matchPreviousWithdrawPassword(String previousPassword); boolean generateForgetPasswordToken(String email, String operatingIp, Date currentTime); @Override UserAccount resetPasswordWithToken(String token,
                                              String password,
                                              String confirmedPassword,
                                              String operatingIp,
                                              Date resetTime); @Override void changeWithdrawPassword(String previousPassword,
                                       String withdrawPassword,
                                       String confirmedWithdrawPassword,
                                       String operatingIp,
                                       Date changedTime); @Override UserEntry findByEmail(String email); @Override int findPasswordResetCount(String email, String ip, Date currentDate); @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired void setPasswordEncoder(PasswordEncoder passwordEncoder); @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired void setCommandGateway(CommandGateway commandGateway); @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired void setUserService(UserService userService); @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired void setUserRepository(UserQueryRepository userRepository); @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired void setPortfolioQueryRepository(PortfolioQueryRepository portfolioQueryRepository); @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired void setUserPasswordResetRepository(UserPasswordResetRepository userPasswordResetRepository); @Autowired void setEmailSender(ForgetPasswordEmailSender emailSender);  }