Search in sources :

Example 31 with Assert.assertNotNull

use of org.junit.Assert.assertNotNull in project CzechIdMng by bcvsolutions.

the class DefaultIdmRoleFormAttributeServiceIntegrationTest method testSubDefinitionOverrideValidationUnique.

@Test
public void testSubDefinitionOverrideValidationUnique() {
    // Create role with attribute (include the sub-definition)
    IdmRoleDto role = createRoleWithAttributes();
    IdmRoleFormAttributeFilter filter = new IdmRoleFormAttributeFilter();
    filter.setRole(role.getId());
    List<IdmRoleFormAttributeDto> list = roleFormAttributeService.find(filter, null).getContent();
    Assert.assertEquals(2, list.size());
    IdmFormDefinitionDto formAttributeSubdefinition = roleService.getFormAttributeSubdefinition(role);
    Assert.assertEquals(2, formAttributeSubdefinition.getFormAttributes().size());
    // Set unique validation on false to IP attribute in the sub-definition
    list.stream().filter(roleFormAttributeDto -> {
        IdmFormAttributeDto formAttributeDto = DtoUtils.getEmbedded(roleFormAttributeDto, IdmRoleFormAttribute_.formAttribute.getName(), IdmFormAttributeDto.class);
        return formAttributeDto.getCode().equals(IP);
    }).forEach(roleFormAttributeDto -> {
        Assert.assertFalse(roleFormAttributeDto.isUnique());
        roleFormAttributeDto.setUnique(true);
        roleFormAttributeService.save(roleFormAttributeDto);
    });
    // Load sub-definition by role
    formAttributeSubdefinition = roleService.getFormAttributeSubdefinition(role);
    Assert.assertEquals(2, formAttributeSubdefinition.getFormAttributes().size());
    IdmFormAttributeDto ipFormAttribute = formAttributeSubdefinition.getFormAttributes().stream().filter(attributeDto -> {
        return attributeDto.getCode().equals(IP);
    }).findFirst().orElse(null);
    Assert.assertNotNull(ipFormAttribute);
    Assert.assertTrue(ipFormAttribute.isUnique());
}
Also used : IdmRoleFormAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleFormAttributeDto) IdmRoleFormAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleFormAttributeDto) IdmConceptRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmConceptRoleRequestService) DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) Autowired(org.springframework.beans.factory.annotation.Autowired) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) PersistentType(eu.bcvsolutions.idm.core.eav.api.domain.PersistentType) BigDecimal(java.math.BigDecimal) Lists(com.google.common.collect.Lists) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) IdmIdentityRole(eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole) ImmutableList(com.google.common.collect.ImmutableList) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmRoleFormAttributeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFormAttributeFilter) IdmIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) Assert.assertNotNull(org.junit.Assert.assertNotNull) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) IdmRoleService(eu.bcvsolutions.idm.core.api.service.IdmRoleService) Test(org.junit.Test) RoleRequestState(eu.bcvsolutions.idm.core.api.domain.RoleRequestState) IdmRoleFormAttributeService(eu.bcvsolutions.idm.core.api.service.IdmRoleFormAttributeService) Serializable(java.io.Serializable) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) LocalDate(java.time.LocalDate) Assert(org.junit.Assert) ConceptRoleRequestOperation(eu.bcvsolutions.idm.core.api.domain.ConceptRoleRequestOperation) Assert.assertEquals(org.junit.Assert.assertEquals) IdmRoleFormAttribute_(eu.bcvsolutions.idm.core.model.entity.IdmRoleFormAttribute_) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) IdmRoleFormAttributeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFormAttributeFilter) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 32 with Assert.assertNotNull

use of org.junit.Assert.assertNotNull in project CzechIdMng by bcvsolutions.

the class DefaultIdmRoleFormAttributeServiceIntegrationTest method testSubDefinitionOverrideDefaultValue.

@Test
public void testSubDefinitionOverrideDefaultValue() {
    // Create role with attribute (include the sub-definition)
    IdmRoleDto role = createRoleWithAttributes();
    IdmRoleFormAttributeFilter filter = new IdmRoleFormAttributeFilter();
    filter.setRole(role.getId());
    List<IdmRoleFormAttributeDto> list = roleFormAttributeService.find(filter, null).getContent();
    Assert.assertEquals(2, list.size());
    IdmFormDefinitionDto formAttributeSubdefinition = roleService.getFormAttributeSubdefinition(role);
    Assert.assertEquals(2, formAttributeSubdefinition.getFormAttributes().size());
    // Set unique defaultValue to IP attribute in the sub-definition
    String uniqueDefaultValue = this.getHelper().createName();
    list.stream().filter(roleFormAttributeDto -> {
        IdmFormAttributeDto formAttributeDto = DtoUtils.getEmbedded(roleFormAttributeDto, IdmRoleFormAttribute_.formAttribute.getName(), IdmFormAttributeDto.class);
        return formAttributeDto.getCode().equals(IP);
    }).forEach(roleFormAttributeDto -> {
        roleFormAttributeDto.setDefaultValue(uniqueDefaultValue);
        roleFormAttributeService.save(roleFormAttributeDto);
    });
    // Load sub-definition by role
    formAttributeSubdefinition = roleService.getFormAttributeSubdefinition(role);
    Assert.assertEquals(2, formAttributeSubdefinition.getFormAttributes().size());
    IdmFormAttributeDto ipFormAttribute = formAttributeSubdefinition.getFormAttributes().stream().filter(attributeDto -> {
        return attributeDto.getCode().equals(IP);
    }).findFirst().orElse(null);
    Assert.assertNotNull(ipFormAttribute);
    Assert.assertEquals(uniqueDefaultValue, ipFormAttribute.getDefaultValue());
}
Also used : IdmRoleFormAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleFormAttributeDto) IdmRoleFormAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleFormAttributeDto) IdmConceptRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmConceptRoleRequestService) DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) Autowired(org.springframework.beans.factory.annotation.Autowired) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) PersistentType(eu.bcvsolutions.idm.core.eav.api.domain.PersistentType) BigDecimal(java.math.BigDecimal) Lists(com.google.common.collect.Lists) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) IdmIdentityRole(eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole) ImmutableList(com.google.common.collect.ImmutableList) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmRoleFormAttributeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFormAttributeFilter) IdmIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) Assert.assertNotNull(org.junit.Assert.assertNotNull) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) IdmRoleService(eu.bcvsolutions.idm.core.api.service.IdmRoleService) Test(org.junit.Test) RoleRequestState(eu.bcvsolutions.idm.core.api.domain.RoleRequestState) IdmRoleFormAttributeService(eu.bcvsolutions.idm.core.api.service.IdmRoleFormAttributeService) Serializable(java.io.Serializable) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) LocalDate(java.time.LocalDate) Assert(org.junit.Assert) ConceptRoleRequestOperation(eu.bcvsolutions.idm.core.api.domain.ConceptRoleRequestOperation) Assert.assertEquals(org.junit.Assert.assertEquals) IdmRoleFormAttribute_(eu.bcvsolutions.idm.core.model.entity.IdmRoleFormAttribute_) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) IdmRoleFormAttributeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFormAttributeFilter) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 33 with Assert.assertNotNull

use of org.junit.Assert.assertNotNull in project CzechIdMng by bcvsolutions.

the class DefaultProvisioningExecutorIntegrationTest method testRetryProvisioning.

@Test
public void testRetryProvisioning() {
    testProvisioningExceptionProcessor.setDisabled(false);
    try {
        SysSystemDto system = getHelper().createTestResourceSystem(true);
        SysProvisioningOperationDto provisioningOperation = createProvisioningOperation(system, "firstname");
        Map<ProvisioningAttributeDto, Object> accoutObject = provisioningOperation.getProvisioningContext().getAccountObject();
        String uid = (String) accoutObject.get(getProvisioningAttribute(TestHelper.ATTRIBUTE_MAPPING_NAME));
        ZonedDateTime now = ZonedDateTime.now();
        // 
        // publish event
        // 1 - create
        provisioningExecutor.execute(provisioningOperation);
        // is necessary to get again operation from service
        SysProvisioningOperationFilter filter = new SysProvisioningOperationFilter();
        filter.setSystemEntityUid(provisioningOperation.getSystemEntityUid());
        filter.setSystemId(system.getId());
        SysProvisioningOperationDto operation = provisioningOperationService.find(filter, null).getContent().get(0);
        SysProvisioningBatchDto batch = provisioningBatchService.findBatch(operation.getSystemEntity());
        Assert.assertEquals(OperationState.EXCEPTION, operation.getResultState());
        Assert.assertEquals(AccResultCode.PROVISIONING_FAILED.name(), operation.getResult().getModel().getStatusEnum());
        Assert.assertEquals(1, operation.getCurrentAttempt());
        Assert.assertTrue(operation.getMaxAttempts() > 1);
        Assert.assertTrue(batch.getNextAttempt().isAfter(now));
        SysSystemEntityDto systemEntity = systemEntityService.getBySystemAndEntityTypeAndUid(system, SystemEntityType.IDENTITY, uid);
        Assert.assertTrue(systemEntity.isWish());
        Assert.assertNull(getHelper().findResource(uid));
        // check failed operation is in archive too
        List<SysProvisioningArchiveDto> archived = provisioningArchiveService.find(filter, PageRequest.of(0, 10, new Sort(Direction.DESC, SysProvisioningArchive_.created.getName()))).getContent();
        Assert.assertEquals(1, archived.size());
        Assert.assertEquals(OperationState.EXCEPTION, archived.get(0).getResultState());
        Assert.assertEquals(AccResultCode.PROVISIONING_FAILED.name(), archived.get(0).getResult().getModel().getStatusEnum());
        // 
        batch.setNextAttempt(ZonedDateTime.now());
        provisioningBatchService.save(batch);
        // 
        // retry - the same exception expected
        RetryProvisioningTaskExecutor retryProvisioningTaskExecutor = new RetryProvisioningTaskExecutor();
        Boolean result = longRunningTaskManager.executeSync(retryProvisioningTaskExecutor);
        Assert.assertTrue(result);
        operation = provisioningOperationService.get(operation.getId());
        batch = provisioningBatchService.findBatch(systemEntity.getId());
        Assert.assertEquals(2, operation.getCurrentAttempt());
        Assert.assertNotNull(batch.getNextAttempt());
        Assert.assertTrue(batch.getNextAttempt().isAfter(now));
        archived = provisioningArchiveService.find(filter, PageRequest.of(0, 10, new Sort(Direction.DESC, SysProvisioningArchive_.created.getName()))).getContent();
        Assert.assertEquals(2, archived.size());
        Assert.assertEquals(OperationState.EXCEPTION, archived.get(0).getResultState());
        Assert.assertEquals(AccResultCode.PROVISIONING_FAILED.name(), archived.get(0).getResult().getModel().getStatusEnum());
        // 
        batch.setNextAttempt(ZonedDateTime.now());
        provisioningBatchService.save(batch);
        // 
        // retry - expected success now
        testProvisioningExceptionProcessor.setDisabled(true);
        retryProvisioningTaskExecutor = new RetryProvisioningTaskExecutor();
        longRunningTaskManager.executeSync(retryProvisioningTaskExecutor);
        // 
        systemEntity = systemEntityService.getBySystemAndEntityTypeAndUid(system, SystemEntityType.IDENTITY, uid);
        Assert.assertFalse(systemEntity.isWish());
        Assert.assertNotNull(getHelper().findResource(uid));
        batch = provisioningBatchService.get(batch.getId());
        Assert.assertNull(batch.getNextAttempt());
        archived = provisioningArchiveService.find(filter, PageRequest.of(0, 10, new Sort(Direction.DESC, SysProvisioningArchive_.created.getName()))).getContent();
        Assert.assertEquals(3, archived.size());
        Assert.assertTrue(archived.stream().anyMatch(a -> a.getResultState() == OperationState.EXECUTED));
    } finally {
        testProvisioningExceptionProcessor.setDisabled(true);
    }
}
Also used : ProvisioningExecutor(eu.bcvsolutions.idm.acc.service.api.ProvisioningExecutor) Lists(org.testng.collections.Lists) DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) ZonedDateTime(java.time.ZonedDateTime) Autowired(org.springframework.beans.factory.annotation.Autowired) SysSystemEntityDto(eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto) ConfigurationService(eu.bcvsolutions.idm.core.api.service.ConfigurationService) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) RetryProvisioningTaskExecutor(eu.bcvsolutions.idm.acc.scheduler.task.impl.RetryProvisioningTaskExecutor) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) SysProvisioningArchiveDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningArchiveDto) Map(java.util.Map) Sort(org.springframework.data.domain.Sort) Task(eu.bcvsolutions.idm.core.scheduler.api.dto.Task) SysProvisioningOperationService(eu.bcvsolutions.idm.acc.service.api.SysProvisioningOperationService) SysProvisioningArchive_(eu.bcvsolutions.idm.acc.entity.SysProvisioningArchive_) PageRequest(org.springframework.data.domain.PageRequest) ProvisioningAttributeDto(eu.bcvsolutions.idm.acc.dto.ProvisioningAttributeDto) UUID(java.util.UUID) SchedulerManager(eu.bcvsolutions.idm.core.scheduler.api.service.SchedulerManager) SysProvisioningOperationFilter(eu.bcvsolutions.idm.acc.dto.filter.SysProvisioningOperationFilter) List(java.util.List) SysProvisioningAttributeRepository(eu.bcvsolutions.idm.acc.repository.SysProvisioningAttributeRepository) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) Assert.assertFalse(org.junit.Assert.assertFalse) SysProvisioningAttribute(eu.bcvsolutions.idm.acc.entity.SysProvisioningAttribute) ProvisioningQueueTaskExecutor(eu.bcvsolutions.idm.acc.scheduler.task.impl.ProvisioningQueueTaskExecutor) HikariDataSource(com.zaxxer.hikari.HikariDataSource) CronTaskTrigger(eu.bcvsolutions.idm.core.scheduler.api.dto.CronTaskTrigger) IcUidAttribute(eu.bcvsolutions.idm.ic.api.IcUidAttribute) SysSchemaObjectClassService(eu.bcvsolutions.idm.acc.service.api.SysSchemaObjectClassService) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) AccResultCode(eu.bcvsolutions.idm.acc.domain.AccResultCode) TestResource(eu.bcvsolutions.idm.acc.entity.TestResource) IcConnectorFacade(eu.bcvsolutions.idm.ic.service.api.IcConnectorFacade) AttributeMappingStrategyType(eu.bcvsolutions.idm.acc.domain.AttributeMappingStrategyType) SysSystemEntityService(eu.bcvsolutions.idm.acc.service.api.SysSystemEntityService) HashMap(java.util.HashMap) IcObjectClassImpl(eu.bcvsolutions.idm.ic.impl.IcObjectClassImpl) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysProvisioningBatchDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningBatchDto) ArrayList(java.util.ArrayList) ConfidentialStorage(eu.bcvsolutions.idm.core.api.service.ConfidentialStorage) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) IcUidAttributeImpl(eu.bcvsolutions.idm.ic.impl.IcUidAttributeImpl) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) IcConnectorObjectImpl(eu.bcvsolutions.idm.ic.impl.IcConnectorObjectImpl) DataSource(javax.sql.DataSource) IcObjectClass(eu.bcvsolutions.idm.ic.api.IcObjectClass) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Direction(org.springframework.data.domain.Sort.Direction) SysProvisioningOperation_(eu.bcvsolutions.idm.acc.entity.SysProvisioningOperation_) ProvisioningOperationType(eu.bcvsolutions.idm.acc.domain.ProvisioningOperationType) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) SysProvisioningOperationDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto) Before(org.junit.Before) ProvisioningContext(eu.bcvsolutions.idm.acc.domain.ProvisioningContext) SysProvisioningArchiveService(eu.bcvsolutions.idm.acc.service.api.SysProvisioningArchiveService) LongRunningTaskManager(eu.bcvsolutions.idm.core.scheduler.api.service.LongRunningTaskManager) Assert.assertNotNull(org.junit.Assert.assertNotNull) SysProvisioningOperation(eu.bcvsolutions.idm.acc.entity.SysProvisioningOperation) SysSystemService(eu.bcvsolutions.idm.acc.service.api.SysSystemService) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmEntityEventFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityEventFilter) Assert.assertTrue(org.junit.Assert.assertTrue) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) Test(org.junit.Test) ApplicationContext(org.springframework.context.ApplicationContext) SysProvisioningBatchService(eu.bcvsolutions.idm.acc.service.api.SysProvisioningBatchService) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) IdmEntityEventService(eu.bcvsolutions.idm.core.api.service.IdmEntityEventService) Assert.assertNull(org.junit.Assert.assertNull) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) TestHelper(eu.bcvsolutions.idm.acc.TestHelper) Assert(org.junit.Assert) SysSystemAttributeMappingService(eu.bcvsolutions.idm.acc.service.api.SysSystemAttributeMappingService) Assert.assertEquals(org.junit.Assert.assertEquals) EntityEventManager(eu.bcvsolutions.idm.core.api.service.EntityEventManager) SysProvisioningOperationFilter(eu.bcvsolutions.idm.acc.dto.filter.SysProvisioningOperationFilter) SysProvisioningArchiveDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningArchiveDto) ProvisioningAttributeDto(eu.bcvsolutions.idm.acc.dto.ProvisioningAttributeDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) ZonedDateTime(java.time.ZonedDateTime) RetryProvisioningTaskExecutor(eu.bcvsolutions.idm.acc.scheduler.task.impl.RetryProvisioningTaskExecutor) Sort(org.springframework.data.domain.Sort) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) SysProvisioningBatchDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningBatchDto) SysSystemEntityDto(eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto) SysProvisioningOperationDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 34 with Assert.assertNotNull

use of org.junit.Assert.assertNotNull in project CzechIdMng by bcvsolutions.

the class DefaultIdmIdentityContractServiceIntegrationTest method testChangeInvalidContractPositionAndValidityWithAutomaticRolesAssigned.

@Test
public void testChangeInvalidContractPositionAndValidityWithAutomaticRolesAssigned() {
    prepareAutomaticRoles();
    // 
    // prepare identity and contract
    IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
    IdmIdentityContractDto contract = new IdmIdentityContractDto();
    contract.setIdentity(identity.getId());
    contract.setWorkPosition(nodeD.getId());
    LocalDate validTill = LocalDate.now().plusDays(1);
    contract.setValidTill(validTill);
    contract = service.save(contract);
    // 
    // test after create
    List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByContract(contract.getId());
    IdmIdentityRoleDto automaticRole = identityRoles.stream().filter(ir -> {
        return roleA.getId().equals(ir.getRole());
    }).findFirst().orElse(null);
    Assert.assertNotNull(automaticRole);
    Assert.assertEquals(validTill, automaticRole.getValidTill());
    UUID automaticRoleId = automaticRole.getId();
    // 
    // change validity of contract to past => LOOKOUT: internal method is used to test only
    LocalDate minusDays = LocalDate.now().minusDays(1);
    contract.setValidTill(minusDays);
    contract = service.saveInternal(contract);
    Assert.assertEquals(minusDays, contract.getValidTill());
    // assigned roles is still unchanged
    identityRoles = identityRoleService.findAllByContract(contract.getId());
    automaticRole = identityRoles.stream().filter(ir -> {
        return roleA.getId().equals(ir.getRole());
    }).findFirst().orElse(null);
    Assert.assertNotNull(automaticRole);
    Assert.assertEquals(validTill, automaticRole.getValidTill());
    // 
    LocalDate newValidTill = LocalDate.now().plusDays(3);
    contract.setValidTill(newValidTill);
    contract = service.save(contract);
    // 
    // test after change
    identityRoles = identityRoleService.findAllByContract(contract.getId());
    Assert.assertTrue(identityRoles.stream().anyMatch(ir -> {
        return roleA.getId().equals(ir.getRole()) && // prevent drop and create
        ir.getId().equals(automaticRoleId) && // validity is changed
        newValidTill.equals(ir.getValidTill());
    }));
}
Also used : Lists(org.testng.collections.Lists) IdmEntityEventDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto) ProcessAutomaticRoleByTreeTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.ProcessAutomaticRoleByTreeTaskExecutor) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContract(eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) Autowired(org.springframework.beans.factory.annotation.Autowired) ProcessSkippedAutomaticRoleByTreeForContractTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.ProcessSkippedAutomaticRoleByTreeForContractTaskExecutor) ConfigurationService(eu.bcvsolutions.idm.core.api.service.ConfigurationService) AutomaticRoleManager(eu.bcvsolutions.idm.core.api.service.AutomaticRoleManager) AutowireHelper(eu.bcvsolutions.idm.core.api.utils.AutowireHelper) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) After(org.junit.After) TransactionContextHolder(eu.bcvsolutions.idm.core.api.domain.TransactionContextHolder) IdmLongRunningTaskFilter(eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter) LongRunningTaskEventType(eu.bcvsolutions.idm.core.scheduler.api.event.LongRunningTaskEvent.LongRunningTaskEventType) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) AutomaticRoleAttributeRuleType(eu.bcvsolutions.idm.core.api.domain.AutomaticRoleAttributeRuleType) RecursionType(eu.bcvsolutions.idm.core.api.domain.RecursionType) IdmIdentityContractService(eu.bcvsolutions.idm.core.api.service.IdmIdentityContractService) ContractPositionEventType(eu.bcvsolutions.idm.core.model.event.ContractPositionEvent.ContractPositionEventType) ContractState(eu.bcvsolutions.idm.core.api.domain.ContractState) IdentityContractEventType(eu.bcvsolutions.idm.core.model.event.IdentityContractEvent.IdentityContractEventType) LongRunningFutureTask(eu.bcvsolutions.idm.core.scheduler.api.dto.LongRunningFutureTask) Set(java.util.Set) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) IdmEntityStateFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityStateFilter) UUID(java.util.UUID) Page(org.springframework.data.domain.Page) IdmContractPositionDto(eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto) IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) RemoveAutomaticRoleTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.RemoveAutomaticRoleTaskExecutor) IdmContractGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto) List(java.util.List) EventConfiguration(eu.bcvsolutions.idm.core.api.config.domain.EventConfiguration) ContractBasePermission(eu.bcvsolutions.idm.core.security.api.domain.ContractBasePermission) Assert.assertFalse(org.junit.Assert.assertFalse) LocalDate(java.time.LocalDate) IdentityContractEvent(eu.bcvsolutions.idm.core.model.event.IdentityContractEvent) ContractPositionEvent(eu.bcvsolutions.idm.core.model.event.ContractPositionEvent) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) IdmIdentityContractFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityContractFilter) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmContractPositionService(eu.bcvsolutions.idm.core.api.service.IdmContractPositionService) IdmTreeNodeService(eu.bcvsolutions.idm.core.api.service.IdmTreeNodeService) IdmRoleTreeNodeService(eu.bcvsolutions.idm.core.api.service.IdmRoleTreeNodeService) PermissionContext(eu.bcvsolutions.idm.core.api.dto.filter.PermissionContext) IdmContractGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractGuaranteeFilter) IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) EntityStateManager(eu.bcvsolutions.idm.core.api.service.EntityStateManager) LookupService(eu.bcvsolutions.idm.core.api.service.LookupService) IdmContractPositionFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractPositionFilter) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) IdmLongRunningTaskService(eu.bcvsolutions.idm.core.scheduler.api.service.IdmLongRunningTaskService) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) Before(org.junit.Before) IdmIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService) SchedulerConfiguration(eu.bcvsolutions.idm.core.scheduler.api.config.SchedulerConfiguration) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) LongRunningTaskManager(eu.bcvsolutions.idm.core.scheduler.api.service.LongRunningTaskManager) Assert.assertNotNull(org.junit.Assert.assertNotNull) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmEntityEventFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityEventFilter) Assert.assertTrue(org.junit.Assert.assertTrue) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) Test(org.junit.Test) IdmContractGuaranteeService(eu.bcvsolutions.idm.core.api.service.IdmContractGuaranteeService) ApplicationContext(org.springframework.context.ApplicationContext) IdmIdentityContract_(eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract_) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) PrivateIdentityConfiguration(eu.bcvsolutions.idm.core.api.config.domain.PrivateIdentityConfiguration) AutomaticRoleAttributeRuleComparison(eu.bcvsolutions.idm.core.api.domain.AutomaticRoleAttributeRuleComparison) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) IdentityConfiguration(eu.bcvsolutions.idm.core.api.config.domain.IdentityConfiguration) EntityEventManager(eu.bcvsolutions.idm.core.api.service.EntityEventManager) Transactional(org.springframework.transaction.annotation.Transactional) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) UUID(java.util.UUID) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) LocalDate(java.time.LocalDate) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 35 with Assert.assertNotNull

use of org.junit.Assert.assertNotNull in project flink by apache.

the class OrcColumnarRowInputFormatTest method innerTestRestore.

private void innerTestRestore(OrcColumnarRowInputFormat<?, FileSourceSplit> format, FileSourceSplit split, int breakCnt, int expectedCnt, long expectedTotalF0) throws IOException {
    AtomicInteger cnt = new AtomicInteger(0);
    AtomicLong totalF0 = new AtomicLong(0);
    Consumer<RowData> consumer = row -> {
        Assert.assertFalse(row.isNullAt(0));
        Assert.assertFalse(row.isNullAt(1));
        totalF0.addAndGet(row.getInt(0));
        assertNotNull(row.getString(1).toString());
        cnt.incrementAndGet();
    };
    // ---------- restore reading ---------------
    long offset = -1;
    long recordSkipCount = -1;
    try (BulkFormat.Reader<RowData> reader = createReader(format, split)) {
        while (cnt.get() < breakCnt) {
            BulkFormat.RecordIterator<RowData> batch = reader.readBatch();
            Assert.assertNotNull(batch);
            RecordAndPosition<RowData> record;
            while ((record = batch.next()) != null && cnt.get() < breakCnt) {
                consumer.accept(record.getRecord());
                offset = record.getOffset();
                recordSkipCount = record.getRecordSkipCount();
            }
            batch.releaseBatch();
        }
    }
    Utils.forEachRemaining(restoreReader(format, split, offset, recordSkipCount), consumer);
    // ---------- end restore reading ---------------
    // the results should be the same as:
    // forEach(format, split, consumer);
    // check that all rows have been read
    assertEquals(expectedCnt, cnt.get());
    assertEquals(expectedTotalF0, totalF0.get());
}
Also used : PartitionFieldExtractor(org.apache.flink.connector.file.table.PartitionFieldExtractor) DecimalDataUtils(org.apache.flink.table.data.DecimalDataUtils) Between(org.apache.flink.orc.OrcFilters.Between) RowType(org.apache.flink.table.types.logical.RowType) CheckpointedPosition(org.apache.flink.connector.file.src.util.CheckpointedPosition) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Equals(org.apache.flink.orc.OrcFilters.Equals) BigDecimal(java.math.BigDecimal) DecimalType(org.apache.flink.table.types.logical.DecimalType) FileSourceSplit(org.apache.flink.connector.file.src.FileSourceSplit) Path(org.apache.flink.core.fs.Path) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Predicate(org.apache.flink.orc.OrcFilters.Predicate) Configuration(org.apache.hadoop.conf.Configuration) Or(org.apache.flink.orc.OrcFilters.Or) ClassRule(org.junit.ClassRule) Utils(org.apache.flink.connector.file.src.util.Utils) FileStatus(org.apache.flink.core.fs.FileStatus) RowData(org.apache.flink.table.data.RowData) IOUtils(org.apache.flink.util.IOUtils) Assert.assertNotNull(org.junit.Assert.assertNotNull) FileOutputStream(java.io.FileOutputStream) DataTypes(org.apache.flink.table.api.DataTypes) Test(org.junit.Test) IOException(java.io.IOException) UUID(java.util.UUID) File(java.io.File) PredicateLeaf(org.apache.hadoop.hive.ql.io.sarg.PredicateLeaf) Consumer(java.util.function.Consumer) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) InternalTypeInfo(org.apache.flink.table.runtime.typeutils.InternalTypeInfo) LogicalType(org.apache.flink.table.types.logical.LogicalType) RecordAndPosition(org.apache.flink.connector.file.src.util.RecordAndPosition) OrcShim(org.apache.flink.orc.shim.OrcShim) PartitionPathUtils.generatePartitionPath(org.apache.flink.table.utils.PartitionPathUtils.generatePartitionPath) BulkFormat(org.apache.flink.connector.file.src.reader.BulkFormat) Assert(org.junit.Assert) Collections(java.util.Collections) TemporaryFolder(org.junit.rules.TemporaryFolder) Assert.assertEquals(org.junit.Assert.assertEquals) AtomicLong(java.util.concurrent.atomic.AtomicLong) RowData(org.apache.flink.table.data.RowData) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BulkFormat(org.apache.flink.connector.file.src.reader.BulkFormat)

Aggregations

List (java.util.List)38 Assert (org.junit.Assert)38 Assert.assertNotNull (org.junit.Assert.assertNotNull)38 Test (org.junit.Test)38 Assert.assertEquals (org.junit.Assert.assertEquals)36 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)28 Autowired (org.springframework.beans.factory.annotation.Autowired)28 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)26 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)25 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)24 FormService (eu.bcvsolutions.idm.core.eav.api.service.FormService)24 Before (org.junit.Before)24 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)23 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)23 Assert.assertTrue (org.junit.Assert.assertTrue)23 IdmFormDefinitionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)22 LocalDate (java.time.LocalDate)22 Assert.assertNull (org.junit.Assert.assertNull)22 Lists (com.google.common.collect.Lists)21 IdmIdentityRoleService (eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService)20