@Test public void testHandleCreateWithdrawPasswordCommand() throws Exception { UserId aggregateIdentifier = new UserId(); final Date time = currentTime(); final String operatingIp = "223.124.18.123"; final Identifier identifier = new Identifier(Identifier.Type.IDENTITY_CARD, "110101201101019252"); Date changedTime = currentTime(); UserEntry userEntry = new UserEntry(); userEntry.setUsername("buyer1"); userEntry.setPrimaryKey(aggregateIdentifier.toString()); userEntry.setLastName("Buyer One"); userEntry.setFirstName("Mr"); userEntry.setIdentifier(identifier); when(userQueryRepository.findByUsername("buyer1")).thenReturn(userEntry); String newPassword = passwordEncoder.encode("newPassword"); CreateWithdrawPasswordCommand command = new CreateWithdrawPasswordCommand(aggregateIdentifier, "buyer1", newPassword, newPassword, operatingIp, changedTime); fixture.given(new UserCreatedEvent(aggregateIdentifier, "buyer1", "Mr", "Buyer One", identifier, "buyer1@163.com", passwordEncoder.encode("buyer1"), UserCommandHandler.DEFAULT_ROLES, time)) .when(command) .expectEventsMatching( Matchers.payloadsMatching( sequenceOf(new PasswordChangedEventMatcher<WithdrawPasswordCreatedEvent>( new WithdrawPasswordCreatedEvent(aggregateIdentifier, "buyer1", "buyer1@163.com", passwordEncoder.encode("buyer1"), passwordEncoder.encode("buyer1"), operatingIp, changedTime), passwordEncoder, "buyer1")))); }
@CommandHandler public void handleCreateWithdrawPasswordCommand(CreateWithdrawPasswordCommand command) { notNull(command.getUserId()); hasLength(command.getConfirmedWithdrawPassword()); hasLength(command.getWithdrawPassword()); isTrue(command.isValid(), "The password and confirmed password should be the same, but password should be different from previous one!"); User user = repository.load(command.getUserId()); if (user == null) { logger.warn("cannot find user {}", command.getUserId()); return; } final Date changedTime = nullSafe(command.getCreatedTime(), currentTime()); user.createWithdrawPassword(passwordEncoder.encode(command.getWithdrawPassword()), passwordEncoder.encode(command.getConfirmedWithdrawPassword()), command.getOperatingIp(), changedTime); logger.info("userid {}, username {} has changed withdraw password!", command.getUserId(), command.getUsername()); }
UserCommandHandler { @CommandHandler public void handleCreateWithdrawPasswordCommand(CreateWithdrawPasswordCommand command) { notNull(command.getUserId()); hasLength(command.getConfirmedWithdrawPassword()); hasLength(command.getWithdrawPassword()); isTrue(command.isValid(), "The password and confirmed password should be the same, but password should be different from previous one!"); User user = repository.load(command.getUserId()); if (user == null) { logger.warn("cannot find user {}", command.getUserId()); return; } final Date changedTime = nullSafe(command.getCreatedTime(), currentTime()); user.createWithdrawPassword(passwordEncoder.encode(command.getWithdrawPassword()), passwordEncoder.encode(command.getConfirmedWithdrawPassword()), command.getOperatingIp(), changedTime); logger.info("userid {}, username {} has changed withdraw password!", command.getUserId(), command.getUsername()); } }
UserCommandHandler { @CommandHandler public void handleCreateWithdrawPasswordCommand(CreateWithdrawPasswordCommand command) { notNull(command.getUserId()); hasLength(command.getConfirmedWithdrawPassword()); hasLength(command.getWithdrawPassword()); isTrue(command.isValid(), "The password and confirmed password should be the same, but password should be different from previous one!"); User user = repository.load(command.getUserId()); if (user == null) { logger.warn("cannot find user {}", command.getUserId()); return; } final Date changedTime = nullSafe(command.getCreatedTime(), currentTime()); user.createWithdrawPassword(passwordEncoder.encode(command.getWithdrawPassword()), passwordEncoder.encode(command.getConfirmedWithdrawPassword()), command.getOperatingIp(), changedTime); logger.info("userid {}, username {} has changed withdraw password!", command.getUserId(), command.getUsername()); }  }
UserCommandHandler { @CommandHandler public void handleCreateWithdrawPasswordCommand(CreateWithdrawPasswordCommand command) { notNull(command.getUserId()); hasLength(command.getConfirmedWithdrawPassword()); hasLength(command.getWithdrawPassword()); isTrue(command.isValid(), "The password and confirmed password should be the same, but password should be different from previous one!"); User user = repository.load(command.getUserId()); if (user == null) { logger.warn("cannot find user {}", command.getUserId()); return; } final Date changedTime = nullSafe(command.getCreatedTime(), currentTime()); user.createWithdrawPassword(passwordEncoder.encode(command.getWithdrawPassword()), passwordEncoder.encode(command.getConfirmedWithdrawPassword()), command.getOperatingIp(), changedTime); logger.info("userid {}, username {} has changed withdraw password!", command.getUserId(), command.getUsername()); }  @CommandHandler UserId handleCreateUser(CreateUserCommand command); @CommandHandler UserAccount handleAuthenticateUser(AuthenticateUserCommand command); @CommandHandler String handleForgetPassword(ForgetPasswordCommand command); @CommandHandler String handlePasswordReset(ResetPasswordCommand command); @CommandHandler void handleChangePassword(ChangePasswordCommand command); @CommandHandler void handleChangeWithdrawPasswordCommand(ChangeWithdrawPasswordCommand command); @CommandHandler void handleCreateWithdrawPasswordCommand(CreateWithdrawPasswordCommand command); @CommandHandler void handleUpdateNotificationCommand(UpdateNotificationSettingsCommand command); @CommandHandler void handleChangeInfoCommand(ChangeInfoCommand command); @CommandHandler void handleChangeAdminInfoCommand(ChangeAdminInfoCommand command); @Autowired @Qualifier("userRepository") void setRepository(Repository<User> userRepository); @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired void setPasswordEncoder(PasswordEncoder passwordEncoder); @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired void setUserPasswordResetRepository(UserPasswordResetRepository userPasswordResetRepository); @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired void setUserRepository(UserQueryRepository userRepository); @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired void setPasswordResetTokenGenerator(PasswordResetTokenGenerator passwordResetTokenGenerator); }
UserCommandHandler { @CommandHandler public void handleCreateWithdrawPasswordCommand(CreateWithdrawPasswordCommand command) { notNull(command.getUserId()); hasLength(command.getConfirmedWithdrawPassword()); hasLength(command.getWithdrawPassword()); isTrue(command.isValid(), "The password and confirmed password should be the same, but password should be different from previous one!"); User user = repository.load(command.getUserId()); if (user == null) { logger.warn("cannot find user {}", command.getUserId()); return; } final Date changedTime = nullSafe(command.getCreatedTime(), currentTime()); user.createWithdrawPassword(passwordEncoder.encode(command.getWithdrawPassword()), passwordEncoder.encode(command.getConfirmedWithdrawPassword()), command.getOperatingIp(), changedTime); logger.info("userid {}, username {} has changed withdraw password!", command.getUserId(), command.getUsername()); }  @CommandHandler UserId handleCreateUser(CreateUserCommand command); @CommandHandler UserAccount handleAuthenticateUser(AuthenticateUserCommand command); @CommandHandler String handleForgetPassword(ForgetPasswordCommand command); @CommandHandler String handlePasswordReset(ResetPasswordCommand command); @CommandHandler void handleChangePassword(ChangePasswordCommand command); @CommandHandler void handleChangeWithdrawPasswordCommand(ChangeWithdrawPasswordCommand command); @CommandHandler void handleCreateWithdrawPasswordCommand(CreateWithdrawPasswordCommand command); @CommandHandler void handleUpdateNotificationCommand(UpdateNotificationSettingsCommand command); @CommandHandler void handleChangeInfoCommand(ChangeInfoCommand command); @CommandHandler void handleChangeAdminInfoCommand(ChangeAdminInfoCommand command); @Autowired @Qualifier("userRepository") void setRepository(Repository<User> userRepository); @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired void setPasswordEncoder(PasswordEncoder passwordEncoder); @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired void setUserPasswordResetRepository(UserPasswordResetRepository userPasswordResetRepository); @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired void setUserRepository(UserQueryRepository userRepository); @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired void setPasswordResetTokenGenerator(PasswordResetTokenGenerator passwordResetTokenGenerator); static List<String> DEFAULT_ROLES; }