use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto in project CzechIdMng by bcvsolutions.
the class ContractSliceManagerTest method clearStateExecutorTest.
@Test
public void clearStateExecutorTest() {
IdmIdentityDto identity = this.getHelper().createIdentity();
// remove all contracts
List<IdmIdentityContractDto> allByIdentity = contractService.findAllByIdentity(identity.getId());
allByIdentity.forEach(contract -> {
contractService.delete(contract);
});
IdmContractSliceDto slice = new IdmContractSliceDto();
slice.setContractCode("test");
slice.setIdentity(identity.getId());
slice.setValidFrom(LocalDate.now().minusDays(1));
slice.setValidTill(LocalDate.now().plusDays(5));
slice.setContractValidFrom(LocalDate.now().minusDays(50));
slice.setMain(true);
IdmContractSliceDto sliceTwo = new IdmContractSliceDto();
sliceTwo.setContractCode("test");
sliceTwo.setIdentity(identity.getId());
sliceTwo.setValidFrom(LocalDate.now().minusDays(10));
sliceTwo.setValidTill(LocalDate.now().minusDays(2));
sliceTwo.setContractValidFrom(LocalDate.now().minusDays(50));
sliceTwo.setMain(true);
EventContext<IdmContractSliceDto> eventContextOne = contractSliceService.publish(new ContractSliceEvent(ContractSliceEventType.CREATE, slice, ImmutableMap.of(IdmContractSliceService.SET_DIRTY_STATE_CONTRACT_SLICE, Boolean.TRUE)));
EventContext<IdmContractSliceDto> eventContextTwo = contractSliceService.publish(new ContractSliceEvent(ContractSliceEventType.CREATE, sliceTwo, ImmutableMap.of(IdmContractSliceService.SET_DIRTY_STATE_CONTRACT_SLICE, Boolean.TRUE)));
// slice has skip recalculation and dirty state isn't create
allByIdentity = contractService.findAllByIdentity(identity.getId());
assertTrue(allByIdentity.isEmpty());
List<IdmEntityStateDto> dirtyStates = findDirtyStatesForSlice(null);
assertFalse(dirtyStates.isEmpty());
assertEquals(2, dirtyStates.size());
ClearDirtyStateForContractSliceTaskExecutor executor = new ClearDirtyStateForContractSliceTaskExecutor();
OperationResult result = longRunningTaskManager.executeSync(executor);
assertEquals(OperationState.EXECUTED, result.getState());
dirtyStates = findDirtyStatesForSlice(null);
assertTrue(dirtyStates.isEmpty());
assertEquals(0, dirtyStates.size());
allByIdentity = contractService.findAllByIdentity(identity.getId());
assertEquals(1, allByIdentity.size());
IdmIdentityContractDto contractDto = allByIdentity.get(0);
assertTrue(contractDto.getControlledBySlices());
assertEquals(LocalDate.now().minusDays(50), contractDto.getValidFrom());
// Delete unused slices
contractSliceService.delete(eventContextOne.getContent());
contractSliceService.delete(eventContextTwo.getContent());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto in project CzechIdMng by bcvsolutions.
the class ContractSliceManagerTest method contractValidityProtectionModeEnabledExpiredTest.
@Test
public void contractValidityProtectionModeEnabledExpiredTest() {
// Enable protection mode (4 days, gap is 5 days)
configurationService.setValue(ContractSliceConfiguration.PROPERTY_PROTECTION_INTERVAL, "4");
IdmIdentityDto identity = helper.createIdentity();
IdmContractSliceDto sliceOne = helper.createContractSlice(identity, "11", null, LocalDate.now().minusDays(100), LocalDate.now().minusDays(100), LocalDate.now().plusDays(5));
IdmContractSliceDto sliceTwo = helper.createContractSlice(identity, "11", null, LocalDate.now().plusDays(10), LocalDate.now().plusDays(10), LocalDate.now().plusDays(100));
assertNotNull(sliceOne.getParentContract());
assertNotNull(sliceTwo.getParentContract());
assertEquals(sliceOne.getParentContract(), sliceTwo.getParentContract());
assertTrue(sliceOne.isUsingAsContract());
assertFalse(sliceTwo.isUsingAsContract());
IdmIdentityContractDto contract = contractService.get(sliceOne.getParentContract());
// Protection mode is enabled, but gap was too long
assertEquals(sliceOne.getContractValidFrom(), contract.getValidFrom());
assertEquals(sliceOne.getContractValidTill(), contract.getValidTill());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto in project CzechIdMng by bcvsolutions.
the class ContractSliceManagerTest method skipRecalculationTest.
@Test
public void skipRecalculationTest() {
IdmIdentityDto identity = this.getHelper().createIdentity();
// remove all contracts
List<IdmIdentityContractDto> allByIdentity = contractService.findAllByIdentity(identity.getId());
allByIdentity.forEach(contract -> {
contractService.delete(contract);
});
IdmContractSliceDto slice = new IdmContractSliceDto();
slice.setContractCode("test");
slice.setIdentity(identity.getId());
slice.setValidFrom(LocalDate.now().minusDays(5));
slice.setValidTill(LocalDate.now().plusDays(5));
slice.setContractValidFrom(LocalDate.now().minusDays(5));
slice.setMain(true);
EventContext<IdmContractSliceDto> eventContext = contractSliceService.publish(new ContractSliceEvent(ContractSliceEventType.CREATE, slice, ImmutableMap.of(IdmContractSliceService.SKIP_RECALCULATE_CONTRACT_SLICE, Boolean.TRUE)));
// slice has skip recalculation and dirty state isn't create
allByIdentity = contractService.findAllByIdentity(identity.getId());
assertTrue(allByIdentity.isEmpty());
List<IdmEntityStateDto> dirtyStates = findDirtyStatesForSlice(null);
assertTrue(dirtyStates.isEmpty());
// Delete unused slice
contractSliceService.delete(eventContext.getContent());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto in project CzechIdMng by bcvsolutions.
the class ContractSliceSyncTest method createContractSlicesTest.
@Test
public void createContractSlicesTest() {
SysSystemDto system = initData();
Assert.assertNotNull(system);
AbstractSysSyncConfigDto config = doCreateSyncConfig(system);
Assert.assertTrue(config instanceof SysSyncContractConfigDto);
helper.createIdentity(CONTRACT_OWNER_ONE);
helper.createIdentity(CONTRACT_OWNER_TWO);
helper.createIdentity(CONTRACT_LEADER_ONE);
IdmTreeTypeDto treeType = helper.createTreeType();
IdmTreeNodeDto defaultNode = helper.createTreeNode(treeType, null);
((SysSyncContractConfigDto) config).setDefaultTreeType(treeType.getId());
((SysSyncContractConfigDto) config).setDefaultTreeNode(defaultNode.getId());
config = syncConfigService.save(config);
IdmContractSliceFilter contractFilter = new IdmContractSliceFilter();
contractFilter.setProperty(IdmIdentityContract_.position.getName());
contractFilter.setValue("1");
Assert.assertEquals(0, contractSliceService.find(contractFilter, null).getTotalElements());
contractFilter.setValue("2");
Assert.assertEquals(0, contractSliceService.find(contractFilter, null).getTotalElements());
helper.startSynchronization(config);
SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 4);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
contractFilter.setValue("1");
Assert.assertEquals(1, contractSliceService.find(contractFilter, null).getTotalElements());
// Find slice guarantees
Assert.assertEquals(1, contractSliceManager.findSliceGuarantees(contractSliceService.find(contractFilter, null).getContent().get(0).getId()).size());
contractFilter.setValue("2");
Assert.assertEquals(1, contractSliceService.find(contractFilter, null).getTotalElements());
contractFilter.setValue("3");
List<IdmContractSliceDto> contractsThree = contractSliceService.find(contractFilter, null).getContent();
Assert.assertEquals(1, contractsThree.size());
Assert.assertEquals(null, contractsThree.get(0).getState());
// Find slice guarantees
Assert.assertEquals(0, contractSliceManager.findSliceGuarantees(contractsThree.get(0).getId()).size());
contractFilter.setValue("4");
Assert.assertEquals(1, contractSliceService.find(contractFilter, null).getTotalElements());
// Delete log
syncLogService.delete(log);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto in project CzechIdMng by bcvsolutions.
the class ContractSliceSyncTest method testIdentityProvisioningOnChangeContractBySlice.
@Test
public void testIdentityProvisioningOnChangeContractBySlice() {
SysSystemDto identitySystem = helper.createSystem(TestResource.TABLE_NAME);
helper.createMapping(identitySystem);
IdmRoleDto roleWithIdentitySystem = helper.createRole();
helper.createRoleSystem(roleWithIdentitySystem, identitySystem);
SysSystemDto system = initData();
Assert.assertNotNull(system);
AbstractSysSyncConfigDto config = doCreateSyncConfig(system);
Assert.assertTrue(config instanceof SysSyncContractConfigDto);
IdmIdentityDto owner = helper.createIdentity(CONTRACT_OWNER_ONE);
helper.createIdentity(CONTRACT_LEADER_ONE);
// Assign identity system to the owner.
helper.assignRoles(helper.getPrimeContract(owner), roleWithIdentitySystem);
SysProvisioningOperationFilter provisioningOperationFilter = new SysProvisioningOperationFilter();
provisioningOperationFilter.setEntityIdentifier(owner.getId());
provisioningOperationFilter.setSystemId(identitySystem.getId());
List<SysProvisioningArchiveDto> provisioningArchiveDtos = provisioningArchiveService.find(provisioningOperationFilter, null).getContent();
Assert.assertEquals(1, provisioningArchiveDtos.size());
IdmContractSliceFilter contractSliceFilter = new IdmContractSliceFilter();
contractSliceFilter.setIdentity(owner.getId());
contractSliceFilter.setProperty(IdmIdentityContract_.position.getName());
contractSliceFilter.setValue("1");
Assert.assertEquals(0, contractSliceService.find(contractSliceFilter, null).getTotalElements());
contractSliceFilter.setValue("2");
Assert.assertEquals(0, contractSliceService.find(contractSliceFilter, null).getTotalElements());
helper.startSynchronization(config);
SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 4);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
contractSliceFilter.setValue("1");
Assert.assertEquals(1, contractSliceService.find(contractSliceFilter, null).getTotalElements());
contractSliceFilter.setValue("2");
List<IdmContractSliceDto> slicesTwo = contractSliceService.find(contractSliceFilter, null).getContent();
Assert.assertEquals(1, slicesTwo.size());
contractSliceFilter.setValue("3");
List<IdmContractSliceDto> contractsThree = contractSliceService.find(contractSliceFilter, null).getContent();
Assert.assertEquals(1, contractsThree.size());
Assert.assertEquals(null, contractsThree.get(0).getState());
contractSliceFilter.setValue("4");
Assert.assertEquals(1, contractSliceService.find(contractSliceFilter, null).getTotalElements());
// Find created contract
IdmIdentityContractFilter contractFilter = new IdmIdentityContractFilter();
contractFilter.setIdentity(owner.getId());
List<IdmIdentityContractDto> contracts = contractService.find(contractFilter, null).getContent();
Assert.assertEquals(3, contracts.size());
// Slice with id "2" should be current using
Assert.assertEquals(1, contracts.stream().filter(c -> c.getPosition().equals("2") && c.isValid()).count());
Assert.assertTrue(slicesTwo.get(0).isUsingAsContract());
provisioningArchiveDtos = provisioningArchiveService.find(provisioningOperationFilter, null).getContent();
Assert.assertEquals(9, provisioningArchiveDtos.size());
// Delete log
syncLogService.delete(log);
// Slice with id "2" reassign from contract ONE to TWO
this.getBean().changeContractData();
helper.startSynchronization(config);
log = checkSyncLog(config, SynchronizationActionType.UPDATE_ENTITY, 4);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
// Find created contract
contractFilter = new IdmIdentityContractFilter();
contractFilter.setIdentity(owner.getId());
contracts = contractService.find(contractFilter, null).getContent();
Assert.assertEquals(3, contracts.size());
// Slice with id "2" should not be current used
Assert.assertEquals(0, contracts.stream().filter(c -> c.getPosition().equals("2") && c.isValid()).count());
// But slice with id "4" should be current used
Assert.assertEquals(1, contracts.stream().filter(c -> c.getPosition().equals("4") && c.isValid()).count());
Assert.assertTrue(slicesTwo.get(0).isUsingAsContract());
provisioningArchiveDtos = provisioningArchiveService.find(provisioningOperationFilter, null).getContent();
Assert.assertEquals(15, provisioningArchiveDtos.size());
// Delete log
syncLogService.delete(log);
}
Aggregations