@Test public void testHandleCreateUser() throws Exception { UserId aggregateIdentifier = new UserId(); final Identifier identifier = new Identifier(Identifier.Type.IDENTITY_CARD, "110101201101019252"); final Date time = currentTime(); fixture.given() .when(new CreateUserCommand(aggregateIdentifier, "buyer1", "Mr", "Buyer One", identifier, "buyer1@163.com", "buyer1", "buyer1", UserCommandHandler.DEFAULT_ROLES, time)) .expectEventsMatching( Matchers.payloadsMatching( sequenceOf(new UserCreatedEventMatcher(new UserCreatedEvent(aggregateIdentifier, "buyer1", "Mr", "Buyer One", identifier, "buyer1@163.com", passwordEncoder.encode("buyer1"), UserCommandHandler.DEFAULT_ROLES, time), passwordEncoder, "buyer1" )))); }
@CommandHandler public UserId handleCreateUser(CreateUserCommand command) { hasLength(command.getUsername()); notNull(command.getIdentifier()); isTrue(command.isValid()); if (!command.getIdentifier().isValid()) { throw new InvalidIdentityException(command.getIdentifier()); } UserAccount account = userQueryRepository.findByUsername(command.getUsername()); if (account != null) { throw new UsernameAlreadyInUseException(command.getUsername()); } UserId identifier = command.getUserId(); User user = new User(identifier, command.getUsername(), command.getFirstName(), command.getLastName(), command.getIdentifier(), command.getEmail(), passwordEncoder.encode(command.getPassword()), isEmpty(command.getRoles()) ? DEFAULT_ROLES : command.getRoles(), command.getTime()); repository.add(user); return identifier; }
UserCommandHandler { @CommandHandler public UserId handleCreateUser(CreateUserCommand command) { hasLength(command.getUsername()); notNull(command.getIdentifier()); isTrue(command.isValid()); if (!command.getIdentifier().isValid()) { throw new InvalidIdentityException(command.getIdentifier()); } UserAccount account = userQueryRepository.findByUsername(command.getUsername()); if (account != null) { throw new UsernameAlreadyInUseException(command.getUsername()); } UserId identifier = command.getUserId(); User user = new User(identifier, command.getUsername(), command.getFirstName(), command.getLastName(), command.getIdentifier(), command.getEmail(), passwordEncoder.encode(command.getPassword()), isEmpty(command.getRoles()) ? DEFAULT_ROLES : command.getRoles(), command.getTime()); repository.add(user); return identifier; } }
UserCommandHandler { @CommandHandler public UserId handleCreateUser(CreateUserCommand command) { hasLength(command.getUsername()); notNull(command.getIdentifier()); isTrue(command.isValid()); if (!command.getIdentifier().isValid()) { throw new InvalidIdentityException(command.getIdentifier()); } UserAccount account = userQueryRepository.findByUsername(command.getUsername()); if (account != null) { throw new UsernameAlreadyInUseException(command.getUsername()); } UserId identifier = command.getUserId(); User user = new User(identifier, command.getUsername(), command.getFirstName(), command.getLastName(), command.getIdentifier(), command.getEmail(), passwordEncoder.encode(command.getPassword()), isEmpty(command.getRoles()) ? DEFAULT_ROLES : command.getRoles(), command.getTime()); repository.add(user); return identifier; }  }
UserCommandHandler { @CommandHandler public UserId handleCreateUser(CreateUserCommand command) { hasLength(command.getUsername()); notNull(command.getIdentifier()); isTrue(command.isValid()); if (!command.getIdentifier().isValid()) { throw new InvalidIdentityException(command.getIdentifier()); } UserAccount account = userQueryRepository.findByUsername(command.getUsername()); if (account != null) { throw new UsernameAlreadyInUseException(command.getUsername()); } UserId identifier = command.getUserId(); User user = new User(identifier, command.getUsername(), command.getFirstName(), command.getLastName(), command.getIdentifier(), command.getEmail(), passwordEncoder.encode(command.getPassword()), isEmpty(command.getRoles()) ? DEFAULT_ROLES : command.getRoles(), command.getTime()); repository.add(user); return identifier; }  @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 UserId handleCreateUser(CreateUserCommand command) { hasLength(command.getUsername()); notNull(command.getIdentifier()); isTrue(command.isValid()); if (!command.getIdentifier().isValid()) { throw new InvalidIdentityException(command.getIdentifier()); } UserAccount account = userQueryRepository.findByUsername(command.getUsername()); if (account != null) { throw new UsernameAlreadyInUseException(command.getUsername()); } UserId identifier = command.getUserId(); User user = new User(identifier, command.getUsername(), command.getFirstName(), command.getLastName(), command.getIdentifier(), command.getEmail(), passwordEncoder.encode(command.getPassword()), isEmpty(command.getRoles()) ? DEFAULT_ROLES : command.getRoles(), command.getTime()); repository.add(user); return identifier; }  @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; }