use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleAttributeIntegrationTest method testTwoAutomaticRoleMoreRules.
@Test
public void testTwoAutomaticRoleMoreRules() {
String testEmail = "testing-email-" + System.currentTimeMillis() + "@example.tld";
String testEavContractValue = "testing-eav-value-" + System.currentTimeMillis();
String testEavIdentityValue = "testing-eav-value-" + System.currentTimeMillis();
String testPositionName = "testing-position-name-" + System.currentTimeMillis();
//
IdmIdentityDto identity = testHelper.createIdentity();
IdmRoleDto role = testHelper.createRole();
IdmRoleDto role2 = testHelper.createRole();
IdmIdentityContractDto primeContract = testHelper.getPrimeContract(identity.getId());
//
// create two eav attributes (for identity and contract)
IdmFormAttributeDto createEavAttribute = testHelper.createEavAttribute("testingEav" + System.currentTimeMillis(), IdmIdentityContract.class, PersistentType.SHORTTEXT);
testHelper.setEavValue(primeContract, createEavAttribute, IdmIdentityContract.class, testEavContractValue + "-not-passed", PersistentType.SHORTTEXT);
IdmFormAttributeDto createEavAttribute2 = testHelper.createEavAttribute("testingEav" + System.currentTimeMillis(), IdmIdentity.class, PersistentType.SHORTTEXT);
testHelper.setEavValue(identity, createEavAttribute2, IdmIdentity.class, testEavIdentityValue + "-not-passed", PersistentType.SHORTTEXT);
//
IdmAutomaticRoleAttributeDto automaticRole = testHelper.createAutomaticRole(role.getId());
IdmAutomaticRoleAttributeDto automaticRole2 = testHelper.createAutomaticRole(role2.getId());
//
// rules for first automatic role
testHelper.createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY, IdmIdentity_.email.getName(), null, testEmail);
testHelper.createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.CONTRACT_EAV, null, createEavAttribute.getId(), testEavContractValue);
//
// rules for second automatic role
testHelper.createAutomaticRoleRule(automaticRole2.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.CONTRACT, IdmIdentityContract_.position.getName(), null, testPositionName);
testHelper.createAutomaticRoleRule(automaticRole2.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY_EAV, null, createEavAttribute2.getId(), testEavIdentityValue);
//
// rules are not passed
List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(0, identityRoles.size());
//
// set attribute for only one part from each rules
primeContract.setPosition(testPositionName);
primeContract = identityContractService.save(primeContract);
identity.setEmail(testEmail);
identity = identityService.save(identity);
//
// still zero, only one part of rules are passed
identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(0, identityRoles.size());
//
testHelper.setEavValue(primeContract, createEavAttribute, IdmIdentityContract.class, testEavContractValue, PersistentType.SHORTTEXT);
//
// one automatic roles has passed all rules
identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(1, identityRoles.size());
IdmIdentityRoleDto identityRole = identityRoles.get(0);
assertEquals(automaticRole.getRole(), identityRole.getRole());
assertEquals(automaticRole.getId(), identityRole.getRoleTreeNode());
//
identity.setEmail(testEmail + "-not-passed");
identity = identityService.save(identity);
//
identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(0, identityRoles.size());
//
testHelper.setEavValue(identity, createEavAttribute2, IdmIdentity.class, testEavIdentityValue, PersistentType.SHORTTEXT);
// passed second automatic role
identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(1, identityRoles.size());
//
identityRole = identityRoles.get(0);
assertEquals(automaticRole2.getRole(), identityRole.getRole());
assertEquals(automaticRole2.getId(), identityRole.getRoleTreeNode());
//
identity.setEmail(testEmail);
identity = identityService.save(identity);
//
identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(2, identityRoles.size());
for (IdmIdentityRoleDto identityRol : identityRoles) {
if (identityRol.getRole().equals(role.getId())) {
assertEquals(automaticRole.getRole(), identityRol.getRole());
assertEquals(automaticRole.getId(), identityRol.getRoleTreeNode());
} else {
assertEquals(automaticRole2.getRole(), identityRol.getRole());
assertEquals(automaticRole2.getId(), identityRol.getRoleTreeNode());
}
}
//
// try delete
automaticRoleAttributeService.delete(automaticRole2);
//
identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(1, identityRoles.size());
identityRole = identityRoles.get(0);
assertEquals(automaticRole.getRole(), identityRole.getRole());
assertEquals(automaticRole.getId(), identityRole.getRoleTreeNode());
//
automaticRoleAttributeService.delete(automaticRole);
identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(0, identityRoles.size());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleAttributeIntegrationTest method testUpdateWithoutAutomaticRoles.
@Test
public void testUpdateWithoutAutomaticRoles() {
IdmIdentityDto identity = testHelper.createIdentity();
IdmIdentityContractDto primeContract = testHelper.getPrimeContract(identity.getId());
IdmRoleDto basicRole = testHelper.createRole();
testHelper.assignRoles(primeContract, basicRole);
IdmTreeTypeDto type = testHelper.createTreeType();
IdmTreeNodeDto node = testHelper.createTreeNode(type, null);
primeContract.setWorkPosition(node.getId());
identity.setDescription(String.valueOf(System.currentTimeMillis()));
identityContractService.save(primeContract);
identityService.save(identity);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleAttributeIntegrationTest method testFutureValidContract.
@Test
public void testFutureValidContract() {
IdmIdentityDto identity = testHelper.createIdentity();
//
IdmRoleDto role = testHelper.createRole();
IdmAutomaticRoleAttributeDto automaticRole = testHelper.createAutomaticRole(role.getId());
testHelper.createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY, IdmIdentity_.username.getName(), null, identity.getUsername());
//
this.recalculateSync(automaticRole.getId());
//
List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(1, identityRoles.size());
//
IdmIdentityContractDto futureValidContract = testHelper.createIdentityContact(identity, null, new LocalDate().plusDays(10), new LocalDate().plusDays(50));
// we must save identity, automatic role will be recalculate after identity save
identity = identityService.save(identity);
//
identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(2, identityRoles.size());
//
identityRoles = identityRoleService.findAllByContract(futureValidContract.getId());
assertEquals(1, identityRoles.size());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleAttributeIntegrationTest method testAssingByContractAttrWithRecalcualte.
@Test
public void testAssingByContractAttrWithRecalcualte() {
String testValue = "123!@#" + System.currentTimeMillis();
IdmIdentityDto identity = testHelper.createIdentity();
//
List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(0, identityRoles.size());
//
IdmIdentityContractDto primeContract = testHelper.getPrimeContract(identity.getId());
primeContract.setPosition(testValue);
primeContract = identityContractService.save(primeContract);
//
IdmRoleDto role = testHelper.createRole();
IdmAutomaticRoleAttributeDto automaticRole = testHelper.createAutomaticRole(role.getId());
testHelper.createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.CONTRACT, IdmIdentityContract_.position.getName(), null, testValue);
//
// add new one
this.recalculateSync(automaticRole.getId());
//
identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(1, identityRoles.size());
//
IdmIdentityRoleDto identityRoleDto = identityRoles.get(0);
assertNotNull(identityRoleDto.getRoleTreeNode());
assertEquals(automaticRole.getId(), identityRoleDto.getRoleTreeNode());
assertEquals(automaticRole.getRole(), identityRoleDto.getRole());
//
// change value and recalculate
primeContract.setPosition(testValue + "test");
primeContract = identityContractService.save(primeContract);
//
// recalculate isn't needed, is done when save identity
//
identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(0, identityRoles.size());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleAttributeIntegrationTest method testSameRoleAssignedMoreThanOne.
@Test
public void testSameRoleAssignedMoreThanOne() {
String testEmail = "testing-email-" + System.currentTimeMillis() + "@example.tld";
String testDescription = "testing-description-" + System.currentTimeMillis();
//
IdmIdentityDto identity = testHelper.createIdentity();
IdmRoleDto role = testHelper.createRole();
IdmIdentityContractDto primeContract = testHelper.getPrimeContract(identity.getId());
//
testHelper.createIdentityRole(primeContract, role);
//
IdmAutomaticRoleAttributeDto automaticRole = testHelper.createAutomaticRole(role.getId());
IdmAutomaticRoleAttributeDto automaticRole2 = testHelper.createAutomaticRole(role.getId());
//
testHelper.createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY, IdmIdentity_.email.getName(), null, testEmail);
//
testHelper.createAutomaticRoleRule(automaticRole2.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY, IdmIdentity_.description.getName(), null, testDescription);
//
// only one role, assigned by direct add
List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(1, identityRoles.size());
IdmIdentityRoleDto identityRole = identityRoles.get(0);
assertNull(identityRole.getRoleTreeNode());
assertEquals(role.getId(), identityRole.getRole());
//
identity.setEmail(testEmail);
identity = identityService.save(identity);
//
// 1 classic role, 1 automatic role
identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(2, identityRoles.size());
int classicRoleCount = 0;
for (IdmIdentityRoleDto idenityRole : identityRoles) {
assertEquals(role.getId(), idenityRole.getRole());
if (idenityRole.getRoleTreeNode() == null) {
classicRoleCount++;
}
}
// must exist one classic role
assertEquals(1, classicRoleCount);
//
identity.setDescription(testDescription);
identity = identityService.save(identity);
//
// 1 classic role, 2 automatic role
identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(3, identityRoles.size());
classicRoleCount = 0;
for (IdmIdentityRoleDto idenityRole : identityRoles) {
assertEquals(role.getId(), idenityRole.getRole());
if (idenityRole.getRoleTreeNode() == null) {
classicRoleCount++;
}
}
// must exist one classic role
assertEquals(1, classicRoleCount);
//
identity.setEmail(null);
identity = identityService.save(identity);
// 1 classic role, 1 automatic role
identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(2, identityRoles.size());
//
identityRoleService.delete(identityRole);
//
// 1 automatic role
identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(1, identityRoles.size());
//
identity.setDescription(testDescription + " ");
identity = identityService.save(identity);
//
identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(0, identityRoles.size());
}
Aggregations