Search in sources :

Example 1 with Event

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

Example 2 with Event

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

Example 4 with 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());
}
Also used : Event(com.enonic.xp.event.Event) BundleEvent(org.osgi.framework.BundleEvent) Test(org.junit.jupiter.api.Test)

Example 5 with Event

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

Aggregations

Event (com.enonic.xp.event.Event)48 Test (org.junit.jupiter.api.Test)46 Node (com.enonic.xp.node.Node)12 NodeId (com.enonic.xp.node.NodeId)7 NodePath (com.enonic.xp.node.NodePath)7 InternalContext (com.enonic.xp.repo.impl.InternalContext)7 EventListener (com.enonic.xp.event.EventListener)6 TaskInfo (com.enonic.xp.task.TaskInfo)6 NodeBranchEntry (com.enonic.xp.node.NodeBranchEntry)3 ScriptEventListener (com.enonic.xp.script.event.ScriptEventListener)3 Branch (com.enonic.xp.branch.Branch)2 PushNodeEntries (com.enonic.xp.node.PushNodeEntries)2 NodeMovedParams (com.enonic.xp.repo.impl.storage.NodeMovedParams)2 RepositoryId (com.enonic.xp.repository.RepositoryId)2 JsonMapGenerator (com.enonic.xp.script.serializer.JsonMapGenerator)2 MapSerializable (com.enonic.xp.script.serializer.MapSerializable)2 AuthenticationInfo (com.enonic.xp.security.auth.AuthenticationInfo)2 Member (com.hazelcast.core.Member)2 Message (com.hazelcast.core.Message)2 List (java.util.List)2