Search in sources :

Example 1 with ScriptEventListener

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);
}
Also used : ScriptEventListener(com.enonic.xp.script.event.ScriptEventListener) ScriptAsyncService(com.enonic.xp.script.impl.async.ScriptAsyncService) Event(com.enonic.xp.event.Event) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) Test(org.junit.jupiter.api.Test)

Example 2 with ScriptEventListener

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);
}
Also used : ScriptEventListener(com.enonic.xp.script.event.ScriptEventListener) Event(com.enonic.xp.event.Event) Test(org.junit.jupiter.api.Test)

Example 3 with ScriptEventListener

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());
}
Also used : ScriptEventListener(com.enonic.xp.script.event.ScriptEventListener) Application(com.enonic.xp.app.Application) Test(org.junit.jupiter.api.Test)

Example 4 with ScriptEventListener

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);
}
Also used : ScriptEventListener(com.enonic.xp.script.event.ScriptEventListener) Event(com.enonic.xp.event.Event) Test(org.junit.jupiter.api.Test)

Example 5 with ScriptEventListener

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;
}
Also used : ScriptEventListener(com.enonic.xp.script.event.ScriptEventListener)

Aggregations

ScriptEventListener (com.enonic.xp.script.event.ScriptEventListener)6 Test (org.junit.jupiter.api.Test)5 Event (com.enonic.xp.event.Event)3 Application (com.enonic.xp.app.Application)1 ScriptAsyncService (com.enonic.xp.script.impl.async.ScriptAsyncService)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1