Search in sources :

Example 16 with MessageHeader

use of org.finra.herd.model.dto.MessageHeader in project herd by FINRAOS.

the class PublishNotificationMessagesAdviceTest method testPublishNotificationMessagesDatabaseException.

@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());
}
Also used : NotificationMessage(org.finra.herd.model.dto.NotificationMessage) AmazonServiceException(com.amazonaws.AmazonServiceException) MessageHeader(org.finra.herd.model.dto.MessageHeader) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest) Test(org.junit.Test)

Aggregations

MessageHeader (org.finra.herd.model.dto.MessageHeader)16 NotificationMessage (org.finra.herd.model.dto.NotificationMessage)13 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)4 ProceedingJoinPoint (org.aspectj.lang.ProceedingJoinPoint)4 MessageHeaderDefinition (org.finra.herd.model.api.xml.MessageHeaderDefinition)4 NotificationMessageDefinition (org.finra.herd.model.api.xml.NotificationMessageDefinition)4 NotificationMessageDefinitions (org.finra.herd.model.api.xml.NotificationMessageDefinitions)4 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)4 AmazonServiceException (com.amazonaws.AmazonServiceException)2 AwsParamsDto (org.finra.herd.model.dto.AwsParamsDto)2 NotificationMessageEntity (org.finra.herd.model.jpa.NotificationMessageEntity)2 PublishResult (com.amazonaws.services.sns.model.PublishResult)1 SendMessageResult (com.amazonaws.services.sqs.model.SendMessageResult)1 IOException (java.io.IOException)1 LogLevel (org.finra.herd.core.helper.LogLevel)1 BusinessObjectDataInvalidateUnregisteredRequest (org.finra.herd.model.api.xml.BusinessObjectDataInvalidateUnregisteredRequest)1 BusinessObjectFormatKey (org.finra.herd.model.api.xml.BusinessObjectFormatKey)1 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)1 ConfigurationEntity (org.finra.herd.model.jpa.ConfigurationEntity)1