use of org.junit.Assert.assertEquals in project CzechIdMng by bcvsolutions.
the class IdentitySyncTest method testCreateIdentityWithAutomaticRoleByEavAttribute.
@Test
public void testCreateIdentityWithAutomaticRoleByEavAttribute() {
String username = getHelper().createName();
SysSystemDto system = initData(username, "mockIdentity@idm.eu");
Assert.assertNotNull(system);
SysSyncIdentityConfigDto config = doCreateSyncConfig(system);
config.setCreateDefaultContract(true);
config.setStartAutoRoleRec(true);
syncConfigService.save(config);
//
// create form definition, roles, automatic role etc.
IdmRoleDto role = getHelper().createRole();
IdmRoleDto subRole = getHelper().createRole();
getHelper().createRoleComposition(role, subRole);
// sync supports default definition only
IdmFormAttributeDto formAttribute = new IdmFormAttributeDto(getHelper().createName());
IdmFormAttributeDto formAttributeIdentity = formService.saveAttribute(IdmIdentityDto.class, formAttribute);
//
IdmAutomaticRoleAttributeDto automaticRole = getHelper().createAutomaticRole(role.getId());
getHelper().createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY_EAV, null, formAttributeIdentity.getId(), "mockIdentity@idm.eu");
//
// create mapping to eav attribute - leader = eav
SysSystemMappingDto syncSystemMapping = systemMappingService.get(config.getSystemMapping());
SysSystemAttributeMappingFilter attributeMappingFilter = new SysSystemAttributeMappingFilter();
attributeMappingFilter.setSystemMappingId(syncSystemMapping.getId());
SysSystemAttributeMappingDto lastnameAttributeMapping = schemaAttributeMappingService.findBySystemMappingAndName(syncSystemMapping.getId(), ATTRIBUTE_EMAIL);
lastnameAttributeMapping.setEntityAttribute(false);
lastnameAttributeMapping.setExtendedAttribute(true);
lastnameAttributeMapping.setIdmPropertyName(formAttributeIdentity.getCode());
schemaAttributeMappingService.save(lastnameAttributeMapping);
//
helper.startSynchronization(config);
SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 1, OperationResultType.SUCCESS);
Assert.assertFalse(log.isRunning());
IdmIdentityFilter identityFilter = new IdmIdentityFilter();
identityFilter.setUsername(username);
identityFilter.setAddEavMetadata(Boolean.TRUE);
List<IdmIdentityDto> identities = identityService.find(identityFilter, null).getContent();
Assert.assertEquals(1, identities.size());
Assert.assertEquals("mockIdentity@idm.eu", identities.get(0).getEavs().stream().filter(fi -> fi.getFormDefinition().isMain()).findFirst().get().getValues().stream().filter(v -> v.getFormAttribute().equals(formAttributeIdentity.getId())).findFirst().get().getShortTextValue());
IdmIdentityRoleFilter identityRoleFilter = new IdmIdentityRoleFilter();
identityRoleFilter.setIdentityId(identities.get(0).getId());
List<IdmIdentityRoleDto> assignedRoles = identityRoleService.find(identityRoleFilter, null).getContent();
Assert.assertEquals(2, assignedRoles.size());
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getRole().equals(role.getId())));
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getRole().equals(subRole.getId())));
// Delete log
syncLogService.delete(log);
syncConfigService.delete(config);
}
use of org.junit.Assert.assertEquals in project CzechIdMng by bcvsolutions.
the class ContractSliceSyncTest method checkSyncLog.
private SysSyncLogDto checkSyncLog(AbstractSysSyncConfigDto config, SynchronizationActionType actionType, int count) {
SysSyncLogFilter logFilter = new SysSyncLogFilter();
logFilter.setSynchronizationConfigId(config.getId());
List<SysSyncLogDto> logs = syncLogService.find(logFilter, null).getContent();
Assert.assertEquals(1, logs.size());
SysSyncLogDto log = logs.get(0);
SysSyncActionLogFilter actionLogFilter = new SysSyncActionLogFilter();
actionLogFilter.setSynchronizationLogId(log.getId());
List<SysSyncActionLogDto> actions = syncActionLogService.find(actionLogFilter, null).getContent();
List<SysSyncActionLogDto> actionLogs = actions.stream().filter(action -> {
return actionType == action.getSyncAction();
}).collect(Collectors.toList());
List<SysSyncItemLogDto> result = new ArrayList<>();
actionLogs.forEach(actionLog -> {
SysSyncItemLogFilter itemLogFilter = new SysSyncItemLogFilter();
itemLogFilter.setSyncActionLogId(actionLog.getId());
List<SysSyncItemLogDto> items = syncItemLogService.find(itemLogFilter, null).getContent();
result.addAll(items);
});
Assert.assertEquals(count, result.size());
return log;
}
use of org.junit.Assert.assertEquals in project CzechIdMng by bcvsolutions.
the class IdentityAddRoleBulkActionIntegrationTest method processBulkActionByIdsWithoutValidityIsGiven.
@Test
public void processBulkActionByIdsWithoutValidityIsGiven() {
IdmIdentityDto identityOne = getHelper().createIdentity((GuardedString) null);
IdmIdentityContractDto primeContract = getHelper().getPrimeContract(identityOne);
IdmIdentityContractDto otherValidContract = getHelper().createContract(identityOne, null, LocalDate.now().plusDays(1), LocalDate.now().plusDays(2));
IdmIdentityContractDto otherInvalidContract = getHelper().createContract(identityOne, null, null, LocalDate.now().minusDays(1));
IdmRoleDto roleOne = getHelper().createRole();
IdmBulkActionDto bulkAction = this.findBulkAction(IdmIdentity.class, IdentityAddRoleBulkAction.NAME);
bulkAction.setIdentifiers(Sets.newHashSet(identityOne.getId()));
Map<String, Object> properties = new HashMap<>();
properties.put(IdentityAddRoleBulkAction.ROLE_CODE, Lists.newArrayList(roleOne.getId().toString()));
properties.put(IdentityAddRoleBulkAction.PRIMARY_CONTRACT_CODE, Boolean.FALSE);
properties.put(IdentityAddRoleBulkAction.APPROVE_CODE, Boolean.FALSE);
bulkAction.setProperties(properties);
IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
checkResultLrt(processAction, 2l, null, null);
List<IdmIdentityContractDto> contracts = identityContractService.findAllByIdentity(identityOne.getId());
// +1 primary vithout validity is set
Assert.assertEquals(3, contracts.size());
Assert.assertTrue(identityRoleService.findAllByContract(otherInvalidContract.getId()).isEmpty());
List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByIdentity(identityOne.getId());
Assert.assertEquals(2, identityRoles.size());
Assert.assertTrue(identityRoles.stream().anyMatch(ir -> ir.getRole().equals(roleOne.getId()) && ir.getIdentityContract().equals(primeContract.getId()) && ir.getValidFrom() == null && ir.getValidTill() == null));
Assert.assertTrue(identityRoles.stream().anyMatch(ir -> ir.getRole().equals(roleOne.getId()) && ir.getIdentityContract().equals(otherValidContract.getId()) && ir.getValidFrom().equals(otherValidContract.getValidFrom()) && ir.getValidTill() == null));
}
use of org.junit.Assert.assertEquals in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityContractServiceIntegrationTest method testSkipAndAssignAutomaticRoleOnPositionAfterChange.
@Test
public void testSkipAndAssignAutomaticRoleOnPositionAfterChange() {
IdmTreeNodeDto otherNode = getHelper().createTreeNode();
IdmTreeNodeDto node = getHelper().createTreeNode();
// define automatic role for parent
IdmRoleDto role = getHelper().createRole();
IdmRoleTreeNodeDto automaticRole = getHelper().createRoleTreeNode(role, node, RecursionType.NO, true);
// create identity with contract on node
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmContractPositionDto position = getHelper().createContractPosition(getHelper().getPrimeContract(identity), otherNode);
// no role should be assigned now
List<IdmIdentityRoleDto> assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertTrue(assignedRoles.isEmpty());
//
position.setWorkPosition(node.getId());
EntityEvent<IdmContractPositionDto> event = new ContractPositionEvent(ContractPositionEventType.UPDATE, position);
event.getProperties().put(AutomaticRoleManager.SKIP_RECALCULATION, Boolean.TRUE);
position = contractPositionService.publish(event).getContent();
UUID positionId = position.getId();
IdmEntityStateFilter filter = new IdmEntityStateFilter();
filter.setStates(Lists.newArrayList(OperationState.BLOCKED));
filter.setResultCode(CoreResultCode.AUTOMATIC_ROLE_SKIPPED.getCode());
filter.setOwnerType(entityStateManager.getOwnerType(IdmContractPositionDto.class));
List<IdmEntityStateDto> skippedStates = entityStateManager.findStates(filter, null).getContent();
Assert.assertTrue(skippedStates.stream().anyMatch(s -> s.getOwnerId().equals(positionId)));
//
assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertTrue(assignedRoles.isEmpty());
//
// recount skipped automatic roles
longRunningTaskManager.execute(new ProcessSkippedAutomaticRoleByTreeForContractTaskExecutor());
skippedStates = entityStateManager.findStates(filter, null).getContent();
Assert.assertFalse(skippedStates.stream().anyMatch(s -> s.getOwnerId().equals(automaticRole.getId())));
//
assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertEquals(1, assignedRoles.size());
Assert.assertEquals(automaticRole.getId(), assignedRoles.get(0).getAutomaticRole());
}
use of org.junit.Assert.assertEquals in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityContractServiceIntegrationTest method testFindContractByOrPermissions.
@Test
public void testFindContractByOrPermissions() {
IdmIdentityDto identity = getHelper().createIdentity();
IdmIdentityContractDto contractOne = getHelper().createContract(identity);
IdmIdentityContractDto contractTwo = getHelper().createContract(identity);
// other - without permission
getHelper().createContract(identity);
//
IdmRoleDto role = getHelper().createRole();
getHelper().createUuidPolicy(role, contractOne, ContractBasePermission.CANBEREQUESTED);
getHelper().createUuidPolicy(role, contractTwo, ContractBasePermission.CHANGEPERMISSION);
//
IdmIdentityDto manager = getHelper().createIdentity();
getHelper().createIdentityRole(manager, role);
//
IdmIdentityContractFilter filter = new IdmIdentityContractFilter();
filter.setIdentity(identity.getId());
filter.setEvaluatePermissionOperator(PermissionContext.OPERATOR_OR);
//
// without login => empty
List<IdmIdentityContractDto> contracts = service.find(filter, null, ContractBasePermission.CANBEREQUESTED, ContractBasePermission.CHANGEPERMISSION).getContent();
Assert.assertTrue(contracts.isEmpty());
//
try {
getHelper().login(manager);
//
contracts = service.find(filter, null, ContractBasePermission.CANBEREQUESTED, ContractBasePermission.CHANGEPERMISSION).getContent();
Assert.assertEquals(2, contracts.size());
Assert.assertTrue(contracts.stream().anyMatch(c -> c.getId().equals(contractOne.getId())));
Assert.assertTrue(contracts.stream().anyMatch(c -> c.getId().equals(contractTwo.getId())));
//
contracts = service.find(filter, null, ContractBasePermission.CANBEREQUESTED).getContent();
Assert.assertEquals(1, contracts.size());
Assert.assertTrue(contracts.stream().anyMatch(c -> c.getId().equals(contractOne.getId())));
//
contracts = service.find(filter, null, ContractBasePermission.CHANGEPERMISSION).getContent();
Assert.assertEquals(1, contracts.size());
Assert.assertTrue(contracts.stream().anyMatch(c -> c.getId().equals(contractTwo.getId())));
//
filter.setEvaluatePermissionOperator(null);
contracts = service.find(filter, null, ContractBasePermission.CANBEREQUESTED, ContractBasePermission.CHANGEPERMISSION).getContent();
Assert.assertTrue(contracts.isEmpty());
//
filter.setEvaluatePermissionOperator(PermissionContext.OPERATOR_AND);
contracts = service.find(filter, null, ContractBasePermission.CANBEREQUESTED, ContractBasePermission.CHANGEPERMISSION).getContent();
Assert.assertTrue(contracts.isEmpty());
} finally {
getHelper().logout();
}
}
Aggregations