use of com.enonic.xp.event.Event in project xp by enonic.
the class ScriptEventListenerImplTest method testEvent.
@Test
public void testEvent() {
final Event event = Event.create("application").localOrigin(true).value("a", 1).build();
this.listener.onEvent(event);
assertNotNull(this.event);
assertTrue(this.event instanceof MapSerializable);
final MapSerializable serializable = (MapSerializable) this.event;
final JsonMapGenerator generator = new JsonMapGenerator();
serializable.serialize(generator);
}
use of com.enonic.xp.event.Event in project xp by enonic.
the class ScriptEventManagerImplTest method testRejectedExecution.
@Test
public void testRejectedExecution() {
final ScriptAsyncService scriptAsyncService = mock(ScriptAsyncService.class);
when(scriptAsyncService.getAsyncExecutor(any())).thenReturn(c -> {
throw new RejectedExecutionException();
});
this.manager = new ScriptEventManagerImpl(scriptAsyncService);
final ScriptEventListener listener1 = newListener("foo.bar");
this.manager.add(listener1);
assertEquals(1, StreamSupport.stream(manager.spliterator(), false).count());
final Event event = Event.create("myEvent").build();
this.manager.onEvent(event);
assertEquals(0, StreamSupport.stream(manager.spliterator(), false).count());
verify(listener1, Mockito.never()).onEvent(event);
}
use of com.enonic.xp.event.Event in project xp by enonic.
the class ScriptEventManagerImplTest method testDeactivate.
@Test
public void testDeactivate() {
final ScriptEventListener listener1 = newListener("foo.bar");
this.manager.add(listener1);
final Event event = Event.create("myEvent").build();
this.manager.onEvent(event);
this.manager.deactivate();
this.manager.onEvent(event);
verify(listener1, Mockito.times(1)).onEvent(event);
}
use of com.enonic.xp.event.Event in project xp by enonic.
the class WebsocketEventListenerTest method testEvent.
@Test
public void testEvent() throws Exception {
final Event event = Event.create("application").distributed(false).value("applicationKey", "module").value("eventType", BundleEvent.INSTALLED).build();
eventListener.onEvent(event);
verify(this.webSocketManager, atLeastOnce()).sendToAll(anyString());
}
use of com.enonic.xp.event.Event in project xp by enonic.
the class EventMulticasterTest method testPublishOneListener.
@Test
public void testPublishOneListener() {
final EventListener listener = mock(EventListener.class);
this.multicaster.add(listener);
final Event event = Event.create("test").build();
this.multicaster.publish(event);
this.multicaster.remove(listener);
this.multicaster.publish(event);
verify(listener, times(1)).onEvent(event);
}
Aggregations