Search in sources :

Example 16 with Event

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

the class MessageStreamTest method setupForDirectMessage.

private Event setupForDirectMessage() 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.targetUser);
            will(returnValue(true));
            exactly(1).of(mockSerializer).serialize(MessageStreamTest.this.targetUser);
            will(returnValue("wiki:XWiki.JaneBuck"));
        }
    });
    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 17 with Event

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

the class MessageStreamTest method testPostPersonalMessageWithEmptyMessage.

@Test
public void testPostPersonalMessageWithEmptyMessage() throws Exception {
    Event postedMessage = setupForPersonalMessage();
    this.stream.postPersonalMessage("");
    Assert.assertEquals("", postedMessage.getBody());
}
Also used : Event(org.xwiki.eventstream.Event) DefaultEvent(org.xwiki.eventstream.internal.DefaultEvent) Test(org.junit.Test)

Example 18 with Event

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

the class MessageStreamTest method testPostGroupMessage.

@Test
public void testPostGroupMessage() throws Exception {
    Event postedMessage = setupForGroupMessage();
    this.stream.postMessageToGroup("Hello Friends!", this.targetGroup);
    Assert.assertEquals("Hello Friends!", postedMessage.getBody());
    Assert.assertEquals(Importance.MAJOR, postedMessage.getImportance());
    Assert.assertEquals("groupMessage", postedMessage.getType());
    Assert.assertEquals("wiki:XWiki.MyFriends", postedMessage.getStream());
    Assert.assertEquals(new ObjectReference("XWiki.XWikiGroups", this.targetGroup), 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 19 with Event

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

the class MessageStreamTest method testGetRecentPersonalMessagesWhenQueryFails.

@Test
public void testGetRecentPersonalMessagesWhenQueryFails() throws Exception {
    final Query mockQuery = getMockQuery();
    final QueryManager mockQueryManager = getComponentManager().getInstance(QueryManager.class);
    final EventStream mockEventStream = getComponentManager().getInstance(EventStream.class);
    final DocumentAccessBridge mockBridge = getComponentManager().getInstance(DocumentAccessBridge.class);
    final EntityReferenceSerializer<String> mockSerializer = getComponentManager().getInstance(EntityReferenceSerializer.TYPE_STRING);
    getMockery().checking(new Expectations() {

        {
            allowing(mockBridge).getCurrentUserReference();
            will(returnValue(MessageStreamTest.this.currentUser));
            allowing(mockSerializer).serialize(MessageStreamTest.this.currentUser);
            will(returnValue("wiki:XWiki.JohnDoe"));
            exactly(1).of(mockQuery).setLimit(30);
            will(returnValue(mockQuery));
            exactly(1).of(mockQuery).setOffset(0);
            will(returnValue(mockQuery));
            allowing(mockQuery).bindValue(with(any(String.class)), with("wiki:XWiki.JohnDoe"));
            allowing(mockQueryManager).createQuery(with(aNonNull(String.class)), with(aNonNull(String.class)));
            will(returnValue(mockQuery));
            exactly(1).of(mockEventStream).searchEvents(with(mockQuery));
            will(throwException(new QueryException("", null, null)));
        }
    });
    List<Event> result = this.stream.getRecentPersonalMessages();
    Assert.assertNotNull(result);
    Assert.assertTrue(result.isEmpty());
}
Also used : Expectations(org.jmock.Expectations) QueryException(org.xwiki.query.QueryException) Query(org.xwiki.query.Query) EventStream(org.xwiki.eventstream.EventStream) QueryManager(org.xwiki.query.QueryManager) DocumentAccessBridge(org.xwiki.bridge.DocumentAccessBridge) Event(org.xwiki.eventstream.Event) DefaultEvent(org.xwiki.eventstream.internal.DefaultEvent) Test(org.junit.Test)

Example 20 with Event

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

the class MessageStreamTest method testPostDirectMessageWithEmptyMessage.

@Test
public void testPostDirectMessageWithEmptyMessage() throws Exception {
    Event postedMessage = setupForDirectMessage();
    this.stream.postDirectMessageToUser("", this.targetUser);
    Assert.assertEquals("", postedMessage.getBody());
}
Also used : Event(org.xwiki.eventstream.Event) DefaultEvent(org.xwiki.eventstream.internal.DefaultEvent) Test(org.junit.Test)

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