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());
}
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);
}
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());
}
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);
}
Aggregations