GusNotifier extends AuditNotifier { @Override protected boolean sendAdditionalNotification(NotificationContext context) { requireArgument(context != null, "Notification context cannot be null."); if (!super.sendAdditionalNotification(context)){ return false; } return sendGusNotification(context, NotificationStatus.TRIGGERED); } @Inject  GusNotifier(MetricService metricService, AnnotationService annotationService, AuditService auditService,
                            SystemConfiguration config, Provider<EntityManager> emf, MonitorService monitorService); @Override String getName(); boolean postToGus(History history,
                             Set<String> to,
                             String feed,
                             SystemConfiguration config,
                             NotificationContext context); @Override Properties getNotifierProperties();  }
@Test public void sendAdditionalNotification_testGusPostFailThenRetryAndPass() throws Exception { int[] postNotificationResponseCode = {405, 201}; sendOrClearAdditionalNotification_mockBehaviorHappyCaseTemplate(); when(httpResponseStatusLine.getStatusCode()).thenReturn(postNotificationResponseCode[0]) .thenReturn(postNotificationResponseCode[1]); when(EntityUtils.toString(any())).thenReturn("[{\"message\": \"BLAH\", \"errorCode\": \"BLAH2\"}]"); notifier = new GusNotifier(metricService, annotationService, auditService, config, emf, monitorService); boolean result = notifier.sendAdditionalNotification(context); assertTrue(result); sendOrClearAdditionalNotification_verifyGusPostMethodMockTemplate(2, 0, 1, true); }
@Test public void sendAdditionalNotification_testGusPostFailRetryMaxTimes() throws Exception { int postNotificationResponseCode = 404; sendOrClearAdditionalNotification_mockBehaviorHappyCaseTemplate(); when(httpResponseStatusLine.getStatusCode()).thenReturn(postNotificationResponseCode); when(EntityUtils.toString(any())).thenReturn("[{\"message\": \"BLAH\", \"errorCode\": \"BLAH2\"}]"); notifier = new GusNotifier(metricService, annotationService, auditService, config, emf, monitorService); boolean result = notifier.sendAdditionalNotification(context); assertFalse(result); sendOrClearAdditionalNotification_verifyGusPostMethodMockTemplate(MAX_ATTEMPTS_GUS_POST, 0, MAX_ATTEMPTS_GUS_POST, false); }
@Test public void sendAdditionalNotification_testAuthHeaderFailThenRetryAndPass() throws Exception { int[] postNotificationResponseCode = {404, 201}; sendOrClearAdditionalNotification_mockBehaviorHappyCaseTemplate(); when(httpResponseStatusLine.getStatusCode()).thenReturn(postNotificationResponseCode[0]) .thenReturn(postNotificationResponseCode[1]); when(EntityUtils.toString(any())).thenReturn("[{\"message\":\"INVALID_HEADER_TYPE\",\"errorCode\":\"INVALID_AUTH_HEADER\"}]"); notifier = new GusNotifier(metricService, annotationService, auditService, config, emf, monitorService); boolean result = notifier.sendAdditionalNotification(context); assertTrue(result); sendOrClearAdditionalNotification_verifyGusPostMethodMockTemplate(2, 1, 1, true); }
@Test public void sendAdditionalNotification_testAuthHeaderFailRetryMaxTimes() throws Exception { int postNotificationResponseCode = 404; sendOrClearAdditionalNotification_mockBehaviorHappyCaseTemplate(); when(httpResponseStatusLine.getStatusCode()).thenReturn(postNotificationResponseCode); when(EntityUtils.toString(any())).thenReturn("[{\"message\":\"INVALID_HEADER_TYPE\",\"errorCode\":\"INVALID_AUTH_HEADER\"}]"); notifier = new GusNotifier(metricService, annotationService, auditService, config, emf, monitorService); boolean result = notifier.sendAdditionalNotification(context); assertFalse(result); sendOrClearAdditionalNotification_verifyGusPostMethodMockTemplate(MAX_ATTEMPTS_GUS_POST, 2, MAX_ATTEMPTS_GUS_POST, false); }