Search in sources :

Example 6 with UntypedRecordableEventDescriptor

use of org.xwiki.eventstream.UntypedRecordableEventDescriptor 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 7 with UntypedRecordableEventDescriptor

use of org.xwiki.eventstream.UntypedRecordableEventDescriptor 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)

Aggregations

UntypedRecordableEventDescriptor (org.xwiki.eventstream.UntypedRecordableEventDescriptor)7 Test (org.junit.Test)5 DocumentUpdatedEvent (org.xwiki.bridge.event.DocumentUpdatedEvent)5 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)1 XDOM (org.xwiki.rendering.block.XDOM)1 WikiPrinter (org.xwiki.rendering.renderer.printer.WikiPrinter)1