test_class.declarator: notificationMessageInMemoryQueue
test_class.modifier: @Mock
      private
test_class.original_string: @Mock
      private NotificationMessageInMemoryQueue notificationMessageInMemoryQueue;
test_class.type: NotificationMessageInMemoryQueue
test_class.var_name: notificationMessageInMemoryQueue
test_class.declarator: notificationMessagePublishingService
test_class.modifier: @Mock
      private
test_class.original_string: @Mock
      private NotificationMessagePublishingServiceImpl notificationMessagePublishingService;
test_class.type: NotificationMessagePublishingServiceImpl
test_class.var_name: notificationMessagePublishingService
test_class.declarator: publishNotificationMessagesAdvice
test_class.modifier: @InjectMocks
      private
test_class.original_string: @InjectMocks
      private PublishNotificationMessagesAdvice publishNotificationMessagesAdvice;
test_class.type: PublishNotificationMessagesAdvice
test_class.var_name: publishNotificationMessagesAdvice
test_class.file: herd-code/herd-service/src/test/java/org/finra/herd/service/advice/PublishNotificationMessagesAdviceTest.java
test_class.identifier: PublishNotificationMessagesAdviceTest
test_class.superclass: extends AbstractServiceTest
test_case.body: @Test
      public void testPublishNotificationMessagesDatabaseException() throws Throwable
      {
          // Create a notification message.
          NotificationMessage notificationMessage = new NotificationMessage(MessageTypeEntity.MessageEventTypes.SQS.name(), AWS_SQS_QUEUE_NAME, MESSAGE_TEXT,
              Collections.singletonList(new MessageHeader(KEY, VALUE)));
  
          // Mock a join point of the method call.
          ProceedingJoinPoint joinPoint = getMockedProceedingJoinPoint("testPublishNotificationMessages");
  
          // Mock the external calls.
          doCallRealMethod().when(notificationMessageInMemoryQueue).clear();
          doCallRealMethod().when(notificationMessageInMemoryQueue).add(notificationMessage);
          when(notificationMessageInMemoryQueue.isEmpty()).thenCallRealMethod();
          doCallRealMethod().when(notificationMessageInMemoryQueue).remove();
          doThrow(new AmazonServiceException(ERROR_MESSAGE)).when(notificationMessagePublishingService).publishNotificationMessage(notificationMessage);
          doThrow(new RuntimeException(ERROR_MESSAGE)).when(notificationMessagePublishingService).addNotificationMessageToDatabaseQueue(notificationMessage);
  
          // Clear the queue.
          notificationMessageInMemoryQueue.clear();
  
          // Add the notification message to the queue.
          notificationMessageInMemoryQueue.add(notificationMessage);
  
          // Validate that the queue is not empty now.
          assertFalse(notificationMessageInMemoryQueue.isEmpty());
  
          // Call the method under test.
          publishNotificationMessagesAdvice.publishNotificationMessages(joinPoint);
  
          // Verify the external calls.
          verify(notificationMessageInMemoryQueue, times(2)).clear();
          verify(notificationMessageInMemoryQueue).add(notificationMessage);
          verify(notificationMessageInMemoryQueue, times(3)).isEmpty();
          verify(notificationMessageInMemoryQueue).remove();
          verify(notificationMessagePublishingService).publishNotificationMessage(notificationMessage);
          verify(notificationMessagePublishingService).addNotificationMessageToDatabaseQueue(notificationMessage);
          verifyNoMoreInteractionsHelper();
  
          // Validate the results.
          assertTrue(notificationMessageInMemoryQueue.isEmpty());
      }
test_case.class_method_signature: PublishNotificationMessagesAdviceTest.testPublishNotificationMessagesDatabaseException()
test_case.full_signature: @Test public void testPublishNotificationMessagesDatabaseException()
test_case.identifier: testPublishNotificationMessagesDatabaseException
test_case.invocations: name singletonList getMockedProceedingJoinPoint clear when doCallRealMethod add when doCallRealMethod thenCallRealMethod when isEmpty remove when doCallRealMethod publishNotificationMessage when doThrow addNotificationMessageToDatabaseQueue when doThrow clear add assertFalse isEmpty publishNotificationMessages clear verify times add verify isEmpty verify times remove verify publishNotificationMessage verify addNotificationMessageToDatabaseQueue verify verifyNoMoreInteractionsHelper assertTrue isEmpty
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testPublishNotificationMessagesDatabaseException()
focal_class.declarator: LOGGER = LoggerFactory.getLogger(PublishNotificationMessagesAdvice.class)
focal_class.modifier: private static final
focal_class.original_string: private static final Logger LOGGER = LoggerFactory.getLogger(PublishNotificationMessagesAdvice.class);
focal_class.type: Logger
focal_class.var_name: LOGGER
focal_class.declarator: notificationMessageInMemoryQueue
focal_class.modifier: @Autowired
      private
focal_class.original_string: @Autowired
      private NotificationMessageInMemoryQueue notificationMessageInMemoryQueue;
focal_class.type: NotificationMessageInMemoryQueue
focal_class.var_name: notificationMessageInMemoryQueue
focal_class.declarator: notificationMessagePublishingService
focal_class.modifier: @Autowired
      private
focal_class.original_string: @Autowired
      private NotificationMessagePublishingService notificationMessagePublishingService;
focal_class.type: NotificationMessagePublishingService
focal_class.var_name: notificationMessagePublishingService
focal_class.file: herd-code/herd-service/src/main/java/org/finra/herd/service/advice/PublishNotificationMessagesAdvice.java
focal_class.identifier: PublishNotificationMessagesAdvice
focal_class.class_method_signature: PublishNotificationMessagesAdvice.publishNotificationMessages(ProceedingJoinPoint joinPoint)
focal_class.full_signature: @Around("serviceMethods()") public Object publishNotificationMessages(ProceedingJoinPoint joinPoint)
focal_class.identifier: publishNotificationMessages
focal_class.modifiers: @Around("serviceMethods()") public
focal_class.parameters: (ProceedingJoinPoint joinPoint)
focal_class.return: Object
focal_class.signature: Object publishNotificationMessages(ProceedingJoinPoint joinPoint)
focal_class.superclass: extends AbstractServiceAdvice
focal_method.body: @Around("serviceMethods()")
      public Object publishNotificationMessages(ProceedingJoinPoint joinPoint) throws Throwable
      {
          MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
          Method method = methodSignature.getMethod();
  
          boolean publishNotificationMessages = method.isAnnotationPresent(PublishNotificationMessages.class);
  
          // Proceed to the join point (i.e. call the method and let it return).
          try
          {
              Object returnValue = joinPoint.proceed();
  
              if (publishNotificationMessages)
              {
                  if (LOGGER.isDebugEnabled())
                  {
                      // Get the target class being called.
                      Class<?> targetClass = joinPoint.getTarget().getClass();
  
                      LOGGER.debug("Method is initiating notification message publishing. javaMethod=\"{}.{}\" notificationMessageInMemoryQueueSize={}",
                          targetClass.getName(), methodSignature.getName(), notificationMessageInMemoryQueue.size());
                  }
  
                  // Publish all notification messages stored in the "in-memory" notification message queue.
                  while (!notificationMessageInMemoryQueue.isEmpty())
                  {
                      // Get notification message from the "in-memory" queue.
                      NotificationMessage notificationMessage = notificationMessageInMemoryQueue.remove();
  
                      // Publish the message.
                      try
                      {
                          notificationMessagePublishingService.publishNotificationMessage(notificationMessage);
                      }
                      catch (Exception sqsException)
                      {
                          // On error, add this notification message to the database queue.
                          try
                          {
                              notificationMessagePublishingService.addNotificationMessageToDatabaseQueue(notificationMessage);
                          }
                          catch (Exception dbException)
                          {
                              // Log the error.
                              LOGGER
                                  .error("Failed to add notification message to the database queue. messageType=\"{}\" messageDestination=\"{}\" messageText={}",
                                      notificationMessage.getMessageType(), notificationMessage.getMessageDestination(), notificationMessage.getMessageText(),
                                      dbException);
                          }
                      }
                  }
              }
  
              return returnValue;
          }
          finally
          {
              // Removes all of the elements from the queue, since the thread might be reused from the thread pool.
              if (publishNotificationMessages)
              {
                  notificationMessageInMemoryQueue.clear();
              }
          }
      }
focal_method.class_method_signature: PublishNotificationMessagesAdvice.publishNotificationMessages(ProceedingJoinPoint joinPoint)
focal_method.full_signature: @Around("serviceMethods()") public Object publishNotificationMessages(ProceedingJoinPoint joinPoint)
focal_method.identifier: publishNotificationMessages
focal_method.invocations: getSignature getMethod isAnnotationPresent proceed isDebugEnabled getClass getTarget debug getName getName size isEmpty remove publishNotificationMessage addNotificationMessageToDatabaseQueue error getMessageType getMessageDestination getMessageText clear
focal_method.modifiers: @Around("serviceMethods()") public
focal_method.parameters: (ProceedingJoinPoint joinPoint)
focal_method.return: Object
focal_method.signature: Object publishNotificationMessages(ProceedingJoinPoint joinPoint)