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);
}
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);
}
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);
}
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());
}
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));
}
Aggregations