use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto in project CzechIdMng by bcvsolutions.
the class ContractSliceManagerTest method contractValidityProtectionModeDisableInfinityTest.
@Test
public void contractValidityProtectionModeDisableInfinityTest() {
// Disable protection mode (0 days)
configurationService.setValue(ContractSliceConfiguration.PROPERTY_PROTECTION_INTERVAL, "0");
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), null, 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 disabled, next slice has contract valid from sets to null
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 clearStateExecutorPageTest.
@Test
public void clearStateExecutorPageTest() {
IdmIdentityDto identity = this.getHelper().createIdentity();
List<IdmEntityStateDto> dirtyStates = findAllDirtyStatesForSlices();
assertEquals(0, dirtyStates.size());
for (int index = 0; index < 21; index++) {
IdmContractSliceDto createContractSlice = this.getHelper().createContractSlice(identity);
createDirtyState(createContractSlice);
}
dirtyStates = findAllDirtyStatesForSlices();
assertEquals(21, dirtyStates.size());
ClearDirtyStateForContractSliceTaskExecutor executor = new ClearDirtyStateForContractSliceTaskExecutor();
OperationResult result = longRunningTaskManager.executeSync(executor);
assertEquals(OperationState.EXECUTED, result.getState());
dirtyStates = findAllDirtyStatesForSlices();
assertEquals(0, dirtyStates.size());
IdmLongRunningTaskDto taskDto = longRunningTaskService.get(executor.getLongRunningTaskId());
assertNotNull(taskDto.getCount());
assertNotNull(taskDto.getCounter());
assertEquals(21, taskDto.getCount().longValue());
assertEquals(21, taskDto.getCounter().longValue());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto in project CzechIdMng by bcvsolutions.
the class ContractSliceManagerTest method setDirtyStateTest.
@Test
public void setDirtyStateTest() {
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.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(1, dirtyStates.size());
// delete the states
entityStateManager.deleteState(dirtyStates.get(0));
// Delete unused slice
contractSliceService.delete(eventContext.getContent());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto in project CzechIdMng by bcvsolutions.
the class ContractGuaranteeSaveAndDeleteProcessorTest method testCreateGuaranteeOfContractWithSlice.
@Test
public void testCreateGuaranteeOfContractWithSlice() {
IdmIdentityDto sliceGuarantee = getHelper().createIdentity();
IdmIdentityDto identity = getHelper().createIdentity();
IdmContractSliceDto slice = getHelper().createContractSlice(identity, null, LocalDate.now().minusDays(1), null, null);
UUID contractId = slice.getParentContract();
// guarantee can't be created directly
try {
getHelper().createContractGuarantee(contractId, sliceGuarantee.getId());
fail("Contract guarantee can't be created directly when slice is applied");
} catch (ResultCodeException ex) {
Assert.assertTrue(CoreResultCode.CONTRACT_IS_CONTROLLED_GUARANTEE_CANNOT_BE_MODIFIED.toString().equals(ex.getError().getErrors().get(0).getStatusEnum()));
}
IdmContractGuaranteeFilter guaranteeFilter = new IdmContractGuaranteeFilter();
guaranteeFilter.setIdentityContractId(contractId);
List<IdmContractGuaranteeDto> contractGuarantees = contractGuaranteeService.find(guaranteeFilter, null).getContent();
Assert.assertEquals(0, contractGuarantees.size());
// contract slice guarantee can be created
getHelper().createContractSliceGuarantee(slice.getId(), sliceGuarantee.getId());
IdmContractSliceGuaranteeFilter sliceGuaranteefilter = new IdmContractSliceGuaranteeFilter();
sliceGuaranteefilter.setGuaranteeId(sliceGuarantee.getId());
List<IdmContractSliceGuaranteeDto> sliceGuarantees = contractSliceGuaranteeService.find(sliceGuaranteefilter, null).getContent();
Assert.assertEquals(1, sliceGuarantees.size());
// applying slice with guarantee causes creating of contract guarantee which is correct
contractGuarantees = contractGuaranteeService.find(guaranteeFilter, null).getContent();
Assert.assertEquals(1, contractGuarantees.size());
IdmIdentityDto sliceGuaranteeIdent = DtoUtils.getEmbedded(sliceGuarantees.get(0), IdmContractSliceGuarantee_.guarantee);
IdmIdentityDto contractGuaranteeIdent = DtoUtils.getEmbedded(contractGuarantees.get(0), IdmContractSliceGuarantee_.guarantee);
Assert.assertEquals(sliceGuaranteeIdent.getId(), contractGuaranteeIdent.getId());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto in project CzechIdMng by bcvsolutions.
the class ContractSliceSyncTest method changeContractBySliceTest.
@Test
public void changeContractBySliceTest() {
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);
IdmContractSliceFilter contractSliceFilter = new IdmContractSliceFilter();
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());
// 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());
// Delete log
syncLogService.delete(log);
}
Aggregations