Search in sources :

Example 1 with NodeMovedParams

use of com.enonic.xp.repo.impl.storage.NodeMovedParams in project xp by enonic.

the class NodeEventListenerTest method node_moved_event.

@Test
public void node_moved_event() throws Exception {
    final NodeId nodeId = NodeId.from("node1");
    final NodePath nodePath = NodePath.create(NodePath.ROOT, "nodeName").build();
    final Node sourceNode = Node.create().id(nodeId).parentPath(nodePath.getParentPath()).name(nodePath.getLastElement().toString()).build();
    final Node movedNode = Node.create(sourceNode).parentPath(NodePath.create("newParent").build()).build();
    final Event localEvent = NodeEvents.moved(MoveNodeResult.create().addMovedNode(MoveNodeResult.MovedNode.create().node(movedNode).previousPath(sourceNode.path()).build()).sourceNode(sourceNode).build());
    nodeEventListener.onEvent(Event.create(localEvent).localOrigin(false).build());
    final NodeMovedParams nodeMovedParams = new NodeMovedParams(sourceNode.path(), movedNode.path(), sourceNode.id());
    Mockito.verify(nodeStorageService, Mockito.times(1)).handleNodeMoved(Mockito.eq(nodeMovedParams), Mockito.isA(InternalContext.class));
}
Also used : InternalContext(com.enonic.xp.repo.impl.InternalContext) Node(com.enonic.xp.node.Node) NodeId(com.enonic.xp.node.NodeId) Event(com.enonic.xp.event.Event) NodeMovedParams(com.enonic.xp.repo.impl.storage.NodeMovedParams) NodePath(com.enonic.xp.node.NodePath) Test(org.junit.jupiter.api.Test)

Example 2 with NodeMovedParams

use of com.enonic.xp.repo.impl.storage.NodeMovedParams in project xp by enonic.

the class NodeMovedHandler method handleEvent.

@Override
public void handleEvent(NodeStorageService nodeStorageService, final Event event, final InternalContext context) {
    final List<Map<Object, Object>> valueMapList = getValueMapList(event);
    for (final Map<Object, Object> map : valueMapList) {
        final InternalContext nodeContext = createNodeContext(map, context);
        final NodeMovedParams nodeMovedParams = new NodeMovedParams(getPath(map), NodePath.create(map.get(NEW_PATH).toString()).build(), getId(map));
        nodeStorageService.handleNodeMoved(nodeMovedParams, nodeContext);
    }
}
Also used : InternalContext(com.enonic.xp.repo.impl.InternalContext) NodeMovedParams(com.enonic.xp.repo.impl.storage.NodeMovedParams) Map(java.util.Map)

Example 3 with NodeMovedParams

use of com.enonic.xp.repo.impl.storage.NodeMovedParams in project xp by enonic.

the class NodeEventListenerTest method node_renamed_event.

@Test
public void node_renamed_event() throws Exception {
    final NodeId nodeId = NodeId.from("node1");
    final NodePath nodePath = NodePath.create(NodePath.ROOT, "nodeName").build();
    final Node sourceNode = Node.create().id(nodeId).parentPath(nodePath.getParentPath()).name(nodePath.getLastElement().toString()).build();
    final Node movedNode = Node.create(sourceNode).parentPath(NodePath.create("newParent").build()).build();
    final Event localEvent = NodeEvents.renamed(sourceNode.path(), movedNode);
    nodeEventListener.onEvent(Event.create(localEvent).localOrigin(false).build());
    final NodeMovedParams nodeMovedParams = new NodeMovedParams(sourceNode.path(), movedNode.path(), sourceNode.id());
    Mockito.verify(nodeStorageService, Mockito.times(1)).handleNodeMoved(Mockito.eq(nodeMovedParams), Mockito.isA(InternalContext.class));
}
Also used : InternalContext(com.enonic.xp.repo.impl.InternalContext) Node(com.enonic.xp.node.Node) NodeId(com.enonic.xp.node.NodeId) Event(com.enonic.xp.event.Event) NodeMovedParams(com.enonic.xp.repo.impl.storage.NodeMovedParams) NodePath(com.enonic.xp.node.NodePath) Test(org.junit.jupiter.api.Test)

Aggregations

InternalContext (com.enonic.xp.repo.impl.InternalContext)3 NodeMovedParams (com.enonic.xp.repo.impl.storage.NodeMovedParams)3 Event (com.enonic.xp.event.Event)2 Node (com.enonic.xp.node.Node)2 NodeId (com.enonic.xp.node.NodeId)2 NodePath (com.enonic.xp.node.NodePath)2 Test (org.junit.jupiter.api.Test)2 Map (java.util.Map)1