Search in sources :

Example 46 with Event

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));
    }
}
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 47 with Event

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));
}
Also used : Event(org.osgi.service.event.Event) Test(org.junit.Test)

Example 48 with Event

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));
}
Also used : Event(org.osgi.service.event.Event) Test(org.junit.Test)

Example 49 with Event

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));
}
Also used : Event(org.osgi.service.event.Event) Test(org.junit.Test)

Example 50 with Event

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));
}
Also used : Event(org.osgi.service.event.Event) Test(org.junit.Test)

Aggregations

Event (org.osgi.service.event.Event)142 Test (org.junit.Test)79 HashMap (java.util.HashMap)48 Hashtable (java.util.Hashtable)44 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)23 ContentTypePredicate (ddf.catalog.pubsub.predicate.ContentTypePredicate)20 EventAdmin (org.osgi.service.event.EventAdmin)19 GeospatialPredicate (ddf.catalog.pubsub.predicate.GeospatialPredicate)18 Predicate (ddf.catalog.pubsub.predicate.Predicate)16 ArrayList (java.util.ArrayList)16 ActivityEvent (org.codice.ddf.activities.ActivityEvent)13 EventHandler (org.osgi.service.event.EventHandler)13 SubscriptionFilterVisitor (ddf.catalog.pubsub.internal.SubscriptionFilterVisitor)11 Date (java.util.Date)11 Job (org.apache.sling.event.jobs.Job)9 Map (java.util.Map)8 List (java.util.List)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 JobManager (org.apache.sling.event.jobs.JobManager)7 JobConsumer (org.apache.sling.event.jobs.consumer.JobConsumer)7