Search in sources :

Example 46 with Event

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

the class DefaultNotificationManagerTest method getEventsUC2.

@Test
public void getEventsUC2() throws Exception {
    // Facts:
    // * Bob comments the page "Bike" (which actually update the page too)
    // Expected:
    // * Bob has commented the page "Bike"
    // Comment: we do not mention that Bob has updated the page "Bike", because it's actually a technical
    // implementation of the "comment" feature.
    // Mocks
    Event eventComment = createMockedEvent();
    Event eventUpdate = createMockedEvent();
    DocumentReference doc = new DocumentReference("xwiki", "Main", "Bike");
    when(eventComment.getDocument()).thenReturn(doc);
    when(eventUpdate.getDocument()).thenReturn(doc);
    when(authorizationManager.hasAccess(Right.VIEW, userReference, doc)).thenReturn(true);
    when(eventComment.getType()).thenReturn("addComment");
    when(eventUpdate.getType()).thenReturn("update");
    when(eventComment.getGroupId()).thenReturn("g1");
    when(eventUpdate.getGroupId()).thenReturn("g1");
    when(eventStream.searchEvents(query)).thenReturn(Arrays.asList(eventComment, eventUpdate));
    // Test
    List<CompositeEvent> results = mocker.getComponentUnderTest().getEvents("xwiki:XWiki.UserA", 2);
    // Verify
    assertEquals(1, results.size());
    assertEquals(eventComment, results.get(0).getEvents().get(0));
    assertEquals(eventUpdate, results.get(0).getEvents().get(1));
}
Also used : CompositeEvent(org.xwiki.notifications.CompositeEvent) Event(org.xwiki.eventstream.Event) CompositeEvent(org.xwiki.notifications.CompositeEvent) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 47 with Event

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

the class DefaultNotificationManagerTest method getEventsUC6.

@Test
public void getEventsUC6() throws Exception {
    // Facts:
    // * Bob updates the page "Bike" (E1)
    // * Alice updates the page "Bike" (E2)
    // * Bob comments the page "Bike" (E3 & E4)
    // * Carol comments the page "Bike" (E5 & E6)
    // * Dave comments the page "Guitar" (E7 & E8)
    // * Bob adds an annotation on page "Bike" (E9 & E10)
    // * Alice adds an annotation on page "Bike" (E11 & E12)
    // * Alice adds an other annotation on page "Bike" (E12 & E13)
    // Expected:
    // * Bob and Alice have updated the page "Bike"
    // * Bob and Carol have commented the page "Bike"
    // * Dave has commented the page "Guitar"
    // * Bob and Alice have annotated the page "Bike"
    // Comment: it's only a mix of other use cases to make sure we have the expected results.
    // Mocks
    DocumentReference doc1 = new DocumentReference("xwiki", "Main", "Bike");
    DocumentReference doc2 = new DocumentReference("xwiki", "Main", "Guitar");
    when(authorizationManager.hasAccess(Right.VIEW, userReference, doc1)).thenReturn(true);
    when(authorizationManager.hasAccess(Right.VIEW, userReference, doc2)).thenReturn(true);
    // * Bob updates the page "Bike" (E1)
    Event event1 = createMockedEvent();
    when(event1.toString()).thenReturn("event1");
    when(event1.getDocument()).thenReturn(doc1);
    when(event1.getType()).thenReturn("update");
    when(event1.getGroupId()).thenReturn("g1");
    // * Alice updates the page "Bike" (E2)
    Event event2 = createMockedEvent();
    when(event2.toString()).thenReturn("event2");
    when(event2.getDocument()).thenReturn(doc1);
    when(event2.getType()).thenReturn("update");
    when(event2.getGroupId()).thenReturn("g2");
    // * Bob comments the page "Bike" (E3 & E4)
    Event event3 = createMockedEvent();
    when(event3.toString()).thenReturn("event3");
    when(event3.getDocument()).thenReturn(doc1);
    when(event3.getType()).thenReturn("addComment");
    when(event3.getGroupId()).thenReturn("g3");
    Event event4 = createMockedEvent();
    when(event4.toString()).thenReturn("event4");
    when(event4.getDocument()).thenReturn(doc1);
    when(event4.getType()).thenReturn("update");
    when(event4.getGroupId()).thenReturn("g3");
    // * Carol comments the page "Bike" (E5 & E6)
    // (note: we put the "update" event before the "addComment", because we can not guarantee the order so
    // it's good to test both)
    Event event5 = createMockedEvent();
    when(event5.toString()).thenReturn("event5");
    when(event5.getDocument()).thenReturn(doc1);
    when(event5.getType()).thenReturn("update");
    when(event5.getGroupId()).thenReturn("g5");
    Event event6 = createMockedEvent();
    when(event6.toString()).thenReturn("event6");
    when(event6.getDocument()).thenReturn(doc1);
    when(event6.getType()).thenReturn("addComment");
    when(event6.getGroupId()).thenReturn("g5");
    // * Dave comments the page "Guitar" (E7 & E8)
    Event event7 = createMockedEvent();
    when(event7.toString()).thenReturn("event7");
    when(event7.getDocument()).thenReturn(doc2);
    when(event7.getType()).thenReturn("update");
    when(event7.getGroupId()).thenReturn("g7");
    Event event8 = createMockedEvent();
    when(event8.toString()).thenReturn("event8");
    when(event8.getDocument()).thenReturn(doc2);
    when(event8.getType()).thenReturn("addComment");
    when(event8.getGroupId()).thenReturn("g7");
    // * Bob adds an annotation on page "Bike" (E9 & E10)
    Event event9 = createMockedEvent();
    when(event8.toString()).thenReturn("event9");
    when(event9.getDocument()).thenReturn(doc1);
    when(event9.getType()).thenReturn("update");
    when(event9.getGroupId()).thenReturn("g9");
    Event event10 = createMockedEvent();
    when(event8.toString()).thenReturn("event10");
    when(event10.getDocument()).thenReturn(doc1);
    when(event10.getType()).thenReturn("addAnnotation");
    when(event10.getGroupId()).thenReturn("g9");
    // * Alice adds an annotation on page "Bike" (E11 & E12)
    Event event11 = createMockedEvent();
    when(event8.toString()).thenReturn("event11");
    when(event11.getDocument()).thenReturn(doc1);
    when(event11.getType()).thenReturn("update");
    when(event11.getGroupId()).thenReturn("g11");
    Event event12 = createMockedEvent();
    when(event8.toString()).thenReturn("event12");
    when(event12.getDocument()).thenReturn(doc1);
    when(event12.getType()).thenReturn("addAnnotation");
    when(event12.getGroupId()).thenReturn("g11");
    // * Alice adds an other annotation on page "Bike" (E12 & E13)
    Event event13 = createMockedEvent();
    when(event8.toString()).thenReturn("event11");
    when(event13.getDocument()).thenReturn(doc1);
    when(event13.getType()).thenReturn("addAnnotation");
    when(event13.getGroupId()).thenReturn("g13");
    Event event14 = createMockedEvent();
    when(event8.toString()).thenReturn("event12");
    when(event14.getDocument()).thenReturn(doc1);
    when(event14.getType()).thenReturn("update");
    when(event14.getGroupId()).thenReturn("g13");
    when(eventStream.searchEvents(query)).thenReturn(Arrays.asList(event1, event2, event3, event4, event5, event6, event7, event8, event9, event10, event11, event12, event13, event14));
    // Test
    List<CompositeEvent> results = mocker.getComponentUnderTest().getEvents("xwiki:XWiki.UserA", 50);
    // Verify
    assertEquals(4, results.size());
    // * Bob and Alice have updated the page "Bike"
    assertTrue(results.get(0).getEvents().contains(event1));
    assertTrue(results.get(0).getEvents().contains(event2));
    // * Bob and Carol have commented the page "Bike"
    assertTrue(results.get(1).getEvents().contains(event3));
    assertTrue(results.get(1).getEvents().contains(event4));
    assertTrue(results.get(1).getEvents().contains(event5));
    assertTrue(results.get(1).getEvents().contains(event6));
    // * Dave has commented the page "Guitar"
    assertTrue(results.get(2).getEvents().contains(event7));
    assertTrue(results.get(2).getEvents().contains(event8));
    // * Bob and Alice have annotated the page "Bike"
    assertTrue(results.get(3).getEvents().contains(event9));
    assertTrue(results.get(3).getEvents().contains(event10));
    assertTrue(results.get(3).getEvents().contains(event11));
    assertTrue(results.get(3).getEvents().contains(event12));
    assertTrue(results.get(3).getEvents().contains(event13));
    assertTrue(results.get(3).getEvents().contains(event14));
}
Also used : CompositeEvent(org.xwiki.notifications.CompositeEvent) Event(org.xwiki.eventstream.Event) CompositeEvent(org.xwiki.notifications.CompositeEvent) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 48 with Event

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

the class DefaultNotificationManagerTest method getEventsWith2Queries.

@Test
public void getEventsWith2Queries() throws Exception {
    // Mocks
    Event event1 = createMockedEvent();
    Event event2 = createMockedEvent();
    Event event3 = createMockedEvent();
    Event event4 = createMockedEvent();
    Event event5 = createMockedEvent();
    Event event6 = createMockedEvent();
    DocumentReference doc1 = new DocumentReference("xwiki", "Main", "WebHome");
    when(event1.getDocument()).thenReturn(doc1);
    DocumentReference doc2 = new DocumentReference("xwiki", "PrivateSpace", "WebHome");
    when(event2.getDocument()).thenReturn(doc2);
    when(event3.getDocument()).thenReturn(doc2);
    when(event4.getDocument()).thenReturn(doc2);
    when(authorizationManager.hasAccess(Right.VIEW, userReference, doc1)).thenReturn(true);
    when(authorizationManager.hasAccess(Right.VIEW, userReference, doc2)).thenReturn(false);
    when(event1.getType()).thenReturn("type1");
    when(event2.getType()).thenReturn("type2");
    when(event3.getType()).thenReturn("type3");
    when(event4.getType()).thenReturn("type4");
    when(event5.getType()).thenReturn("type5");
    when(event6.getType()).thenReturn("type6");
    when(eventStream.searchEvents(query)).thenReturn(Arrays.asList(event1, event2, event3, event4), Arrays.asList(event5, event6));
    // Test
    List<CompositeEvent> results = mocker.getComponentUnderTest().getEvents("xwiki:XWiki.UserA", 2);
    // Verify
    assertEquals(2, results.size());
    assertEquals(event1, results.get(0).getEvents().get(0));
    assertEquals(event5, results.get(1).getEvents().get(0));
}
Also used : CompositeEvent(org.xwiki.notifications.CompositeEvent) Event(org.xwiki.eventstream.Event) CompositeEvent(org.xwiki.notifications.CompositeEvent) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 49 with Event

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

the class DefaultNotificationManagerTest method getEvents1Update2Events.

@Test
public void getEvents1Update2Events() throws Exception {
    // Facts:
    // * Bob comment and annotate the page "Bike" in the same time
    // Expected:
    // * Bob has commented the page "Bike"
    // * Bob has annotated the page "Bike"
    // Mocks
    Event event1 = createMockedEvent();
    when(event1.toString()).thenReturn("event1");
    Event event2 = createMockedEvent();
    when(event1.toString()).thenReturn("event2");
    Event event3 = createMockedEvent();
    when(event1.toString()).thenReturn("event3");
    DocumentReference doc = new DocumentReference("xwiki", "Main", "Bike");
    when(event1.getDocument()).thenReturn(doc);
    when(event2.getDocument()).thenReturn(doc);
    when(event3.getDocument()).thenReturn(doc);
    when(authorizationManager.hasAccess(Right.VIEW, userReference, doc)).thenReturn(true);
    when(event1.getType()).thenReturn("update");
    when(event2.getType()).thenReturn("addComment");
    when(event3.getType()).thenReturn("addAnnotation");
    when(event1.getGroupId()).thenReturn("g1");
    when(event2.getGroupId()).thenReturn("g1");
    when(event3.getGroupId()).thenReturn("g1");
    when(eventStream.searchEvents(query)).thenReturn(Arrays.asList(event1, event2, event3));
    // Test
    List<CompositeEvent> results = mocker.getComponentUnderTest().getEvents("xwiki:XWiki.UserA", 50);
    // Verify
    assertEquals(1, results.size());
    assertTrue(results.get(0).getEvents().contains(event1));
    assertTrue(results.get(0).getEvents().contains(event2));
    assertTrue(results.get(0).getEvents().contains(event3));
}
Also used : CompositeEvent(org.xwiki.notifications.CompositeEvent) Event(org.xwiki.eventstream.Event) CompositeEvent(org.xwiki.notifications.CompositeEvent) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 50 with Event

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

the class DefaultNotificationManagerTest method getEventsXWIKI14719.

@Test
public void getEventsXWIKI14719() throws Exception {
    DocumentReference userA = new DocumentReference("xwiki", "XWiki", "UserA");
    // Example taken from a real case
    Event event0 = createMockedEvent("update", userA, userA, new Date(1510567729000L), "1997830249-1510567729000-Puhs4MSa");
    Event event1 = createMockedEvent("update", userA, userA, new Date(1510567724000L), "1997830249-1510567724000-aCjmsmSh");
    Event event2 = createMockedEvent("update", userA, userA, new Date(1510567718000L), "1997830249-1510567718000-hEErMBp9");
    Event event3 = createMockedEvent("update", userA, userA, new Date(1510567717000L), "1997830249-1510567718000-hEErMBp9");
    Event event4 = createMockedEvent("update", userA, userA, new Date(1510567715000L), "1997830249-1510567715000-B723WWBC");
    Event event5 = createMockedEvent("update", userA, userA, new Date(1510567715000L), "1997830249-1510567715000-B723WWBC");
    Event event6 = createMockedEvent("update", userA, userA, new Date(1510567714000L), "1997830249-1510567714000-SHPmruCG");
    Event event7 = createMockedEvent("update", userA, userA, new Date(1510567712000L), "1997830249-1510567712000-Fy19J0v1");
    Event event8 = createMockedEvent("update", userA, userA, new Date(1510567711000L), "1997830249-1510567711000-zDfFnZbD");
    Event event9 = createMockedEvent("update", userA, userA, new Date(1510567711000L), "1997830249-1510567711000-zDfFnZbD");
    when(authorizationManager.hasAccess(eq(Right.VIEW), eq(userReference), any(DocumentReference.class))).thenReturn(true);
    when(eventStream.searchEvents(query)).thenReturn(Arrays.asList(event0, event1, event2, event3, event4, event5, event6, event7, event8, event9), Collections.emptyList());
    // Test
    List<CompositeEvent> results = mocker.getComponentUnderTest().getEvents("xwiki:XWiki.UserA", 5);
    assertEquals(1, results.size());
}
Also used : CompositeEvent(org.xwiki.notifications.CompositeEvent) Event(org.xwiki.eventstream.Event) CompositeEvent(org.xwiki.notifications.CompositeEvent) DocumentReference(org.xwiki.model.reference.DocumentReference) Date(java.util.Date) 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