EmailNotifier extends AuditNotifier { protected String getEmailSubject(NotificationContext context) { String subject = context.getNotification().getEmailSubject(); if (StringUtils.isBlank(subject)) { subject = generateDefaultEmailSubjectTemplate(context); } return TemplateReplacer.applyTemplateChanges(context, subject); } @Inject  EmailNotifier(MetricService metricService, AnnotationService annotationService, AuditService auditService,
                         MailService mailService, SystemConfiguration config, Provider<EntityManager> emf); @Override String getName();  }
@Test public void getEmailSubject_testDefaultValueWithOnly1Trigger1Notification() { String subjectTemplate = "[Argus] Notification for Alert: ${alert.name}"; String expectedSubject = TemplateReplacer.applyTemplateChanges(notificationContext, subjectTemplate); String subject = emailNotifier.getEmailSubject(notificationContext); assertEquals(expectedSubject, subject); notificationContext.getNotification().setEmailSubject(" "); subject = emailNotifier.getEmailSubject(notificationContext); assertEquals(expectedSubject, subject); }
@Test public void getEmailSubject_testDefaultValueWith2Triggers2Notifications() { Alert alert = notificationContext.getAlert(); Trigger trigger2 = getTrigger(alert, TRIGGER_TYPE, TRIGGER_NAME2, TRIGGER_THRESHOLD2, TRIGGER_INERTIA_MILLIS); alert.setTriggers(Arrays.asList(notificationContext.getTrigger(), trigger2)); Notification notification2 = getNotification("name2", EMAIL_NOTIFIER_NAME, alert, SUBSCRIPTION_LIST); alert.setNotifications(Arrays.asList(notificationContext.getNotification(), notification2)); String subjectTemplate = "[Argus] Notification for Alert: ${alert.name} Notification: ${notification.name} Trigger:${trigger.name}"; String expectedSubject = TemplateReplacer.applyTemplateChanges(notificationContext, subjectTemplate); String subject = emailNotifier.getEmailSubject(notificationContext); assertEquals(expectedSubject, subject); }
@Test public void getEmailSubject_testDefaultValueWith2Notifications() { Alert alert = notificationContext.getAlert(); Notification notification2 = getNotification("name2", EMAIL_NOTIFIER_NAME, alert, SUBSCRIPTION_LIST); alert.setNotifications(Arrays.asList(notificationContext.getNotification(), notification2)); String subjectTemplate = "[Argus] Notification for Alert: ${alert.name} Notification: ${notification.name}"; String expectedSubject = TemplateReplacer.applyTemplateChanges(notificationContext, subjectTemplate); String subject = emailNotifier.getEmailSubject(notificationContext); assertEquals(expectedSubject, subject); }
@Test public void getEmailSubject_testDefaultValueWith2Triggers() { Alert alert = notificationContext.getAlert(); Trigger trigger2 = getTrigger(alert, TRIGGER_TYPE, TRIGGER_NAME2, TRIGGER_THRESHOLD2, TRIGGER_INERTIA_MILLIS); alert.setTriggers(Arrays.asList(notificationContext.getTrigger(), trigger2)); String subjectTemplate = "[Argus] Notification for Alert: ${alert.name} Trigger:${trigger.name}"; String expectedSubject = TemplateReplacer.applyTemplateChanges(notificationContext, subjectTemplate); String subject = emailNotifier.getEmailSubject(notificationContext); assertEquals(expectedSubject, subject); }
@Test public void getEmailSubject_test() { String expectedSubject = "TEST SUBJECT"; notificationContext.getNotification().setEmailSubject(expectedSubject); String subject = emailNotifier.getEmailSubject(notificationContext); assertEquals(expectedSubject, subject); }