use of eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto in project CzechIdMng by bcvsolutions.
the class RoleDuplicateBulkActionIntegrationTest method testDuplicateRoleWithRoleAttributes.
@Test
public void testDuplicateRoleWithRoleAttributes() {
IdmRoleDto role = createRole();
// create attributes, automatic roles etc.
String definitionCode = getHelper().createName();
createRoleFormAttribute(role, definitionCode, getHelper().createName());
createRoleFormAttribute(role, definitionCode, getHelper().createName());
//
List<IdmRoleFormAttributeDto> roleFormAttributes = findRoleFormAttributes(role);
Assert.assertFalse(roleFormAttributes.isEmpty());
//
String roleBaseCode = role.getBaseCode();
String targetEnvironment = getHelper().createName();
IdmBulkActionDto bulkAction = findBulkAction(IdmRole.class, RoleDuplicateBulkAction.NAME);
bulkAction.setIdentifiers(Sets.newHashSet(role.getId()));
bulkAction.getProperties().put(RoleDuplicateBulkAction.PROPERTY_ENVIRONMENT, targetEnvironment);
bulkAction.getProperties().put(DuplicateRoleFormAttributeProcessor.PARAMETER_INCLUDE_ROLE_FORM_ATTRIBUTE, true);
IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
//
checkResultLrt(processAction, 1l, null, null);
//
IdmRoleDto duplicate = roleService.getByBaseCodeAndEnvironment(roleBaseCode, targetEnvironment);
//
List<IdmRoleFormAttributeDto> duplicateFormAttributes = findRoleFormAttributes(duplicate);
Assert.assertFalse(duplicateFormAttributes.isEmpty());
Assert.assertEquals(roleFormAttributes.size(), duplicateFormAttributes.size());
Assert.assertTrue(duplicateFormAttributes.stream().allMatch(d -> roleFormAttributes.stream().anyMatch(r -> d.getFormAttribute().equals(r.getFormAttribute()))));
}
use of eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto in project CzechIdMng by bcvsolutions.
the class RoleDuplicateBulkActionIntegrationTest method testUpdateAutomaticRole.
@Test
public void testUpdateAutomaticRole() {
// automatic role on sub role
IdmRoleDto parentRole = createRole();
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmRoleDto subRole = createRole();
getHelper().createRoleComposition(parentRole, subRole);
// create attributes, automatic roles etc.
IdmAutomaticRoleAttributeDto automaticRoleAttribute = createAutomaticRole(subRole, identity.getUsername());
List<IdmIdentityRoleDto> assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> automaticRoleAttribute.getId().equals(ir.getAutomaticRole())));
//
String targetEnvironment = getHelper().createName();
IdmBulkActionDto bulkAction = findBulkAction(IdmRole.class, RoleDuplicateBulkAction.NAME);
bulkAction.setIdentifiers(Sets.newHashSet(parentRole.getId()));
bulkAction.getProperties().put(RoleDuplicateBulkAction.PROPERTY_ENVIRONMENT, targetEnvironment);
bulkAction.getProperties().put(DuplicateRoleAutomaticByTreeProcessor.PARAMETER_INCLUDE_AUTOMATIC_ROLE, true);
bulkAction.getProperties().put(DuplicateRoleCompositionProcessor.PARAMETER_INCLUDE_ROLE_COMPOSITION, true);
IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
//
checkResultLrt(processAction, 1l, null, null);
//
IdmRoleDto duplicate = roleService.getByBaseCodeAndEnvironment(subRole.getBaseCode(), targetEnvironment);
//
IdmAutomaticRoleAttributeDto duplicateAutomaticRoleAttribute = findAutomaticRolesByAttribute(duplicate).get(0);
//
assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> automaticRoleAttribute.getId().equals(ir.getAutomaticRole())));
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> duplicateAutomaticRoleAttribute.getId().equals(ir.getAutomaticRole())));
//
IdmIdentityDto otherIdentity = getHelper().createIdentity((GuardedString) null);
IdmAutomaticRoleAttributeRuleDto rule = automaticRoleAttributeRuleService.findAllRulesForAutomaticRole(automaticRoleAttribute.getId()).get(0);
rule.setValue(otherIdentity.getUsername());
automaticRoleAttributeRuleService.save(rule);
automaticRoleAttributeService.recalculate(automaticRoleAttribute.getId());
//
processAction = bulkActionManager.processAction(bulkAction);
//
checkResultLrt(processAction, 1l, null, null);
//
duplicate = roleService.getByBaseCodeAndEnvironment(subRole.getBaseCode(), targetEnvironment);
//
assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertTrue(assignedRoles.isEmpty());
//
assignedRoles = identityRoleService.findAllByIdentity(otherIdentity.getId());
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> automaticRoleAttribute.getId().equals(ir.getAutomaticRole())));
}
use of eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto in project CzechIdMng by bcvsolutions.
the class RoleDuplicateBulkActionIntegrationTest method testDuplicateRoleWithCompositionAndAutomaticRoles.
@Test
public void testDuplicateRoleWithCompositionAndAutomaticRoles() {
// automatic role on sub role
IdmRoleDto parentRole = createRole();
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmTreeNodeDto treeNode = getHelper().createTreeNode();
IdmIdentityContractDto contract = getHelper().getPrimeContract(identity);
contract.setWorkPosition(treeNode.getId());
contractService.save(contract);
IdmRoleDto subRole = createRole();
getHelper().createRoleComposition(parentRole, subRole);
// create attributes, automatic roles etc.
IdmAutomaticRoleAttributeDto automaticRoleAttribute = createAutomaticRole(subRole, identity.getUsername());
IdmRoleTreeNodeDto automaticRoleTree = createAutomaticRole(subRole, treeNode);
List<IdmIdentityRoleDto> assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> automaticRoleAttribute.getId().equals(ir.getAutomaticRole())));
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> automaticRoleTree.getId().equals(ir.getAutomaticRole())));
//
String targetEnvironment = getHelper().createName();
IdmBulkActionDto bulkAction = findBulkAction(IdmRole.class, RoleDuplicateBulkAction.NAME);
bulkAction.setIdentifiers(Sets.newHashSet(parentRole.getId()));
bulkAction.getProperties().put(RoleDuplicateBulkAction.PROPERTY_ENVIRONMENT, targetEnvironment);
bulkAction.getProperties().put(DuplicateRoleAutomaticByTreeProcessor.PARAMETER_INCLUDE_AUTOMATIC_ROLE, true);
bulkAction.getProperties().put(DuplicateRoleCompositionProcessor.PARAMETER_INCLUDE_ROLE_COMPOSITION, true);
IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
//
checkResultLrt(processAction, 1l, null, null);
//
IdmRoleDto duplicate = roleService.getByBaseCodeAndEnvironment(subRole.getBaseCode(), targetEnvironment);
//
IdmAutomaticRoleAttributeDto duplicateAutomaticRoleAttribute = findAutomaticRolesByAttribute(duplicate).get(0);
IdmRoleTreeNodeDto duplicateAtomaticRoleTree = findAutomaticRolesByTree(duplicate).get(0);
//
assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> automaticRoleAttribute.getId().equals(ir.getAutomaticRole())));
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> automaticRoleTree.getId().equals(ir.getAutomaticRole())));
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> duplicateAutomaticRoleAttribute.getId().equals(ir.getAutomaticRole())));
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> duplicateAtomaticRoleTree.getId().equals(ir.getAutomaticRole())));
}
use of eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto in project CzechIdMng by bcvsolutions.
the class RoleDuplicateBulkActionIntegrationTest method testDuplicateRoleOnTheSameEnvironmentWithComposition.
/**
* Sub roles are used the same as on parent
*/
@Test
public void testDuplicateRoleOnTheSameEnvironmentWithComposition() {
IdmRoleDto role = createRole();
List<IdmRoleCompositionDto> subRoles = findAllSubRoles(role);
Assert.assertFalse(subRoles.isEmpty());
//
String roleBaseCode = role.getBaseCode();
//
IdmBulkActionDto bulkAction = findBulkAction(IdmRole.class, RoleDuplicateBulkAction.NAME);
bulkAction.setIdentifiers(Sets.newHashSet(role.getId()));
bulkAction.getProperties().put(DuplicateRoleCompositionProcessor.PARAMETER_INCLUDE_ROLE_COMPOSITION, true);
IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
//
checkResultLrt(processAction, 1l, null, null);
IdmRoleFilter filter = new IdmRoleFilter();
filter.setEnvironment(role.getEnvironment());
List<IdmRoleDto> roles = roleService.find(filter, null).getContent();
IdmRoleDto duplicate = roles.stream().filter(r -> r.getBaseCode().startsWith(roleBaseCode) && !r.getBaseCode().equals(roleBaseCode)).findFirst().get();
//
List<IdmRoleCompositionDto> duplicateSubRoles = findAllSubRoles(duplicate);
Assert.assertFalse(duplicateSubRoles.isEmpty());
Assert.assertEquals(subRoles.size(), duplicateSubRoles.size());
Assert.assertTrue(duplicateSubRoles.stream().allMatch(s -> subRoles.stream().anyMatch(r -> r.getSub().equals(s.getSub()))));
}
use of eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto in project CzechIdMng by bcvsolutions.
the class RoleDuplicateBulkActionIntegrationTest method testDuplicateRoleOnlyOnTheSameEnvironmentGivenAsProperty.
@Test
public void testDuplicateRoleOnlyOnTheSameEnvironmentGivenAsProperty() {
IdmRoleDto role = createRole();
// create attributes, automatic roles etc.
createRoleFormAttribute(role, getHelper().createName(), getHelper().createName());
createAutomaticRole(role, getHelper().createTreeNode());
createAutomaticRole(role, getHelper().createName());
//
Assert.assertFalse(findAllSubRoles(role).isEmpty());
Assert.assertFalse(findAutomaticRolesByTree(role).isEmpty());
Assert.assertFalse(findRoleFormAttributes(role).isEmpty());
Assert.assertFalse(findAutomaticRolesByAttribute(role).isEmpty());
//
String roleBaseCode = role.getBaseCode();
//
String targetEnvironment = role.getEnvironment();
IdmBulkActionDto bulkAction = findBulkAction(IdmRole.class, RoleDuplicateBulkAction.NAME);
bulkAction.setIdentifiers(Sets.newHashSet(role.getId()));
bulkAction.getProperties().put(RoleDuplicateBulkAction.PROPERTY_ENVIRONMENT, targetEnvironment);
bulkAction.getProperties().put(DuplicateRoleAutomaticByTreeProcessor.PARAMETER_INCLUDE_AUTOMATIC_ROLE, false);
bulkAction.getProperties().put(DuplicateRoleFormAttributeProcessor.PARAMETER_INCLUDE_ROLE_FORM_ATTRIBUTE, false);
bulkAction.getProperties().put(DuplicateRoleCompositionProcessor.PARAMETER_INCLUDE_ROLE_COMPOSITION, false);
IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
//
checkResultLrt(processAction, 1l, null, null);
IdmRoleFilter filter = new IdmRoleFilter();
filter.setEnvironment(targetEnvironment);
List<IdmRoleDto> roles = roleService.find(filter, null).getContent();
IdmRoleDto duplicate = roles.stream().filter(r -> r.getBaseCode().startsWith(roleBaseCode) && !r.getBaseCode().equals(roleBaseCode)).findFirst().get();
Assert.assertEquals(role.getName(), duplicate.getName());
Assert.assertEquals(role.getDescription(), duplicate.getDescription());
//
Assert.assertTrue(findAllSubRoles(duplicate).isEmpty());
Assert.assertTrue(findAutomaticRolesByTree(duplicate).isEmpty());
Assert.assertTrue(findRoleFormAttributes(duplicate).isEmpty());
Assert.assertTrue(findAutomaticRolesByAttribute(duplicate).isEmpty());
//
role.setDescription(getHelper().createName());
//
processAction = bulkActionManager.processAction(bulkAction);
//
checkResultLrt(processAction, 1l, null, null);
//
filter = new IdmRoleFilter();
filter.setProperty(IdmRole_.name.getName());
filter.setValue(role.getName());
roles = roleService.find(filter, null).getContent();
// on the same environment is created the second duplicate
Assert.assertEquals(3, roles.size());
}
Aggregations