@Test public void testSendingMailDefaults() { String fromAddress = "snidley.whiplash@gmail.com"; Mockito .when( configuration .getPropertyString( BasicMailAlertNotifier.CONFIGURATION_INTERACTIVESPACES_SERVICE_ALERT_NOTIFIER_MAIL_FROM)) .thenReturn(fromAddress); String toAddress = "dudley.doright@gmail.com"; Mockito .when( configuration .getPropertyString(BasicMailAlertNotifier.CONFIGURATION_INTERACTIVESPACES_SERVICE_ALERT_NOTIFIER_MAIL_TO)) .thenReturn(toAddress); String subject = "But Nell..."; Mockito .when( configuration .getPropertyString(BasicMailAlertNotifier.CONFIGURATION_INTERACTIVESPACES_SERVICE_ALERT_NOTIFIER_MAIL_SUBJECT)) .thenReturn(subject); String alertType = "kiwi"; String id = "orange"; String message = "mango"; ArgumentCaptor<MailMessage> argument = ArgumentCaptor.forClass(MailMessage.class); notifier.notify(alertType, id, message); Mockito.verify(mailSenderService).sendMailMessage(argument.capture()); assertEquals(fromAddress, argument.getValue().getFromAddress()); assertEquals(toAddress, argument.getValue().getToAdresses().get(0)); assertEquals(subject, argument.getValue().getSubject()); assertEquals(message, argument.getValue().getBody()); }
@Override public void notify(String alertType, String id, String message) { try { Configuration config = getSpaceEnvironment().getSystemConfiguration(); ComposableMailMessage mail = new SimpleMailMessage(); try { addToAddresses(alertType, mail, config); addFromAddress(alertType, mail, config); addSubject(alertType, mail, config); } catch (SimpleInteractiveSpacesException e) { getSpaceEnvironment().getLog().warn(e.getCompoundMessage()); getSpaceEnvironment().getLog().warn( String.format("Email alert failed for alert type %s, id %s, message %s", alertType, id, message)); return; } mail.setBody(message); mailSenderService.sendMailMessage(mail); } catch (Throwable e) { getSpaceEnvironment().getLog().error( String.format("Email alert for alert type %s, id %s, message %s", alertType, id, message), e); } }
BasicMailAlertNotifier extends BaseSupportedService implements AlertNotifier { @Override public void notify(String alertType, String id, String message) { try { Configuration config = getSpaceEnvironment().getSystemConfiguration(); ComposableMailMessage mail = new SimpleMailMessage(); try { addToAddresses(alertType, mail, config); addFromAddress(alertType, mail, config); addSubject(alertType, mail, config); } catch (SimpleInteractiveSpacesException e) { getSpaceEnvironment().getLog().warn(e.getCompoundMessage()); getSpaceEnvironment().getLog().warn( String.format("Email alert failed for alert type %s, id %s, message %s", alertType, id, message)); return; } mail.setBody(message); mailSenderService.sendMailMessage(mail); } catch (Throwable e) { getSpaceEnvironment().getLog().error( String.format("Email alert for alert type %s, id %s, message %s", alertType, id, message), e); } } }
BasicMailAlertNotifier extends BaseSupportedService implements AlertNotifier { @Override public void notify(String alertType, String id, String message) { try { Configuration config = getSpaceEnvironment().getSystemConfiguration(); ComposableMailMessage mail = new SimpleMailMessage(); try { addToAddresses(alertType, mail, config); addFromAddress(alertType, mail, config); addSubject(alertType, mail, config); } catch (SimpleInteractiveSpacesException e) { getSpaceEnvironment().getLog().warn(e.getCompoundMessage()); getSpaceEnvironment().getLog().warn( String.format("Email alert failed for alert type %s, id %s, message %s", alertType, id, message)); return; } mail.setBody(message); mailSenderService.sendMailMessage(mail); } catch (Throwable e) { getSpaceEnvironment().getLog().error( String.format("Email alert for alert type %s, id %s, message %s", alertType, id, message), e); } } BasicMailAlertNotifier(AlertService alertService, MailSenderService mailSenderService); }
BasicMailAlertNotifier extends BaseSupportedService implements AlertNotifier { @Override public void notify(String alertType, String id, String message) { try { Configuration config = getSpaceEnvironment().getSystemConfiguration(); ComposableMailMessage mail = new SimpleMailMessage(); try { addToAddresses(alertType, mail, config); addFromAddress(alertType, mail, config); addSubject(alertType, mail, config); } catch (SimpleInteractiveSpacesException e) { getSpaceEnvironment().getLog().warn(e.getCompoundMessage()); getSpaceEnvironment().getLog().warn( String.format("Email alert failed for alert type %s, id %s, message %s", alertType, id, message)); return; } mail.setBody(message); mailSenderService.sendMailMessage(mail); } catch (Throwable e) { getSpaceEnvironment().getLog().error( String.format("Email alert for alert type %s, id %s, message %s", alertType, id, message), e); } } BasicMailAlertNotifier(AlertService alertService, MailSenderService mailSenderService); @Override String getName(); @Override void startup(); @Override void shutdown(); @Override void notify(String alertType, String id, String message); }
BasicMailAlertNotifier extends BaseSupportedService implements AlertNotifier { @Override public void notify(String alertType, String id, String message) { try { Configuration config = getSpaceEnvironment().getSystemConfiguration(); ComposableMailMessage mail = new SimpleMailMessage(); try { addToAddresses(alertType, mail, config); addFromAddress(alertType, mail, config); addSubject(alertType, mail, config); } catch (SimpleInteractiveSpacesException e) { getSpaceEnvironment().getLog().warn(e.getCompoundMessage()); getSpaceEnvironment().getLog().warn( String.format("Email alert failed for alert type %s, id %s, message %s", alertType, id, message)); return; } mail.setBody(message); mailSenderService.sendMailMessage(mail); } catch (Throwable e) { getSpaceEnvironment().getLog().error( String.format("Email alert for alert type %s, id %s, message %s", alertType, id, message), e); } } BasicMailAlertNotifier(AlertService alertService, MailSenderService mailSenderService); @Override String getName(); @Override void startup(); @Override void shutdown(); @Override void notify(String alertType, String id, String message); static final String CONFIGURATION_PREFIX_INTERACTIVESPACES_SERVICE_ALERT_NOTIFIER_MAIL; static final String CONFIGURATION_INTERACTIVESPACES_SERVICE_ALERT_NOTIFIER_MAIL_TO; static final String CONFIGURATION_INTERACTIVESPACES_SERVICE_ALERT_NOTIFIER_MAIL_FROM; static final String CONFIGURATION_INTERACTIVESPACES_SERVICE_ALERT_NOTIFIER_MAIL_SUBJECT; static final String NAME; }