Search in sources :

Example 21 with IdmContractSliceFilter

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

the class ContractSliceManagerTest method createSliceValidInFutureTest.

@Test
public void createSliceValidInFutureTest() {
    IdmIdentityDto identity = helper.createIdentity();
    String contractCode = "contract-one";
    IdmContractSliceDto slice = helper.createContractSlice(identity, null, LocalDate.now().plusDays(10), null, LocalDate.now().plusDays(100));
    slice.setContractCode(contractCode);
    contractSliceService.save(slice);
    IdmContractSliceFilter filter = new IdmContractSliceFilter();
    filter.setIdentity(identity.getId());
    List<IdmContractSliceDto> results = contractSliceService.find(filter, null).getContent();
    assertEquals(1, results.size());
    IdmContractSliceDto createdSlice = results.get(0);
    assertFalse(createdSlice.isValid());
    assertEquals(null, createdSlice.getValidTill());
    // Check created contract by that slice
    IdmIdentityContractFilter contractFilter = new IdmIdentityContractFilter();
    contractFilter.setIdentity(identity.getId());
    List<IdmIdentityContractDto> resultsContract = // 
    contractService.find(filter, null).getContent().stream().filter(// 
    c -> contractService.get(c.getId()).getControlledBySlices()).collect(Collectors.toList());
    assertEquals(1, resultsContract.size());
    IdmIdentityContractDto contract = resultsContract.get(0);
    assertTrue(contract.isValidNowOrInFuture());
}
Also used : IdmContractSliceGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceGuaranteeFilter) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmIdentityContract(eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract) ContractSliceEventType(eu.bcvsolutions.idm.core.model.event.ContractSliceEvent.ContractSliceEventType) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) Autowired(org.springframework.beans.factory.annotation.Autowired) ClearDirtyStateForContractSliceTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.ClearDirtyStateForContractSliceTaskExecutor) ConfigurationService(eu.bcvsolutions.idm.core.api.service.ConfigurationService) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) ContractSliceEvent(eu.bcvsolutions.idm.core.model.event.ContractSliceEvent) AutowireHelper(eu.bcvsolutions.idm.core.api.utils.AutowireHelper) BigDecimal(java.math.BigDecimal) Map(java.util.Map) After(org.junit.After) ContractSliceConfiguration(eu.bcvsolutions.idm.core.api.config.domain.ContractSliceConfiguration) IdmIdentityContractService(eu.bcvsolutions.idm.core.api.service.IdmIdentityContractService) ImmutableMap(com.google.common.collect.ImmutableMap) IdmEntityStateFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityStateFilter) UUID(java.util.UUID) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) SelectCurrentContractSliceTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.SelectCurrentContractSliceTaskExecutor) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) LocalDate(java.time.LocalDate) IdmContractSliceFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) IdmIdentityContractFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityContractFilter) IdmContractSliceService(eu.bcvsolutions.idm.core.api.service.IdmContractSliceService) HashMap(java.util.HashMap) IdmContractSliceGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceGuaranteeDto) PersistentType(eu.bcvsolutions.idm.core.eav.api.domain.PersistentType) IdmContractSliceDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto) EntityStateManager(eu.bcvsolutions.idm.core.api.service.EntityStateManager) Lists(com.google.common.collect.Lists) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) TestHelper(eu.bcvsolutions.idm.test.api.TestHelper) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) IdmContractSliceGuaranteeService(eu.bcvsolutions.idm.core.api.service.IdmContractSliceGuaranteeService) IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) IdmLongRunningTaskService(eu.bcvsolutions.idm.core.scheduler.api.service.IdmLongRunningTaskService) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) Before(org.junit.Before) IdmContractSlice(eu.bcvsolutions.idm.core.model.entity.IdmContractSlice) LongRunningTaskManager(eu.bcvsolutions.idm.core.scheduler.api.service.LongRunningTaskManager) Assert.assertNotNull(org.junit.Assert.assertNotNull) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Assert.assertTrue(org.junit.Assert.assertTrue) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) Test(org.junit.Test) EventContext(eu.bcvsolutions.idm.core.api.event.EventContext) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) Assert.assertNull(org.junit.Assert.assertNull) IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) ContractSliceManager(eu.bcvsolutions.idm.core.api.service.ContractSliceManager) IdmIdentityContractFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityContractFilter) IdmContractSliceFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmContractSliceDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 22 with IdmContractSliceFilter

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

the class ContractSliceSyncTest method unlinkAccountTest.

@Test
public void unlinkAccountTest() {
    SysSystemDto system = initData();
    Assert.assertNotNull(system);
    AbstractSysSyncConfigDto config = doCreateSyncConfig(system);
    Assert.assertTrue(config instanceof SysSyncContractConfigDto);
    helper.createIdentity(CONTRACT_OWNER_ONE);
    helper.createIdentity(CONTRACT_OWNER_TWO);
    helper.createIdentity(CONTRACT_LEADER_ONE);
    IdmContractSliceFilter contractFilter = new IdmContractSliceFilter();
    contractFilter.setProperty(IdmIdentityContract_.position.getName());
    contractFilter.setValue("1");
    Assert.assertEquals(0, contractSliceService.find(contractFilter, null).getTotalElements());
    contractFilter.setValue("2");
    Assert.assertEquals(0, contractSliceService.find(contractFilter, null).getTotalElements());
    helper.startSynchronization(config);
    SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 4);
    Assert.assertFalse(log.isRunning());
    Assert.assertFalse(log.isContainsError());
    contractFilter.setValue("1");
    List<IdmContractSliceDto> contractSlices = contractSliceService.find(contractFilter, null).getContent();
    Assert.assertEquals(1, contractSlices.size());
    // Find the account for this contract slice
    IdmContractSliceDto slice = contractSlices.get(0);
    AccContractSliceAccountFilter contractAccountFilter = new AccContractSliceAccountFilter();
    contractAccountFilter.setSliceId(slice.getId());
    contractAccountFilter.setSystemId(system.getId());
    List<AccContractSliceAccountDto> contractAccounts = contractSliceAccountService.find(contractAccountFilter, null).getContent();
    Assert.assertEquals(1, contractAccounts.size());
    AccContractSliceAccountDto contractAccount = contractAccounts.get(0);
    AccAccountDto account = accountService.get(contractAccount.getAccount());
    Assert.assertNotNull(account);
    // Delete log
    syncLogService.delete(log);
    // Change settings of sync and run
    config.setLinkedAction(SynchronizationLinkedActionType.UNLINK);
    config.setUnlinkedAction(SynchronizationUnlinkedActionType.IGNORE);
    config.setMissingEntityAction(SynchronizationMissingEntityActionType.IGNORE);
    config.setMissingAccountAction(ReconciliationMissingAccountActionType.IGNORE);
    config = syncConfigService.save(config);
    helper.startSynchronization(config);
    log = checkSyncLog(config, SynchronizationActionType.UNLINK, 4);
    Assert.assertFalse(log.isRunning());
    Assert.assertFalse(log.isContainsError());
    // Find the account for this contract slice ... unlink operation was executed,
    // none relation can be found
    contractAccountFilter = new AccContractSliceAccountFilter();
    contractAccountFilter.setSliceId(slice.getId());
    contractAccountFilter.setSystemId(system.getId());
    contractAccounts = contractSliceAccountService.find(contractAccountFilter, null).getContent();
    Assert.assertEquals(0, contractAccounts.size());
    account = accountService.get(account.getId());
    Assert.assertNull(account);
    // Delete log
    syncLogService.delete(log);
}
Also used : AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) SysSyncContractConfigDto(eu.bcvsolutions.idm.acc.dto.SysSyncContractConfigDto) IdmContractSliceFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter) AccContractSliceAccountDto(eu.bcvsolutions.idm.acc.dto.AccContractSliceAccountDto) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto) IdmContractSliceDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto) AccContractSliceAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccContractSliceAccountFilter) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 23 with IdmContractSliceFilter

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

the class ContractSliceSyncTest method updateAccountTest.

@Test
public void updateAccountTest() {
    SysSystemDto system = initData();
    Assert.assertNotNull(system);
    AbstractSysSyncConfigDto config = doCreateSyncConfig(system);
    Assert.assertTrue(config instanceof SysSyncContractConfigDto);
    config = syncConfigService.save(config);
    helper.createIdentity(CONTRACT_OWNER_ONE);
    helper.createIdentity(CONTRACT_OWNER_TWO);
    helper.createIdentity(CONTRACT_LEADER_ONE);
    IdmContractSliceFilter contractFilter = new IdmContractSliceFilter();
    contractFilter.setProperty(IdmIdentityContract_.position.getName());
    contractFilter.setValue("1");
    Assert.assertEquals(0, contractSliceService.find(contractFilter, null).getTotalElements());
    contractFilter.setValue("2");
    Assert.assertEquals(0, contractSliceService.find(contractFilter, null).getTotalElements());
    helper.startSynchronization(config);
    SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 4);
    Assert.assertFalse(log.isRunning());
    Assert.assertFalse(log.isContainsError());
    contractFilter.setValue("1");
    List<IdmContractSliceDto> contractSlices = contractSliceService.find(contractFilter, null).getContent();
    Assert.assertEquals(1, contractSlices.size());
    // Find the account for this contract slice
    IdmContractSliceDto slice = contractSlices.get(0);
    AccContractSliceAccountFilter contractAccountFilter = new AccContractSliceAccountFilter();
    contractAccountFilter.setSliceId(slice.getId());
    contractAccountFilter.setSystemId(system.getId());
    List<AccContractSliceAccountDto> contractAccounts = contractSliceAccountService.find(contractAccountFilter, null).getContent();
    Assert.assertEquals(1, contractAccounts.size());
    AccContractSliceAccountDto contractAccount = contractAccounts.get(0);
    AccAccountDto account = accountService.get(contractAccount.getAccount());
    Assert.assertNotNull(account);
    // Delete log
    syncLogService.delete(log);
    TestContractSliceResource accountOnTargetSystem = this.getBean().findSliceOnTargetSystem("1");
    Assert.assertNull(accountOnTargetSystem.getState());
    // Set slice to disabled
    slice.setState(ContractState.DISABLED);
    // Change settings of sync and run
    config.setLinkedAction(SynchronizationLinkedActionType.UPDATE_ACCOUNT);
    config.setUnlinkedAction(SynchronizationUnlinkedActionType.IGNORE);
    config.setMissingEntityAction(SynchronizationMissingEntityActionType.IGNORE);
    config.setMissingAccountAction(ReconciliationMissingAccountActionType.IGNORE);
    config = syncConfigService.save(config);
    helper.startSynchronization(config);
    log = checkSyncLog(config, SynchronizationActionType.UPDATE_ACCOUNT, 4);
    Assert.assertFalse(log.isRunning());
    Assert.assertFalse(log.isContainsError());
    // Sync of slice does not supports provisioning now (account was not changed)!
    accountOnTargetSystem = this.getBean().findSliceOnTargetSystem("1");
    Assert.assertEquals(null, accountOnTargetSystem.getState());
    // Delete log
    syncLogService.delete(log);
}
Also used : AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) SysSyncContractConfigDto(eu.bcvsolutions.idm.acc.dto.SysSyncContractConfigDto) TestContractSliceResource(eu.bcvsolutions.idm.acc.entity.TestContractSliceResource) IdmContractSliceFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter) AccContractSliceAccountDto(eu.bcvsolutions.idm.acc.dto.AccContractSliceAccountDto) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto) IdmContractSliceDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto) AccContractSliceAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccContractSliceAccountFilter) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 24 with IdmContractSliceFilter

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

the class ContractSliceSyncTest method setDirtyStateAndCheckIt.

@Test
public void setDirtyStateAndCheckIt() {
    // create tree type and node, tree node is used as position in contrac slice synchronization
    IdmTreeTypeDto treeType = this.getHelper().createTreeType();
    IdmTreeNodeDto treeNode = this.getHelper().createTreeNode(treeType, null);
    // create two roles, one role is used as automatic role by organization structure
    // second role is used as manually added
    IdmRoleDto roleOne = this.getHelper().createRole();
    IdmRoleDto roleTwo = this.getHelper().createRole();
    this.getHelper().createAutomaticRole(roleOne, treeNode);
    // init system
    SysSystemDto system = initData();
    // set default tree type for synchronization
    SysSyncContractConfigDto config = (SysSyncContractConfigDto) doCreateSyncConfig(system);
    config.setDefaultTreeType(treeType.getId());
    syncConfigService.save(config);
    IdmIdentityDto identity = helper.createIdentity();
    // for sure remove all contracts
    contractService.findAllByIdentity(identity.getId()).forEach(contract -> {
        contractService.delete(contract);
    });
    // check current delete audits record for identity (and their related entities)
    IdmAuditFilter filter = new IdmAuditFilter();
    filter.setOwnerId(identity.getId().toString());
    filter.setModification("DELETE");
    List<IdmAuditDto> audits = auditService.find(filter, null).getContent();
    assertEquals(0, audits.size());
    // check current slices
    IdmContractSliceFilter contractSliceFilter = new IdmContractSliceFilter();
    contractSliceFilter.setIdentity(identity.getId());
    List<IdmContractSliceDto> slices = contractSliceService.find(contractSliceFilter, null).getContent();
    assertEquals(0, slices.size());
    // check current contracts
    List<IdmIdentityContractDto> allByIdentity = contractService.findAllByIdentity(identity.getId());
    assertEquals(0, allByIdentity.size());
    // delete all data in resource
    this.getBean().deleteAllResourceData();
    // create step one data, please see inside method
    this.getBean().createTestDataStepOne(identity.getUsername(), treeNode.getCode());
    // start synchronization
    helper.startSynchronization(config);
    SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 1);
    Assert.assertFalse(log.isRunning());
    Assert.assertFalse(log.isContainsError());
    // after first synchronization exists one contract
    allByIdentity = contractService.findAllByIdentity(identity.getId());
    assertEquals(1, allByIdentity.size());
    // after first synchronization exists one slice
    slices = contractSliceService.find(contractSliceFilter, null).getContent();
    assertEquals(1, slices.size());
    // after first synchronization exists one identity role - automatic role
    List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(1, identityRoles.size());
    IdmIdentityRoleDto identityRoleDto = identityRoles.get(0);
    // manually create identity account for check if identity account will be changed or deleted after second synchronization
    // this state create two audit records for the identity account
    AccIdentityAccountDto identityAccount = helper.createIdentityAccount(system, identity);
    identityAccount.setIdentityRole(identityRoleDto.getId());
    identityAccount = identityAccountService.save(identityAccount);
    // add manually role
    IdmIdentityContractDto identityContractDto = allByIdentity.get(0);
    this.getHelper().createIdentityRole(identityContractDto, roleTwo);
    // check current identity roles - one is automatic, second is manually added
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(2, identityRoles.size());
    // prepare data for second step
    this.getBean().createTestDataStepTwo(identity.getUsername(), treeNode.getCode());
    helper.startSynchronization(config);
    Assert.assertFalse(log.isRunning());
    Assert.assertFalse(log.isContainsError());
    // after second synchronization still exists one contract
    allByIdentity = contractService.findAllByIdentity(identity.getId());
    assertEquals(1, allByIdentity.size());
    // after second synchronization exists two slices
    slices = contractSliceService.find(contractSliceFilter, null).getContent();
    assertEquals(2, slices.size());
    // after second synchronization must also exists both roles
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(2, identityRoles.size());
    // check delete operation for identity and their related entities
    filter = new IdmAuditFilter();
    filter.setOwnerId(identity.getId().toString());
    filter.setModification("DELETE");
    audits = auditService.find(filter, null).getContent();
    assertEquals(0, audits.size());
    // check audit for identity roles
    for (IdmIdentityRoleDto identityRole : identityRoles) {
        filter = new IdmAuditFilter();
        filter.setEntityId(identityRole.getId());
        List<IdmAuditDto> auditsForIdentityRole = auditService.find(filter, null).getContent();
        if (identityRole.getAutomaticRole() == null) {
            // manually added role, just create
            assertEquals(1, auditsForIdentityRole.size());
        } else {
            // automatic role change validity
            assertEquals(2, auditsForIdentityRole.size());
        }
    }
    // Check audit records for identity account, exists three record, because helper
    // create one and second create save with change identity role and third is
    // delete of this identity-account (role does not mapping the system)
    filter = new IdmAuditFilter();
    filter.setEntityId(identityAccount.getId());
    List<IdmAuditDto> auditsForIdentityAccount = auditService.find(filter, null).getContent();
    assertEquals(3, auditsForIdentityAccount.size());
    // some tests expect data as contract slice with id 1. Just for sure we clear test slices
    slices = contractSliceService.find(contractSliceFilter, null).getContent();
    slices.forEach(slice -> {
        contractSliceService.delete(slice);
    });
    identityService.delete(identity);
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmAuditDto(eu.bcvsolutions.idm.core.api.audit.dto.IdmAuditDto) IdmAuditFilter(eu.bcvsolutions.idm.core.api.audit.dto.filter.IdmAuditFilter) IdmContractSliceFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) AccIdentityAccountDto(eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) IdmContractSliceDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto) IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) SysSyncContractConfigDto(eu.bcvsolutions.idm.acc.dto.SysSyncContractConfigDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 25 with IdmContractSliceFilter

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

the class ContractSliceSyncTest method addTwoNewAndDeleteFirstContractSlice.

@Test
public void addTwoNewAndDeleteFirstContractSlice() {
    // init system
    SysSystemDto system = initData();
    this.getBean().deleteAllResourceData();
    IdmIdentityDto identity = helper.createIdentity();
    List<IdmIdentityContractDto> contracts = contractService.findAllByIdentity(identity.getId());
    assertEquals(1, contracts.size());
    contractService.delete(contracts.get(0));
    // first valid slice
    this.getBean().createSlice("1", identity.getUsername(), null, null, null, null, null, LocalDate.now().minusDays(20), null, LocalDate.now().minusDays(20), "ONE");
    SysSyncContractConfigDto config = (SysSyncContractConfigDto) doCreateSyncConfig(system);
    config.setStartOfHrProcesses(true);
    config.setMissingAccountAction(ReconciliationMissingAccountActionType.DELETE_ENTITY);
    config = (SysSyncContractConfigDto) syncConfigService.save(config);
    // start sync
    helper.startSynchronization(config);
    IdmContractSliceFilter filter = new IdmContractSliceFilter();
    filter.setIdentity(identity.getId());
    List<IdmContractSliceDto> slices = contractSliceService.find(filter, null).getContent();
    assertEquals(1, slices.size());
    IdmContractSliceDto sliceDto = slices.get(0);
    assertEquals(LocalDate.now().minusDays(20), sliceDto.getValidFrom());
    assertEquals(null, sliceDto.getValidTill());
    // create invalid slice
    this.getBean().createSlice("2", identity.getUsername(), null, null, null, null, null, LocalDate.now().minusDays(20), LocalDate.now().minusDays(10), LocalDate.now().minusDays(10), "ONE");
    // create valid slice
    this.getBean().createSlice("3", identity.getUsername(), null, null, null, null, null, LocalDate.now().minusDays(10), null, LocalDate.now().minusDays(9), "ONE");
    // delete first
    this.getBean().deleteSlice("1");
    // start sync
    helper.startSynchronization(config);
    slices = contractSliceService.find(filter, null).getContent();
    assertEquals(2, slices.size());
    for (IdmContractSliceDto slice : slices) {
        if ("2".equals(slice.getDescription())) {
            assertEquals(LocalDate.now().minusDays(10), slice.getValidFrom());
            assertEquals(LocalDate.now().minusDays(9).minusDays(1), slice.getValidTill());
            assertNotNull(slice.getParentContract());
        } else if ("3".equals(slice.getDescription())) {
            assertEquals(LocalDate.now().minusDays(9), slice.getValidFrom());
            assertEquals(null, slice.getValidTill());
            assertTrue(slice.isUsingAsContract());
            assertNotNull(slice.getParentContract());
        } else {
            fail("Slice with bad id!");
        }
    }
    contracts = contractService.findAllByIdentity(identity.getId());
    assertEquals(1, contracts.size());
    IdmIdentityContractDto contract = contracts.get(0);
    assertEquals(LocalDate.now().minusDays(10), contract.getValidFrom());
    assertEquals(null, contract.getValidTill());
    // some tests expect data as contract slice with id 1. Just for sure we clear test slices
    slices = contractSliceService.find(filter, null).getContent();
    slices.forEach(slice -> {
        contractSliceService.delete(slice);
    });
    identityService.delete(identity);
}
Also used : SysSyncContractConfigDto(eu.bcvsolutions.idm.acc.dto.SysSyncContractConfigDto) IdmContractSliceFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) IdmContractSliceDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

IdmContractSliceFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter)45 IdmContractSliceDto (eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto)32 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)29 Test (org.junit.Test)29 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)24 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)23 UUID (java.util.UUID)20 IdmTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto)18 SysSyncContractConfigDto (eu.bcvsolutions.idm.acc.dto.SysSyncContractConfigDto)16 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)16 IdmIdentityContractFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityContractFilter)16 HashMap (java.util.HashMap)14 SysSyncLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)13 DefaultResultModel (eu.bcvsolutions.idm.core.api.dto.DefaultResultModel)13 IdmEntityStateDto (eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto)13 OperationResultDto (eu.bcvsolutions.idm.core.api.dto.OperationResultDto)13 IdmContractSliceGuaranteeFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceGuaranteeFilter)13 IdmFormDefinitionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)13 ContractSliceEvent (eu.bcvsolutions.idm.core.model.event.ContractSliceEvent)13 LocalDate (java.time.LocalDate)13