Search in sources :

Example 1 with EventStream

use of org.xwiki.eventstream.EventStream 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 2 with EventStream

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

the class MessageStreamTest method setupForNewMessage.

private Event setupForNewMessage() throws ComponentLookupException, Exception {
    final EventFactory mockEventFactory = getComponentManager().getInstance(EventFactory.class);
    final Event e = new DefaultEvent();
    e.setId(UUID.randomUUID().toString());
    final ModelContext mockContext = getComponentManager().getInstance(ModelContext.class);
    final EventStream mockEventStream = getComponentManager().getInstance(EventStream.class);
    getMockery().checking(new Expectations() {

        {
            exactly(1).of(mockEventFactory).createEvent();
            will(returnValue(e));
            exactly(1).of(mockContext).getCurrentEntityReference();
            will(returnValue(new DocumentReference("wiki", "Space", "Page")));
            exactly(1).of(mockEventStream).addEvent(e);
        }
    });
    return e;
}
Also used : ModelContext(org.xwiki.model.ModelContext) Expectations(org.jmock.Expectations) DefaultEvent(org.xwiki.eventstream.internal.DefaultEvent) EventStream(org.xwiki.eventstream.EventStream) EventFactory(org.xwiki.eventstream.EventFactory) Event(org.xwiki.eventstream.Event) DefaultEvent(org.xwiki.eventstream.internal.DefaultEvent) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 3 with EventStream

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

the class MessageStreamTest method setupForLimitQueries.

private void setupForLimitQueries(final int expectedLimit, final int expectedOffset) throws ComponentLookupException, 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(expectedLimit);
            will(returnValue(mockQuery));
            exactly(1).of(mockQuery).setOffset(expectedOffset);
            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(returnValue(null));
        }
    });
}
Also used : Expectations(org.jmock.Expectations) Query(org.xwiki.query.Query) EventStream(org.xwiki.eventstream.EventStream) QueryManager(org.xwiki.query.QueryManager) DocumentAccessBridge(org.xwiki.bridge.DocumentAccessBridge)

Example 4 with EventStream

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

the class DefaultNotificationManagerTest method setUp.

@Before
public void setUp() throws Exception {
    eventStream = mocker.getInstance(EventStream.class);
    queryGenerator = mocker.getInstance(QueryGenerator.class);
    documentAccessBridge = mocker.getInstance(DocumentAccessBridge.class);
    documentReferenceResolver = mocker.getInstance(DocumentReferenceResolver.TYPE_STRING);
    notificationPreferenceManager = mocker.getInstance(NotificationPreferenceManager.class);
    authorizationManager = mocker.getInstance(AuthorizationManager.class);
    startDate = new Date(10);
    when(documentReferenceResolver.resolve("xwiki:XWiki.UserA")).thenReturn(userReference);
    query = mock(Query.class);
    when(queryGenerator.generateQuery(any(DocumentReference.class), any(NotificationFormat.class), nullable(Date.class), nullable(Date.class), nullable(List.class))).thenReturn(query);
    NotificationPreference pref1 = mock(NotificationPreference.class);
    when(pref1.getProperties()).thenReturn(Collections.singletonMap(NotificationPreferenceProperty.EVENT_TYPE, "create"));
    when(pref1.isNotificationEnabled()).thenReturn(true);
    when(notificationPreferenceManager.getAllPreferences(userReference)).thenReturn(Arrays.asList(pref1));
}
Also used : NotificationPreference(org.xwiki.notifications.preferences.NotificationPreference) NotificationPreferenceManager(org.xwiki.notifications.preferences.NotificationPreferenceManager) Query(org.xwiki.query.Query) EventStream(org.xwiki.eventstream.EventStream) NotificationFormat(org.xwiki.notifications.NotificationFormat) DocumentAccessBridge(org.xwiki.bridge.DocumentAccessBridge) ComponentList(org.xwiki.test.annotation.ComponentList) List(java.util.List) AuthorizationManager(org.xwiki.security.authorization.AuthorizationManager) Date(java.util.Date) DocumentReference(org.xwiki.model.reference.DocumentReference) Before(org.junit.Before)

Aggregations

EventStream (org.xwiki.eventstream.EventStream)4 Expectations (org.jmock.Expectations)3 DocumentAccessBridge (org.xwiki.bridge.DocumentAccessBridge)3 Query (org.xwiki.query.Query)3 Event (org.xwiki.eventstream.Event)2 DefaultEvent (org.xwiki.eventstream.internal.DefaultEvent)2 DocumentReference (org.xwiki.model.reference.DocumentReference)2 QueryManager (org.xwiki.query.QueryManager)2 Date (java.util.Date)1 List (java.util.List)1 Before (org.junit.Before)1 Test (org.junit.Test)1 EventFactory (org.xwiki.eventstream.EventFactory)1 ModelContext (org.xwiki.model.ModelContext)1 NotificationFormat (org.xwiki.notifications.NotificationFormat)1 NotificationPreference (org.xwiki.notifications.preferences.NotificationPreference)1 NotificationPreferenceManager (org.xwiki.notifications.preferences.NotificationPreferenceManager)1 QueryException (org.xwiki.query.QueryException)1 AuthorizationManager (org.xwiki.security.authorization.AuthorizationManager)1 ComponentList (org.xwiki.test.annotation.ComponentList)1