use of org.osgi.service.event.Event in project ddf by codice.
the class NotificationControllerTest method verifyGetPersistedNotificationsWithMessageData.
private void verifyGetPersistedNotificationsWithMessageData(Map<String, Object> messageData, boolean notificationPublished) {
Message message = new HashMapMessage();
message.put(Message.DATA_FIELD, messageData);
List<Map<String, Object>> notifications = new ArrayList<>();
notifications.add(testEventProperties);
NotificationController spyNotificationController = spy(notificationController);
doReturn(notifications).when(spyNotificationController).getNotificationsForUser(anyString());
// Don't want queuePersistedMessages to start up a new thread.
doNothing().when(spyNotificationController).queuePersistedMessages(any(ServerSession.class), Matchers.<List<Map<String, Object>>>any(), anyString());
spyNotificationController.getPersistedNotifications(mockServerSession, message);
if (notificationPublished) {
ArgumentCaptor<Event> eventArgumentCaptor = ArgumentCaptor.forClass(Event.class);
verify(spyNotificationController.eventAdmin, times(1)).postEvent(eventArgumentCaptor.capture());
Event event = eventArgumentCaptor.getValue();
assertThat(event.getProperty(Notification.NOTIFICATION_KEY_APPLICATION), is(MOCK_APPLICATION));
assertThat(event.getProperty(Notification.NOTIFICATION_KEY_MESSAGE), is(MOCK_MESSAGE));
assertThat(event.getProperty(Notification.NOTIFICATION_KEY_TIMESTAMP), is(ISODateTimeFormat.dateTime().print(MOCK_TIMESTAMP)));
assertThat(event.getProperty(Notification.NOTIFICATION_KEY_TITLE), is(MOCK_TITLE));
assertThat(event.getProperty(Notification.NOTIFICATION_KEY_SESSION_ID), is(MOCK_SESSION_ID));
assertThat(event.getProperty(Notification.NOTIFICATION_KEY_USER_ID), is(MOCK_SESSION_ID));
} else {
verify(spyNotificationController, times(1)).queuePersistedMessages(eq(mockServerSession), eq(notifications), startsWith(EXPECTED_COMETD_NOTIFICATIONS_CHANNEL_PREFIX));
}
}
use of org.osgi.service.event.Event in project ddf by codice.
the class NotificationControllerTest method testHandleEventThrowsIllegalArgumentExceptionOnNullTitle.
/**
* Test method for {@link NotificationController#handleEvent(org.osgi.service.event.Event)}
* <p>
* Verifies that {@code IllegalArgumentException} is thrown when {@code Event}'s
* {@link Notification#NOTIFICATION_KEY_TITLE} property is null.
*/
@Test(expected = IllegalArgumentException.class)
public void testHandleEventThrowsIllegalArgumentExceptionOnNullTitle() {
testEventProperties.put(Notification.NOTIFICATION_KEY_TITLE, null);
notificationController.handleEvent(new Event(Notification.NOTIFICATION_TOPIC_BROADCAST, testEventProperties));
}
use of org.osgi.service.event.Event in project ddf by codice.
the class NotificationControllerTest method testHandleEventThrowsIllegalArgumentExceptionOnNullUserAndSessionId.
/**
* Test method for {@link NotificationController#handleEvent(org.osgi.service.event.Event)}
* <p>
* Verifies that {@code IllegalArgumentException} is thrown when {@code Event}'s
* {@link Notification#NOTIFICATION_KEY_USER_ID} and
* {@link Notification#NOTIFICATION_KEY_SESSION_ID} properties are null.
*/
@Test(expected = IllegalArgumentException.class)
public void testHandleEventThrowsIllegalArgumentExceptionOnNullUserAndSessionId() {
testEventProperties.put(Notification.NOTIFICATION_KEY_USER_ID, null);
testEventProperties.put(Notification.NOTIFICATION_KEY_SESSION_ID, null);
notificationController.handleEvent(new Event(Notification.NOTIFICATION_TOPIC_BROADCAST, testEventProperties));
}
use of org.osgi.service.event.Event in project ddf by codice.
the class NotificationControllerTest method testHandleEventThrowsIllegalArgumentExceptionOnEmptyUserAndSessionId.
/**
* Test method for {@link NotificationController#handleEvent(org.osgi.service.event.Event)}
* <p>
* Verifies that {@code IllegalArgumentException} is thrown when {@code Event}'s
* {@link Notification#NOTIFICATION_KEY_USER_ID} and
* {@link Notification#NOTIFICATION_KEY_SESSION_ID} properties are null.
*/
@Test(expected = IllegalArgumentException.class)
public void testHandleEventThrowsIllegalArgumentExceptionOnEmptyUserAndSessionId() {
testEventProperties.put(Notification.NOTIFICATION_KEY_USER_ID, "");
testEventProperties.put(Notification.NOTIFICATION_KEY_SESSION_ID, "");
notificationController.handleEvent(new Event(Notification.NOTIFICATION_TOPIC_BROADCAST, testEventProperties));
}
use of org.osgi.service.event.Event in project ddf by codice.
the class NotificationControllerTest method testHandleEventThrowsIllegalArgumentExceptionOnNullMessage.
/**
* Test method for {@link NotificationController#handleEvent(org.osgi.service.event.Event)}
* <p>
* Verifies that {@code IllegalArgumentException} is thrown when {@code Event}'s
* {@link Notification#NOTIFICATION_KEY_MESSAGE} property is null.
*/
@Test(expected = IllegalArgumentException.class)
public void testHandleEventThrowsIllegalArgumentExceptionOnNullMessage() {
testEventProperties.put(Notification.NOTIFICATION_KEY_MESSAGE, null);
notificationController.handleEvent(new Event(Notification.NOTIFICATION_TOPIC_BROADCAST, testEventProperties));
}
Aggregations