Search in sources :

Example 11 with MessageHeader

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

the class NotificationMessagePublishingServiceTest method testPublishNotificationMessage.

@Test
public void testPublishNotificationMessage() {
    // Publish a notification message with SQS message type.
    notificationMessagePublishingService.publishNotificationMessage(new NotificationMessage(MessageTypeEntity.MessageEventTypes.SQS.name(), MESSAGE_DESTINATION, MESSAGE_TEXT, Collections.singletonList(new MessageHeader(KEY, VALUE))));
    // Publish a notification message with SNS message type.
    notificationMessagePublishingService.publishNotificationMessage(new NotificationMessage(MessageTypeEntity.MessageEventTypes.SNS.name(), MESSAGE_DESTINATION, MESSAGE_TEXT, Collections.singletonList(new MessageHeader(KEY, VALUE))));
}
Also used : NotificationMessage(org.finra.herd.model.dto.NotificationMessage) MessageHeader(org.finra.herd.model.dto.MessageHeader) Test(org.junit.Test)

Example 12 with MessageHeader

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

the class NotificationMessagePublishingServiceTest method testAddNotificationMessageToDatabaseQueue.

@Test
public void testAddNotificationMessageToDatabaseQueue() {
    // Create a message type entity.
    messageTypeDaoTestHelper.createMessageTypeEntity(MESSAGE_TYPE);
    // Create a message header.
    List<MessageHeader> messageHeaders = Collections.singletonList(new MessageHeader(KEY, VALUE));
    // Create a notification message.
    NotificationMessage notificationMessage = new NotificationMessage(MESSAGE_TYPE, MESSAGE_DESTINATION, MESSAGE_TEXT, messageHeaders);
    // Add a notification message to the database queue.
    notificationMessagePublishingService.addNotificationMessageToDatabaseQueue(notificationMessage);
    // Retrieve the oldest notification message from the database queue.
    NotificationMessageEntity notificationMessageEntity = notificationMessageDao.getOldestNotificationMessage();
    // Validate the results.
    assertNotNull(notificationMessageEntity);
    assertEquals(MESSAGE_TYPE, notificationMessageEntity.getMessageType().getCode());
    assertEquals(MESSAGE_DESTINATION, notificationMessageEntity.getMessageDestination());
    assertEquals(MESSAGE_TEXT, notificationMessageEntity.getMessageText());
    assertEquals(jsonHelper.objectToJson(messageHeaders), notificationMessageEntity.getMessageHeaders());
}
Also used : NotificationMessage(org.finra.herd.model.dto.NotificationMessage) NotificationMessageEntity(org.finra.herd.model.jpa.NotificationMessageEntity) MessageHeader(org.finra.herd.model.dto.MessageHeader) Test(org.junit.Test)

Example 13 with MessageHeader

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

the class DefaultNotificationMessageBuilder method buildBusinessObjectDataStatusChangeMessages.

@Override
public List<NotificationMessage> buildBusinessObjectDataStatusChangeMessages(BusinessObjectDataKey businessObjectDataKey, String newBusinessObjectDataStatus, String oldBusinessObjectDataStatus) {
    // Create a result list.
    List<NotificationMessage> notificationMessages = new ArrayList<>();
    // Get notification message definitions.
    NotificationMessageDefinitions notificationMessageDefinitions = configurationDaoHelper.getXmlClobPropertyAndUnmarshallToObject(NotificationMessageDefinitions.class, ConfigurationValue.HERD_NOTIFICATION_BUSINESS_OBJECT_DATA_STATUS_CHANGE_MESSAGE_DEFINITIONS.getKey());
    // Continue processing if notification message definitions are configured.
    if (notificationMessageDefinitions != null && CollectionUtils.isNotEmpty(notificationMessageDefinitions.getNotificationMessageDefinitions())) {
        // Create a context map of values that can be used when building the message.
        Map<String, Object> velocityContextMap = getBusinessObjectDataStatusChangeMessageVelocityContextMap(businessObjectDataKey, newBusinessObjectDataStatus, oldBusinessObjectDataStatus);
        // Generate notification message for each notification message definition.
        for (NotificationMessageDefinition notificationMessageDefinition : notificationMessageDefinitions.getNotificationMessageDefinitions()) {
            // Validate the notification message type.
            if (StringUtils.isBlank(notificationMessageDefinition.getMessageType())) {
                throw new IllegalStateException(String.format("Notification message type must be specified. Please update \"%s\" configuration entry.", ConfigurationValue.HERD_NOTIFICATION_BUSINESS_OBJECT_DATA_STATUS_CHANGE_MESSAGE_DEFINITIONS.getKey()));
            }
            // Validate the notification message destination.
            if (StringUtils.isBlank(notificationMessageDefinition.getMessageDestination())) {
                throw new IllegalStateException(String.format("Notification message destination must be specified. Please update \"%s\" configuration entry.", ConfigurationValue.HERD_NOTIFICATION_BUSINESS_OBJECT_DATA_STATUS_CHANGE_MESSAGE_DEFINITIONS.getKey()));
            }
            // Evaluate the template to generate the message text.
            String messageText = evaluateVelocityTemplate(notificationMessageDefinition.getMessageVelocityTemplate(), velocityContextMap, "businessObjectDataStatusChangeEvent");
            // Build a list of optional message headers.
            List<MessageHeader> messageHeaders = new ArrayList<>();
            if (CollectionUtils.isNotEmpty(notificationMessageDefinition.getMessageHeaderDefinitions())) {
                for (MessageHeaderDefinition messageHeaderDefinition : notificationMessageDefinition.getMessageHeaderDefinitions()) {
                    messageHeaders.add(new MessageHeader(messageHeaderDefinition.getKey(), evaluateVelocityTemplate(messageHeaderDefinition.getValueVelocityTemplate(), velocityContextMap, String.format("businessObjectDataStatusChangeEvent_messageHeader_%s", messageHeaderDefinition.getKey()))));
                }
            }
            // Create a notification message and add it to the result list.
            notificationMessages.add(new NotificationMessage(notificationMessageDefinition.getMessageType(), notificationMessageDefinition.getMessageDestination(), messageText, messageHeaders));
        }
    }
    // Return the results.
    return notificationMessages;
}
Also used : NotificationMessageDefinition(org.finra.herd.model.api.xml.NotificationMessageDefinition) NotificationMessageDefinitions(org.finra.herd.model.api.xml.NotificationMessageDefinitions) MessageHeaderDefinition(org.finra.herd.model.api.xml.MessageHeaderDefinition) NotificationMessage(org.finra.herd.model.dto.NotificationMessage) ArrayList(java.util.ArrayList) MessageHeader(org.finra.herd.model.dto.MessageHeader)

Example 14 with MessageHeader

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

the class DefaultNotificationMessageBuilderTest method getExpectedMessageHeaders.

/**
 * Returns a list of expected message headers.
 *
 * @param expectedUuid the expected UUID
 *
 * @return the list of message headers
 */
private List<MessageHeader> getExpectedMessageHeaders(String expectedUuid) {
    List<MessageHeader> messageHeaders = new ArrayList<>();
    messageHeaders.add(new MessageHeader(MESSAGE_HEADER_KEY_ENVIRONMENT, configurationHelper.getProperty(ConfigurationValue.HERD_ENVIRONMENT)));
    messageHeaders.add(new MessageHeader(MESSAGE_HEADER_KEY_MESSAGE_TYPE, MESSAGE_TYPE));
    messageHeaders.add(new MessageHeader(MESSAGE_HEADER_KEY_MESSAGE_VERSION, MESSAGE_VERSION));
    messageHeaders.add(new MessageHeader(MESSAGE_HEADER_KEY_SOURCE_SYSTEM, SOURCE_SYSTEM));
    messageHeaders.add(new MessageHeader(MESSAGE_HEADER_KEY_MESSAGE_ID, expectedUuid));
    messageHeaders.add(new MessageHeader(MESSAGE_HEADER_KEY_USER_ID, HerdDaoSecurityHelper.SYSTEM_USER));
    messageHeaders.add(new MessageHeader(MESSAGE_HEADER_KEY_NAMESPACE, BDEF_NAMESPACE));
    return messageHeaders;
}
Also used : ArrayList(java.util.ArrayList) MessageHeader(org.finra.herd.model.dto.MessageHeader)

Example 15 with MessageHeader

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

the class PublishNotificationMessagesAdviceTest method testPublishNotificationMessagesAmazonServiceException.

@Test
public void testPublishNotificationMessagesAmazonServiceException() 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);
    // 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