Search in sources :

Example 1 with HashMapMessage

use of org.cometd.common.HashMapMessage 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));
    }
}
Also used : HashMapMessage(org.cometd.common.HashMapMessage) ServerSession(org.cometd.bayeux.server.ServerSession) ServerMessage(org.cometd.bayeux.server.ServerMessage) HashMapMessage(org.cometd.common.HashMapMessage) Message(org.cometd.bayeux.Message) ArrayList(java.util.ArrayList) Event(org.osgi.service.event.Event) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with HashMapMessage

use of org.cometd.common.HashMapMessage in project ddf by codice.

the class ActivityControllerTest method verifyGetPersistedActivitiesWithMessageData.

private void verifyGetPersistedActivitiesWithMessageData(Map<String, Object> messageData, boolean expectPublish) {
    Message message = new HashMapMessage();
    message.put(Message.DATA_FIELD, messageData);
    List<Map<String, Object>> activities = new ArrayList<>();
    activities.add(testEventProperties);
    ActivityController spyActivityController = spy(activityController);
    doReturn(activities).when(spyActivityController).getActivitiesForUser(anyString());
    // Don't want queuePersistedMessages to start up a new thread.
    doNothing().when(spyActivityController).queuePersistedMessages(any(ServerSession.class), Matchers.<List<Map<String, Object>>>any(), anyString());
    spyActivityController.getPersistedActivities(mockServerSession, message);
    if (expectPublish) {
        verify(spyActivityController, times(1)).queuePersistedMessages(eq(mockServerSession), eq(activities), startsWith(EXPECTED_COMETD_ACTIVITIES_CHANNEL_PREFIX));
    } else {
        verify(spyActivityController, never()).queuePersistedMessages(any(ServerSession.class), Matchers.<List<Map<String, Object>>>any(), anyString());
    }
}
Also used : HashMapMessage(org.cometd.common.HashMapMessage) ServerSession(org.cometd.bayeux.server.ServerSession) ServerMessage(org.cometd.bayeux.server.ServerMessage) HashMapMessage(org.cometd.common.HashMapMessage) Message(org.cometd.bayeux.Message) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Message (org.cometd.bayeux.Message)2 ServerMessage (org.cometd.bayeux.server.ServerMessage)2 ServerSession (org.cometd.bayeux.server.ServerSession)2 HashMapMessage (org.cometd.common.HashMapMessage)2 Event (org.osgi.service.event.Event)1