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());
}
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;
}
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));
}
});
}
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));
}
Aggregations