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());
}
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()));
}