use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto in project CzechIdMng by bcvsolutions.
the class ContractSliceManagerTest method mainFilterTest.
@Test
public void mainFilterTest() {
IdmIdentityDto identity = helper.createIdentity();
IdmIdentityDto identity2 = helper.createIdentity();
IdmTreeNodeDto node = helper.createTreeNode();
IdmTreeNodeDto node2 = helper.createTreeNode();
IdmContractSliceDto slice = helper.createContractSlice(identity, node, null, null, null);
IdmContractSliceDto slice2 = helper.createContractSlice(identity2, node2, null, null, null);
slice.setMain(true);
contractSliceService.save(slice);
slice2.setMain(false);
contractSliceService.save(slice2);
IdmContractSliceFilter filter = new IdmContractSliceFilter();
filter.setMain(true);
Page<IdmContractSliceDto> result = contractSliceService.find(filter, null);
assertTrue(result.getContent().contains(slice));
assertFalse(result.getContent().contains(slice2));
filter.setMain(false);
result = contractSliceService.find(filter, null);
assertTrue(result.getContent().contains(slice2));
assertFalse(result.getContent().contains(slice));
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto in project CzechIdMng by bcvsolutions.
the class ContractSliceManagerTest method contractValidityProtectionModeDisabledTest.
@Test
public void contractValidityProtectionModeDisabledTest() {
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), 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 disabled, contract must have validity fields same as slice
// One
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 createSlicesForOneContractTest.
@Test
public void createSlicesForOneContractTest() {
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);
IdmContractSliceDto nextSlice = contractSliceManager.findNextSlice(validSlice, slices);
// Next slice should be futureSlice
assertEquals(sliceFuture, nextSlice);
IdmContractSliceDto previousSlice = contractSliceManager.findPreviousSlice(validSlice, slices);
// Previous slice should be pasSlice
assertEquals(slicePast, previousSlice);
List<IdmContractSliceDto> unvalidSlices = contractSliceManager.findUnvalidSlices(null).getContent();
assertEquals(0, unvalidSlices.size());
// 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());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto in project CzechIdMng by bcvsolutions.
the class ContractSliceManagerTest method createSliceValidInFutureTest.
@Test
public void createSliceValidInFutureTest() {
IdmIdentityDto identity = helper.createIdentity();
String contractCode = "contract-one";
IdmContractSliceDto slice = helper.createContractSlice(identity, null, LocalDate.now().plusDays(10), null, LocalDate.now().plusDays(100));
slice.setContractCode(contractCode);
contractSliceService.save(slice);
IdmContractSliceFilter filter = new IdmContractSliceFilter();
filter.setIdentity(identity.getId());
List<IdmContractSliceDto> results = contractSliceService.find(filter, null).getContent();
assertEquals(1, results.size());
IdmContractSliceDto createdSlice = results.get(0);
assertFalse(createdSlice.isValid());
assertEquals(null, createdSlice.getValidTill());
// 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());
IdmIdentityContractDto contract = resultsContract.get(0);
assertTrue(contract.isValidNowOrInFuture());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto in project CzechIdMng by bcvsolutions.
the class DefaultTestHelper method createContractSlice.
@Override
public IdmContractSliceDto createContractSlice(IdmIdentityDto identity, String contractCode, IdmTreeNodeDto position, LocalDate validFrom, LocalDate contractValidFrom, LocalDate contractValidTill) {
IdmContractSliceDto contract = new IdmContractSliceDto();
contract.setIdentity(identity.getId());
contract.setPosition(createName());
contract.setContractCode(contractCode);
contract.setWorkPosition(position == null ? null : position.getId());
contract.setValidFrom(validFrom);
contract.setContractValidFrom(contractValidFrom);
contract.setContractValidTill(contractValidTill);
return contractSliceService.save(contract);
}
Aggregations