use of eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleAttributeIntegrationTest method testAssingByIdentityAttrWithoutRecalcualte.
@Test
public void testAssingByIdentityAttrWithoutRecalcualte() {
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();
identity.setDescription(testValue);
identity = identityService.save(identity);
//
List<IdmIdentityRoleDto> 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
identity.setDescription(testValue + "-test");
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 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.IdmAutomaticRoleAttributeDto 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.IdmAutomaticRoleAttributeDto 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());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleAttributeIntegrationTest method testAutomaticRoleDateEav.
@Test
public void testAutomaticRoleDateEav() {
DateTime testValue = new DateTime(1514764800);
IdmIdentityDto identity = testHelper.createIdentity();
//
IdmFormAttributeDto createEavAttribute = testHelper.createEavAttribute("testingEav" + System.currentTimeMillis(), IdmIdentity.class, PersistentType.DATE);
//
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.DATE);
//
identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(1, identityRoles.size());
}
Aggregations