use of eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmTreeNodeServiceIntegrationTest method testMoveChildren.
/**
* Move childern to new parent a delete previous parent
*/
@Test
@Transactional
public void testMoveChildren() {
IdmTreeTypeDto treeType = getHelper().createTreeType();
// create root node
IdmTreeNodeDto root = getHelper().createTreeNode(treeType, null);
IdmTreeNodeDto subRoot = getHelper().createTreeNode(treeType, root);
// create children
IdmTreeNodeDto nodeOne = getHelper().createTreeNode(treeType, subRoot);
IdmTreeNodeDto nodeTwo = getHelper().createTreeNode(treeType, subRoot);
IdmTreeNodeDto nodeThree = getHelper().createTreeNode(treeType, subRoot);
//
Assert.assertEquals(4, treeNodeForestContentService.findAllChildren(root.getId(), null).getTotalElements());
Assert.assertEquals(3, treeNodeForestContentService.findAllChildren(subRoot.getId(), null).getTotalElements());
//
// move children to other parent
IdmTreeNodeDto subRootTwo = getHelper().createTreeNode(treeType, root);
nodeOne.setParent(subRootTwo.getId());
nodeOne = service.save(nodeOne);
nodeTwo.setParent(subRootTwo.getId());
nodeTwo = service.save(nodeTwo);
nodeThree.setParent(subRootTwo.getId());
nodeThree = service.save(nodeThree);
//
// delete previous parent
service.delete(subRoot);
//
Assert.assertEquals(4, treeNodeForestContentService.findAllChildren(root.getId(), null).getTotalElements());
Assert.assertEquals(3, treeNodeForestContentService.findAllChildren(subRootTwo.getId(), null).getTotalElements());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmTreeNodeServiceIntegrationTest method testEmptyCode.
@Transactional
@Test(expected = ResultCodeException.class)
public void testEmptyCode() {
IdmTreeTypeDto treeType = getHelper().createTreeType();
IdmTreeNodeDto node = new IdmTreeNodeDto();
node.setTreeType(treeType.getId());
node.setName("test-" + getHelper().createName());
node.setCode(" ");
service.save(node);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmTreeNodeServiceIntegrationTest method testForestIndexAfterBulkMoveWithTransaction.
@Test
@Transactional
public void testForestIndexAfterBulkMoveWithTransaction() {
int rootCount = 5;
// prepare new tree type
IdmTreeTypeDto treeType = getHelper().createTreeType();
// create root nodes
for (int i = 0; i < rootCount; i++) {
getHelper().createTreeNode(treeType, null);
}
// move nodes to the first node
IdmTreeNodeFilter filter = new IdmTreeNodeFilter();
filter.setTreeTypeId(treeType.getId());
List<IdmTreeNodeDto> nodes = service.find(filter, null).getContent();
IdmTreeNodeDto root = nodes.get(0);
for (int i = 0; i < nodes.size(); i++) {
IdmTreeNodeDto node = nodes.get(i);
if (node.equals(root)) {
continue;
}
node.setParent(root.getId());
node = service.save(node);
}
// check
Assert.assertEquals(1L, service.findRoots(treeType.getId(), null).getTotalElements());
Assert.assertEquals(rootCount - 1, service.findChildrenByParent(root.getId(), null).getTotalElements());
Assert.assertEquals(rootCount - 1, treeNodeForestContentService.findDirectChildren(root.getId(), null).getTotalElements());
Assert.assertEquals(rootCount - 1, treeNodeForestContentService.findAllChildren(root.getId(), null).getTotalElements());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmTreeNodeServiceIntegrationTest method testRebuildIndex.
@Test
public void testRebuildIndex() {
IdmTreeTypeDto treeType = getHelper().createTreeType();
IdmTreeNodeDto node1 = getHelper().createTreeNode(treeType, null);
IdmTreeNodeDto node2 = getHelper().createTreeNode(treeType, node1);
IdmTreeNodeDto node3 = getHelper().createTreeNode(treeType, node2);
IdmTreeNodeDto node4 = getHelper().createTreeNode(treeType, node3);
// before index will be droped
IdmTreeNodeFilter filter = new IdmTreeNodeFilter();
filter.setParent(node2.getId());
filter.setRecursively(true);
//
List<IdmTreeNodeDto> results = service.find(filter, null).getContent();
//
Assert.assertEquals(2, results.size());
Assert.assertTrue(results.stream().anyMatch(n -> n.equals(node3)));
Assert.assertTrue(results.stream().anyMatch(n -> n.equals(node4)));
//
// drop indexes
forestIndexService.dropIndexes(IdmTreeNode.toForestTreeType(treeType.getId()));
//
results = service.find(filter, null).getContent();
Assert.assertEquals(0, results.size());
//
// reindex tree type
service.rebuildIndexes(treeType.getId());
//
results = service.find(filter, null).getContent();
Assert.assertEquals(2, results.size());
Assert.assertTrue(results.stream().anyMatch(n -> n.equals(node3)));
Assert.assertTrue(results.stream().anyMatch(n -> n.equals(node4)));
}
use of eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmTreeNodeServiceIntegrationTest method testBadTreeTypeCreate.
@Test
@Transactional
public void testBadTreeTypeCreate() {
IdmTreeTypeDto parent1 = getHelper().createTreeType();
IdmTreeTypeDto parent2 = getHelper().createTreeType();
//
IdmTreeNodeDto node1 = getHelper().createTreeNode(parent1, null);
IdmTreeNodeDto node2 = getHelper().createTreeNode(parent1, node1);
IdmTreeNodeDto node3 = getHelper().createTreeNode(parent1, node2);
//
try {
getHelper().createTreeNode(parent2, node1);
Assert.fail();
} catch (TreeNodeException ex) {
Assert.assertTrue(ex.getMessage().contains("bad type"));
} catch (Exception e) {
Assert.fail();
}
//
try {
getHelper().createTreeNode(parent2, node3);
Assert.fail();
} catch (TreeNodeException ex) {
Assert.assertTrue(ex.getMessage().contains("bad type"));
} catch (Exception e) {
Assert.fail();
}
}
Aggregations