Search in sources :

Example 21 with DocumentUpdatedEvent

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

the class UntypedEventListenerTest method onEventWithBlankValidationAndBlankTarget.

@Test
public void onEventWithBlankValidationAndBlankTarget() throws Exception {
    // Mocks
    mockDescriptor();
    // 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());
    assertTrue(answer.getSentEvent().getTarget().isEmpty());
    assertEquals("myCustomEvent", answer.getSentEvent().getEventType());
}
Also used : DocumentUpdatedEvent(org.xwiki.bridge.event.DocumentUpdatedEvent) Test(org.junit.Test)

Example 22 with DocumentUpdatedEvent

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

the class UntypedEventListenerTest method onEventWithIncorrectValidation.

@Test
public void onEventWithIncorrectValidation() throws Exception {
    // Mocks
    UntypedRecordableEventDescriptor descriptor = mockDescriptor();
    when(descriptor.getValidationExpression()).thenReturn("someVelocityCode");
    when(scriptContext.getAttribute("xreturn")).thenReturn(false);
    // 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 23 with DocumentUpdatedEvent

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

the class UntypedEventListenerTest method onEventWithCorrectValidation.

@Test
public void onEventWithCorrectValidation() throws Exception {
    // Mocks
    UntypedRecordableEventDescriptor descriptor = mockDescriptor();
    when(descriptor.getValidationExpression()).thenReturn("someVelocityCode");
    when(scriptContext.getAttribute("xreturn")).thenReturn(true);
    // Test
    Object source = mock(Object.class);
    mocker.getComponentUnderTest().onEvent(new DocumentUpdatedEvent(), source, 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) DocumentUpdatedEvent(org.xwiki.bridge.event.DocumentUpdatedEvent) Test(org.junit.Test)

Example 24 with DocumentUpdatedEvent

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

the class UntypedEventListenerTest method onEventWithoutXObject.

@Test
public void onEventWithoutXObject() throws Exception {
    // Mocks
    mockDescriptor();
    // Same than onEventWithBlankValidationAndBlankTarget() but with no XObject
    when(modelBridge.checkXObjectPresence(any(), any())).thenReturn(false);
    // Test
    Object source = mock(Object.class);
    mocker.getComponentUnderTest().onEvent(new DocumentUpdatedEvent(), source, null);
    // Verify
    verify(this.observationManager, never()).notify(any(), any(), any());
    assertNull(answer.getSentEvent());
}
Also used : DocumentUpdatedEvent(org.xwiki.bridge.event.DocumentUpdatedEvent) Test(org.junit.Test)

Example 25 with DocumentUpdatedEvent

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

the class LegacyNotificationDispatcher method getEvents.

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

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

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