Search in sources :

Example 1 with ReorderChildNodesParams

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

the class NodeServiceImplTest method testReorderChildren.

@Test
public void testReorderChildren() {
    final Node parent = createNode(CreateNodeParams.create().name("my-parent").parent(NodePath.ROOT).childOrder(ChildOrder.manualOrder()).build());
    final Node child1 = createNode(CreateNodeParams.create().name("my-child-1").parent(parent.path()).build());
    final Node child2 = createNode(CreateNodeParams.create().name("my-child-2").parent(parent.path()).build());
    final Node child3 = createNode(CreateNodeParams.create().name("my-child-3").parent(parent.path()).build());
    final ReorderChildNodesParams params = ReorderChildNodesParams.create().add(ReorderChildNodeParams.create().nodeId(child1.id()).moveBefore(child2.id()).build()).add(ReorderChildNodeParams.create().nodeId(child3.id()).moveBefore(child1.id()).build()).processor(data -> {
        data.addString("processedValue", "value");
        return data;
    }).build();
    final ReorderChildNodesResult result = this.nodeService.reorderChildren(params);
    assertThat(result.getNodeIds()).containsExactly(child1.id(), child3.id());
    assertThat(result.getParentNodes().getIds()).containsExactly(parent.id());
    assertThat(nodeService.findByParent(FindNodesByParentParams.create().parentId(parent.id()).build()).getNodeIds()).containsExactly(child3.id(), child1.id(), child2.id());
    nodeService.refresh(RefreshMode.ALL);
    final Node processedParent = this.nodeService.getById(parent.id());
    assertEquals("value", processedParent.data().getString("processedValue"));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) IdProviderKey(com.enonic.xp.security.IdProviderKey) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) Permission(com.enonic.xp.security.acl.Permission) NodeCommitId(com.enonic.xp.node.NodeCommitId) ContextAccessor(com.enonic.xp.context.ContextAccessor) NodeVersionsMetadata(com.enonic.xp.node.NodeVersionsMetadata) ContextBuilder(com.enonic.xp.context.ContextBuilder) BinaryReference(com.enonic.xp.util.BinaryReference) User(com.enonic.xp.security.User) NodeIndexPath(com.enonic.xp.node.NodeIndexPath) CreateRootNodeParams(com.enonic.xp.node.CreateRootNodeParams) Instant(java.time.Instant) AccessControlList(com.enonic.xp.security.acl.AccessControlList) NodeId(com.enonic.xp.node.NodeId) RenameNodeParams(com.enonic.xp.node.RenameNodeParams) Test(org.junit.jupiter.api.Test) NodeCommitEntry(com.enonic.xp.node.NodeCommitEntry) OrderExpr(com.enonic.xp.query.expr.OrderExpr) RoutableNodeVersionId(com.enonic.xp.node.RoutableNodeVersionId) ReorderChildNodesResult(com.enonic.xp.node.ReorderChildNodesResult) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) RoleKeys(com.enonic.xp.security.RoleKeys) Context(com.enonic.xp.context.Context) FindNodesByParentParams(com.enonic.xp.node.FindNodesByParentParams) AccessControlEntry(com.enonic.xp.security.acl.AccessControlEntry) ChildOrder(com.enonic.xp.index.ChildOrder) RefreshMode(com.enonic.xp.node.RefreshMode) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) EventPublisher(com.enonic.xp.event.EventPublisher) RoutableNodeVersionIds(com.enonic.xp.node.RoutableNodeVersionIds) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) Node(com.enonic.xp.node.Node) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) DuplicateNodeParams(com.enonic.xp.node.DuplicateNodeParams) NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) ReorderChildNodesParams(com.enonic.xp.node.ReorderChildNodesParams) NodeVersionMetadata(com.enonic.xp.node.NodeVersionMetadata) FieldOrderExpr(com.enonic.xp.query.expr.FieldOrderExpr) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ByteSource(com.google.common.io.ByteSource) PropertyTree(com.enonic.xp.data.PropertyTree) Iterator(java.util.Iterator) NodePath(com.enonic.xp.node.NodePath) IOException(java.io.IOException) ReorderChildNodeParams(com.enonic.xp.node.ReorderChildNodeParams) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo) GetNodeVersionsParams(com.enonic.xp.node.GetNodeVersionsParams) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) Mockito(org.mockito.Mockito) NodeName(com.enonic.xp.node.NodeName) BranchNotFoundException(com.enonic.xp.repository.BranchNotFoundException) PrincipalKey(com.enonic.xp.security.PrincipalKey) MoveNodeParams(com.enonic.xp.node.MoveNodeParams) NodeIds(com.enonic.xp.node.NodeIds) RepositoryNotFoundException(com.enonic.xp.repository.RepositoryNotFoundException) ReorderChildNodesParams(com.enonic.xp.node.ReorderChildNodesParams) Node(com.enonic.xp.node.Node) ReorderChildNodesResult(com.enonic.xp.node.ReorderChildNodesResult) Test(org.junit.jupiter.api.Test)

Aggregations

Context (com.enonic.xp.context.Context)1 ContextAccessor (com.enonic.xp.context.ContextAccessor)1 ContextBuilder (com.enonic.xp.context.ContextBuilder)1 PropertyTree (com.enonic.xp.data.PropertyTree)1 EventPublisher (com.enonic.xp.event.EventPublisher)1 ChildOrder (com.enonic.xp.index.ChildOrder)1 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)1 CreateRootNodeParams (com.enonic.xp.node.CreateRootNodeParams)1 DuplicateNodeParams (com.enonic.xp.node.DuplicateNodeParams)1 FindNodesByParentParams (com.enonic.xp.node.FindNodesByParentParams)1 GetNodeVersionsParams (com.enonic.xp.node.GetNodeVersionsParams)1 MoveNodeParams (com.enonic.xp.node.MoveNodeParams)1 Node (com.enonic.xp.node.Node)1 NodeCommitEntry (com.enonic.xp.node.NodeCommitEntry)1 NodeCommitId (com.enonic.xp.node.NodeCommitId)1 NodeId (com.enonic.xp.node.NodeId)1 NodeIds (com.enonic.xp.node.NodeIds)1 NodeIndexPath (com.enonic.xp.node.NodeIndexPath)1 NodeName (com.enonic.xp.node.NodeName)1 NodeNotFoundException (com.enonic.xp.node.NodeNotFoundException)1