use of eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmContractPositionServiceIntegrationTest method testReferentialIntegritye.
@Test
@Transactional
public void testReferentialIntegritye() {
// prepare data
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmIdentityContractDto contract = getHelper().createContract(identity);
IdmContractPositionDto contractPosition = getHelper().createContractPosition(contract);
IdmRoleDto role = getHelper().createRole();
//
IdmIdentityRoleDto identityRole = getHelper().createIdentityRole(contractPosition, role);
Assert.assertNotNull(identityRoleService.get(identityRole));
//
service.delete(contractPosition);
//
Assert.assertNull(identityRoleService.get(identityRole));
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmContractPositionServiceIntegrationTest method testChangePositionWithAutomaticRolesAssigned.
@Test
@Transactional
public void testChangePositionWithAutomaticRolesAssigned() {
IdmRoleDto role = getHelper().createRole();
IdmTreeNodeDto treeNode = getHelper().createTreeNode();
IdmRoleTreeNodeDto automaticRole = getHelper().createAutomaticRole(role, treeNode);
//
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmIdentityContractDto contract = getHelper().getPrimeContract(identity);
List<IdmIdentityRoleDto> assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertTrue(assignedRoles.isEmpty());
//
IdmContractPositionDto position = getHelper().createContractPosition(contract);
//
assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertTrue(assignedRoles.isEmpty());
//
position.setWorkPosition(treeNode.getId());
position = service.save(position);
//
assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertEquals(1, assignedRoles.size());
Assert.assertEquals(automaticRole.getId(), assignedRoles.get(0).getAutomaticRole());
Assert.assertEquals(position.getId(), assignedRoles.get(0).getContractPosition());
//
position.setWorkPosition(null);
position = service.save(position);
//
assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertTrue(assignedRoles.isEmpty());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmContractPositionServiceIntegrationTest method testDontAssingRoleForInvalidContractWhenPositionIsChanged.
@Test
@Transactional
public void testDontAssingRoleForInvalidContractWhenPositionIsChanged() {
IdmRoleDto role = getHelper().createRole();
IdmTreeNodeDto treeNode = getHelper().createTreeNode();
getHelper().createAutomaticRole(role, treeNode);
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmIdentityContractDto contract = getHelper().createContract(identity, null, null, LocalDate.now().minusDays(1));
IdmContractPositionDto position = getHelper().createContractPosition(contract, null);
//
List<IdmIdentityRoleDto> assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertTrue(assignedRoles.isEmpty());
//
position.setWorkPosition(treeNode.getId());
position = service.save(position);
//
assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertTrue(assignedRoles.isEmpty());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmContractPositionServiceIntegrationTest method testPreventToRemoveRoles.
/**
* Prevent to remove automatic roles assigned by contract position, when contract primary position is changed.
*/
@Test
public void testPreventToRemoveRoles() {
IdmRoleDto roleOne = getHelper().createRole();
IdmTreeNodeDto treeNodeOne = getHelper().createTreeNode();
IdmRoleTreeNodeDto automaticRoleOne = getHelper().createAutomaticRole(roleOne, treeNodeOne);
//
IdmRoleDto roleTwo = getHelper().createRole();
IdmTreeNodeDto treeNodeTwo = getHelper().createTreeNode();
IdmRoleTreeNodeDto automaticRoleTwo = getHelper().createAutomaticRole(roleTwo, treeNodeTwo);
//
// create identity
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmIdentityContractDto contract = getHelper().getPrimeContract(identity);
//
// empty roles
IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
filter.setIdentityId(identity.getId());
List<IdmIdentityRoleDto> assignedRoles = identityRoleService.find(filter, null).getContent();
Assert.assertTrue(assignedRoles.isEmpty());
//
// create contract positon
IdmContractPositionDto contractPosition = getHelper().createContractPosition(contract, treeNodeOne);
assignedRoles = identityRoleService.find(filter, null).getContent();
Assert.assertEquals(1, assignedRoles.size());
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getAutomaticRole().equals(automaticRoleOne.getId())));
//
// update contract
contract.setWorkPosition(treeNodeTwo.getId());
contract = contractService.save(contract);
//
assignedRoles = identityRoleService.find(filter, null).getContent();
Assert.assertEquals(2, assignedRoles.size());
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getAutomaticRole().equals(automaticRoleOne.getId())));
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getAutomaticRole().equals(automaticRoleTwo.getId())));
//
// clear prime contract position
contract.setWorkPosition(null);
contract = contractService.save(contract);
//
assignedRoles = identityRoleService.find(filter, null).getContent();
Assert.assertEquals(1, assignedRoles.size());
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getAutomaticRole().equals(automaticRoleOne.getId())));
//
contract.setWorkPosition(treeNodeTwo.getId());
contract = contractService.save(contract);
//
// remove contract
service.delete(contractPosition);
//
assignedRoles = identityRoleService.find(filter, null).getContent();
Assert.assertEquals(1, assignedRoles.size());
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getAutomaticRole().equals(automaticRoleTwo.getId())));
//
// remove contract position
contractService.delete(contract);
//
assignedRoles = identityRoleService.find(filter, null).getContent();
Assert.assertTrue(assignedRoles.isEmpty());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmContractPositionServiceIntegrationTest method testChangeContractValidityWithAssignedRoles.
@Test
@Transactional
public void testChangeContractValidityWithAssignedRoles() {
IdmRoleDto role = getHelper().createRole();
IdmTreeNodeDto treeNode = getHelper().createTreeNode();
IdmRoleTreeNodeDto automaticRole = getHelper().createAutomaticRole(role, treeNode);
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmIdentityContractDto contract = getHelper().getPrimeContract(identity);
IdmContractPositionDto position = getHelper().createContractPosition(contract, treeNode);
// other
getHelper().createContractPosition(contract, getHelper().createTreeNode());
//
List<IdmIdentityRoleDto> assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertEquals(1, assignedRoles.size());
Assert.assertEquals(automaticRole.getId(), assignedRoles.get(0).getAutomaticRole());
Assert.assertEquals(position.getId(), assignedRoles.get(0).getContractPosition());
Assert.assertNull(assignedRoles.get(0).getValidTill());
//
contract.setValidTill(LocalDate.now().plusDays(2));
contract = contractService.save(contract);
//
assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertEquals(1, assignedRoles.size());
Assert.assertEquals(contract.getValidTill(), assignedRoles.get(0).getValidTill());
}
Aggregations