use of com.enonic.xp.script.event.ScriptEventListener 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.script.event.ScriptEventListener 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.script.event.ScriptEventListener in project xp by enonic.
the class ScriptEventManagerImplTest method testInvalidate.
@Test
public void testInvalidate() {
final ScriptEventListener listener1 = newListener("foo.bar");
final ScriptEventListener listener2 = newListener("foo.other");
this.manager.add(listener1);
this.manager.add(listener2);
assertEquals(2, StreamSupport.stream(manager.spliterator(), false).count());
Application application = mock(Application.class);
when(application.getKey()).thenReturn(ApplicationKey.from("foo.bar"));
this.manager.invalidate(ApplicationKey.from("foo.bar"), ApplicationInvalidationLevel.FULL);
assertEquals(1, StreamSupport.stream(manager.spliterator(), false).count());
}
use of com.enonic.xp.script.event.ScriptEventListener in project xp by enonic.
the class ScriptEventManagerImplTest method testOnEvent.
@Test
public void testOnEvent() {
final ScriptEventListener listener1 = newListener("foo.bar");
final ScriptEventListener listener2 = newListener("foo.other");
this.manager.add(listener1);
this.manager.add(listener2);
final Event event = Event.create("myEvent").build();
this.manager.onEvent(event);
verify(listener1, Mockito.times(1)).onEvent(event);
verify(listener2, Mockito.times(1)).onEvent(event);
}
use of com.enonic.xp.script.event.ScriptEventListener in project xp by enonic.
the class ScriptEventManagerImplTest method newListener.
private ScriptEventListener newListener(final String app) {
final ScriptEventListener listener = mock(ScriptEventListener.class);
when(listener.getApplication()).thenReturn(ApplicationKey.from(app));
return listener;
}
Aggregations