Search in sources :

Example 6 with NotificationMessageEntity

use of org.finra.herd.model.jpa.NotificationMessageEntity in project herd by FINRAOS.

the class NotificationMessagePublishingServiceTest method testAddNotificationMessageToDatabaseQueueNoMessageHeaders.

@Test
public void testAddNotificationMessageToDatabaseQueueNoMessageHeaders() {
    // Create a message type entity.
    messageTypeDaoTestHelper.createMessageTypeEntity(MESSAGE_TYPE);
    // Create a notification message without message headers.
    NotificationMessage notificationMessage = new NotificationMessage(MESSAGE_TYPE, MESSAGE_DESTINATION, MESSAGE_TEXT, NO_MESSAGE_HEADERS);
    // 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());
    assertNull(notificationMessageEntity.getMessageHeaders());
}
Also used : NotificationMessage(org.finra.herd.model.dto.NotificationMessage) NotificationMessageEntity(org.finra.herd.model.jpa.NotificationMessageEntity) Test(org.junit.Test)

Example 7 with NotificationMessageEntity

use of org.finra.herd.model.jpa.NotificationMessageEntity in project herd by FINRAOS.

the class NotificationMessagePublishingServiceTest method testPublishOldestNotificationMessageFromDatabaseQueueAwsServiceException.

@Test
public void testPublishOldestNotificationMessageFromDatabaseQueueAwsServiceException() {
    // Prepare database entries required for testing.
    NotificationMessageEntity notificationMessageEntity = notificationMessageDaoTestHelper.createNotificationMessageEntity(MessageTypeEntity.MessageEventTypes.SQS.name(), MockSqsOperationsImpl.MOCK_SQS_QUEUE_NOT_FOUND_NAME, MESSAGE_TEXT);
    // Try to publish notification message.
    try {
        notificationMessagePublishingService.publishOldestNotificationMessageFromDatabaseQueue();
        fail();
    } catch (IllegalStateException e) {
        assertEquals(String.format("AWS SQS queue with \"%s\" name not found.", MockSqsOperationsImpl.MOCK_SQS_QUEUE_NOT_FOUND_NAME), e.getMessage());
    }
    // Check that the test notification message is still the oldest message in the database queue.
    assertEquals(notificationMessageDao.getOldestNotificationMessage(), notificationMessageEntity);
}
Also used : NotificationMessageEntity(org.finra.herd.model.jpa.NotificationMessageEntity) Test(org.junit.Test)

Example 8 with NotificationMessageEntity

use of org.finra.herd.model.jpa.NotificationMessageEntity 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 9 with NotificationMessageEntity

use of org.finra.herd.model.jpa.NotificationMessageEntity in project herd by FINRAOS.

the class NotificationMessagePublishingServiceImpl method addNotificationMessageToDatabaseQueueImpl.

/**
 * Adds a notification message to the database queue.
 *
 * @param notificationMessage the notification message
 */
protected void addNotificationMessageToDatabaseQueueImpl(NotificationMessage notificationMessage) {
    // Get a message type entity and ensure it exists.
    MessageTypeEntity messageTypeEntity = messageTypeDaoHelper.getMessageTypeEntity(notificationMessage.getMessageType());
    // Create and persist a notification message entity.
    NotificationMessageEntity notificationMessageEntity = new NotificationMessageEntity();
    notificationMessageEntity.setMessageType(messageTypeEntity);
    notificationMessageEntity.setMessageDestination(notificationMessage.getMessageDestination());
    notificationMessageEntity.setMessageText(notificationMessage.getMessageText());
    if (CollectionUtils.isNotEmpty(notificationMessage.getMessageHeaders())) {
        notificationMessageEntity.setMessageHeaders(jsonHelper.objectToJson(notificationMessage.getMessageHeaders()));
    }
    notificationMessageDao.saveAndRefresh(notificationMessageEntity);
}
Also used : NotificationMessageEntity(org.finra.herd.model.jpa.NotificationMessageEntity) MessageTypeEntity(org.finra.herd.model.jpa.MessageTypeEntity)

Aggregations

NotificationMessageEntity (org.finra.herd.model.jpa.NotificationMessageEntity)9 Test (org.junit.Test)5 NotificationMessage (org.finra.herd.model.dto.NotificationMessage)3 MessageHeader (org.finra.herd.model.dto.MessageHeader)2 MessageTypeEntity (org.finra.herd.model.jpa.MessageTypeEntity)2 IOException (java.io.IOException)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1