use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityContractServiceIntegrationTest method datesValidFilterTest.
@Test
public void datesValidFilterTest() {
IdmIdentityDto identity = helper.createIdentity();
IdmIdentityDto identity2 = helper.createIdentity();
IdmIdentityDto identity3 = helper.createIdentity();
IdmIdentityDto identity4 = helper.createIdentity();
IdmTreeNodeDto node = helper.createTreeNode();
IdmTreeNodeDto node2 = helper.createTreeNode();
IdmTreeNodeDto node3 = helper.createTreeNode();
IdmTreeNodeDto node4 = helper.createTreeNode();
IdmIdentityContractDto contract = helper.createIdentityContact(identity, node, org.joda.time.LocalDate.now(), org.joda.time.LocalDate.parse("2021-06-05"));
IdmIdentityContractDto contract2 = helper.createIdentityContact(identity2, node2, org.joda.time.LocalDate.now(), org.joda.time.LocalDate.parse("2020-05-05"));
IdmIdentityContractDto contract3 = helper.createIdentityContact(identity3, node3, org.joda.time.LocalDate.now(), org.joda.time.LocalDate.parse("2016-05-05"));
IdmIdentityContractDto contract4 = helper.createIdentityContact(identity4, node4, org.joda.time.LocalDate.parse("2018-05-05"), org.joda.time.LocalDate.parse("2025-05-05"));
IdmIdentityContractFilter filter = new IdmIdentityContractFilter();
filter.setValidFrom(contract.getValidFrom());
Page<IdmIdentityContractDto> result = service.find(filter, null);
assertTrue(result.getContent().contains(contract));
filter.setValidFrom(null);
filter.setValidTill(contract2.getValidTill());
result = service.find(filter, null);
assertTrue(result.getContent().contains(contract2));
filter.setValidTill(null);
filter.setValid(true);
result = service.find(filter, null);
assertTrue(result.getContent().contains(contract));
assertTrue(result.getContent().contains(contract2));
assertFalse(result.getContent().contains(contract3));
filter.setValid(null);
filter.setValidNowOrInFuture(true);
result = service.find(filter, null);
assertTrue(result.getContent().contains(contract4));
filter.setValidNowOrInFuture(false);
result = service.find(filter, null);
assertTrue(result.getContent().contains(contract3));
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityContractServiceIntegrationTest method testChangeContractValidityWithAssignedRoles.
@Test
public void testChangeContractValidityWithAssignedRoles() {
prepareAutomaticRoles();
//
// prepare identity and contract
IdmIdentityDto identity = helper.createIdentity();
IdmIdentityContractDto contract = new IdmIdentityContractDto();
contract.setIdentity(identity.getId());
contract.setValidFrom(new LocalDate().minusDays(1));
contract.setValidTill(new LocalDate().plusMonths(1));
contract.setWorkPosition(nodeD.getId());
contract = service.save(contract);
//
// test after create
List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByContract(contract.getId());
assertEquals(3, identityRoles.size());
for (IdmIdentityRoleDto identityRole : identityRoles) {
assertEquals(contract.getValidFrom(), identityRole.getValidFrom());
assertEquals(contract.getValidTill(), identityRole.getValidTill());
}
;
// test after change
contract.setValidFrom(new LocalDate().minusDays(2));
contract.setValidTill(new LocalDate().plusMonths(4));
contract = service.save(contract);
identityRoles = identityRoleService.findAllByContract(contract.getId());
assertEquals(3, identityRoles.size());
for (IdmIdentityRoleDto identityRole : identityRoles) {
assertEquals(contract.getValidFrom(), identityRole.getValidFrom());
assertEquals(contract.getValidTill(), identityRole.getValidTill());
}
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityContractServiceIntegrationTest method testEnableIdentityAfterEnableContract.
@Test
public void testEnableIdentityAfterEnableContract() {
IdmIdentityDto identity = helper.createIdentity();
IdmIdentityContractDto contract = helper.getPrimeContract(identity.getId());
contract.setState(ContractState.DISABLED);
contract = service.save(contract);
//
identity = (IdmIdentityDto) lookupService.lookupDto(IdmIdentityDto.class, identity.getId());
Assert.assertTrue(identity.isDisabled());
//
contract.setState(null);
contract = service.save(contract);
//
identity = (IdmIdentityDto) lookupService.lookupDto(IdmIdentityDto.class, identity.getId());
Assert.assertFalse(identity.isDisabled());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityContractServiceIntegrationTest method textFilterTest.
@Test
public void textFilterTest() {
IdmIdentityDto identity = helper.createIdentity();
IdmIdentityDto identity2 = helper.createIdentity();
IdmIdentityDto identity3 = helper.createIdentity();
IdmIdentityDto identity4 = helper.createIdentity();
IdmTreeNodeDto node = helper.createTreeNode();
node.setName("Position105");
treeNodeService.save(node);
IdmTreeNodeDto node2 = helper.createTreeNode();
node2.setName("Position006");
treeNodeService.save(node2);
IdmTreeNodeDto node3 = helper.createTreeNode();
node3.setCode("Position007");
treeNodeService.save(node3);
IdmTreeNodeDto node4 = helper.createTreeNode();
node4.setCode("Position108");
treeNodeService.save(node4);
IdmIdentityContractDto contract = helper.createIdentityContact(identity, node);
IdmIdentityContractDto contract2 = helper.createIdentityContact(identity2, node2);
IdmIdentityContractDto contract3 = helper.createIdentityContact(identity3, node3);
IdmIdentityContractDto contract4 = helper.createIdentityContact(identity4, node4);
contract.setPosition("Position001");
contract = service.save(contract);
contract2.setPosition("Position102");
service.save(contract2);
contract3.setPosition("Position103");
service.save(contract3);
contract4.setPosition("Position104");
service.save(contract4);
IdmIdentityContractFilter filter = new IdmIdentityContractFilter();
filter.setText("Position00");
Page<IdmIdentityContractDto> result = service.find(filter, null);
assertEquals("Wrong Text", 3, result.getTotalElements());
assertTrue(result.getContent().contains(contract));
assertTrue(result.getContent().contains(contract2));
assertTrue(result.getContent().contains(contract3));
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityContractServiceIntegrationTest method testCRUDContractWithAutomaticRoles.
@Test
public void testCRUDContractWithAutomaticRoles() {
prepareAutomaticRoles();
//
// prepare identity and contract
IdmIdentityDto identity = helper.createIdentity();
IdmIdentityContractDto contract = service.getPrimeContract(identity.getId());
contract.setIdentity(identity.getId());
contract.setValidFrom(new LocalDate().minusDays(1));
contract.setValidTill(new LocalDate().plusMonths(1));
contract.setWorkPosition(nodeD.getId());
contract.setMain(true);
contract.setDescription("test-node-d");
service.save(contract);
//
contract = service.getPrimeContract(identity.getId());
//
// test after create
assertEquals(nodeD.getId(), contract.getWorkPosition());
assertEquals("test-node-d", contract.getDescription());
List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByContract(contract.getId());
assertEquals(3, identityRoles.size());
for (IdmIdentityRoleDto identityRole : identityRoles) {
assertEquals(contract.getValidFrom(), identityRole.getValidFrom());
assertEquals(contract.getValidTill(), identityRole.getValidTill());
if (identityRole.getRoleTreeNode().equals(nodeA.getId())) {
assertEquals(roleA, identityRole.getRole());
}
if (identityRole.getRoleTreeNode().equals(nodeD.getId())) {
assertEquals(roleB, identityRole.getRole());
}
if (identityRole.getRoleTreeNode().equals(nodeF.getId())) {
assertEquals(roleC, identityRole.getRole());
}
}
identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(3, identityRoles.size());
//
// test after delete
service.delete(contract);
assertTrue(identityRoleService.findAllByIdentity(identity.getId()).isEmpty());
}
Aggregations