Search in sources :

Example 1 with DocumentUpdatedEvent

use of org.xwiki.bridge.event.DocumentUpdatedEvent in project xwiki-platform by xwiki.

the class UntypedEventListenerTest method onEventWithTarget.

@Test
public void onEventWithTarget() throws Exception {
    // Mocks
    UntypedRecordableEventDescriptor descriptor = mockDescriptor();
    when(descriptor.getTargetExpression()).thenReturn("someVelocityCode");
    // Target velocity
    when(scriptContext.getAttribute("xreturn")).thenReturn(Arrays.asList("UserA", "UserB"));
    // Test
    mocker.getComponentUnderTest().onEvent(new DocumentUpdatedEvent(), mock(Object.class), null);
    // Verify
    verify(this.observationManager, times(1)).notify(any(DefaultUntypedRecordableEvent.class), any(), any());
    assertNotNull(answer.getSentEvent());
    assertNotNull(answer.getSentEvent().getTarget());
    assertTrue(answer.getSentEvent().getTarget().contains("UserA"));
    assertTrue(answer.getSentEvent().getTarget().contains("UserB"));
    assertEquals(2, answer.getSentEvent().getTarget().size());
}
Also used : UntypedRecordableEventDescriptor(org.xwiki.eventstream.UntypedRecordableEventDescriptor) DocumentUpdatedEvent(org.xwiki.bridge.event.DocumentUpdatedEvent) Test(org.junit.Test)

Example 2 with DocumentUpdatedEvent

use of org.xwiki.bridge.event.DocumentUpdatedEvent in project xwiki-platform by xwiki.

the class UntypedEventListenerTest method onEventWithCorrectValidation2.

@Test
public void onEventWithCorrectValidation2() throws Exception {
    // Mocks
    UntypedRecordableEventDescriptor descriptor = mockDescriptor();
    when(descriptor.getValidationExpression()).thenReturn("someVelocityCode");
    doAnswer(invocationOnMock -> {
        WikiPrinter wikiPrinter = invocationOnMock.getArgument(1);
        wikiPrinter.println("    true ");
        return null;
    }).when(renderer).render(any(XDOM.class), any(WikiPrinter.class));
    // Test
    mocker.getComponentUnderTest().onEvent(new DocumentUpdatedEvent(), mock(Object.class), null);
    // Verify
    verify(this.observationManager, times(1)).notify(any(DefaultUntypedRecordableEvent.class), any(), any());
    assertNotNull(answer.getSentEvent());
    assertEquals("myCustomEvent", answer.getSentEvent().getEventType());
}
Also used : UntypedRecordableEventDescriptor(org.xwiki.eventstream.UntypedRecordableEventDescriptor) XDOM(org.xwiki.rendering.block.XDOM) DocumentUpdatedEvent(org.xwiki.bridge.event.DocumentUpdatedEvent) WikiPrinter(org.xwiki.rendering.renderer.printer.WikiPrinter) Test(org.junit.Test)

Example 3 with DocumentUpdatedEvent

use of org.xwiki.bridge.event.DocumentUpdatedEvent in project xwiki-platform by xwiki.

the class UntypedEventListenerTest method onEventWithIncorrectValidation2.

@Test
public void onEventWithIncorrectValidation2() throws Exception {
    // Mocks
    UntypedRecordableEventDescriptor descriptor = mockDescriptor();
    when(descriptor.getValidationExpression()).thenReturn("someVelocityCode");
    // Test
    mocker.getComponentUnderTest().onEvent(new DocumentUpdatedEvent(), mock(Object.class), null);
    // Verify
    verify(this.observationManager, never()).notify(any(), any(), any());
    assertNull(answer.getSentEvent());
}
Also used : UntypedRecordableEventDescriptor(org.xwiki.eventstream.UntypedRecordableEventDescriptor) DocumentUpdatedEvent(org.xwiki.bridge.event.DocumentUpdatedEvent) Test(org.junit.Test)

Example 4 with DocumentUpdatedEvent

use of org.xwiki.bridge.event.DocumentUpdatedEvent in project xwiki-platform by xwiki.

the class LegacyEventDispatcherTest method testLegacyDocumentUpdateEventGetsDispatched.

@Test
public void testLegacyDocumentUpdateEventGetsDispatched() throws Exception {
    this.registerListenerWithLegacyEvent(new DocumentUpdateEvent());
    this.om.notify(new DocumentUpdatedEvent(new DocumentReference("wiki", "space", "name")), null);
    // The notification is synchronous, so the following assertion will only be tested
    // once all matching event listeners have been notified.
    Assert.assertNotNull("Should have been notified by legacy event dispatcher", this.receivedEvent);
    Assert.assertEquals("Wrong event filter", "wiki:space.name", ((FilterableEvent) this.receivedEvent).getEventFilter().getFilter());
}
Also used : DocumentUpdateEvent(org.xwiki.observation.event.DocumentUpdateEvent) FilterableEvent(org.xwiki.observation.event.FilterableEvent) DocumentUpdatedEvent(org.xwiki.bridge.event.DocumentUpdatedEvent) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 5 with DocumentUpdatedEvent

use of org.xwiki.bridge.event.DocumentUpdatedEvent in project xwiki-platform by xwiki.

the class LegacyEventDispatcher method getEvents.

@Override
public List<Event> getEvents() {
    return new ArrayList<Event>() {

        {
            add(new DocumentDeletedEvent());
            add(new DocumentCreatedEvent());
            add(new DocumentUpdatedEvent());
            add(new ActionExecutedEvent());
        }
    };
}
Also used : DocumentDeletedEvent(org.xwiki.bridge.event.DocumentDeletedEvent) ArrayList(java.util.ArrayList) DocumentCreatedEvent(org.xwiki.bridge.event.DocumentCreatedEvent) ActionExecutedEvent(org.xwiki.bridge.event.ActionExecutedEvent) DocumentUpdatedEvent(org.xwiki.bridge.event.DocumentUpdatedEvent)

Aggregations

DocumentUpdatedEvent (org.xwiki.bridge.event.DocumentUpdatedEvent)45 Test (org.junit.Test)30 DocumentDeletedEvent (org.xwiki.bridge.event.DocumentDeletedEvent)26 DocumentCreatedEvent (org.xwiki.bridge.event.DocumentCreatedEvent)25 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)16 DocumentReference (org.xwiki.model.reference.DocumentReference)13 Event (org.xwiki.observation.event.Event)13 XWikiContext (com.xpn.xwiki.XWikiContext)9 ArrayList (java.util.ArrayList)6 UntypedRecordableEventDescriptor (org.xwiki.eventstream.UntypedRecordableEventDescriptor)5 BaseObject (com.xpn.xwiki.objects.BaseObject)4 ObservationManager (org.xwiki.observation.ObservationManager)4 DocumentUpdatingEvent (org.xwiki.bridge.event.DocumentUpdatingEvent)3 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)2 AttachmentAddedEvent (com.xpn.xwiki.internal.event.AttachmentAddedEvent)2 AttachmentDeletedEvent (com.xpn.xwiki.internal.event.AttachmentDeletedEvent)2 AttachmentUpdatedEvent (com.xpn.xwiki.internal.event.AttachmentUpdatedEvent)2 Date (java.util.Date)2 DocumentModelBridge (org.xwiki.bridge.DocumentModelBridge)2 ActionExecutedEvent (org.xwiki.bridge.event.ActionExecutedEvent)2