use of eu.bcvsolutions.idm.acc.dto.SysSyncLogDto in project CzechIdMng by bcvsolutions.
the class DefaultAccTestHelper method checkSyncLog.
@Override
public SysSyncLogDto checkSyncLog(AbstractSysSyncConfigDto config, SynchronizationActionType actionType, int count, OperationResultType resultType) {
SysSyncConfigFilter logFilter = new SysSyncConfigFilter();
logFilter.setId(config.getId());
logFilter.setIncludeLastLog(Boolean.TRUE);
List<AbstractSysSyncConfigDto> configs = syncConfigService.find(logFilter, null).getContent();
assertEquals(1, configs.size());
SysSyncLogDto log = configs.get(0).getLastSyncLog();
if (actionType == null) {
return log;
}
SysSyncActionLogFilter actionLogFilter = new SysSyncActionLogFilter();
actionLogFilter.setSynchronizationLogId(log.getId());
List<SysSyncActionLogDto> actions = syncActionLogService.find(actionLogFilter, null).getContent();
SysSyncActionLogDto actionLog = actions.stream().filter(action -> {
if (resultType == null) {
return actionType == action.getSyncAction();
}
return actionType == action.getSyncAction() && action.getOperationResult() == resultType;
}).findFirst().get();
if (resultType != null) {
assertEquals(resultType, actionLog.getOperationResult());
}
SysSyncItemLogFilter itemLogFilter = new SysSyncItemLogFilter();
itemLogFilter.setSyncActionLogId(actionLog.getId());
List<SysSyncItemLogDto> items = syncItemLogService.find(itemLogFilter, null).getContent();
assertEquals(count, items.size());
return log;
}
use of eu.bcvsolutions.idm.acc.dto.SysSyncLogDto 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.acc.dto.SysSyncLogDto 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.acc.dto.SysSyncLogDto 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.acc.dto.SysSyncLogDto in project CzechIdMng by bcvsolutions.
the class IdentityContractSyncTest method testContractPositions.
@Test
public void testContractPositions() {
SysSystemDto system = initData();
Assert.assertNotNull(system);
AbstractSysSyncConfigDto config = doCreateSyncConfig(system);
Assert.assertTrue(config instanceof SysSyncContractConfigDto);
helper.createIdentity(CONTRACT_OWNER_THREE);
// Set default tree type to sync configuration
IdmTreeTypeDto treeType = treeTypeService.getByCode(InitApplicationData.DEFAULT_TREE_TYPE);
Assert.assertNotNull(treeType);
SysSyncContractConfigDto configContract = (SysSyncContractConfigDto) config;
configContract.setDefaultTreeType(treeType.getId());
config = syncConfigService.save(configContract);
IdmIdentityContractFilter contractFilter = new IdmIdentityContractFilter();
contractFilter.setProperty(IdmIdentityContract_.position.getName());
// Set work positions to resources
this.getBean().initContractPositionTest();
// Start sync again (we want to see some work positions)
helper.startSynchronization(config);
SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 1);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
// For contract One must be found workposition (one)
contractFilter.setValue("1");
IdmIdentityContractDto contractOne = contractService.find(contractFilter, null).getContent().get(0);
Assert.assertNotNull(contractOne);
//
IdmContractPositionFilter positionFitler = new IdmContractPositionFilter();
positionFitler.setIdentityContractId(contractOne.getId());
List<IdmContractPositionDto> positions = contractPositionService.find(positionFitler, null).getContent();
Assert.assertEquals(1, positions.size());
Assert.assertEquals("one", DtoUtils.getEmbedded(positions.get(0), IdmContractPosition_.workPosition, IdmTreeNodeDto.class).getCode());
// Delete log
syncLogService.delete(log);
}
Aggregations