use of eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter 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.filter.IdmContractSliceFilter in project CzechIdMng by bcvsolutions.
the class ContractSliceSyncTest method unlinkAccountTest.
@Test
public void unlinkAccountTest() {
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);
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");
List<IdmContractSliceDto> contractSlices = contractSliceService.find(contractFilter, null).getContent();
Assert.assertEquals(1, contractSlices.size());
// Find the account for this contract slice
IdmContractSliceDto slice = contractSlices.get(0);
AccContractSliceAccountFilter contractAccountFilter = new AccContractSliceAccountFilter();
contractAccountFilter.setSliceId(slice.getId());
contractAccountFilter.setSystemId(system.getId());
List<AccContractSliceAccountDto> contractAccounts = contractSliceAccountService.find(contractAccountFilter, null).getContent();
Assert.assertEquals(1, contractAccounts.size());
AccContractSliceAccountDto contractAccount = contractAccounts.get(0);
AccAccountDto account = accountService.get(contractAccount.getAccount());
Assert.assertNotNull(account);
// Delete log
syncLogService.delete(log);
// Change settings of sync and run
config.setLinkedAction(SynchronizationLinkedActionType.UNLINK);
config.setUnlinkedAction(SynchronizationUnlinkedActionType.IGNORE);
config.setMissingEntityAction(SynchronizationMissingEntityActionType.IGNORE);
config.setMissingAccountAction(ReconciliationMissingAccountActionType.IGNORE);
config = syncConfigService.save(config);
helper.startSynchronization(config);
log = checkSyncLog(config, SynchronizationActionType.UNLINK, 4);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
// Find the account for this contract slice ... unlink operation was executed,
// none relation can be found
contractAccountFilter = new AccContractSliceAccountFilter();
contractAccountFilter.setSliceId(slice.getId());
contractAccountFilter.setSystemId(system.getId());
contractAccounts = contractSliceAccountService.find(contractAccountFilter, null).getContent();
Assert.assertEquals(0, contractAccounts.size());
account = accountService.get(account.getId());
Assert.assertNull(account);
// Delete log
syncLogService.delete(log);
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter in project CzechIdMng by bcvsolutions.
the class ContractSliceSyncTest method updateAccountTest.
@Test
public void updateAccountTest() {
SysSystemDto system = initData();
Assert.assertNotNull(system);
AbstractSysSyncConfigDto config = doCreateSyncConfig(system);
Assert.assertTrue(config instanceof SysSyncContractConfigDto);
config = syncConfigService.save(config);
helper.createIdentity(CONTRACT_OWNER_ONE);
helper.createIdentity(CONTRACT_OWNER_TWO);
helper.createIdentity(CONTRACT_LEADER_ONE);
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");
List<IdmContractSliceDto> contractSlices = contractSliceService.find(contractFilter, null).getContent();
Assert.assertEquals(1, contractSlices.size());
// Find the account for this contract slice
IdmContractSliceDto slice = contractSlices.get(0);
AccContractSliceAccountFilter contractAccountFilter = new AccContractSliceAccountFilter();
contractAccountFilter.setSliceId(slice.getId());
contractAccountFilter.setSystemId(system.getId());
List<AccContractSliceAccountDto> contractAccounts = contractSliceAccountService.find(contractAccountFilter, null).getContent();
Assert.assertEquals(1, contractAccounts.size());
AccContractSliceAccountDto contractAccount = contractAccounts.get(0);
AccAccountDto account = accountService.get(contractAccount.getAccount());
Assert.assertNotNull(account);
// Delete log
syncLogService.delete(log);
TestContractSliceResource accountOnTargetSystem = this.getBean().findSliceOnTargetSystem("1");
Assert.assertNull(accountOnTargetSystem.getState());
// Set slice to disabled
slice.setState(ContractState.DISABLED);
// Change settings of sync and run
config.setLinkedAction(SynchronizationLinkedActionType.UPDATE_ACCOUNT);
config.setUnlinkedAction(SynchronizationUnlinkedActionType.IGNORE);
config.setMissingEntityAction(SynchronizationMissingEntityActionType.IGNORE);
config.setMissingAccountAction(ReconciliationMissingAccountActionType.IGNORE);
config = syncConfigService.save(config);
helper.startSynchronization(config);
log = checkSyncLog(config, SynchronizationActionType.UPDATE_ACCOUNT, 4);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
// Sync of slice does not supports provisioning now (account was not changed)!
accountOnTargetSystem = this.getBean().findSliceOnTargetSystem("1");
Assert.assertEquals(null, accountOnTargetSystem.getState());
// Delete log
syncLogService.delete(log);
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter in project CzechIdMng by bcvsolutions.
the class ContractSliceSyncTest method setDirtyStateAndCheckIt.
@Test
public void setDirtyStateAndCheckIt() {
// create tree type and node, tree node is used as position in contrac slice synchronization
IdmTreeTypeDto treeType = this.getHelper().createTreeType();
IdmTreeNodeDto treeNode = this.getHelper().createTreeNode(treeType, null);
// create two roles, one role is used as automatic role by organization structure
// second role is used as manually added
IdmRoleDto roleOne = this.getHelper().createRole();
IdmRoleDto roleTwo = this.getHelper().createRole();
this.getHelper().createAutomaticRole(roleOne, treeNode);
// init system
SysSystemDto system = initData();
// set default tree type for synchronization
SysSyncContractConfigDto config = (SysSyncContractConfigDto) doCreateSyncConfig(system);
config.setDefaultTreeType(treeType.getId());
syncConfigService.save(config);
IdmIdentityDto identity = helper.createIdentity();
// for sure remove all contracts
contractService.findAllByIdentity(identity.getId()).forEach(contract -> {
contractService.delete(contract);
});
// check current delete audits record for identity (and their related entities)
IdmAuditFilter filter = new IdmAuditFilter();
filter.setOwnerId(identity.getId().toString());
filter.setModification("DELETE");
List<IdmAuditDto> audits = auditService.find(filter, null).getContent();
assertEquals(0, audits.size());
// check current slices
IdmContractSliceFilter contractSliceFilter = new IdmContractSliceFilter();
contractSliceFilter.setIdentity(identity.getId());
List<IdmContractSliceDto> slices = contractSliceService.find(contractSliceFilter, null).getContent();
assertEquals(0, slices.size());
// check current contracts
List<IdmIdentityContractDto> allByIdentity = contractService.findAllByIdentity(identity.getId());
assertEquals(0, allByIdentity.size());
// delete all data in resource
this.getBean().deleteAllResourceData();
// create step one data, please see inside method
this.getBean().createTestDataStepOne(identity.getUsername(), treeNode.getCode());
// start synchronization
helper.startSynchronization(config);
SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 1);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
// after first synchronization exists one contract
allByIdentity = contractService.findAllByIdentity(identity.getId());
assertEquals(1, allByIdentity.size());
// after first synchronization exists one slice
slices = contractSliceService.find(contractSliceFilter, null).getContent();
assertEquals(1, slices.size());
// after first synchronization exists one identity role - automatic role
List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(1, identityRoles.size());
IdmIdentityRoleDto identityRoleDto = identityRoles.get(0);
// manually create identity account for check if identity account will be changed or deleted after second synchronization
// this state create two audit records for the identity account
AccIdentityAccountDto identityAccount = helper.createIdentityAccount(system, identity);
identityAccount.setIdentityRole(identityRoleDto.getId());
identityAccount = identityAccountService.save(identityAccount);
// add manually role
IdmIdentityContractDto identityContractDto = allByIdentity.get(0);
this.getHelper().createIdentityRole(identityContractDto, roleTwo);
// check current identity roles - one is automatic, second is manually added
identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(2, identityRoles.size());
// prepare data for second step
this.getBean().createTestDataStepTwo(identity.getUsername(), treeNode.getCode());
helper.startSynchronization(config);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
// after second synchronization still exists one contract
allByIdentity = contractService.findAllByIdentity(identity.getId());
assertEquals(1, allByIdentity.size());
// after second synchronization exists two slices
slices = contractSliceService.find(contractSliceFilter, null).getContent();
assertEquals(2, slices.size());
// after second synchronization must also exists both roles
identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(2, identityRoles.size());
// check delete operation for identity and their related entities
filter = new IdmAuditFilter();
filter.setOwnerId(identity.getId().toString());
filter.setModification("DELETE");
audits = auditService.find(filter, null).getContent();
assertEquals(0, audits.size());
// check audit for identity roles
for (IdmIdentityRoleDto identityRole : identityRoles) {
filter = new IdmAuditFilter();
filter.setEntityId(identityRole.getId());
List<IdmAuditDto> auditsForIdentityRole = auditService.find(filter, null).getContent();
if (identityRole.getAutomaticRole() == null) {
// manually added role, just create
assertEquals(1, auditsForIdentityRole.size());
} else {
// automatic role change validity
assertEquals(2, auditsForIdentityRole.size());
}
}
// Check audit records for identity account, exists three record, because helper
// create one and second create save with change identity role and third is
// delete of this identity-account (role does not mapping the system)
filter = new IdmAuditFilter();
filter.setEntityId(identityAccount.getId());
List<IdmAuditDto> auditsForIdentityAccount = auditService.find(filter, null).getContent();
assertEquals(3, auditsForIdentityAccount.size());
// some tests expect data as contract slice with id 1. Just for sure we clear test slices
slices = contractSliceService.find(contractSliceFilter, null).getContent();
slices.forEach(slice -> {
contractSliceService.delete(slice);
});
identityService.delete(identity);
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter in project CzechIdMng by bcvsolutions.
the class ContractSliceSyncTest method addTwoNewAndDeleteFirstContractSlice.
@Test
public void addTwoNewAndDeleteFirstContractSlice() {
// init system
SysSystemDto system = initData();
this.getBean().deleteAllResourceData();
IdmIdentityDto identity = helper.createIdentity();
List<IdmIdentityContractDto> contracts = contractService.findAllByIdentity(identity.getId());
assertEquals(1, contracts.size());
contractService.delete(contracts.get(0));
// first valid slice
this.getBean().createSlice("1", identity.getUsername(), null, null, null, null, null, LocalDate.now().minusDays(20), null, LocalDate.now().minusDays(20), "ONE");
SysSyncContractConfigDto config = (SysSyncContractConfigDto) doCreateSyncConfig(system);
config.setStartOfHrProcesses(true);
config.setMissingAccountAction(ReconciliationMissingAccountActionType.DELETE_ENTITY);
config = (SysSyncContractConfigDto) syncConfigService.save(config);
// start sync
helper.startSynchronization(config);
IdmContractSliceFilter filter = new IdmContractSliceFilter();
filter.setIdentity(identity.getId());
List<IdmContractSliceDto> slices = contractSliceService.find(filter, null).getContent();
assertEquals(1, slices.size());
IdmContractSliceDto sliceDto = slices.get(0);
assertEquals(LocalDate.now().minusDays(20), sliceDto.getValidFrom());
assertEquals(null, sliceDto.getValidTill());
// create invalid slice
this.getBean().createSlice("2", identity.getUsername(), null, null, null, null, null, LocalDate.now().minusDays(20), LocalDate.now().minusDays(10), LocalDate.now().minusDays(10), "ONE");
// create valid slice
this.getBean().createSlice("3", identity.getUsername(), null, null, null, null, null, LocalDate.now().minusDays(10), null, LocalDate.now().minusDays(9), "ONE");
// delete first
this.getBean().deleteSlice("1");
// start sync
helper.startSynchronization(config);
slices = contractSliceService.find(filter, null).getContent();
assertEquals(2, slices.size());
for (IdmContractSliceDto slice : slices) {
if ("2".equals(slice.getDescription())) {
assertEquals(LocalDate.now().minusDays(10), slice.getValidFrom());
assertEquals(LocalDate.now().minusDays(9).minusDays(1), slice.getValidTill());
assertNotNull(slice.getParentContract());
} else if ("3".equals(slice.getDescription())) {
assertEquals(LocalDate.now().minusDays(9), slice.getValidFrom());
assertEquals(null, slice.getValidTill());
assertTrue(slice.isUsingAsContract());
assertNotNull(slice.getParentContract());
} else {
fail("Slice with bad id!");
}
}
contracts = contractService.findAllByIdentity(identity.getId());
assertEquals(1, contracts.size());
IdmIdentityContractDto contract = contracts.get(0);
assertEquals(LocalDate.now().minusDays(10), contract.getValidFrom());
assertEquals(null, contract.getValidTill());
// some tests expect data as contract slice with id 1. Just for sure we clear test slices
slices = contractSliceService.find(filter, null).getContent();
slices.forEach(slice -> {
contractSliceService.delete(slice);
});
identityService.delete(identity);
}
Aggregations