use of eu.bcvsolutions.idm.core.scheduler.task.impl.SelectCurrentContractSliceTaskExecutor in project CzechIdMng by bcvsolutions.
the class ContractSliceManagerTest method selectCurrentSliceAsContractLrtTest.
@Test
public void selectCurrentSliceAsContractLrtTest() {
IdmIdentityDto identity = helper.createIdentity();
String contractCode = "contract-one";
IdmContractSliceDto sliceFuture = helper.createContractSlice(identity, null, LocalDate.now().plusDays(10), null, LocalDate.now().plusDays(100));
sliceFuture.setContractCode(contractCode);
contractSliceService.save(sliceFuture);
IdmContractSliceDto sliceCurrent = helper.createContractSlice(identity, null, LocalDate.now(), null, LocalDate.now().plusDays(50));
sliceCurrent.setContractCode(contractCode);
contractSliceService.save(sliceCurrent);
IdmContractSliceDto slicePast = helper.createContractSlice(identity, null, LocalDate.now().minusDays(10), null, LocalDate.now().plusDays(200));
slicePast.setContractCode(contractCode);
contractSliceService.save(slicePast);
IdmContractSliceFilter filter = new IdmContractSliceFilter();
filter.setIdentity(identity.getId());
List<IdmContractSliceDto> results = contractSliceService.find(filter, null).getContent();
assertEquals(3, results.size());
UUID parentContract = results.get(0).getParentContract();
List<IdmContractSliceDto> slices = contractSliceManager.findAllSlices(parentContract);
assertEquals(3, slices.size());
IdmContractSliceDto validSlice = contractSliceManager.findValidSlice(parentContract);
// Valid slice should be currentSlice
assertEquals(sliceCurrent, validSlice);
// Check created contract by that slice
IdmIdentityContractFilter contractFilter = new IdmIdentityContractFilter();
contractFilter.setIdentity(identity.getId());
List<IdmIdentityContractDto> resultsContract = //
contractService.find(filter, null).getContent().stream().filter(//
c -> contractService.get(c.getId()).getControlledBySlices()).collect(Collectors.toList());
assertEquals(1, resultsContract.size());
// Current slice should be contract
IdmIdentityContractDto contract = resultsContract.get(0);
assertTrue(contract.isValid());
assertEquals(sliceCurrent.getContractValidFrom(), contract.getValidFrom());
// None invalid slices
List<IdmContractSliceDto> unvalidSlices = contractSliceManager.findUnvalidSlices(null).getContent();
assertEquals(0, unvalidSlices.size());
// Set current slice as not currently using
sliceCurrent = contractSliceService.get(sliceCurrent.getId());
sliceCurrent.setUsingAsContract(false);
// Save without recalculation
contractSliceService.publish(new ContractSliceEvent(ContractSliceEventType.UPDATE, sliceCurrent, ImmutableMap.of(IdmContractSliceService.SKIP_RECALCULATE_CONTRACT_SLICE, Boolean.TRUE)));
// One invalid slice
unvalidSlices = contractSliceManager.findUnvalidSlices(null).getContent();
assertEquals(1, unvalidSlices.size());
SelectCurrentContractSliceTaskExecutor lrt = new SelectCurrentContractSliceTaskExecutor();
AutowireHelper.autowire(lrt);
OperationResult result = lrt.process();
assertEquals(OperationState.EXECUTED, result.getState());
}
Aggregations