Search in sources :

Example 31 with Event

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

the class EventPublisherImplTest method testPublish_noListener.

@Test
public void testPublish_noListener() {
    final Event event = Event.create("test").build();
    this.publisher.publish(event);
}
Also used : Event(com.enonic.xp.event.Event) Test(org.junit.jupiter.api.Test)

Example 32 with Event

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

the class EventPublisherImplTest method testPublish_withListener.

@Test
public void testPublish_withListener() throws Exception {
    final EventListener listener = mock(EventListener.class);
    this.publisher.addListener(listener);
    final Event event = Event.create("test").build();
    for (int i = 0; i < 100; i++) {
        this.publisher.publish(event);
    }
    verify(listener, times(100)).onEvent(Mockito.any());
}
Also used : Event(com.enonic.xp.event.Event) EventListener(com.enonic.xp.event.EventListener) Test(org.junit.jupiter.api.Test)

Example 33 with Event

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

the class NodeEventsTest method testRenamed.

@Test
public void testRenamed() {
    final Node sourceNode = createNode("before", NodePath.create("/mynode1/child1").build(), "myId");
    final Node targetNode = createNode("after", NodePath.create("/mynode1/child1").build(), "myId");
    Event event = NodeEvents.renamed(sourceNode.path(), targetNode);
    assertNotNull(event);
    assertTrue(event.isDistributed());
    assertEquals(NodeEvents.NODE_RENAMED_EVENT, event.getType());
    assertEquals("[{id=myId, path=/mynode1/child1/before, branch=draft, repo=com.enonic.cms.default, newPath=/mynode1/child1/after}]", event.getValue("nodes").get().toString());
}
Also used : Node(com.enonic.xp.node.Node) Event(com.enonic.xp.event.Event) Test(org.junit.jupiter.api.Test)

Example 34 with Event

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

the class NodeEventsTest method testStateUpdated.

@Test
public void testStateUpdated() {
    final Node pushed1 = createNode("state_updated1", NodePath.create("/mynode1/state_updated1").build(), "id1");
    final Node pushed2 = createNode("state_updated2", NodePath.create("/mynode1/state_updated2").build(), "id2");
    final Node pushed3 = createNode("state_updated3", NodePath.create("/mynode1/state_updated3").build(), "id3");
    final Nodes nodes = Nodes.from(pushed1, pushed2, pushed3);
    Event event = NodeEvents.stateUpdated(nodes);
    assertNotNull(event);
    assertTrue(event.isDistributed());
    assertTrue(event.hasValue("nodes"));
    assertTrue(event.hasValue("state"));
    assertEquals(NodeEvents.NODE_STATE_UPDATED_EVENT, event.getType());
    assertEquals(NodeState.DEFAULT.toString(), event.getValue("state").get());
    assertEquals("[{id=id1, path=/mynode1/state_updated1/state_updated1, branch=draft, repo=com.enonic.cms.default}" + ", {id=id2, path=/mynode1/state_updated2/state_updated2, branch=draft, repo=com.enonic.cms.default}" + ", {id=id3, path=/mynode1/state_updated3/state_updated3, branch=draft, repo=com.enonic.cms.default}]", event.getValue("nodes").get().toString());
}
Also used : Node(com.enonic.xp.node.Node) Event(com.enonic.xp.event.Event) Nodes(com.enonic.xp.node.Nodes) Test(org.junit.jupiter.api.Test)

Example 35 with Event

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

the class NodeEventsTest method testMoved.

@Test
public void testMoved() {
    final Node sourceNode = createNode("before", NodePath.create("/mynode1/child1").build(), "myId");
    final Node targetNode = createNode("after", NodePath.create("/mynode1").build(), "myId");
    Event event = NodeEvents.moved(MoveNodeResult.create().addMovedNode(MoveNodeResult.MovedNode.create().node(targetNode).previousPath(sourceNode.path()).build()).sourceNode(sourceNode).build());
    assertNotNull(event);
    assertTrue(event.isDistributed());
    assertEquals(NodeEvents.NODE_MOVED_EVENT, event.getType());
    assertEquals("[{id=myId, path=/mynode1/child1/before, branch=draft, repo=com.enonic.cms.default, newPath=/mynode1/after}]", event.getValue("nodes").get().toString());
}
Also used : Node(com.enonic.xp.node.Node) 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