Search in sources :

Example 56 with Event

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));
}
Also used : Event(org.xwiki.eventstream.Event) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 57 with Event

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));
}
Also used : Event(org.xwiki.eventstream.Event) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 58 with Event

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));
}
Also used : CompositeEvent(org.xwiki.notifications.CompositeEvent) Event(org.xwiki.eventstream.Event) Date(java.util.Date) DocumentReference(org.xwiki.model.reference.DocumentReference) Template(org.xwiki.template.Template)

Example 59 with Event

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);
}
Also used : RecordableEventDescriptor(org.xwiki.eventstream.RecordableEventDescriptor) EventStreamAddedEvent(org.xwiki.eventstream.events.EventStreamAddedEvent) Event(org.xwiki.eventstream.Event) EventStreamAddedEvent(org.xwiki.eventstream.events.EventStreamAddedEvent) Test(org.junit.Test)

Example 60 with Event

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()));
}
Also used : Event(org.xwiki.eventstream.Event) 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