use of org.xwiki.eventstream.UntypedRecordableEventDescriptor in project xwiki-platform by xwiki.
the class UntypedEventListener method onEvent.
@Override
public void onEvent(Event event, Object source, Object data) {
try {
// Get every UntypedEventDescriptor registered in the ComponentManager
List<UntypedRecordableEventDescriptor> descriptors = this.componentManagerProvider.get().getInstanceList(UntypedRecordableEventDescriptor.class);
// Filter the event descriptors concerned by the event, then create the concerned events
for (UntypedRecordableEventDescriptor descriptor : descriptors) {
// If the event is expected by our descriptor
if (eventMatchesDescriptor(event, source, descriptor)) {
Set<String> target = getTarget(event, source, descriptor.getAuthorReference(), descriptor.getTargetExpression());
observationManager.notify(new DefaultUntypedRecordableEvent(descriptor.getEventType(), target), EVENT_STREAM_MODULE, source);
}
}
} catch (ComponentLookupException e) {
logger.error("Unable to retrieve a list of registered UntypedRecordableEventDescriptor " + "from the ComponentManager.", e);
}
}
use of org.xwiki.eventstream.UntypedRecordableEventDescriptor 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.eventstream.UntypedRecordableEventDescriptor 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.eventstream.UntypedRecordableEventDescriptor 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.eventstream.UntypedRecordableEventDescriptor in project xwiki-platform by xwiki.
the class UntypedEventListenerTest method mockDescriptor.
private UntypedRecordableEventDescriptor mockDescriptor() throws Exception {
UntypedRecordableEventDescriptor descriptor = mock(UntypedRecordableEventDescriptor.class);
when(descriptor.getEventTriggers()).thenReturn(Arrays.asList(DocumentUpdatedEvent.class.getCanonicalName()));
when(descriptor.getEventType()).thenReturn("myCustomEvent");
when(modelBridge.checkXObjectPresence(any(), any())).thenReturn(true);
when(componentManager.getInstanceList(any())).thenReturn(Arrays.asList(descriptor));
return descriptor;
}
Aggregations