use of com.enonic.xp.node.FindNodesByParentResult in project xp by enonic.
the class FindNodesByParentCommandTest method size.
@Test
public void size() throws Exception {
this.createDefaultRootNode();
final Node createdNode = createNode(CreateNodeParams.create().parent(NodePath.ROOT).name("my-node").build());
int size = 20;
createChildren(createdNode, size);
FindNodesByParentResult children = findByParent(FindNodesByParentParams.create().parentPath(createdNode.path()).size(9).build());
assertEquals(9, children.getHits());
children = findByParent(FindNodesByParentParams.create().parentPath(createdNode.path()).size(100).build());
assertEquals(20, children.getHits());
}
use of com.enonic.xp.node.FindNodesByParentResult in project xp by enonic.
the class FindNodesByParentCommandTest method getChildren.
@Test
public void getChildren() throws Exception {
this.createDefaultRootNode();
final String nodeName = "my-node";
final Node createdNode = createNode(CreateNodeParams.create().parent(NodePath.ROOT).name(nodeName).build());
createNode(CreateNodeParams.create().parent(createdNode.path()).name("my-child1").build());
createNode(CreateNodeParams.create().parent(createdNode.path()).name("my-child2").build());
refresh();
final FindNodesByParentResult children = findByParent(FindNodesByParentParams.create().parentPath(createdNode.path()).build());
assertEquals(2, children.getHits());
assertEquals(2, children.getNodeIds().getSize());
}
use of com.enonic.xp.node.FindNodesByParentResult in project xp by enonic.
the class FindNodesByParentCommandTest method get_children_order.
@Test
public void get_children_order() throws Exception {
this.createDefaultRootNode();
final Node createdNode = createNode(CreateNodeParams.create().setNodeId(NodeId.from("parent")).name("my-node").parent(NodePath.ROOT).childOrder(ChildOrder.from(NodeIndexPath.NAME + " ASC")).build());
final Node childNode_b_3 = createNode(CreateNodeParams.create().setNodeId(NodeId.from("childnode_b_3")).parent(createdNode.path()).name("b").data(createOrderProperty(3.0)).build());
final Node childNode_a_2 = createNode(CreateNodeParams.create().setNodeId(NodeId.from("childnode_a_2")).parent(createdNode.path()).name("a").data(createOrderProperty(2.0)).build());
final Node childNode_c_1 = createNode(CreateNodeParams.create().setNodeId(NodeId.from("childnode_c_1")).parent(createdNode.path()).name("c").data(createOrderProperty(1.0)).build());
refresh();
// Use default parent ordering; name
FindNodesByParentResult result = FindNodesByParentCommand.create().params(FindNodesByParentParams.create().parentPath(createdNode.path()).build()).indexServiceInternal(indexServiceInternal).storageService(this.storageService).searchService(this.searchService).build().execute();
Nodes childNodes = GetNodesByIdsCommand.create().ids(result.getNodeIds()).indexServiceInternal(indexServiceInternal).storageService(storageService).searchService(searchService).build().execute();
assertEquals(3, childNodes.getSize());
Iterator<Node> iterator = childNodes.iterator();
assertEquals(childNode_a_2, iterator.next());
assertEquals(childNode_b_3, iterator.next());
assertEquals(childNode_c_1, iterator.next());
// Override by specify childOrder-parameter by order-field
result = FindNodesByParentCommand.create().params(FindNodesByParentParams.create().parentPath(createdNode.path()).childOrder(ChildOrder.from("order ASC")).build()).indexServiceInternal(indexServiceInternal).storageService(this.storageService).searchService(this.searchService).build().execute();
childNodes = GetNodesByIdsCommand.create().ids(result.getNodeIds()).indexServiceInternal(indexServiceInternal).storageService(storageService).searchService(searchService).build().execute();
assertEquals(3, childNodes.getSize());
iterator = childNodes.iterator();
assertEquals(childNode_c_1, iterator.next());
assertEquals(childNode_a_2, iterator.next());
assertEquals(childNode_b_3, iterator.next());
}
use of com.enonic.xp.node.FindNodesByParentResult in project xp by enonic.
the class FindNodeIdsByParentCommandTest method find_after_move_to_folder_with_same_name.
@Test
public void find_after_move_to_folder_with_same_name() throws Exception {
final Node node = createNode(CreateNodeParams.create().setNodeId(NodeId.from("node")).parent(NodePath.ROOT).name("node").build());
final Node node1_1 = createNode(CreateNodeParams.create().setNodeId(NodeId.from("node1_1")).parent(node.path()).name("node1_1").build());
createNode(CreateNodeParams.create().setNodeId(NodeId.from("node1_1_1")).parent(node1_1.path()).name("node1_1_1").build());
final Node node2 = createNode(CreateNodeParams.create().setNodeId(NodeId.from("node1")).parent(NodePath.ROOT).name("node1").build());
refresh();
MoveNodeCommand.create().newParent(node2.path()).id(node1_1.id()).indexServiceInternal(indexServiceInternal).searchService(searchService).storageService(storageService).build().execute();
final FindNodesByParentResult children = FindNodeIdsByParentCommand.create().parentPath(node.path()).recursive(true).searchService(this.searchService).storageService(this.storageService).indexServiceInternal(this.indexServiceInternal).build().execute();
assertEquals(0, children.getNodeIds().getSize());
}
Aggregations