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());
}
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());
}
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());
}
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());
}
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());
}
};
}
Aggregations