GOCNotifier extends AuditNotifier { @Override protected boolean sendAdditionalNotification(NotificationContext context) { requireArgument(context != null, "Notification context cannot be null."); super.sendAdditionalNotification(context); return _sendAdditionalNotification(context, NotificationStatus.TRIGGERED); } @Inject  GOCNotifier(MetricService metricService, AnnotationService annotationService, AuditService auditService,
					   SystemConfiguration config, Provider<EntityManager> emf,
					   MonitorService monitorService); @Override String getName(); @Override Properties getNotifierProperties();  }
@Test public void sendAdditionalNotification_testPostGOCNotificationRespCode401RetryAndPass() throws Exception { int[] postNotificationResponseCode = {401, 201}; sendOrClearAdditionalNotification_mockBehaviorHappyCaseTemplate(); when(httpResponseStatusLine.getStatusCode()).thenReturn(postNotificationResponseCode[0]) .thenReturn(postNotificationResponseCode[1]); notifier = new GOCNotifier(metricService, annotationService, auditService, config, emf, monitorService); boolean result = notifier.sendAdditionalNotification(context); assertTrue(result); sendOrClearAdditionalNotification_verifyMocksTemplate(2, 0, 1, 1, true); }
@Test public void sendAdditionalNotification_testPostGOCNotificationRespCode401RetryMaxTimes() throws Exception { int postNotificationResponseCode = 401; sendOrClearAdditionalNotification_mockBehaviorHappyCaseTemplate(); when(httpResponseStatusLine.getStatusCode()).thenReturn(postNotificationResponseCode); notifier = new GOCNotifier(metricService, annotationService, auditService, config, emf, monitorService); boolean result = notifier.sendAdditionalNotification(context); assertFalse(result); sendOrClearAdditionalNotification_verifyMocksTemplate(MAX_ATTEMPTS_GOC_POST, 0, 2, MAX_ATTEMPTS_GOC_POST, false); }
@Test public void sendAdditionalNotification_testPostGOCNotificationRespCode500RetryAndPass() throws Exception { int[] postNotificationResponseCode = {500, 201}; sendOrClearAdditionalNotification_mockBehaviorHappyCaseTemplate(); when(httpResponseStatusLine.getStatusCode()).thenReturn(postNotificationResponseCode[0]) .thenReturn(postNotificationResponseCode[1]); notifier = new GOCNotifier(metricService, annotationService, auditService, config, emf, monitorService); boolean result = notifier.sendAdditionalNotification(context); assertTrue(result); sendOrClearAdditionalNotification_verifyMocksTemplate(2, 0, 0, 1, true); }
@Test public void sendAdditionalNotification_testPostGOCNotificationRespCode500RetryMaxTimes() throws Exception { int postNotificationResponseCode = 500; sendOrClearAdditionalNotification_mockBehaviorHappyCaseTemplate(); when(httpResponseStatusLine.getStatusCode()).thenReturn(postNotificationResponseCode); notifier = new GOCNotifier(metricService, annotationService, auditService, config, emf, monitorService); boolean result = notifier.sendAdditionalNotification(context); assertFalse(result); sendOrClearAdditionalNotification_verifyMocksTemplate(MAX_ATTEMPTS_GOC_POST, 0, 0, MAX_ATTEMPTS_GOC_POST, false); }
@Test public void sendAdditionalNotification_testSocketTimeoutExceptionRetryAndPass() throws Exception { sendOrClearAdditionalNotification_mockBehaviorHappyCaseTemplate(); when(httpClient.execute(any())).thenThrow(new SocketTimeoutException()) .thenReturn(httpResponse); when(httpResponseStatusLine.getStatusCode()).thenReturn(201); notifier = new GOCNotifier(metricService, annotationService, auditService, config, emf, monitorService); boolean result = notifier.sendAdditionalNotification(context); assertTrue(result); sendOrClearAdditionalNotification_verifyMocksTemplate(2, 1, 0, 0, true); }
@Test public void sendAdditionalNotification_testSocketTimeoutExceptionRetryMaxTimes() throws Exception { sendOrClearAdditionalNotification_mockBehaviorHappyCaseTemplate(); when(httpClient.execute(any())).thenThrow(new SocketTimeoutException()); notifier = new GOCNotifier(metricService, annotationService, auditService, config, emf, monitorService); boolean result = notifier.sendAdditionalNotification(context); assertFalse(result); sendOrClearAdditionalNotification_verifyMocksTemplate(MAX_ATTEMPTS_GOC_POST, 3, 0, 0, false); }
@Test public void sendAdditionalNotification_testRespCode400AuthHeaderFailRetryMaxTimes() throws Exception { int postNotificationResponseCode = 400; sendOrClearAdditionalNotification_mockBehaviorHappyCaseTemplate(); when(httpResponseStatusLine.getStatusCode()).thenReturn(postNotificationResponseCode); when(EntityUtils.toString(any())).thenReturn("[{\"message\":\"INVALID_HEADER_TYPE\", \"errorCode\":\"INVALID_AUTH_HEADER\"}]"); notifier = new GOCNotifier(metricService, annotationService, auditService, config, emf, monitorService); boolean result = notifier.sendAdditionalNotification(context); assertFalse(result); sendOrClearAdditionalNotification_verifyMocksTemplate(MAX_ATTEMPTS_GOC_POST, 0, 2, MAX_ATTEMPTS_GOC_POST, false); }