use of eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto in project CzechIdMng by bcvsolutions.
the class IdmTreeNodeServiceIntegrationTest method testFilters.
@Test
public void testFilters() {
// ****** PREPARE DATA ******
IdmTreeTypeDto t1 = treeTypeService.save(helper.createTreeType("TYPE1"));
IdmTreeTypeDto t2 = treeTypeService.save(helper.createTreeType("TYPE2"));
UUID t1Id = t1.getId();
UUID t2Id = t2.getId();
/*
o r1
/ \
n1 o o n3
/ \
n2 o o n4
\
o n5
*/
IdmTreeNodeDto r1 = helper.createTreeNode(t1, "ROOT1", null);
IdmTreeNodeDto n1 = helper.createTreeNode(t1, "NODE1", r1);
helper.createTreeNode(t1, "NODE2", n1);
helper.createTreeNode(t1, "NODE3", r1);
IdmTreeNodeDto n4 = helper.createTreeNode(t1, "NODE4", n1);
IdmTreeNodeDto n5 = helper.createTreeNode(t1, "NODE5", n4);
/*
o r2
/
n12 o-o n11
*/
IdmTreeNodeDto r2 = helper.createTreeNode(t2, "ROOT2", null);
IdmTreeNodeDto n11 = helper.createTreeNode(t2, "NODE11", r2);
IdmTreeNodeDto n12 = helper.createTreeNode(t2, "NODE12", n11);
//
final UUID r1Uuid = r1.getId();
final UUID n1Uuid = n1.getId();
final UUID n5Uuid = n5.getId();
final UUID r2Uuid = r2.getId();
final UUID n12Uuid = n12.getId();
//
// ******* TEST *******
//
final IdmTreeNodeFilter t1Flter = new IdmTreeNodeFilter();
t1Flter.setTreeTypeId(t1Id);
Page<IdmTreeNodeDto> res1 = treeNodeService.find(t1Flter, null);
Assert.assertEquals(6, res1.getTotalElements());
//
final IdmTreeNodeFilter t2Flter = new IdmTreeNodeFilter();
t2Flter.setTreeTypeId(t2Id);
Page<IdmTreeNodeDto> res2 = treeNodeService.find(t2Flter, null);
Assert.assertEquals(3, res2.getTotalElements());
//
// Subtrees
//
final IdmTreeNodeFilter subTreeFilter1 = new IdmTreeNodeFilter();
subTreeFilter1.setTreeNode(n1Uuid);
subTreeFilter1.setTreeTypeId(t1Id);
subTreeFilter1.setRecursively(true);
Page<IdmTreeNodeDto> res3 = treeNodeService.find(subTreeFilter1, null);
Assert.assertEquals(3, res3.getTotalElements());
//
final IdmTreeNodeFilter subTreeFilter2 = new IdmTreeNodeFilter();
subTreeFilter2.setTreeNode(n1Uuid);
subTreeFilter2.setRecursively(false);
Page<IdmTreeNodeDto> res4 = treeNodeService.find(subTreeFilter2, null);
Assert.assertEquals(2, res4.getTotalElements());
//
final IdmTreeNodeFilter subTreeFilter3 = new IdmTreeNodeFilter();
subTreeFilter3.setTreeNode(r2Uuid);
subTreeFilter3.setRecursively(false);
Page<IdmTreeNodeDto> res5 = treeNodeService.find(subTreeFilter3, null);
Assert.assertEquals(1, res5.getTotalElements());
//
final IdmTreeNodeFilter subTreeFilter4 = new IdmTreeNodeFilter();
subTreeFilter4.setTreeNode(r2Uuid);
subTreeFilter4.setTreeTypeId(t2Id);
subTreeFilter4.setRecursively(true);
Page<IdmTreeNodeDto> res6 = treeNodeService.find(subTreeFilter4, null);
Assert.assertEquals(2, res6.getTotalElements());
//
final IdmTreeNodeFilter subTreeFilter5 = new IdmTreeNodeFilter();
subTreeFilter5.setTreeNode(n12Uuid);
subTreeFilter5.setTreeTypeId(t2Id);
subTreeFilter5.setRecursively(true);
Page<IdmTreeNodeDto> res7 = treeNodeService.find(subTreeFilter5, null);
Assert.assertEquals(0, res7.getTotalElements());
//
final IdmTreeNodeFilter subTreeFilter6 = new IdmTreeNodeFilter();
subTreeFilter6.setTreeNode(n12Uuid);
subTreeFilter6.setTreeTypeId(t2Id);
subTreeFilter6.setRecursively(false);
Page<IdmTreeNodeDto> res8 = treeNodeService.find(subTreeFilter6, null);
Assert.assertEquals(0, res8.getTotalElements());
//
// Fulltext
//
final IdmTreeNodeFilter fullTextFilter1 = new IdmTreeNodeFilter();
fullTextFilter1.setText("NODE5");
Page<IdmTreeNodeDto> res9 = treeNodeService.find(fullTextFilter1, null);
Assert.assertEquals(1, res9.getTotalElements());
Assert.assertEquals(n5Uuid, res9.getContent().get(0).getId());
//
final IdmTreeNodeFilter fullTextFilter2 = new IdmTreeNodeFilter();
fullTextFilter2.setText("NODE");
fullTextFilter2.setTreeTypeId(t1Id);
Page<IdmTreeNodeDto> res10 = treeNodeService.find(fullTextFilter2, null);
Assert.assertEquals(5, res10.getTotalElements());
//
final IdmTreeNodeFilter fullTextFilter3 = new IdmTreeNodeFilter();
fullTextFilter3.setText("odE");
fullTextFilter3.setTreeTypeId(t1Id);
Page<IdmTreeNodeDto> res13 = treeNodeService.find(fullTextFilter3, null);
Assert.assertEquals(5, res13.getTotalElements());
//
// Property - value pairs
//
final IdmTreeNodeFilter dynPropFilter1 = new IdmTreeNodeFilter();
dynPropFilter1.setProperty("name");
dynPropFilter1.setValue("ROOT1");
Page<IdmTreeNodeDto> res11 = treeNodeService.find(dynPropFilter1, null);
Assert.assertEquals(1, res11.getTotalElements());
Assert.assertEquals(r1Uuid, res11.getContent().get(0).getId());
//
final IdmTreeNodeFilter dynPropFilter2 = new IdmTreeNodeFilter();
dynPropFilter2.setProperty("code");
dynPropFilter2.setValue("ROOT2");
Page<IdmTreeNodeDto> res12 = treeNodeService.find(dynPropFilter2, null);
Assert.assertEquals(1, res12.getTotalElements());
Assert.assertEquals(r2Uuid, res12.getContent().get(0).getId());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto in project CzechIdMng by bcvsolutions.
the class IdmTreeNodeServiceIntegrationTest method testBadTreeTypeUpdate.
@Test
public void testBadTreeTypeUpdate() {
IdmTreeTypeDto parent1 = helper.createTreeType();
IdmTreeTypeDto parent2 = helper.createTreeType();
//
IdmTreeNodeDto node1 = helper.createTreeNode(parent1, null);
IdmTreeNodeDto node2 = helper.createTreeNode(parent1, node1);
IdmTreeNodeDto node3 = helper.createTreeNode(parent1, node2);
//
node3.setTreeType(parent2.getId());
try {
node3 = treeNodeService.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 = treeNodeService.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.IdmTreeNodeDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleRequestServiceIntegrationTest method testDeleteTreeAutomaticRole.
@Test
public void testDeleteTreeAutomaticRole() {
IdmRoleDto role = prepareRole();
IdmTreeNodeDto nodeOne = helper.createTreeNode();
IdmRoleTreeNodeDto automaticRole = new IdmRoleTreeNodeDto();
automaticRole.setRole(role.getId());
automaticRole.setName(role.getName());
automaticRole.setTreeNode(nodeOne.getId());
// Create automatic role via manager
automaticRole = automaticRoleManager.createAutomaticRoleByTree(automaticRole, true);
Assert.assertNotNull(automaticRole.getId());
IdmRoleTreeNodeDto treeAutomaticRole = roleTreeNodeService.get(automaticRole.getId());
Assert.assertNotNull(treeAutomaticRole);
Assert.assertEquals(nodeOne.getId(), treeAutomaticRole.getTreeNode());
Assert.assertEquals(role.getId(), treeAutomaticRole.getRole());
// Delete automatic role via manager
automaticRoleManager.deleteAutomaticRole(automaticRole, true);
IdmRoleTreeNodeDto deletedAutomaticRole = roleTreeNodeService.get(automaticRole.getId());
Assert.assertNull(deletedAutomaticRole);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleRequestServiceIntegrationTest method testCreateTreeAutomaticRole.
@Test
public void testCreateTreeAutomaticRole() {
IdmRoleDto role = prepareRole();
IdmTreeNodeDto nodeOne = helper.createTreeNode();
IdmRoleTreeNodeDto automaticRole = new IdmRoleTreeNodeDto();
automaticRole.setRole(role.getId());
automaticRole.setName(role.getName());
automaticRole.setTreeNode(nodeOne.getId());
// Create automatic role via manager
automaticRole = automaticRoleManager.createAutomaticRoleByTree(automaticRole, true);
Assert.assertNotNull(automaticRole.getId());
IdmRoleTreeNodeDto treeAutomaticRole = roleTreeNodeService.get(automaticRole.getId());
Assert.assertNotNull(treeAutomaticRole);
Assert.assertEquals(nodeOne.getId(), treeAutomaticRole.getTreeNode());
Assert.assertEquals(role.getId(), treeAutomaticRole.getRole());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleRequestServiceIntegrationTest method testDeleteTreeAutomaticRoleApproval.
@Test
public void testDeleteTreeAutomaticRoleApproval() {
IdmRoleDto role = prepareRole();
IdmTreeNodeDto nodeOne = helper.createTreeNode();
IdmIdentityDto guaranteeIdentity = helper.createIdentity();
IdmRoleGuaranteeDto guarantee = new IdmRoleGuaranteeDto();
guarantee.setRole(role.getId());
guarantee.setGuarantee(guaranteeIdentity.getId());
role.getGuarantees().add(guarantee);
role = roleService.save(role);
IdmRoleTreeNodeDto automaticRole = new IdmRoleTreeNodeDto();
automaticRole.setRole(role.getId());
automaticRole.setName(role.getName());
automaticRole.setTreeNode(nodeOne.getId());
// Create automatic role via manager
automaticRole = automaticRoleManager.createAutomaticRoleByTree(automaticRole, true);
Assert.assertNotNull(automaticRole.getId());
IdmRoleTreeNodeDto treeAutomaticRole = roleTreeNodeService.get(automaticRole.getId());
Assert.assertNotNull(treeAutomaticRole);
Assert.assertEquals(nodeOne.getId(), treeAutomaticRole.getTreeNode());
Assert.assertEquals(role.getId(), treeAutomaticRole.getRole());
// Delete automatic role via manager
try {
automaticRoleManager.deleteAutomaticRole(automaticRole, false);
} catch (AcceptedException ex) {
// The request is in approval
Assert.assertNotNull(ex.getIdentifier());
UUID requestId = UUID.fromString(ex.getIdentifier());
loginAsNoAdmin(guaranteeIdentity.getUsername());
try {
completeTasksFromUsers(guaranteeIdentity.getUsername(), "approve");
} catch (ResultCodeException e) {
fail("User has permission to approve task. Error message: " + e.getLocalizedMessage());
} catch (Exception e) {
fail("Some problem: " + e.getLocalizedMessage());
}
IdmAutomaticRoleRequestDto request = roleRequestService.get(requestId);
Assert.assertEquals(RequestState.EXECUTED, request.getState());
IdmRoleTreeNodeDto deletedAutomaticRole = roleTreeNodeService.get(automaticRole.getId());
Assert.assertNull(deletedAutomaticRole);
return;
}
fail("Automatic role request have to be approving by gurantee!");
}
Aggregations