use of eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmTreeNodeServiceIntegrationTest method testReferentialIntegrityDeleteNodeWithChildren.
@Transactional
@Test(expected = TreeNodeException.class)
public void testReferentialIntegrityDeleteNodeWithChildren() {
IdmTreeTypeDto treeType = getHelper().createTreeType();
IdmTreeNodeDto treeNode = getHelper().createTreeNode(treeType, null);
getHelper().createTreeNode(treeType, treeNode);
// tree node cannot be deleted, when some contract are defined on this node
service.delete(treeNode);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmTreeNodeServiceIntegrationTest method testNullCode.
@Transactional
@Test(expected = ResultCodeException.class)
public void testNullCode() {
IdmTreeTypeDto treeType = getHelper().createTreeType();
IdmTreeNodeDto node = new IdmTreeNodeDto();
node.setTreeType(treeType.getId());
node.setName("test-" + getHelper().createName());
node.setCode(null);
service.save(node);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmTreeNodeServiceIntegrationTest method testBadTreeTypeUpdate.
@Test
@Transactional
public void testBadTreeTypeUpdate() {
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);
//
node3.setTreeType(parent2.getId());
try {
node3 = service.save(node3);
Assert.fail();
} catch (TreeNodeException ex) {
Assert.assertTrue(ex.getMessage().contains("bad type"));
} catch (Exception e) {
Assert.fail();
}
//
node1.setTreeType(parent2.getId());
try {
node1 = service.save(node1);
Assert.fail();
} catch (TreeNodeException ex) {
Assert.assertTrue(ex.getMessage().contains("bad type"));
} catch (Exception e) {
Assert.fail();
}
}
use of eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmTreeNodeServiceIntegrationTest method testForestIndexAfterBulkMoveWithoutTransaction.
@Test
public // @Transactional - TODO: fix recount index in transaction
void testForestIndexAfterBulkMoveWithoutTransaction() {
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 testFindAllParents.
@Test
@Transactional
public void testFindAllParents() {
// TODO: map in filter and move to rest test
//
IdmTreeTypeDto treeType = getHelper().createTreeType();
IdmTreeNodeDto node1 = getHelper().createTreeNode(treeType, null);
IdmTreeNodeDto node2 = getHelper().createTreeNode(treeType, node1);
IdmTreeNodeDto node3 = getHelper().createTreeNode(treeType, node2);
getHelper().createTreeNode(treeType, node3);
//
List<IdmTreeNodeDto> parents = service.findAllParents(node3.getId(), null);
//
Assert.assertEquals(2, parents.size());
Assert.assertTrue(parents.stream().anyMatch(n -> n.equals(node1)));
Assert.assertTrue(parents.stream().anyMatch(n -> n.equals(node2)));
}
Aggregations