Search in sources :

Example 1 with NodesHasChildrenResult

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

the class ContentNodeTranslatorTest method testFromNodesResolvingChildren.

@Test
public void testFromNodesResolvingChildren() throws Exception {
    final Nodes nodes = createNodes();
    final NodesHasChildrenResult hasChildrenResult = NodesHasChildrenResult.create().add(ID_1, true).add(ID_2, true).add(ID_3, false).build();
    Mockito.when(this.nodeService.hasChildren(Mockito.any(Nodes.class))).thenReturn(hasChildrenResult);
    final Contents contents = this.contentNodeTranslator.fromNodes(nodes, true);
    assertEquals(3, contents.getSize());
    final Content content1 = contents.getContentById(ContentId.from(ID_1.toString()));
    final Content content3 = contents.getContentById(ContentId.from(ID_3.toString()));
    final Content content2 = contents.getContentById(ContentId.from(ID_2.toString()));
    assertTrue(content1.hasChildren());
    assertTrue(content2.hasChildren());
    assertFalse(content3.hasChildren());
}
Also used : NodesHasChildrenResult(com.enonic.xp.node.NodesHasChildrenResult) Contents(com.enonic.xp.content.Contents) Content(com.enonic.xp.content.Content) Nodes(com.enonic.xp.node.Nodes) Test(org.junit.jupiter.api.Test)

Example 2 with NodesHasChildrenResult

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

the class NodeHasChildResolverTest method nodes_has_children.

@Test
public void nodes_has_children() throws Exception {
    final Node parentNode1 = createNode(CreateNodeParams.create().parent(NodePath.ROOT).name("my-node-1").build());
    final Node parentNode2 = createNode(CreateNodeParams.create().parent(NodePath.ROOT).name("my-node-2").build());
    final Node parentNode3 = createNode(CreateNodeParams.create().parent(NodePath.ROOT).name("my-node-3").build());
    createNode(CreateNodeParams.create().parent(parentNode1.path()).name("my-child-node-1").build());
    createNode(CreateNodeParams.create().parent(parentNode2.path()).name("my-child-node-2").build());
    final NodesHasChildrenResult result = NodeHasChildResolver.create().searchService(this.searchService).build().resolve(Nodes.from(parentNode1, parentNode2, parentNode3));
    assertTrue(result.hasChild(parentNode1.id()));
    assertTrue(result.hasChild(parentNode2.id()));
    assertFalse(result.hasChild(parentNode3.id()));
}
Also used : NodesHasChildrenResult(com.enonic.xp.node.NodesHasChildrenResult) Node(com.enonic.xp.node.Node) Test(org.junit.jupiter.api.Test)

Aggregations

NodesHasChildrenResult (com.enonic.xp.node.NodesHasChildrenResult)2 Test (org.junit.jupiter.api.Test)2 Content (com.enonic.xp.content.Content)1 Contents (com.enonic.xp.content.Contents)1 Node (com.enonic.xp.node.Node)1 Nodes (com.enonic.xp.node.Nodes)1