Search in sources :

Example 41 with Event

use of org.xwiki.eventstream.Event in project xwiki-platform by xwiki.

the class MessageStreamTest method testPostDirectMessageWithLongMessage.

@Test
public void testPostDirectMessageWithLongMessage() throws Exception {
    Event postedMessage = setupForDirectMessage();
    this.stream.postDirectMessageToUser(StringUtils.repeat('a', 10000), this.targetUser);
    Assert.assertEquals(StringUtils.repeat('a', 2000), postedMessage.getBody());
}
Also used : Event(org.xwiki.eventstream.Event) DefaultEvent(org.xwiki.eventstream.internal.DefaultEvent) Test(org.junit.Test)

Example 42 with Event

use of org.xwiki.eventstream.Event in project xwiki-platform by xwiki.

the class MessageStreamTest method testPostDirectMessage.

@Test
public void testPostDirectMessage() throws Exception {
    Event postedMessage = setupForDirectMessage();
    this.stream.postDirectMessageToUser("Hello World!", this.targetUser);
    Assert.assertEquals("Hello World!", postedMessage.getBody());
    Assert.assertEquals(Importance.CRITICAL, postedMessage.getImportance());
    Assert.assertEquals("directMessage", postedMessage.getType());
    Assert.assertEquals("wiki:XWiki.JaneBuck", postedMessage.getStream());
    Assert.assertEquals(new ObjectReference("XWiki.XWikiUsers", this.targetUser), postedMessage.getRelatedEntity());
}
Also used : ObjectReference(org.xwiki.model.reference.ObjectReference) Event(org.xwiki.eventstream.Event) DefaultEvent(org.xwiki.eventstream.internal.DefaultEvent) Test(org.junit.Test)

Example 43 with Event

use of org.xwiki.eventstream.Event in project xwiki-platform by xwiki.

the class MessageStreamTest method setupForGroupMessage.

private Event setupForGroupMessage() throws ComponentLookupException, Exception {
    final Event e = setupForNewMessage();
    final EntityReferenceSerializer<String> mockSerializer = getComponentManager().getInstance(EntityReferenceSerializer.TYPE_STRING);
    final DocumentAccessBridge mockBridge = getComponentManager().getInstance(DocumentAccessBridge.class);
    getMockery().checking(new Expectations() {

        {
            exactly(1).of(mockBridge).exists(MessageStreamTest.this.targetGroup);
            will(returnValue(true));
            exactly(1).of(mockSerializer).serialize(MessageStreamTest.this.targetGroup);
            will(returnValue("wiki:XWiki.MyFriends"));
        }
    });
    return e;
}
Also used : Expectations(org.jmock.Expectations) DocumentAccessBridge(org.xwiki.bridge.DocumentAccessBridge) Event(org.xwiki.eventstream.Event) DefaultEvent(org.xwiki.eventstream.internal.DefaultEvent)

Example 44 with Event

use of org.xwiki.eventstream.Event in project xwiki-platform by xwiki.

the class BridgeEventStream method getRelatedEvents.

@Override
public EventGroup getRelatedEvents(Event e) {
    XWikiContext context = getXWikiContext();
    ActivityStreamPlugin plugin = getPlugin(context);
    EventGroup result = new EventGroup();
    try {
        result.addEvents(convertActivitiesToEvents(plugin.getActivityStream().getRelatedEvents(eventConverter.convertEventToActivity(e), context)).toArray(new Event[0]));
    } catch (ActivityStreamException ex) {
    // Should not happen, and the eventual error was already reported downstream
    }
    return result;
}
Also used : XWikiContext(com.xpn.xwiki.XWikiContext) EventStreamDeletedEvent(org.xwiki.eventstream.events.EventStreamDeletedEvent) ActivityEvent(com.xpn.xwiki.plugin.activitystream.api.ActivityEvent) Event(org.xwiki.eventstream.Event) EventStreamAddedEvent(org.xwiki.eventstream.events.EventStreamAddedEvent) ActivityStreamException(com.xpn.xwiki.plugin.activitystream.api.ActivityStreamException) EventGroup(org.xwiki.eventstream.EventGroup) ActivityStreamPlugin(com.xpn.xwiki.plugin.activitystream.plugin.ActivityStreamPlugin)

Example 45 with Event

use of org.xwiki.eventstream.Event in project xwiki-platform by xwiki.

the class DefaultNotificationManagerTest method createMockedEvent.

private Event createMockedEvent(String type, DocumentReference user, DocumentReference doc, Date date, String groupId) {
    Event event = mock(Event.class);
    when(event.getDate()).thenReturn(date);
    when(event.getDocument()).thenReturn(doc);
    when(event.getUser()).thenReturn(user);
    when(event.getType()).thenReturn(type);
    when(event.getGroupId()).thenReturn(groupId);
    when(event.toString()).thenReturn(String.format("[%s] Event [%s] on document [%s] by [%s] on [%s]", groupId, type, doc, user, date.toString()));
    return event;
}
Also used : CompositeEvent(org.xwiki.notifications.CompositeEvent) Event(org.xwiki.eventstream.Event)

Aggregations

Event (org.xwiki.eventstream.Event)60 Test (org.junit.Test)31 DocumentReference (org.xwiki.model.reference.DocumentReference)21 DefaultEvent (org.xwiki.eventstream.internal.DefaultEvent)20 CompositeEvent (org.xwiki.notifications.CompositeEvent)17 ArrayList (java.util.ArrayList)7 Query (org.xwiki.query.Query)7 Date (java.util.Date)6 Expectations (org.jmock.Expectations)6 DocumentAccessBridge (org.xwiki.bridge.DocumentAccessBridge)5 QueryException (org.xwiki.query.QueryException)5 ObjectReference (org.xwiki.model.reference.ObjectReference)4 HashMap (java.util.HashMap)3 WikiReference (org.xwiki.model.reference.WikiReference)3 XWikiContext (com.xpn.xwiki.XWikiContext)2 ActivityEvent (com.xpn.xwiki.plugin.activitystream.api.ActivityEvent)2 EventStatus (org.xwiki.eventstream.EventStatus)2 EventStream (org.xwiki.eventstream.EventStream)2 EventStreamAddedEvent (org.xwiki.eventstream.events.EventStreamAddedEvent)2 SpaceReference (org.xwiki.model.reference.SpaceReference)2