Search in sources :

Example 36 with NodeId

use of com.enonic.xp.node.NodeId in project xp by enonic.

the class LoadNodeCommandTest method node_already_exists_in_path.

@Test
public void node_already_exists_in_path() throws Exception {
    final Node originalNode = createNode(NodePath.ROOT, "fisk");
    final Node nodeToLoad = Node.create(originalNode).id(new NodeId()).parentPath(NodePath.ROOT).name("fisk").timestamp(Instant.now()).nodeVersionId(NodeVersionId.from("nodeVersionId")).build();
    final LoadNodeParams loadParams = LoadNodeParams.create().node(nodeToLoad).build();
    refresh();
    doLoadNode(loadParams);
    refresh();
    final Node storedNode = getNodeByPath(nodeToLoad.path());
    assertNotNull(storedNode);
    assertNotEquals(originalNode.id(), storedNode.id());
}
Also used : Node(com.enonic.xp.node.Node) NodeId(com.enonic.xp.node.NodeId) LoadNodeParams(com.enonic.xp.node.LoadNodeParams) Test(org.junit.jupiter.api.Test)

Example 37 with NodeId

use of com.enonic.xp.node.NodeId in project xp by enonic.

the class LoadNodeCommandTest method parent_does_not_exist.

@Test
public void parent_does_not_exist() throws Exception {
    final LoadNodeParams loadParams = LoadNodeParams.create().node(Node.create().id(new NodeId()).parentPath(NodePath.create("ost").build()).name("fisk").timestamp(Instant.now()).nodeVersionId(NodeVersionId.from("nodeVersionId")).build()).build();
    assertThrows(NodeLoadException.class, () -> doLoadNode(loadParams));
}
Also used : NodeId(com.enonic.xp.node.NodeId) LoadNodeParams(com.enonic.xp.node.LoadNodeParams) Test(org.junit.jupiter.api.Test)

Example 38 with NodeId

use of com.enonic.xp.node.NodeId in project xp by enonic.

the class ReorderChildNodeCommandTest method move_in_between.

@Test
public void move_in_between() throws Exception {
    final Node parentNode = createNode(CreateNodeParams.create().name("my-node").parent(NodePath.ROOT).build());
    createChildNodes(parentNode);
    setChildOrder(parentNode, NodeIndexPath.NAME, OrderExpr.Direction.ASC);
    setChildOrder(parentNode, NodeIndexPath.MANUAL_ORDER_VALUE, OrderExpr.Direction.DESC);
    // current node order: a,b,c,d,e,f
    ReorderChildNodeCommand.create().parentNode(getNodeById(parentNode.id())).nodeToMove(getNodeById(NodeId.from("c"))).nodeToMoveBefore(getNodeById(NodeId.from("b"))).indexServiceInternal(this.indexServiceInternal).storageService(this.storageService).searchService(this.searchService).build().execute();
    refresh();
    final FindNodesByParentResult reOrderedResult = findByParent(FindNodesByParentParams.create().parentPath(parentNode.path()).build());
    // updated node order: a,c,b,d,e,f
    final Iterator<NodeId> iterator = reOrderedResult.getNodeIds().iterator();
    assertEquals("a", iterator.next().toString());
    assertEquals("c", iterator.next().toString());
    assertEquals("b", iterator.next().toString());
    assertEquals("d", iterator.next().toString());
    assertEquals("e", iterator.next().toString());
    assertEquals("f", iterator.next().toString());
}
Also used : Node(com.enonic.xp.node.Node) NodeId(com.enonic.xp.node.NodeId) FindNodesByParentResult(com.enonic.xp.node.FindNodesByParentResult) Test(org.junit.jupiter.api.Test)

Example 39 with NodeId

use of com.enonic.xp.node.NodeId in project xp by enonic.

the class ReorderChildNodeCommandTest method move_first.

@Test
public void move_first() throws Exception {
    final Node parentNode = createNode(CreateNodeParams.create().name("my-node").parent(NodePath.ROOT).build());
    createChildNodes(parentNode);
    setChildOrder(parentNode, NodeIndexPath.NAME, OrderExpr.Direction.ASC);
    setChildOrder(parentNode, NodeIndexPath.MANUAL_ORDER_VALUE, OrderExpr.Direction.DESC);
    // current node order: a,b,c,d,e,f
    ReorderChildNodeCommand.create().parentNode(getNodeById(parentNode.id())).nodeToMove(getNodeById(NodeId.from("c"))).nodeToMoveBefore(getNodeById(NodeId.from("a"))).indexServiceInternal(this.indexServiceInternal).storageService(this.storageService).searchService(this.searchService).build().execute();
    refresh();
    final FindNodesByParentResult reOrderedResult = findByParent(FindNodesByParentParams.create().parentPath(parentNode.path()).build());
    // updated node order: c,a,b,d,e,f
    final Iterator<NodeId> iterator = reOrderedResult.getNodeIds().iterator();
    assertEquals("c", iterator.next().toString());
    assertEquals("a", iterator.next().toString());
    assertEquals("b", iterator.next().toString());
    assertEquals("d", iterator.next().toString());
    assertEquals("e", iterator.next().toString());
    assertEquals("f", iterator.next().toString());
}
Also used : Node(com.enonic.xp.node.Node) NodeId(com.enonic.xp.node.NodeId) FindNodesByParentResult(com.enonic.xp.node.FindNodesByParentResult) Test(org.junit.jupiter.api.Test)

Example 40 with NodeId

use of com.enonic.xp.node.NodeId in project xp by enonic.

the class SetNodeChildOrderCommandTest method order_by_name_desc.

@Test
public void order_by_name_desc() throws Exception {
    final FindNodesByParentResult result = createNodeAndReturnOrderedChildren(NodeIndexPath.NAME, OrderExpr.Direction.DESC);
    String previousName = "";
    for (final NodeId n : result.getNodeIds()) {
        final Node node = getNode(n);
        final boolean largerThanPreviousName = previousName.compareTo(node.name().toString()) > 0;
        assertTrue(Objects.equals(previousName, "") || largerThanPreviousName);
        previousName = node.name().toString();
    }
}
Also used : Node(com.enonic.xp.node.Node) NodeId(com.enonic.xp.node.NodeId) FindNodesByParentResult(com.enonic.xp.node.FindNodesByParentResult) Test(org.junit.jupiter.api.Test)

Aggregations

NodeId (com.enonic.xp.node.NodeId)91 Node (com.enonic.xp.node.Node)44 Test (org.junit.jupiter.api.Test)36 NodePath (com.enonic.xp.node.NodePath)23 InternalContext (com.enonic.xp.repo.impl.InternalContext)18 FindNodesByParentResult (com.enonic.xp.node.FindNodesByParentResult)15 NodeIds (com.enonic.xp.node.NodeIds)14 NodeNotFoundException (com.enonic.xp.node.NodeNotFoundException)11 Context (com.enonic.xp.context.Context)10 PropertyTree (com.enonic.xp.data.PropertyTree)10 Branch (com.enonic.xp.branch.Branch)9 ContextAccessor (com.enonic.xp.context.ContextAccessor)9 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)9 NodeVersionId (com.enonic.xp.node.NodeVersionId)9 NodeVersionMetadata (com.enonic.xp.node.NodeVersionMetadata)8 RefreshMode (com.enonic.xp.node.RefreshMode)8 UpdateNodeParams (com.enonic.xp.node.UpdateNodeParams)8 ContextBuilder (com.enonic.xp.context.ContextBuilder)6 Event (com.enonic.xp.event.Event)6 RenameNodeParams (com.enonic.xp.node.RenameNodeParams)6