use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto in project CzechIdMng by bcvsolutions.
the class ContractSliceManagerTest method externeFilterTest.
@Test
public void externeFilterTest() {
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.setExterne(true);
contractSliceService.save(slice);
slice2.setExterne(false);
contractSliceService.save(slice2);
IdmContractSliceFilter filter = new IdmContractSliceFilter();
filter.setExterne(true);
Page<IdmContractSliceDto> result = contractSliceService.find(filter, null);
assertTrue(result.getContent().contains(slice));
assertFalse(result.getContent().contains(slice2));
filter.setExterne(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 createSliceValidFromSameDateAsSomeExisting.
@Test
public void createSliceValidFromSameDateAsSomeExisting() {
IdmIdentityDto identity = helper.createIdentity();
String contractCode = "contract-three";
LocalDate now = LocalDate.now();
IdmContractSliceDto sliceCurrent = helper.createContractSlice(identity, contractCode, null, now, now, now.plusDays(200));
IdmContractSliceDto sliceCurrentNew = helper.createContractSlice(identity, contractCode, null, now, now, now.plusDays(50));
IdmContractSliceFilter filter = new IdmContractSliceFilter();
filter.setIdentity(identity.getId());
List<IdmContractSliceDto> results = contractSliceService.find(filter, null).getContent();
assertEquals(2, results.size());
UUID parentContract = results.get(0).getParentContract();
List<IdmContractSliceDto> slices = contractSliceManager.findAllSlices(parentContract);
assertEquals(2, slices.size());
IdmContractSliceDto validSlice = contractSliceManager.findValidSlice(parentContract);
// Valid slice should be currentSliceNew
assertEquals(sliceCurrentNew, validSlice);
IdmContractSliceDto previousSlice = contractSliceManager.findPreviousSlice(validSlice, slices);
// Previous slice should be sliceCurrent with longer validity
assertEquals(sliceCurrent, previousSlice);
assertNotNull(previousSlice.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());
// Current slice should be contract
IdmIdentityContractDto contract = resultsContract.get(0);
assertTrue(contract.isValid());
assertEquals(sliceCurrentNew.getContractValidFrom(), contract.getValidFrom());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto in project CzechIdMng by bcvsolutions.
the class ContractSliceManagerTest method createSliceValidInPastTest.
@Test
public void createSliceValidInPastTest() {
IdmIdentityDto identity = helper.createIdentity();
String contractCode = "contract-one";
IdmContractSliceDto slice = helper.createContractSlice(identity, null, LocalDate.now().minusDays(10), null, LocalDate.now().minusDays(5));
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);
assertTrue(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);
assertEquals(slice.getContractValidFrom(), contract.getValidFrom());
assertEquals(slice.getContractValidTill(), contract.getValidTill());
assertFalse(contract.isValidNowOrInFuture());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto in project CzechIdMng by bcvsolutions.
the class ContractSliceManagerTest method contractValidityProtectionModeEnabledTest.
@Test
public void contractValidityProtectionModeEnabledTest() {
// Enable protection mode (5 days, gap is 5 days)
configurationService.setValue(ContractSliceConfiguration.PROPERTY_PROTECTION_INTERVAL, "5");
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
assertEquals(sliceOne.getContractValidFrom(), contract.getValidFrom());
assertEquals(sliceTwo.getContractValidFrom(), contract.getValidTill());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto in project CzechIdMng by bcvsolutions.
the class ContractSliceManagerTest method contractValidityProtectionModeEnabledInfinityTest.
@Test
public void contractValidityProtectionModeEnabledInfinityTest() {
// Enable protection mode (1 days)
configurationService.setValue(ContractSliceConfiguration.PROPERTY_PROTECTION_INTERVAL, "1");
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 enabled, next slice has contract valid from sets to null
assertEquals(null, contract.getValidTill());
assertEquals(sliceOne.getContractValidFrom(), contract.getValidFrom());
}
Aggregations