Search in sources :

Example 11 with Event

use of com.enonic.xp.event.Event in project xp by enonic.

the class EventMulticasterTest method testListenerOrder.

@Test
public void testListenerOrder() {
    final EventListener listener1 = mock(EventListener.class);
    when(listener1.getOrder()).thenReturn(Integer.MIN_VALUE);
    when(listener1.toString()).thenReturn("listener1");
    final EventListener listener2 = mock(EventListener.class);
    when(listener2.getOrder()).thenReturn(200);
    when(listener2.toString()).thenReturn("listener2");
    final EventListener listener3 = mock(EventListener.class);
    when(listener3.getOrder()).thenReturn(Integer.MAX_VALUE);
    when(listener3.toString()).thenReturn("listener3");
    this.multicaster.add(listener2);
    this.multicaster.add(listener1);
    this.multicaster.add(listener3);
    final Event event = Event.create("test").build();
    this.multicaster.publish(event);
    InOrder inOrder = inOrder(listener1, listener2, listener3);
    inOrder.verify(listener1, times(1)).onEvent(event);
    inOrder.verify(listener2, times(1)).onEvent(event);
    inOrder.verify(listener3, times(1)).onEvent(event);
}
Also used : InOrder(org.mockito.InOrder) Event(com.enonic.xp.event.Event) EventListener(com.enonic.xp.event.EventListener) Test(org.junit.jupiter.api.Test)

Example 12 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)

Example 13 with Event

use of com.enonic.xp.event.Event in project xp by enonic.

the class ClusterEventReceiverTest method testLocalMemberIgnored.

@Test
void testLocalMemberIgnored() {
    final ClusterEventReceiver clusterEventReceiver = new ClusterEventReceiver(hazelcastInstance, eventPublisher);
    final Event event = Event.create("eventType").build();
    final Member publishingMember = mock(Member.class);
    when(publishingMember.localMember()).thenReturn(true);
    Message<Event> message = new Message<>("", event, System.currentTimeMillis(), publishingMember);
    clusterEventReceiver.onMessage(message);
    verifyNoInteractions(this.eventPublisher);
}
Also used : Message(com.hazelcast.core.Message) Event(com.enonic.xp.event.Event) Member(com.hazelcast.core.Member) Test(org.junit.jupiter.api.Test)

Example 14 with Event

use of com.enonic.xp.event.Event in project xp by enonic.

the class ClusterEventReceiverTest method testMessageReceived.

@Test
void testMessageReceived() {
    final ClusterEventReceiver clusterEventReceiver = new ClusterEventReceiver(hazelcastInstance, eventPublisher);
    // Creates an event
    Event event = Event.create("eventType").timestamp(123L).distributed(true).value("key1", "value1").value("key2", 1234L).build();
    // Passes the event received to SendEventRequestHandler
    Message<Event> message = new Message<>("", event, System.currentTimeMillis(), null);
    clusterEventReceiver.onMessage(message);
    // Checks that the event was correctly published
    ArgumentCaptor<Event> argumentCaptor = ArgumentCaptor.forClass(Event.class);
    verify(this.eventPublisher).publish(argumentCaptor.capture());
    final Event eventForwarded = argumentCaptor.getValue();
    assertEquals(eventForwarded.getType(), event.getType());
    assertEquals(eventForwarded.getTimestamp(), event.getTimestamp());
    assertFalse(eventForwarded.isDistributed());
    assertEquals(eventForwarded.getData(), event.getData());
}
Also used : Message(com.hazelcast.core.Message) Event(com.enonic.xp.event.Event) Test(org.junit.jupiter.api.Test)

Example 15 with Event

use of com.enonic.xp.event.Event in project xp by enonic.

the class ClusterEventSenderTest method onEvent.

@Test
void onEvent() {
    final Event event = Event.create("aaa").distributed(true).build();
    this.clusterEventSender.onEvent(event);
    verify(topic).publish(eq(event));
}
Also used : Event(com.enonic.xp.event.Event) 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