@Test public void testHandleUserCreated() throws Exception { final UserId userId = new UserId(); final String firstName = "buyer"; final String lastName = "abc"; final String username = "buyerAbc"; final String email = "buyerAbc@163.com"; final Identifier identifier = new Identifier(Identifier.Type.IDENTITY_CARD, "110101201101019252"); final String password = "sjfsudm9ei8r899e9e87745jkdkjfhd"; final Date time = currentTime(); final UserQueryRepository repository = mock(UserQueryRepository.class); final UserCreatedEvent event = new UserCreatedEvent(userId, username, firstName, lastName, identifier, email, password, UserCommandHandler.DEFAULT_ROLES, time); final UserListener listener = new UserListener(); listener.setUserRepository(repository); listener.handleUserCreated(event); final ArgumentCaptor<UserEntry> captor = ArgumentCaptor.forClass(UserEntry.class); verify(repository).save(captor.capture()); final UserEntry userEntry = captor.getValue(); assertThat(userEntry, notNullValue()); assertThat(userEntry.getPrimaryKey(), equalTo(userId.toString())); assertThat(userEntry.getName(), equalTo(username)); assertThat(userEntry.getFullName(), equalTo(lastName + " " + firstName)); assertThat(userEntry.getUsername(), equalTo(username)); assertThat(userEntry.getPassword(), equalTo(password)); assertThat(userEntry.getIdentifier(), equalTo(identifier)); assertThat(userEntry.getId(), equalTo(username)); assertThat(userEntry.getFirstName(), equalTo(firstName)); assertThat(userEntry.getLastName(), equalTo(lastName)); assertThat(userEntry.getEmail(), equalTo(email)); }
@EventHandler public void handleUserCreated(UserCreatedEvent event) { UserEntry userEntry = new UserEntry(); userEntry.setPrimaryKey(event.getUserIdentifier().toString()); userEntry.setLastName(event.getLastName()); userEntry.setFirstName(event.getFirstName()); userEntry.setIdentifier(event.getIdentifier()); userEntry.setUsername(event.getUsername()); userEntry.setEmail(event.getEmail()); userEntry.setPassword(event.getPassword()); userEntry.setRoles(event.getRoles()); userRepository.save(userEntry); }
UserListener { @EventHandler public void handleUserCreated(UserCreatedEvent event) { UserEntry userEntry = new UserEntry(); userEntry.setPrimaryKey(event.getUserIdentifier().toString()); userEntry.setLastName(event.getLastName()); userEntry.setFirstName(event.getFirstName()); userEntry.setIdentifier(event.getIdentifier()); userEntry.setUsername(event.getUsername()); userEntry.setEmail(event.getEmail()); userEntry.setPassword(event.getPassword()); userEntry.setRoles(event.getRoles()); userRepository.save(userEntry); } }
UserListener { @EventHandler public void handleUserCreated(UserCreatedEvent event) { UserEntry userEntry = new UserEntry(); userEntry.setPrimaryKey(event.getUserIdentifier().toString()); userEntry.setLastName(event.getLastName()); userEntry.setFirstName(event.getFirstName()); userEntry.setIdentifier(event.getIdentifier()); userEntry.setUsername(event.getUsername()); userEntry.setEmail(event.getEmail()); userEntry.setPassword(event.getPassword()); userEntry.setRoles(event.getRoles()); userRepository.save(userEntry); }  }
UserListener { @EventHandler public void handleUserCreated(UserCreatedEvent event) { UserEntry userEntry = new UserEntry(); userEntry.setPrimaryKey(event.getUserIdentifier().toString()); userEntry.setLastName(event.getLastName()); userEntry.setFirstName(event.getFirstName()); userEntry.setIdentifier(event.getIdentifier()); userEntry.setUsername(event.getUsername()); userEntry.setEmail(event.getEmail()); userEntry.setPassword(event.getPassword()); userEntry.setRoles(event.getRoles()); userRepository.save(userEntry); }  @EventHandler void handleUserCreated(UserCreatedEvent event); @EventHandler void handleUserPasswordChanged(PasswordChangedEvent event); @EventHandler void handleUserWithdrawPasswordCreated(WithdrawPasswordCreatedEvent event); @EventHandler void handleUserWithdrawPasswordChanged(WithdrawPasswordChangedEvent event); @EventHandler void handleUserInfoChanged(UserInfoChangedEvent event); @EventHandler void handleUserAdminInfoChanged(UserAdminInfoChangedEvent event); @EventHandler void handleUpdateNotification(NotificationSettingsUpdatedEvent event); @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired void setUserRepository(UserQueryRepository userRepository); }
UserListener { @EventHandler public void handleUserCreated(UserCreatedEvent event) { UserEntry userEntry = new UserEntry(); userEntry.setPrimaryKey(event.getUserIdentifier().toString()); userEntry.setLastName(event.getLastName()); userEntry.setFirstName(event.getFirstName()); userEntry.setIdentifier(event.getIdentifier()); userEntry.setUsername(event.getUsername()); userEntry.setEmail(event.getEmail()); userEntry.setPassword(event.getPassword()); userEntry.setRoles(event.getRoles()); userRepository.save(userEntry); }  @EventHandler void handleUserCreated(UserCreatedEvent event); @EventHandler void handleUserPasswordChanged(PasswordChangedEvent event); @EventHandler void handleUserWithdrawPasswordCreated(WithdrawPasswordCreatedEvent event); @EventHandler void handleUserWithdrawPasswordChanged(WithdrawPasswordChangedEvent event); @EventHandler void handleUserInfoChanged(UserInfoChangedEvent event); @EventHandler void handleUserAdminInfoChanged(UserAdminInfoChangedEvent event); @EventHandler void handleUpdateNotification(NotificationSettingsUpdatedEvent event); @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired void setUserRepository(UserQueryRepository userRepository);  }