Search in sources :

Example 11 with IdmAutomaticRoleAttributeDto

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());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 12 with IdmAutomaticRoleAttributeDto

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());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 13 with IdmAutomaticRoleAttributeDto

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());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 14 with IdmAutomaticRoleAttributeDto

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());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) DateTime(org.joda.time.DateTime) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 15 with IdmAutomaticRoleAttributeDto

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);
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

IdmAutomaticRoleAttributeDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto)56 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)44 Test (org.junit.Test)41 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)37 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)34 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)30 IdmAutomaticRoleAttributeRuleDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto)20 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)17 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)15 UUID (java.util.UUID)12 AbstractCoreWorkflowIntegrationTest (eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest)7 AcceptedException (eu.bcvsolutions.idm.core.api.exception.AcceptedException)7 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)7 IdmAutomaticRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto)6 AbstractIdmAutomaticRoleDto (eu.bcvsolutions.idm.core.api.dto.AbstractIdmAutomaticRoleDto)5 IdmAutomaticRoleAttributeRuleFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleAttributeRuleFilter)5 LocalDate (org.joda.time.LocalDate)5 IdmRoleTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto)4 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)4 RoleRequestException (eu.bcvsolutions.idm.core.api.exception.RoleRequestException)4