Search in sources :

Example 11 with IdmContractGuaranteeDto

use of eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto in project CzechIdMng by bcvsolutions.

the class IdentityChangeContractGuaranteeBulkActionTest method changeWhereContractContainsOldGuarantee.

// Test that there are changed only contracts which contained at least one old guarantee.
@Test
public void changeWhereContractContainsOldGuarantee() {
    List<IdmIdentityDto> oldGuarantees = this.createIdentities(2);
    List<IdmIdentityDto> newGuarantees = this.createIdentities(1);
    IdmIdentityDto employee = getHelper().createIdentity();
    IdmIdentityContractDto contract1 = getHelper().getPrimeContract(employee);
    IdmIdentityContractDto contract2 = getHelper().createContract(employee);
    createContractGuarantees(contract1, oldGuarantees.subList(0, 1));
    createContractGuarantees(contract2, oldGuarantees.subList(1, oldGuarantees.size()));
    Assert.assertTrue(isContractGuarantee(contract1, oldGuarantees.subList(0, 1)).isEmpty());
    Assert.assertTrue(isContractGuarantee(contract2, oldGuarantees.subList(1, oldGuarantees.size())).isEmpty());
    IdmBulkActionDto bulkAction = this.findBulkAction(IdmIdentity.class, IdentityChangeContractGuaranteeBulkAction.NAME);
    Set<UUID> ids = this.getIdFromList(Arrays.asList(employee));
    bulkAction.setIdentifiers(ids);
    Map<String, Object> properties = new HashMap<>();
    properties.put(IdentityAddContractGuaranteeBulkAction.PROPERTY_OLD_GUARANTEE, oldGuarantees.get(0).getId().toString());
    properties.put(IdentityAddContractGuaranteeBulkAction.PROPERTY_NEW_GUARANTEE, newGuarantees.get(0).getId().toString());
    bulkAction.setProperties(properties);
    bulkActionManager.processAction(bulkAction);
    // test that there remains on both contracts only one guarantee
    // CONTRACT1
    List<IdmContractGuaranteeDto> assigned = getGuaranteesForContract(contract1.getId());
    Assert.assertEquals(1, assigned.size());
    List<IdmIdentityDto> expectedDto = new ArrayList<IdmIdentityDto>(newGuarantees);
    Assert.assertTrue(isContractGuarantee(contract1, expectedDto).isEmpty());
    // CONTRACT2
    assigned = getGuaranteesForContract(contract2.getId());
    Assert.assertEquals(1, assigned.size());
    // old guarantee stayed added
    expectedDto = new ArrayList<IdmIdentityDto>(oldGuarantees.subList(1, 2));
    Assert.assertTrue(isContractGuarantee(contract2, expectedDto).isEmpty());
    // newly set guarantee is not applied
    expectedDto = new ArrayList<IdmIdentityDto>(newGuarantees);
    Assert.assertEquals(1, isContractGuarantee(contract2, expectedDto).size());
}
Also used : IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IdmContractGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) AbstractBulkActionTest(eu.bcvsolutions.idm.test.api.AbstractBulkActionTest) Test(org.junit.Test)

Example 12 with IdmContractGuaranteeDto

use of eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto in project CzechIdMng by bcvsolutions.

the class IdentityChangeContractGuaranteeBulkActionTest method processByIdsChangeSelected.

@Test
public void processByIdsChangeSelected() {
    List<IdmIdentityDto> oldGuarantees = this.createIdentities(2);
    List<IdmIdentityDto> newGuarantees = this.createIdentities(1);
    IdmIdentityDto employee = getHelper().createIdentity();
    IdmIdentityContractDto contract1 = getHelper().getPrimeContract(employee);
    IdmIdentityContractDto contract2 = getHelper().createContract(employee);
    createContractGuarantees(contract1, oldGuarantees);
    createContractGuarantees(contract2, oldGuarantees);
    Assert.assertTrue(isContractGuarantee(contract1, oldGuarantees).isEmpty());
    Assert.assertTrue(isContractGuarantee(contract2, oldGuarantees).isEmpty());
    IdmBulkActionDto bulkAction = this.findBulkAction(IdmIdentity.class, IdentityChangeContractGuaranteeBulkAction.NAME);
    Set<UUID> ids = this.getIdFromList(Arrays.asList(employee));
    bulkAction.setIdentifiers(ids);
    Map<String, Object> properties = new HashMap<>();
    properties.put(IdentityAddContractGuaranteeBulkAction.PROPERTY_OLD_GUARANTEE, oldGuarantees.get(0).getId().toString());
    properties.put(IdentityAddContractGuaranteeBulkAction.PROPERTY_NEW_GUARANTEE, newGuarantees.get(0).getId().toString());
    bulkAction.setProperties(properties);
    bulkActionManager.processAction(bulkAction);
    // test that there remains on both contracts only one guarantee
    // CONTRACT1
    List<IdmContractGuaranteeDto> assigned = getGuaranteesForContract(contract1.getId());
    Assert.assertEquals(2, assigned.size());
    List<IdmIdentityDto> expectedDto = new ArrayList<IdmIdentityDto>(oldGuarantees.subList(1, 2));
    expectedDto.addAll(newGuarantees);
    Assert.assertTrue(isContractGuarantee(contract1, expectedDto).isEmpty());
    // CONTRACT2
    assigned = getGuaranteesForContract(contract2.getId());
    Assert.assertEquals(2, assigned.size());
    expectedDto = new ArrayList<IdmIdentityDto>(oldGuarantees.subList(1, 2));
    expectedDto.addAll(newGuarantees);
    Assert.assertTrue(isContractGuarantee(contract2, expectedDto).isEmpty());
}
Also used : IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IdmContractGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) AbstractBulkActionTest(eu.bcvsolutions.idm.test.api.AbstractBulkActionTest) Test(org.junit.Test)

Example 13 with IdmContractGuaranteeDto

use of eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto in project CzechIdMng by bcvsolutions.

the class IdentityAddContractGuaranteeBulkActionTest method processByIdsNoGuaranteesMoreContracts.

@Test
public void processByIdsNoGuaranteesMoreContracts() {
    List<IdmIdentityDto> guarantees = this.createIdentities(3);
    IdmIdentityDto employee = getHelper().createIdentity();
    IdmIdentityContractDto contract1 = getHelper().getPrimeContract(employee);
    IdmIdentityContractDto contract2 = getHelper().createContract(employee);
    List<IdmIdentityContractDto> contracts = Arrays.asList(contract1, contract2);
    IdmBulkActionDto bulkAction = this.findBulkAction(IdmIdentity.class, IdentityAddContractGuaranteeBulkAction.NAME);
    Set<UUID> ids = this.getIdFromList(Arrays.asList(employee));
    bulkAction.setIdentifiers(ids);
    Map<String, Object> properties = new HashMap<>();
    List<String> uuidStrings = guarantees.stream().map(AbstractDto::getId).map(Object::toString).collect(Collectors.toList());
    properties.put(IdentityAddContractGuaranteeBulkAction.PROPERTY_NEW_GUARANTEE, uuidStrings);
    bulkAction.setProperties(properties);
    bulkActionManager.processAction(bulkAction);
    // test guarantes on all contracts
    for (IdmIdentityContractDto contract : contracts) {
        // expected number of guarantees
        List<IdmContractGuaranteeDto> assigned = getGuaranteesForContract(contract.getId());
        Assert.assertEquals(guarantees.size(), assigned.size());
        // none of expected guarantees are missing in created cintractGuarantee bindings
        Assert.assertTrue(isContractGuarantee(contract, guarantees).isEmpty());
    }
}
Also used : IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) HashMap(java.util.HashMap) IdmContractGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) AbstractBulkActionTest(eu.bcvsolutions.idm.test.api.AbstractBulkActionTest) Test(org.junit.Test)

Example 14 with IdmContractGuaranteeDto

use of eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto in project CzechIdMng by bcvsolutions.

the class IdentityAddContractGuaranteeBulkActionTest method processByIdsGuaranteeNotSetTwice.

@Test
public void processByIdsGuaranteeNotSetTwice() {
    List<IdmIdentityDto> guarantees = this.createIdentities(1);
    IdmIdentityDto employee = getHelper().createIdentity();
    IdmIdentityContractDto contract1 = getHelper().getPrimeContract(employee);
    // set guarantee before reassigned by BA
    createContractGuarantees(contract1, guarantees);
    Assert.assertTrue(isContractGuarantee(contract1, guarantees).isEmpty());
    IdmBulkActionDto bulkAction = this.findBulkAction(IdmIdentity.class, IdentityAddContractGuaranteeBulkAction.NAME);
    Set<UUID> ids = this.getIdFromList(Arrays.asList(employee));
    bulkAction.setIdentifiers(ids);
    Map<String, Object> properties = new HashMap<>();
    List<String> uuidStrings = guarantees.stream().map(AbstractDto::getId).map(Object::toString).collect(Collectors.toList());
    properties.put(IdentityAddContractGuaranteeBulkAction.PROPERTY_NEW_GUARANTEE, uuidStrings);
    bulkAction.setProperties(properties);
    bulkActionManager.processAction(bulkAction);
    // test guarantees on all contracts
    List<IdmContractGuaranteeDto> assigned = getGuaranteesForContract(contract1.getId());
    // same guarantee is assigned only once
    Assert.assertEquals(guarantees.size(), assigned.size());
    Set<UUID> assignedGuarUUID = assigned.stream().map(IdmContractGuaranteeDto::getGuarantee).collect(Collectors.toSet());
    guarantees.forEach(guarantee -> {
        Assert.assertTrue(assignedGuarUUID.contains(guarantee.getId()));
    });
}
Also used : IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) HashMap(java.util.HashMap) IdmContractGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) AbstractBulkActionTest(eu.bcvsolutions.idm.test.api.AbstractBulkActionTest) Test(org.junit.Test)

Example 15 with IdmContractGuaranteeDto

use of eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto in project CzechIdMng by bcvsolutions.

the class DefaultAuditServiceIntegrationTest method testContractGuaranteeOwner.

@Test
public void testContractGuaranteeOwner() {
    IdmIdentityDto subordinate = getHelper().createIdentity((GuardedString) null);
    IdmIdentityDto manager = getHelper().createIdentity((GuardedString) null);
    IdmContractGuaranteeDto contractGuarantee = getHelper().createContractGuarantee(getHelper().getPrimeContract(subordinate), manager);
    // 
    IdmAuditFilter filter = new IdmAuditFilter();
    filter.setOwnerId(subordinate.getId().toString());
    filter.setType(IdmContractGuarantee.class.getCanonicalName());
    // 
    List<IdmAuditDto> revisions = auditService.find(filter, null).getContent();
    Assert.assertEquals(1, revisions.size());
    Assert.assertEquals(RevisionType.ADD.name(), revisions.get(0).getModification());
    Assert.assertEquals(contractGuarantee.getId(), revisions.get(0).getEntityId());
    Assert.assertEquals(subordinate.getId().toString(), revisions.get(0).getOwnerId());
    Assert.assertEquals(manager.getId().toString(), revisions.get(0).getSubOwnerId());
    // 
    // non transactional test => cleanup
    identityService.delete(subordinate);
    identityService.delete(manager);
}
Also used : IdmContractGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto) IdmContractGuarantee(eu.bcvsolutions.idm.core.model.entity.IdmContractGuarantee) IdmAuditDto(eu.bcvsolutions.idm.core.api.audit.dto.IdmAuditDto) IdmAuditFilter(eu.bcvsolutions.idm.core.api.audit.dto.filter.IdmAuditFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

IdmContractGuaranteeDto (eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto)54 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)42 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)41 Test (org.junit.Test)31 UUID (java.util.UUID)27 IdmContractGuaranteeFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmContractGuaranteeFilter)20 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)17 HashMap (java.util.HashMap)16 IdmBulkActionDto (eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto)15 AbstractBulkActionTest (eu.bcvsolutions.idm.test.api.AbstractBulkActionTest)13 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)12 List (java.util.List)12 Transactional (org.springframework.transaction.annotation.Transactional)10 IdmContractGuaranteeService (eu.bcvsolutions.idm.core.api.service.IdmContractGuaranteeService)9 Map (java.util.Map)9 Autowired (org.springframework.beans.factory.annotation.Autowired)9 Collectors (java.util.stream.Collectors)8 IdmTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto)7 IdmTreeTypeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto)6 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)6