use of org.junit.Assert.assertEquals in project CzechIdMng by bcvsolutions.
the class DefaultSysProvisioningServiceTest method compileAttributesOverrloadedStrategyMergeAuthoDisableTest.
@Test
@Transactional
public void compileAttributesOverrloadedStrategyMergeAuthoDisableTest() {
List<SysRoleSystemAttributeDto> overloadingAttributes = new ArrayList<>();
List<AttributeMapping> defaultAttributes = new ArrayList<>();
initDataSystem();
initOverloadedAttributes(overloadingAttributes, defaultAttributes);
// roleOne
SysRoleSystemDto roleSystem1 = roleSystemService.get(overloadingAttributes.get(0).getRoleSystem());
IdmRoleDto roleDto = roleService.get(roleSystem1.getRole());
roleDto.setPriority(200);
roleDto = roleService.save(roleDto);
// roleTwo
SysRoleSystemDto roleSystem2 = roleSystemService.get(overloadingAttributes.get(1).getRoleSystem());
roleDto = roleService.get(roleSystem2.getRole());
roleDto.setPriority(500);
roleDto = roleService.save(roleDto);
// overloadedRoleOne
SysRoleSystemAttributeDto attribute1 = overloadingAttributes.get(0);
attribute1.setStrategyType(AttributeMappingStrategyType.AUTHORITATIVE_MERGE);
attribute1 = roleSystemAttributeService.save(attribute1);
overloadingAttributes.set(0, attribute1);
// overloadedRoleTwo
SysRoleSystemAttributeDto attribute2 = overloadingAttributes.get(1);
attribute2.setStrategyType(AttributeMappingStrategyType.AUTHORITATIVE_MERGE);
attribute2.setDisabledDefaultAttribute(true);
attribute2 = roleSystemAttributeService.save(attribute2);
overloadingAttributes.set(1, attribute2);
List<AttributeMapping> compilledAttributes = provisioningService.compileAttributes(defaultAttributes, overloadingAttributes, SystemEntityType.IDENTITY);
Assert.assertEquals(2, compilledAttributes.size());
Assert.assertTrue(compilledAttributes.stream().filter(attribute -> {
return "defOneOverloaded".equals(attribute.getName());
}).findFirst().isPresent());
}
use of org.junit.Assert.assertEquals in project CzechIdMng by bcvsolutions.
the class DefaultSysProvisioningServiceTest method compileAttributesOverrloadedDiffPriorityTest.
@Test
@Transactional
public void compileAttributesOverrloadedDiffPriorityTest() {
List<SysRoleSystemAttributeDto> overloadingAttributes = new ArrayList<>();
List<AttributeMapping> defaultAttributes = new ArrayList<>();
initDataSystem();
initOverloadedAttributes(overloadingAttributes, defaultAttributes);
// roleOne
SysRoleSystemDto roleSystem1 = roleSystemService.get(overloadingAttributes.get(0).getRoleSystem());
IdmRoleDto roleDto = roleService.get(roleSystem1.getRole());
roleDto.setPriority(200);
roleDto = roleService.save(roleDto);
// roleTwo
SysRoleSystemDto roleSystem2 = roleSystemService.get(overloadingAttributes.get(1).getRoleSystem());
roleDto = roleService.get(roleSystem2.getRole());
roleDto.setPriority(100);
roleDto = roleService.save(roleDto);
List<SysRoleSystemAttributeDto> freshOverloadingAttributes = new ArrayList<>();
overloadingAttributes.forEach(attribute -> {
freshOverloadingAttributes.add(roleSystemAttributeService.get(attribute.getId()));
});
List<AttributeMapping> compilledAttributes = provisioningService.compileAttributes(defaultAttributes, freshOverloadingAttributes, SystemEntityType.IDENTITY);
Assert.assertEquals(2, compilledAttributes.size());
Assert.assertTrue(compilledAttributes.stream().filter(attribute -> {
return "defOneOverloaded".equals(attribute.getName());
}).findFirst().isPresent());
}
use of org.junit.Assert.assertEquals in project CzechIdMng by bcvsolutions.
the class DefaultSysProvisioningServiceTest method compileAttributesOverrloadedStrategyCreateTest.
@Test
@Transactional
public void compileAttributesOverrloadedStrategyCreateTest() {
List<SysRoleSystemAttributeDto> overloadingAttributes = new ArrayList<>();
List<AttributeMapping> defaultAttributes = new ArrayList<>();
initDataSystem();
initOverloadedAttributes(overloadingAttributes, defaultAttributes);
// roleOne
SysRoleSystemDto roleSystem1 = roleSystemService.get(overloadingAttributes.get(0).getRoleSystem());
IdmRoleDto roleDto = roleService.get(roleSystem1.getRole());
roleDto.setPriority(200);
roleDto = roleService.save(roleDto);
// roleTwo
SysRoleSystemDto roleSystem2 = roleSystemService.get(overloadingAttributes.get(1).getRoleSystem());
roleDto = roleService.get(roleSystem2.getRole());
roleDto.setPriority(500);
roleDto = roleService.save(roleDto);
// overloadedRoleOne
SysRoleSystemAttributeDto attribute1 = overloadingAttributes.get(0);
attribute1.setStrategyType(AttributeMappingStrategyType.CREATE);
attribute1 = roleSystemAttributeService.save(attribute1);
overloadingAttributes.set(0, attribute1);
// overloadedRoleTwo
SysRoleSystemAttributeDto attribute2 = overloadingAttributes.get(1);
attribute2.setStrategyType(AttributeMappingStrategyType.CREATE);
attribute2 = roleSystemAttributeService.save(attribute2);
overloadingAttributes.set(1, attribute2);
List<AttributeMapping> compilledAttributes = provisioningService.compileAttributes(defaultAttributes, overloadingAttributes, SystemEntityType.IDENTITY);
Assert.assertEquals(2, compilledAttributes.size());
Assert.assertTrue(compilledAttributes.stream().filter(attribute -> {
return "defOneOverloadedRoleTwo".equals(attribute.getName());
}).findFirst().isPresent());
}
use of org.junit.Assert.assertEquals in project CzechIdMng by bcvsolutions.
the class IdentityPasswordProvisioningTest method testSendPasswordNotificationCreateCancelled.
@Test
public void testSendPasswordNotificationCreateCancelled() {
// init readOnly system
SysSystemDto system = initSystem();
system.setReadonly(true);
system = systemService.save(system);
IdmRoleDto role = initRole(system);
IdmIdentityDto identity = helper.createIdentity();
// CREATE operation
IdmIdentityRoleDto identityRole = helper.createIdentityRole(identity, role);
checkIdentityAccount(identity, identityRole, 1);
// => new password is sent for valid identity only
identity.setState(IdentityState.VALID);
identity.setFirstName(getHelper().createName());
// UPDATE operation
identityService.save(identity);
//
AccAccountDto account = accountService.getAccount(identity.getUsername(), system.getId());
Assert.assertNotNull(account);
TestResource entityOnSystem = helper.findResource(account.getUid());
Assert.assertNull(entityOnSystem);
//
// Check for send password notification
IdmNotificationFilter notificationFilter = new IdmNotificationFilter();
notificationFilter.setTopic(AccModuleDescriptor.TOPIC_NEW_PASSWORD);
notificationFilter.setRecipient(identity.getUsername());
List<IdmNotificationLogDto> notifications = //
notificationLogService.find(notificationFilter, null).getContent().stream().filter(//
notification -> IdmEmailLog.NOTIFICATION_TYPE.equals(notification.getType())).collect(Collectors.toList());
Assert.assertTrue(notifications.isEmpty());
//
// cancel the first provisioning operation
SysProvisioningOperationFilter filter = new SysProvisioningOperationFilter();
filter.setEntityType(SystemEntityType.IDENTITY);
filter.setEntityIdentifier(identity.getId());
List<SysProvisioningOperationDto> operations = provisioningOperationService.find(filter, null).getContent();
Assert.assertEquals(2, operations.size());
// ~ readonly
Assert.assertTrue(operations.stream().allMatch(o -> o.getResultState() == OperationState.NOT_EXECUTED));
SysProvisioningOperationDto createOperation = operations.stream().filter(o -> o.getOperationType() == ProvisioningEventType.CREATE).findFirst().get();
SysProvisioningOperationDto updateOperation = operations.stream().filter(o -> o.getOperationType() == ProvisioningEventType.UPDATE).findFirst().get();
//
// active system
system.setReadonly(false);
system = systemService.save(system);
//
// cancel the first operation
provisioningExecutor.cancel(createOperation);
operations = provisioningOperationService.find(filter, null).getContent();
Assert.assertEquals(1, operations.size());
notifications = //
notificationLogService.find(notificationFilter, null).getContent().stream().filter(//
notification -> IdmEmailLog.NOTIFICATION_TYPE.equals(notification.getType())).collect(Collectors.toList());
Assert.assertTrue(notifications.isEmpty());
//
provisioningExecutor.execute(updateOperation);
operations = provisioningOperationService.find(filter, null).getContent();
Assert.assertTrue(operations.isEmpty());
notifications = //
notificationLogService.find(notificationFilter, null).getContent().stream().filter(//
notification -> IdmEmailLog.NOTIFICATION_TYPE.equals(notification.getType())).collect(Collectors.toList());
Assert.assertEquals(1, notifications.size());
}
use of org.junit.Assert.assertEquals in project CzechIdMng by bcvsolutions.
the class IdentityContractSyncTest method testInvalidateAndCreateAnotherContractWithAutomaticRoles.
@Test
public void testInvalidateAndCreateAnotherContractWithAutomaticRoles() {
SysSystemDto system = initData();
SysSystemDto systemProvisioning = helper.createTestResourceSystem(true);
Assert.assertNotNull(system);
AbstractSysSyncConfigDto config = doCreateSyncConfig(system);
Assert.assertTrue(config instanceof SysSyncContractConfigDto);
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
contractService.delete(getHelper().getPrimeContract(identity));
//
// create first contract with validity and automatic role
String positionCode = getHelper().createName();
IdmTreeNodeDto node = getHelper().createTreeNode();
IdmRoleDto role = getHelper().createRole();
helper.createRoleSystem(role, systemProvisioning);
getHelper().createAutomaticRole(role, node);
IdmIdentityContractDto contract = new IdmIdentityContractDto();
contract.setIdentity(identity.getId());
contract.setValidFrom(LocalDate.now().minusMonths(1));
contract.setValidTill(LocalDate.now().plusMonths(1));
contract.setDescription(positionCode);
contract.setPosition(positionCode);
contract.setWorkPosition(node.getId());
contract = contractService.save(contract);
IdmIdentityContractFilter contractFilter = new IdmIdentityContractFilter();
contractFilter.setIdentity(identity.getId());
Assert.assertEquals(1, contractService.find(contractFilter, null).getTotalElements());
IdmIdentityRoleFilter identityRoleFilter = new IdmIdentityRoleFilter();
identityRoleFilter.setIdentityId(identity.getId());
List<IdmIdentityRoleDto> assignedRoles = identityRoleService.find(identityRoleFilter, null).getContent();
Assert.assertEquals(1, assignedRoles.size());
Assert.assertNotNull(assignedRoles.get(0).getValidFrom());
Assert.assertNotNull(assignedRoles.get(0).getValidTill());
Assert.assertEquals(contract.getValidFrom(), assignedRoles.get(0).getValidFrom());
Assert.assertEquals(contract.getValidTill(), assignedRoles.get(0).getValidTill());
// create target system entity - invalid
TestContractResource invalidContractResource = new TestContractResource();
invalidContractResource.setId(positionCode);
invalidContractResource.setName(positionCode);
invalidContractResource.setOwner(identity.getUsername());
invalidContractResource.setMain(Boolean.TRUE.toString());
invalidContractResource.setWorkposition(node.getId().toString());
invalidContractResource.setDescription(positionCode);
invalidContractResource.setValidTill(LocalDate.now().minusDays(1));
this.getBean().createContractData(invalidContractResource);
//
String validPositionCode = getHelper().createName();
TestContractResource validContractResource = new TestContractResource();
validContractResource.setId(validPositionCode);
validContractResource.setName(validPositionCode);
validContractResource.setOwner(identity.getUsername());
validContractResource.setMain(Boolean.FALSE.toString());
validContractResource.setWorkposition(node.getId().toString());
validContractResource.setDescription(validPositionCode);
this.getBean().createContractData(validContractResource);
//
helper.startSynchronization(config);
SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.LINK_AND_UPDATE_ENTITY, 1);
checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 1);
UUID transactionId = log.getTransactionId();
Assert.assertFalse(log.isRunning());
List<IdmIdentityContractDto> contracts = contractService.find(contractFilter, null).getContent();
Assert.assertEquals(2, contracts.size());
Assert.assertTrue(contracts.stream().allMatch(c -> c.getTransactionId().equals(transactionId)));
Assert.assertTrue(contracts.stream().anyMatch(c -> c.isValid()));
Assert.assertTrue(contracts.stream().anyMatch(c -> !c.isValid()));
assignedRoles = identityRoleService.find(identityRoleFilter, null).getContent();
Assert.assertEquals(1, assignedRoles.size());
Assert.assertNull(assignedRoles.get(0).getValidFrom());
Assert.assertNull(assignedRoles.get(0).getValidTill());
Assert.assertEquals(transactionId, assignedRoles.get(0).getTransactionId());
// find provisioning archive => prevent drop and create => update only in this transaction id
SysProvisioningOperationFilter filter = new SysProvisioningOperationFilter();
filter.setSystemId(systemProvisioning.getId());
filter.setTransactionId(transactionId);
List<SysProvisioningArchiveDto> executedOperations = provisioningArchiveService.find(filter, null).getContent();
Assert.assertFalse(executedOperations.isEmpty());
Assert.assertTrue(executedOperations.stream().allMatch(o -> o.getOperationType() != ProvisioningEventType.DELETE));
Assert.assertTrue(executedOperations.stream().allMatch(o -> o.getResultState() == OperationState.EXECUTED));
// Delete log
syncLogService.delete(log);
}
Aggregations