@Test public void shouldNotSendEventIfPasswordReminderIsDisabled() throws Exception { List<MotechUser> users = prepareMotechUsersOne(); when(settingService.isPasswordResetReminderEnabled()).thenReturn(false); when(allUsers.retrieveAll()).thenReturn(users); eventHandler.handleEvent(event); verify(allUsers, never()).retrieveAll(); verify(eventRelay, never()).sendEventMessage(any(MotechEvent.class)); verify(settingService).isPasswordResetReminderEnabled(); verify(settingService, never()).getNumberOfDaysForReminder(); verify(settingService, never()).getNumberOfDaysToChangePassword(); }
@MotechListener(subjects = PASSWORD_EXPIRATION_CHECK_EVENT) public void handleEvent(MotechEvent event) { if (settingService.isPasswordResetReminderEnabled()) { LOGGER.info("Daily password reset reminder triggered"); final int passwordExpirationInDays = settingService.getNumberOfDaysToChangePassword(); final int daysBeforeExpirationToSendReminder = settingService.getNumberOfDaysForReminder(); final int daysWithNoPassChangeForReminder = passwordExpirationInDays - daysBeforeExpirationToSendReminder; for (MotechUser user : allUsers.retrieveAll()) { final int daysWithoutPasswordChange = daysWithoutPasswordChange(user); LOGGER.debug("User {} hasn't changed password in {} days. Notification is being after {} days without" + " password change, {} days before expiration", user.getUserName(), daysWithoutPasswordChange, daysWithNoPassChangeForReminder, daysBeforeExpirationToSendReminder); if (daysWithoutPasswordChange == daysWithNoPassChangeForReminder) { if (StringUtils.isNotBlank(user.getEmail())) { sendPasswordReminderEvent(user, passwordExpirationInDays, daysBeforeExpirationToSendReminder); } else { LOGGER.debug("User {} doesn't have an email address set, skipping sending of reminder", user.getUserName()); } } } } else { LOGGER.info("Daily password reset reminder is disabled, skipping processing of users"); } }
PasswordExpirationCheckEventHandler { @MotechListener(subjects = PASSWORD_EXPIRATION_CHECK_EVENT) public void handleEvent(MotechEvent event) { if (settingService.isPasswordResetReminderEnabled()) { LOGGER.info("Daily password reset reminder triggered"); final int passwordExpirationInDays = settingService.getNumberOfDaysToChangePassword(); final int daysBeforeExpirationToSendReminder = settingService.getNumberOfDaysForReminder(); final int daysWithNoPassChangeForReminder = passwordExpirationInDays - daysBeforeExpirationToSendReminder; for (MotechUser user : allUsers.retrieveAll()) { final int daysWithoutPasswordChange = daysWithoutPasswordChange(user); LOGGER.debug("User {} hasn't changed password in {} days. Notification is being after {} days without" + " password change, {} days before expiration", user.getUserName(), daysWithoutPasswordChange, daysWithNoPassChangeForReminder, daysBeforeExpirationToSendReminder); if (daysWithoutPasswordChange == daysWithNoPassChangeForReminder) { if (StringUtils.isNotBlank(user.getEmail())) { sendPasswordReminderEvent(user, passwordExpirationInDays, daysBeforeExpirationToSendReminder); } else { LOGGER.debug("User {} doesn't have an email address set, skipping sending of reminder", user.getUserName()); } } } } else { LOGGER.info("Daily password reset reminder is disabled, skipping processing of users"); } } }
PasswordExpirationCheckEventHandler { @MotechListener(subjects = PASSWORD_EXPIRATION_CHECK_EVENT) public void handleEvent(MotechEvent event) { if (settingService.isPasswordResetReminderEnabled()) { LOGGER.info("Daily password reset reminder triggered"); final int passwordExpirationInDays = settingService.getNumberOfDaysToChangePassword(); final int daysBeforeExpirationToSendReminder = settingService.getNumberOfDaysForReminder(); final int daysWithNoPassChangeForReminder = passwordExpirationInDays - daysBeforeExpirationToSendReminder; for (MotechUser user : allUsers.retrieveAll()) { final int daysWithoutPasswordChange = daysWithoutPasswordChange(user); LOGGER.debug("User {} hasn't changed password in {} days. Notification is being after {} days without" + " password change, {} days before expiration", user.getUserName(), daysWithoutPasswordChange, daysWithNoPassChangeForReminder, daysBeforeExpirationToSendReminder); if (daysWithoutPasswordChange == daysWithNoPassChangeForReminder) { if (StringUtils.isNotBlank(user.getEmail())) { sendPasswordReminderEvent(user, passwordExpirationInDays, daysBeforeExpirationToSendReminder); } else { LOGGER.debug("User {} doesn't have an email address set, skipping sending of reminder", user.getUserName()); } } } } else { LOGGER.info("Daily password reset reminder is disabled, skipping processing of users"); } }  }
PasswordExpirationCheckEventHandler { @MotechListener(subjects = PASSWORD_EXPIRATION_CHECK_EVENT) public void handleEvent(MotechEvent event) { if (settingService.isPasswordResetReminderEnabled()) { LOGGER.info("Daily password reset reminder triggered"); final int passwordExpirationInDays = settingService.getNumberOfDaysToChangePassword(); final int daysBeforeExpirationToSendReminder = settingService.getNumberOfDaysForReminder(); final int daysWithNoPassChangeForReminder = passwordExpirationInDays - daysBeforeExpirationToSendReminder; for (MotechUser user : allUsers.retrieveAll()) { final int daysWithoutPasswordChange = daysWithoutPasswordChange(user); LOGGER.debug("User {} hasn't changed password in {} days. Notification is being after {} days without" + " password change, {} days before expiration", user.getUserName(), daysWithoutPasswordChange, daysWithNoPassChangeForReminder, daysBeforeExpirationToSendReminder); if (daysWithoutPasswordChange == daysWithNoPassChangeForReminder) { if (StringUtils.isNotBlank(user.getEmail())) { sendPasswordReminderEvent(user, passwordExpirationInDays, daysBeforeExpirationToSendReminder); } else { LOGGER.debug("User {} doesn't have an email address set, skipping sending of reminder", user.getUserName()); } } } } else { LOGGER.info("Daily password reset reminder is disabled, skipping processing of users"); } }  @MotechListener(subjects = PASSWORD_EXPIRATION_CHECK_EVENT) void handleEvent(MotechEvent event); @Autowired void setAllUsers(MotechUsersDataService allUsers); @Autowired void setSettingsService(SettingService settingService); @Autowired void setEventRelay(EventRelay eventRelay); }
PasswordExpirationCheckEventHandler { @MotechListener(subjects = PASSWORD_EXPIRATION_CHECK_EVENT) public void handleEvent(MotechEvent event) { if (settingService.isPasswordResetReminderEnabled()) { LOGGER.info("Daily password reset reminder triggered"); final int passwordExpirationInDays = settingService.getNumberOfDaysToChangePassword(); final int daysBeforeExpirationToSendReminder = settingService.getNumberOfDaysForReminder(); final int daysWithNoPassChangeForReminder = passwordExpirationInDays - daysBeforeExpirationToSendReminder; for (MotechUser user : allUsers.retrieveAll()) { final int daysWithoutPasswordChange = daysWithoutPasswordChange(user); LOGGER.debug("User {} hasn't changed password in {} days. Notification is being after {} days without" + " password change, {} days before expiration", user.getUserName(), daysWithoutPasswordChange, daysWithNoPassChangeForReminder, daysBeforeExpirationToSendReminder); if (daysWithoutPasswordChange == daysWithNoPassChangeForReminder) { if (StringUtils.isNotBlank(user.getEmail())) { sendPasswordReminderEvent(user, passwordExpirationInDays, daysBeforeExpirationToSendReminder); } else { LOGGER.debug("User {} doesn't have an email address set, skipping sending of reminder", user.getUserName()); } } } } else { LOGGER.info("Daily password reset reminder is disabled, skipping processing of users"); } }  @MotechListener(subjects = PASSWORD_EXPIRATION_CHECK_EVENT) void handleEvent(MotechEvent event); @Autowired void setAllUsers(MotechUsersDataService allUsers); @Autowired void setSettingsService(SettingService settingService); @Autowired void setEventRelay(EventRelay eventRelay);  }