use of eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleAttributeIntegrationTest method testEmptyContract.
@Test
public void testEmptyContract() {
String testValue = "123!@#" + System.currentTimeMillis();
IdmRoleDto role = testHelper.createRole();
IdmAutomaticRoleAttributeDto automaticRole = testHelper.createAutomaticRole(role.getId());
testHelper.createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY, IdmIdentity_.description.getName(), null, testValue);
//
IdmIdentityDto identity = testHelper.createIdentity();
//
// remove contract
IdmIdentityContractDto primeContract = identityContractService.getPrimeContract(identity.getId());
identityContractService.delete(primeContract);
primeContract = identityContractService.getPrimeContract(identity.getId());
assertNull(primeContract);
//
identity.setDescription(testValue);
identity = identityService.save(identity);
//
List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(0, identityRoles.size());
// change value and recalculate
identity.setDescription(testValue + "-test");
identity = identityService.save(identity);
//
identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(0, identityRoles.size());
//
// chnage back
identity.setDescription(testValue);
identity = identityService.save(identity);
//
identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(0, identityRoles.size());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto 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.IdmAutomaticRoleAttributeDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleAttributeIntegrationTest method testAutomaticRoleLongEav.
@Test
public void testAutomaticRoleLongEav() {
Long testValue = 123456l;
IdmIdentityDto identity = testHelper.createIdentity();
//
IdmFormAttributeDto createEavAttribute = testHelper.createEavAttribute("testingEav" + System.currentTimeMillis(), IdmIdentity.class, PersistentType.LONG);
//
IdmRoleDto role = testHelper.createRole();
IdmAutomaticRoleAttributeDto automaticRole = testHelper.createAutomaticRole(role.getId());
testHelper.createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY_EAV, null, createEavAttribute.getId(), testValue.toString());
//
List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(0, identityRoles.size());
//
// change eav value
testHelper.setEavValue(identity, createEavAttribute, IdmIdentity.class, testValue, PersistentType.LONG);
//
identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(1, identityRoles.size());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleAttributeIntegrationTest method testAutomaticRoleDateTimeEav.
@Test
public void testAutomaticRoleDateTimeEav() {
DateTime testValue = new DateTime(System.currentTimeMillis());
IdmIdentityDto identity = testHelper.createIdentity();
//
IdmFormAttributeDto createEavAttribute = testHelper.createEavAttribute("testingEav" + System.currentTimeMillis(), IdmIdentity.class, PersistentType.DATETIME);
//
IdmRoleDto role = testHelper.createRole();
IdmAutomaticRoleAttributeDto automaticRole = testHelper.createAutomaticRole(role.getId());
testHelper.createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY_EAV, null, createEavAttribute.getId(), testValue.toString());
//
List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(0, identityRoles.size());
//
// change eav value
testHelper.setEavValue(identity, createEavAttribute, IdmIdentity.class, testValue, PersistentType.DATETIME);
//
identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(1, identityRoles.size());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleAttributeIntegrationTest method testTextTypeInEav.
@Test(expected = ResultCodeException.class)
public void testTextTypeInEav() {
String testValue = "123!@#" + System.currentTimeMillis();
IdmIdentityDto identity = testHelper.createIdentity();
//
IdmFormAttributeDto createEavAttribute = testHelper.createEavAttribute("testingEav" + System.currentTimeMillis(), IdmIdentity.class, PersistentType.TEXT);
testHelper.setEavValue(identity, createEavAttribute, IdmIdentity.class, testValue, PersistentType.TEXT);
//
//
IdmRoleDto role = testHelper.createRole();
IdmAutomaticRoleAttributeDto automaticRole = testHelper.createAutomaticRole(role.getId());
testHelper.createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY_EAV, null, createEavAttribute.getId(), testValue);
}
Aggregations