use of org.xwiki.eventstream.Event in project xwiki-platform by xwiki.
the class SimilarityCalculatorTest method testComputeSimilarity.
@Test
public void testComputeSimilarity() throws Exception {
DocumentReference document = new DocumentReference("xwiki", "somewhere", "something");
String group = "myGroupId";
String type = "type";
Event event1 = mock(Event.class);
Event event2 = mock(Event.class);
when(event1.getDocument()).thenReturn(document);
when(event2.getDocument()).thenReturn(document);
when(event1.getGroupId()).thenReturn(group);
when(event2.getGroupId()).thenReturn(group);
assertEquals(SimilarityCalculator.SAME_GROUP_ID_AND_DOCUMENT_BUT_DIFFERENT_TYPES, this.sq.computeSimilarity(event1, event2));
when(event2.getGroupId()).thenReturn("somethingElse");
assertEquals(SimilarityCalculator.NO_SIMILARITY, this.sq.computeSimilarity(event1, event2));
when(event1.getType()).thenReturn(type);
when(event2.getType()).thenReturn(type);
assertEquals(SimilarityCalculator.SAME_DOCUMENT_AND_TYPE, this.sq.computeSimilarity(event1, event2));
// Even if the group is the same, if they share the same type, we consider not as the same groupid
when(event2.getGroupId()).thenReturn(group);
assertEquals(SimilarityCalculator.SAME_DOCUMENT_AND_TYPE, this.sq.computeSimilarity(event1, event2));
}
use of org.xwiki.eventstream.Event in project xwiki-platform by xwiki.
the class MinorEventNotificationFilterTest method filterEvent.
@Test
public void filterEvent() throws Exception {
DocumentReference randomUser = new DocumentReference("xwiki", "XWiki", "UserA");
Event event1 = mock(Event.class);
Event event2 = mock(Event.class);
Event event3 = mock(Event.class);
when(event1.getType()).thenReturn("update");
when(event1.getDocumentVersion()).thenReturn("2.12");
when(event2.getType()).thenReturn("addComment");
when(event2.getDocumentVersion()).thenReturn("2.12");
when(event3.getType()).thenReturn("update");
when(event3.getDocumentVersion()).thenReturn("2.1");
assertEquals(NotificationFilter.FilterPolicy.FILTER, mocker.getComponentUnderTest().filterEvent(event1, randomUser, NotificationFormat.ALERT));
assertEquals(NotificationFilter.FilterPolicy.NO_EFFECT, mocker.getComponentUnderTest().filterEvent(event2, randomUser, NotificationFormat.ALERT));
assertEquals(NotificationFilter.FilterPolicy.NO_EFFECT, mocker.getComponentUnderTest().filterEvent(event3, randomUser, NotificationFormat.ALERT));
}
use of org.xwiki.eventstream.Event in project xwiki-platform by xwiki.
the class DefaultNotificationRSSRendererTest method mockEvent.
private void mockEvent(CompositeEvent testCompositeEvent) throws Exception {
Event testEvent1 = mock(Event.class);
Date testEventDate = mock(Date.class);
when(testEvent1.getTitle()).thenReturn("EventTitle");
when(testEvent1.getDocumentTitle()).thenReturn("EventDocumentTitle");
when(this.contextualLocalizationManager.getTranslationPlain("EventTitle", "EventDocumentTitle")).thenReturn("TranslatedEventTitle");
DocumentReference testEventAuthor1 = new DocumentReference("xwiki", "XWiki", "AuthorName");
when(this.templateManager.getTemplate(ArgumentMatchers.any())).thenReturn(Mockito.mock(Template.class));
when(testCompositeEvent.getEvents()).thenReturn(Arrays.asList(testEvent1));
when(testCompositeEvent.getUsers()).thenReturn(new HashSet<>(Arrays.asList(testEventAuthor1)));
when(testCompositeEvent.getEventIds()).thenReturn(Arrays.asList("id1"));
when(testCompositeEvent.getType()).thenReturn("eventType");
when(testCompositeEvent.getDates()).thenReturn(Arrays.asList(testEventDate));
}
use of org.xwiki.eventstream.Event in project xwiki-platform by xwiki.
the class LiveNotificationEmailListenerTest method testOnEvent.
@Test
public void testOnEvent() throws Exception {
Event eventStreamEvent = mock(Event.class);
EventStreamAddedEvent event = mock(EventStreamAddedEvent.class);
RecordableEventDescriptor eventDescriptor = mock(RecordableEventDescriptor.class);
when(eventDescriptor.getEventType()).thenReturn("eventType");
when(this.recordableEventDescriptorManager.getRecordableEventDescriptors(true)).thenReturn(Arrays.asList(eventDescriptor));
when(eventStreamEvent.getType()).thenReturn("eventType");
when(this.notificationConfiguration.areEmailsEnabled()).thenReturn(true);
when(this.notificationConfiguration.isEnabled()).thenReturn(true);
this.mocker.getComponentUnderTest().onEvent(event, eventStreamEvent, null);
verify(this.liveNotificationEmailManager, times(1)).addEvent(eventStreamEvent);
}
use of org.xwiki.eventstream.Event in project xwiki-platform by xwiki.
the class LiveNotificationEmailManagerTest method testAddNewEvent.
@Test
public void testAddNewEvent() throws Exception {
// No event is currently defined
Event event1 = mock(Event.class);
Event event2 = mock(Event.class);
Event event3 = mock(Event.class);
when(this.similarityCalculator.computeSimilarity(event1, event2)).thenReturn(SimilarityCalculator.NO_SIMILARITY);
when(this.similarityCalculator.computeSimilarity(event2, event3)).thenReturn(SimilarityCalculator.SAME_DOCUMENT_AND_TYPE);
this.mocker.getComponentUnderTest().initialize();
this.mocker.getComponentUnderTest().addEvent(event1);
this.mocker.getComponentUnderTest().addEvent(event2);
this.mocker.getComponentUnderTest().addEvent(event3);
// We assume that this test will take no more than 15 seconds to execute
assertTrue(this.mocker.getComponentUnderTest().getNextExecutionDate().isAfter(DateTime.now().plusSeconds(45).getMillis()));
assertTrue(this.mocker.getComponentUnderTest().getNextExecutionDate().isBefore(DateTime.now().plusMinutes(1).getMillis()));
}
Aggregations