PagerDutyNotifier extends AuditNotifier { @Override protected boolean sendAdditionalNotification(NotificationContext context) { requireArgument(context != null, "Notification context cannot be null."); super.sendAdditionalNotification(context); return sendPagerDutyNotification(context, NotificationStatus.TRIGGERED); } @Inject  PagerDutyNotifier(MetricService metricService, AnnotationService annotationService, AuditService auditService, SystemConfiguration config, Provider<EntityManager> emf,
                             MonitorService monitorService); protected  PagerDutyNotifier(MetricService metricService, AnnotationService annotationService, AuditService auditService,
                                SystemConfiguration config, Provider<EntityManager> emf,
                                MonitorService monitorService, String endpoint, String token, long httpResponseCode429RetryDelayTime); @Override String getName(); @Override Properties getNotifierProperties(); static final ThreadLocal<DateFormat> DATE_FORMAT; }
@Test public void sendAdditionalNotification_testPostPagerDutyNotificationResponseCode202() throws Exception { sendOrClearAdditionalNotification_mockBehaviorTemplate(); when(httpResponseStatusLine.getStatusCode()).thenReturn(202); notifier = new PagerDutyNotifier(metricService, annotationService, auditService, config, emf, monitorService); boolean result = notifier.sendAdditionalNotification(context); assertTrue(result); sendOrClearAdditionalNotification_verifyMocksTemplate(1, 0, 0, result); }
@Test public void sendAdditionalNotification_testPostPagerDutyNotificationResponseCode400() throws Exception { sendOrClearAdditionalNotification_mockBehaviorTemplate(); when(httpResponseStatusLine.getStatusCode()).thenReturn(400); notifier = new PagerDutyNotifier(metricService, annotationService, auditService, config, emf, monitorService); boolean result = notifier.sendAdditionalNotification(context); assertFalse(result); sendOrClearAdditionalNotification_verifyMocksTemplate(1, 0, 1, result); }
@Test public void sendAdditionalNotification_testPostPagerDutyNotificationResponseCode429RetryAndPass() throws Exception { sendOrClearAdditionalNotification_mockBehaviorTemplate(); when(httpResponseStatusLine.getStatusCode()).thenReturn(429).thenReturn(202); notifier = new PagerDutyNotifier(metricService, annotationService, auditService, config, emf, monitorService, properties.getProperty(PAGERDUTY_NOTIFIER_ENDPOINT), properties.getProperty(PAGERDUTY_NOTIFIER_TOKEN), 1L); boolean result = notifier.sendAdditionalNotification(context); assertTrue(result); sendOrClearAdditionalNotification_verifyMocksTemplate(2, 0, 0, result); }
@Test public void sendAdditionalNotification_testPostPagerDutyNotificationResponseCode4XX() throws Exception { sendOrClearAdditionalNotification_mockBehaviorTemplate(); when(httpResponseStatusLine.getStatusCode()).thenReturn(402); notifier = new PagerDutyNotifier(metricService, annotationService, auditService, config, emf, monitorService); boolean result = notifier.sendAdditionalNotification(context); assertFalse(result); sendOrClearAdditionalNotification_verifyMocksTemplate(1, 0, 1, result); }
@Test public void sendAdditionalNotification_testPostPagerDutyNotificationResponseCode500RetryAndPass() throws Exception { sendOrClearAdditionalNotification_mockBehaviorTemplate(); when(httpResponseStatusLine.getStatusCode()).thenReturn(500).thenReturn(202); notifier = new PagerDutyNotifier(metricService, annotationService, auditService, config, emf, monitorService); boolean result = notifier.sendAdditionalNotification(context); assertTrue(result); sendOrClearAdditionalNotification_verifyMocksTemplate(2, 0, 0, result); }
@Test public void sendAdditionalNotification_testPostPagerDutyNotificationThrowsInterruptedIOException() throws Exception { sendOrClearAdditionalNotification_mockBehaviorTemplate(); when(httpClient.execute(any())).thenThrow(new InterruptedIOException("TEST")); notifier = new PagerDutyNotifier(metricService, annotationService, auditService, config, emf, monitorService); boolean result = notifier.sendAdditionalNotification(context); assertFalse(result); sendOrClearAdditionalNotification_verifyMocksTemplate(MAX_POST_ATTEMPTS, MAX_POST_ATTEMPTS, 0, result); }
@Test public void sendAdditionalNotification_testPostPagerDutyNotificationThrowsException() throws Exception { sendOrClearAdditionalNotification_mockBehaviorTemplate(); when(httpClient.execute(any())).thenThrow(new RuntimeException("TEST")); notifier = new PagerDutyNotifier(metricService, annotationService, auditService, config, emf, monitorService); boolean result = notifier.sendAdditionalNotification(context); assertFalse(result); sendOrClearAdditionalNotification_verifyMocksTemplate(1, 1, 0, result); }