Search in sources :

Example 16 with Assert.assertTrue

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

the class DefaultEntityEventManagerIntergationTest method testSaveStates.

@Test
@Transactional
public void testSaveStates() {
    MockOwner mockOwner = new MockOwner();
    // 
    IdmEntityEventDto entityEventDto = manager.prepareEvent(mockOwner, null);
    entityEventDto.setResult(new OperationResultDto.Builder(OperationState.RUNNING).build());
    entityEventDto.setEventType(CoreEventType.CREATE.name());
    entityEventDto.setPriority(PriorityType.HIGH);
    entityEventDto = manager.saveEvent(entityEventDto);
    // 
    List<IdmEntityStateDto> states = manager.saveStates(manager.toEvent(entityEventDto), null, null);
    Assert.assertEquals(1, states.size());
    Assert.assertTrue(states.stream().anyMatch(s -> s.getResult().getState() == OperationState.EXECUTED));
    // 
    states = manager.saveStates(manager.toEvent(entityEventDto), states, new DefaultEventResult.Builder<>(manager.toEvent(entityEventDto), new EmptyEntityEventProcessor<>()).build());
    // 
    Assert.assertEquals(1, states.size());
    Assert.assertTrue(states.stream().anyMatch(s -> s.getResult().getState() == OperationState.EXECUTED));
    // 
    EventResult<?> result = new DefaultEventResult.Builder<>(manager.toEvent(entityEventDto), new EmptyEntityEventProcessor<>()).setResults(Lists.newArrayList(new OperationResult.Builder(OperationState.EXCEPTION).build(), new OperationResult.Builder(OperationState.CANCELED).build())).build();
    // 
    states = manager.saveStates(manager.toEvent(entityEventDto), null, result);
    // 
    Assert.assertEquals(2, states.size());
    Assert.assertTrue(states.stream().anyMatch(s -> s.getResult().getState() == OperationState.EXCEPTION));
    Assert.assertTrue(states.stream().anyMatch(s -> s.getResult().getState() == OperationState.CANCELED));
    // 
    result = new DefaultEventResult.Builder<>(manager.toEvent(entityEventDto), new EmptyEntityEventProcessor<>()).setResults(Lists.newArrayList(new OperationResult.Builder(OperationState.BLOCKED).build())).build();
    states = manager.saveStates(manager.toEvent(entityEventDto), states, result);
    // 
    Assert.assertEquals(1, states.size());
    Assert.assertTrue(states.stream().anyMatch(s -> s.getResult().getState() == OperationState.BLOCKED));
}
Also used : IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) DefaultEventContext(eu.bcvsolutions.idm.core.api.event.DefaultEventContext) IdmEntityEventDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto) AcceptedContent(eu.bcvsolutions.idm.core.event.AcceptedContent) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) EntityGenerateValuesProcessor(eu.bcvsolutions.idm.core.model.event.processor.EntityGenerateValuesProcessor) Autowired(org.springframework.beans.factory.annotation.Autowired) SecurityService(eu.bcvsolutions.idm.core.security.api.service.SecurityService) CoreEvent(eu.bcvsolutions.idm.core.api.event.CoreEvent) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) MockDto(eu.bcvsolutions.idm.core.event.domain.MockDto) TransactionContextHolder(eu.bcvsolutions.idm.core.api.domain.TransactionContextHolder) IdentityEventType(eu.bcvsolutions.idm.core.model.event.IdentityEvent.IdentityEventType) ObserveDtoProcessor(eu.bcvsolutions.idm.core.model.event.processor.ObserveDtoProcessor) TestEntityEventProcessorConfiguration(eu.bcvsolutions.idm.core.event.TestEntityEventProcessorConfiguration) EntityEventProcessorFilter(eu.bcvsolutions.idm.core.api.dto.filter.EntityEventProcessorFilter) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) IdentityContractEventType(eu.bcvsolutions.idm.core.model.event.IdentityContractEvent.IdentityContractEventType) PageRequest(org.springframework.data.domain.PageRequest) IdmEntityStateFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityStateFilter) UUID(java.util.UUID) PriorityType(eu.bcvsolutions.idm.core.api.domain.PriorityType) Serializable(java.io.Serializable) IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) List(java.util.List) EventConfiguration(eu.bcvsolutions.idm.core.api.config.domain.EventConfiguration) NeverEndingProcessor(eu.bcvsolutions.idm.core.model.event.processor.NeverEndingProcessor) EventType(eu.bcvsolutions.idm.core.api.event.EventType) IdentityContractEvent(eu.bcvsolutions.idm.core.model.event.IdentityContractEvent) IdentityEvent(eu.bcvsolutions.idm.core.model.event.IdentityEvent) EntityEventProcessorDto(eu.bcvsolutions.idm.core.api.dto.EntityEventProcessorDto) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) RoleRequestEventType(eu.bcvsolutions.idm.core.model.event.RoleRequestEvent.RoleRequestEventType) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) TestContentTwo(eu.bcvsolutions.idm.core.event.TestContentTwo) EntityEventProcessor(eu.bcvsolutions.idm.core.api.event.EntityEventProcessor) MockOwner(eu.bcvsolutions.idm.core.event.domain.MockOwner) ArrayList(java.util.ArrayList) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) 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) Qualifier(org.springframework.beans.factory.annotation.Qualifier) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) EventResult(eu.bcvsolutions.idm.core.api.event.EventResult) IdentityRoleEventType(eu.bcvsolutions.idm.core.model.event.IdentityRoleEvent.IdentityRoleEventType) 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) ConditionalContent(eu.bcvsolutions.idm.core.event.ConditionalContent) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) TestIdentityNotifyProcessor(eu.bcvsolutions.idm.core.model.event.processor.TestIdentityNotifyProcessor) 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) EventContext(eu.bcvsolutions.idm.core.api.event.EventContext) EmptyEntityEventProcessor(eu.bcvsolutions.idm.core.api.event.EmptyEntityEventProcessor) IdmEntityEventService(eu.bcvsolutions.idm.core.api.service.IdmEntityEventService) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) CoreEventType(eu.bcvsolutions.idm.core.api.event.CoreEvent.CoreEventType) TestContent(eu.bcvsolutions.idm.core.event.TestContent) BaseDto(eu.bcvsolutions.idm.core.api.dto.BaseDto) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) Transactional(org.springframework.transaction.annotation.Transactional) MockOwner(eu.bcvsolutions.idm.core.event.domain.MockOwner) EmptyEntityEventProcessor(eu.bcvsolutions.idm.core.api.event.EmptyEntityEventProcessor) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdmEntityEventDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 17 with Assert.assertTrue

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

the class DefaultAuditServiceIntegrationTest method testFillTransactionalIdCreateIdentity.

@Test
public void testFillTransactionalIdCreateIdentity() {
    // start transaction
    TransactionContextHolder.setContext(TransactionContextHolder.createEmptyContext());
    UUID transactionId = TransactionContextHolder.getContext().getTransactionId();
    Assert.assertNotNull(transactionId);
    // 
    // with password
    IdmIdentityDto identity = getHelper().createIdentity();
    Assert.assertEquals(transactionId, identity.getTransactionId());
    // default contract and password has to have the same transaction id
    IdmIdentityContractDto contract = getHelper().getPrimeContract(identity);
    Assert.assertEquals(transactionId, contract.getTransactionId());
    // default password
    IdmPasswordDto password = getHelper().getPassword(identity);
    Assert.assertEquals(transactionId, password.getTransactionId());
    // audit for identity, contract and password with the same transaction id
    IdmAuditFilter filter = new IdmAuditFilter();
    filter.setTransactionId(transactionId);
    List<IdmAuditDto> audits = auditService.find(filter, null).getContent();
    Assert.assertEquals(3, audits.size());
    // 
    Assert.assertTrue(audits.stream().anyMatch(a -> a.getEntityId().equals(identity.getId())));
    Assert.assertTrue(audits.stream().anyMatch(a -> a.getEntityId().equals(contract.getId())));
    Assert.assertTrue(audits.stream().anyMatch(a -> a.getEntityId().equals(password.getId())));
}
Also used : IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) ZonedDateTime(java.time.ZonedDateTime) 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) IdmPasswordDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) Map(java.util.Map) IdmIdentityFormValue(eu.bcvsolutions.idm.core.model.entity.eav.IdmIdentityFormValue) TransactionContextHolder(eu.bcvsolutions.idm.core.api.domain.TransactionContextHolder) Assert.fail(org.junit.Assert.fail) Pageable(org.springframework.data.domain.Pageable) Sort(org.springframework.data.domain.Sort) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) PageRequest(org.springframework.data.domain.PageRequest) UUID(java.util.UUID) Page(org.springframework.data.domain.Page) Serializable(java.io.Serializable) IdmContractGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto) List(java.util.List) IdmAuthenticationException(eu.bcvsolutions.idm.core.security.api.exception.IdmAuthenticationException) RevisionType(org.hibernate.envers.RevisionType) IdmAuditService(eu.bcvsolutions.idm.core.api.audit.service.IdmAuditService) Assert.assertFalse(org.junit.Assert.assertFalse) TransactionStatus(org.springframework.transaction.TransactionStatus) TransactionCallback(org.springframework.transaction.support.TransactionCallback) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmProfile(eu.bcvsolutions.idm.core.model.entity.IdmProfile) LoginDto(eu.bcvsolutions.idm.core.security.api.dto.LoginDto) IdmRole(eu.bcvsolutions.idm.core.model.entity.IdmRole) IdmAuditDto(eu.bcvsolutions.idm.core.api.audit.dto.IdmAuditDto) IdmContractGuarantee(eu.bcvsolutions.idm.core.model.entity.IdmContractGuarantee) PersistentType(eu.bcvsolutions.idm.core.eav.api.domain.PersistentType) Lists(com.google.common.collect.Lists) BaseEntity(eu.bcvsolutions.idm.core.api.entity.BaseEntity) IdmAuditEntityDto(eu.bcvsolutions.idm.core.api.audit.dto.IdmAuditEntityDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) AuthenticationManager(eu.bcvsolutions.idm.core.security.api.authentication.AuthenticationManager) Assert.assertNotNull(org.junit.Assert.assertNotNull) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmProfileDto(eu.bcvsolutions.idm.core.api.dto.IdmProfileDto) IdmRoleService(eu.bcvsolutions.idm.core.api.service.IdmRoleService) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) Assert.assertNull(org.junit.Assert.assertNull) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmAuditFilter(eu.bcvsolutions.idm.core.api.audit.dto.filter.IdmAuditFilter) IdmIdentity_(eu.bcvsolutions.idm.core.model.entity.IdmIdentity_) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) PasswordChangeDto(eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto) Transactional(org.springframework.transaction.annotation.Transactional) IdmPasswordDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto) IdmAuditDto(eu.bcvsolutions.idm.core.api.audit.dto.IdmAuditDto) IdmAuditFilter(eu.bcvsolutions.idm.core.api.audit.dto.filter.IdmAuditFilter) UUID(java.util.UUID) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 18 with Assert.assertTrue

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

the class DefaultAuditServiceIntegrationTest method testFindByTypes.

@Test
public void testFindByTypes() {
    IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
    IdmProfileDto profile = getHelper().createProfile(identity);
    // 
    IdmAuditFilter filter = new IdmAuditFilter();
    filter.setRelatedOwnerId(identity.getId());
    filter.setTypes(Lists.newArrayList(IdmProfile.class.getCanonicalName(), IdmIdentity.class.getCanonicalName()));
    // 
    List<IdmAuditDto> revisions = auditService.find(filter, null).getContent();
    Assert.assertEquals(2, revisions.size());
    Assert.assertEquals(RevisionType.ADD.name(), revisions.get(0).getModification());
    Assert.assertTrue(revisions.stream().anyMatch(r -> r.getEntityId().equals(profile.getId())));
    Assert.assertTrue(revisions.stream().anyMatch(r -> r.getEntityId().equals(identity.getId())));
    // 
    // non transactional test => cleanup
    identityService.delete(identity);
}
Also used : IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) ZonedDateTime(java.time.ZonedDateTime) 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) IdmPasswordDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) Map(java.util.Map) IdmIdentityFormValue(eu.bcvsolutions.idm.core.model.entity.eav.IdmIdentityFormValue) TransactionContextHolder(eu.bcvsolutions.idm.core.api.domain.TransactionContextHolder) Assert.fail(org.junit.Assert.fail) Pageable(org.springframework.data.domain.Pageable) Sort(org.springframework.data.domain.Sort) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) PageRequest(org.springframework.data.domain.PageRequest) UUID(java.util.UUID) Page(org.springframework.data.domain.Page) Serializable(java.io.Serializable) IdmContractGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto) List(java.util.List) IdmAuthenticationException(eu.bcvsolutions.idm.core.security.api.exception.IdmAuthenticationException) RevisionType(org.hibernate.envers.RevisionType) IdmAuditService(eu.bcvsolutions.idm.core.api.audit.service.IdmAuditService) Assert.assertFalse(org.junit.Assert.assertFalse) TransactionStatus(org.springframework.transaction.TransactionStatus) TransactionCallback(org.springframework.transaction.support.TransactionCallback) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmProfile(eu.bcvsolutions.idm.core.model.entity.IdmProfile) LoginDto(eu.bcvsolutions.idm.core.security.api.dto.LoginDto) IdmRole(eu.bcvsolutions.idm.core.model.entity.IdmRole) IdmAuditDto(eu.bcvsolutions.idm.core.api.audit.dto.IdmAuditDto) IdmContractGuarantee(eu.bcvsolutions.idm.core.model.entity.IdmContractGuarantee) PersistentType(eu.bcvsolutions.idm.core.eav.api.domain.PersistentType) Lists(com.google.common.collect.Lists) BaseEntity(eu.bcvsolutions.idm.core.api.entity.BaseEntity) IdmAuditEntityDto(eu.bcvsolutions.idm.core.api.audit.dto.IdmAuditEntityDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) AuthenticationManager(eu.bcvsolutions.idm.core.security.api.authentication.AuthenticationManager) Assert.assertNotNull(org.junit.Assert.assertNotNull) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmProfileDto(eu.bcvsolutions.idm.core.api.dto.IdmProfileDto) IdmRoleService(eu.bcvsolutions.idm.core.api.service.IdmRoleService) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) Assert.assertNull(org.junit.Assert.assertNull) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmAuditFilter(eu.bcvsolutions.idm.core.api.audit.dto.filter.IdmAuditFilter) IdmIdentity_(eu.bcvsolutions.idm.core.model.entity.IdmIdentity_) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) PasswordChangeDto(eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto) Transactional(org.springframework.transaction.annotation.Transactional) IdmProfileDto(eu.bcvsolutions.idm.core.api.dto.IdmProfileDto) 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)

Example 19 with Assert.assertTrue

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

the class ChangeIdentityPermissionTest method testAccessIsAddedForOwnerAndImplementerToSubprocesses.

@Test
public void testAccessIsAddedForOwnerAndImplementerToSubprocesses() {
    // reset approvers
    getHelper().setConfigurationValue(APPROVE_BY_USERMANAGER_ENABLE, false);
    getHelper().setConfigurationValue(APPROVE_BY_SECURITY_ENABLE, false);
    getHelper().setConfigurationValue(APPROVE_BY_MANAGER_ENABLE, false);
    getHelper().setConfigurationValue(APPROVE_BY_HELPDESK_ENABLE, false);
    // role with guarantees and critical 2 => approve by guarantee
    IdmRoleDto role = new IdmRoleDto();
    role.setCode(getHelper().createName());
    // default by configuration
    role.setPriority(2);
    IdmRoleDto roleOne = roleService.save(role);
    role = new IdmRoleDto();
    role.setCode(getHelper().createName());
    // default by configuration
    role.setPriority(2);
    IdmRoleDto roleTwo = roleService.save(role);
    // 
    IdmIdentityDto implementer = getHelper().createIdentity();
    IdmIdentityDto applicant = getHelper().createIdentity();
    IdmIdentityContractDto applicantContract = getHelper().getPrimeContract(applicant);
    IdmIdentityDto guaranteeOne = getHelper().createIdentity();
    IdmIdentityDto guaranteeTwo = getHelper().createIdentity();
    // 
    getHelper().createRoleGuarantee(roleOne, guaranteeOne);
    getHelper().createRoleGuarantee(roleTwo, guaranteeTwo);
    // 
    // login as implementer
    loginAsAdmin(implementer.getUsername());
    // 
    IdmRoleRequestDto request = createRoleRequest(applicant);
    request = roleRequestService.save(request);
    IdmConceptRoleRequestDto concept = createRoleConcept(roleOne, applicantContract, request);
    conceptRoleRequestService.save(concept);
    concept = createRoleConcept(roleTwo, applicantContract, request);
    conceptRoleRequestService.save(concept);
    roleRequestService.startRequestInternal(request.getId(), true);
    request = roleRequestService.get(request.getId());
    Assert.assertEquals(RoleRequestState.IN_PROGRESS, request.getState());
    IdmRequestIdentityRoleFilter requestIdentityRoleFilter = new IdmRequestIdentityRoleFilter();
    requestIdentityRoleFilter.setIncludeCandidates(true);
    requestIdentityRoleFilter.setRoleRequestId(request.getId());
    requestIdentityRoleFilter.setIdentityId(applicant.getId());
    List<IdmRequestIdentityRoleDto> requestIdentityRoles = requestIdentityRoleService.find(requestIdentityRoleFilter, null).getContent();
    Assert.assertEquals(2, requestIdentityRoles.size());
    Assert.assertTrue(requestIdentityRoles.stream().anyMatch(rir -> rir.getRole().equals(roleOne.getId()) && rir.getCandidates().size() == 1 && rir.getCandidates().iterator().next().getId().equals(guaranteeOne.getId())));
    Assert.assertTrue(requestIdentityRoles.stream().anyMatch(rir -> rir.getRole().equals(roleTwo.getId()) && rir.getCandidates().size() == 1 && rir.getCandidates().iterator().next().getId().equals(guaranteeTwo.getId())));
    // 
    // check applicant and implemented can read process instance
    getHelper().login(implementer);
    List<WorkflowProcessInstanceDto> processes = workflowProcessInstanceService.find(new WorkflowFilterDto(), null, IdmBasePermission.READ).getContent();
    Assert.assertEquals(3, processes.size());
    getHelper().login(applicant);
    Assert.assertEquals(3, workflowProcessInstanceService.find(new WorkflowFilterDto(), null, IdmBasePermission.READ).getTotalElements());
    getHelper().login(guaranteeOne);
    Assert.assertEquals(1, workflowProcessInstanceService.find(new WorkflowFilterDto(), null, IdmBasePermission.READ).getTotalElements());
    getHelper().login(guaranteeTwo);
    Assert.assertEquals(1, workflowProcessInstanceService.find(new WorkflowFilterDto(), null, IdmBasePermission.READ).getTotalElements());
    // 
    // test identity links are created (=> access added)
    processes.forEach(process -> {
        List<IdentityLink> links = runtimeService.getIdentityLinksForProcessInstance(process.getProcessInstanceId());
        Assert.assertTrue(links.stream().anyMatch(l -> l.getUserId().equals(implementer.getId().toString()) && l.getType().equals(IdentityLinkType.STARTER)));
        Assert.assertTrue(links.stream().anyMatch(l -> l.getUserId().equals(applicant.getId().toString()) && l.getType().equals(IdentityLinkType.OWNER)));
    });
}
Also used : RuntimeService(org.activiti.engine.RuntimeService) IdmConceptRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmConceptRoleRequestService) IdmRequestIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestIdentityRoleDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) ZonedDateTime(java.time.ZonedDateTime) WorkflowProcessInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowProcessInstanceDto) Autowired(org.springframework.beans.factory.annotation.Autowired) WorkflowTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto) SecurityService(eu.bcvsolutions.idm.core.security.api.service.SecurityService) IdmRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmRoleRequestService) CoreGroupPermission(eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission) IdmRequestIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmRequestIdentityRoleService) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) After(org.junit.After) WorkflowTaskInstanceService(eu.bcvsolutions.idm.core.workflow.service.WorkflowTaskInstanceService) Assert.fail(org.junit.Assert.fail) LoginService(eu.bcvsolutions.idm.core.security.api.service.LoginService) IdentityLink(org.activiti.engine.task.IdentityLink) IdmIdentityContractService(eu.bcvsolutions.idm.core.api.service.IdmIdentityContractService) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) Set(java.util.Set) UUID(java.util.UUID) Page(org.springframework.data.domain.Page) RoleConfiguration(eu.bcvsolutions.idm.core.api.config.domain.RoleConfiguration) WorkflowHistoricProcessInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowHistoricProcessInstanceDto) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) LocalDate(java.time.LocalDate) IdmRoleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleRequestFilter) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) RoleRequestedByType(eu.bcvsolutions.idm.core.api.domain.RoleRequestedByType) IdmConfigurationService(eu.bcvsolutions.idm.core.api.service.IdmConfigurationService) IdentityLinkType(org.activiti.engine.task.IdentityLinkType) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) AbstractCoreWorkflowIntegrationTest(eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) InitTestDataProcessor(eu.bcvsolutions.idm.core.model.event.processor.module.InitTestDataProcessor) WorkflowProcessInstanceService(eu.bcvsolutions.idm.core.workflow.service.WorkflowProcessInstanceService) WorkflowFilterDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) WorkflowHistoricTaskInstanceService(eu.bcvsolutions.idm.core.workflow.service.WorkflowHistoricTaskInstanceService) Before(org.junit.Before) IdmIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService) WorkflowHistoricProcessInstanceService(eu.bcvsolutions.idm.core.workflow.service.WorkflowHistoricProcessInstanceService) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) Assert.assertNotNull(org.junit.Assert.assertNotNull) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmRoleService(eu.bcvsolutions.idm.core.api.service.IdmRoleService) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) RoleRequestState(eu.bcvsolutions.idm.core.api.domain.RoleRequestState) IdmIncompatibleRoleService(eu.bcvsolutions.idm.core.api.service.IdmIncompatibleRoleService) HttpStatus(org.springframework.http.HttpStatus) Assert.assertNull(org.junit.Assert.assertNull) ChronoUnit(java.time.temporal.ChronoUnit) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) WorkflowHistoricTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowHistoricTaskInstanceDto) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) ResolvedIncompatibleRoleDto(eu.bcvsolutions.idm.core.api.dto.ResolvedIncompatibleRoleDto) IdmRequestIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestIdentityRoleFilter) IdmGroupPermission(eu.bcvsolutions.idm.core.security.api.domain.IdmGroupPermission) Assert(org.junit.Assert) IdmIncompatibleRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIncompatibleRoleDto) ConceptRoleRequestOperation(eu.bcvsolutions.idm.core.api.domain.ConceptRoleRequestOperation) Assert.assertEquals(org.junit.Assert.assertEquals) Transactional(org.springframework.transaction.annotation.Transactional) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRequestIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestIdentityRoleDto) IdentityLink(org.activiti.engine.task.IdentityLink) IdmRequestIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestIdentityRoleFilter) WorkflowFilterDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) WorkflowProcessInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowProcessInstanceDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) AbstractCoreWorkflowIntegrationTest(eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest) Test(org.junit.Test)

Example 20 with Assert.assertTrue

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

the class ChangeIdentityPermissionTest method addRoleWithSubprocessManagerTest.

@Test
public void addRoleWithSubprocessManagerTest() {
    ZonedDateTime now = ZonedDateTime.now().truncatedTo(ChronoUnit.MILLIS);
    getHelper().waitForResult(null, 1, 1);
    loginAsAdmin();
    IdmIdentityDto test1 = identityService.getByUsername(InitTestDataProcessor.TEST_USER_1);
    IdmIdentityDto test2 = identityService.getByUsername(InitTestDataProcessor.TEST_USER_2);
    // Guarantee
    int priority = 500;
    IdmRoleDto role = getHelper().createRole();
    role.setPriority(priority);
    IdmRoleDto directRole = roleService.save(role);
    getHelper().createRoleGuarantee(directRole, test2);
    IdmRoleDto subRole = getHelper().createRole();
    getHelper().createRoleComposition(role, subRole);
    configurationService.setValue(IdmRoleService.WF_BY_ROLE_PRIORITY_PREFIX + priority, APPROVE_ROLE_BY_MANAGER_KEY);
    IdmIdentityContractDto contract = getHelper().getPrimeContract(test1.getId());
    IdmRoleRequestDto request = createRoleRequest(test1);
    request = roleRequestService.save(request);
    IdmConceptRoleRequestDto concept = createRoleConcept(directRole, contract, request);
    concept = conceptRoleRequestService.save(concept);
    roleRequestService.startRequestInternal(request.getId(), true);
    request = roleRequestService.get(request.getId());
    assertEquals(RoleRequestState.IN_PROGRESS, request.getState());
    WorkflowFilterDto taskFilter = new WorkflowFilterDto();
    taskFilter.setCreatedAfter(now);
    taskFilter.setCandidateOrAssigned(securityService.getCurrentUsername());
    List<WorkflowTaskInstanceDto> tasks = workflowTaskInstanceService.find(taskFilter, null).getContent();
    assertEquals(0, tasks.size());
    // HELPDESK - must be skipped
    // MANAGER
    loginAsAdmin(InitTestDataProcessor.TEST_USER_2);
    taskFilter.setCandidateOrAssigned(InitTestDataProcessor.TEST_USER_2);
    checkAndCompleteOneTask(taskFilter, InitTestDataProcessor.TEST_USER_1, "approve");
    // USER MANAGER
    loginAsAdmin();
    taskFilter.setCandidateOrAssigned(InitTestDataProcessor.TEST_ADMIN_USERNAME);
    checkAndCompleteOneTask(taskFilter, InitTestDataProcessor.TEST_USER_1, "approve");
    // Subprocess - approve by Manager
    request = roleRequestService.get(request.getId());
    loginAsAdmin(InitTestDataProcessor.TEST_USER_2);
    taskFilter.setCandidateOrAssigned(InitTestDataProcessor.TEST_USER_2);
    checkAndCompleteOneTask(taskFilter, InitTestDataProcessor.TEST_USER_1, "approve");
    // SECURITY
    loginAsAdmin();
    taskFilter.setCandidateOrAssigned(InitTestDataProcessor.TEST_ADMIN_USERNAME);
    checkAndCompleteOneTask(taskFilter, InitTestDataProcessor.TEST_USER_1, "approve");
    request = roleRequestService.get(request.getId());
    assertEquals(RoleRequestState.EXECUTED, request.getState());
    assertNotNull(request.getWfProcessId());
    concept = conceptRoleRequestService.get(concept.getId());
    assertNotNull(concept.getWfProcessId());
    List<IdmIdentityRoleDto> assigedRoles = identityRoleService.findAllByContract(contract.getId());
    Assert.assertEquals(2, assigedRoles.size());
    Assert.assertTrue(assigedRoles.stream().anyMatch(ir -> ir.getRole().equals(directRole.getId())));
    Assert.assertTrue(assigedRoles.stream().anyMatch(ir -> ir.getRole().equals(subRole.getId())));
}
Also used : RuntimeService(org.activiti.engine.RuntimeService) IdmConceptRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmConceptRoleRequestService) IdmRequestIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestIdentityRoleDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) ZonedDateTime(java.time.ZonedDateTime) WorkflowProcessInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowProcessInstanceDto) Autowired(org.springframework.beans.factory.annotation.Autowired) WorkflowTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto) SecurityService(eu.bcvsolutions.idm.core.security.api.service.SecurityService) IdmRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmRoleRequestService) CoreGroupPermission(eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission) IdmRequestIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmRequestIdentityRoleService) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) After(org.junit.After) WorkflowTaskInstanceService(eu.bcvsolutions.idm.core.workflow.service.WorkflowTaskInstanceService) Assert.fail(org.junit.Assert.fail) LoginService(eu.bcvsolutions.idm.core.security.api.service.LoginService) IdentityLink(org.activiti.engine.task.IdentityLink) IdmIdentityContractService(eu.bcvsolutions.idm.core.api.service.IdmIdentityContractService) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) Set(java.util.Set) UUID(java.util.UUID) Page(org.springframework.data.domain.Page) RoleConfiguration(eu.bcvsolutions.idm.core.api.config.domain.RoleConfiguration) WorkflowHistoricProcessInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowHistoricProcessInstanceDto) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) LocalDate(java.time.LocalDate) IdmRoleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleRequestFilter) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) RoleRequestedByType(eu.bcvsolutions.idm.core.api.domain.RoleRequestedByType) IdmConfigurationService(eu.bcvsolutions.idm.core.api.service.IdmConfigurationService) IdentityLinkType(org.activiti.engine.task.IdentityLinkType) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) AbstractCoreWorkflowIntegrationTest(eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) InitTestDataProcessor(eu.bcvsolutions.idm.core.model.event.processor.module.InitTestDataProcessor) WorkflowProcessInstanceService(eu.bcvsolutions.idm.core.workflow.service.WorkflowProcessInstanceService) WorkflowFilterDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) WorkflowHistoricTaskInstanceService(eu.bcvsolutions.idm.core.workflow.service.WorkflowHistoricTaskInstanceService) Before(org.junit.Before) IdmIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService) WorkflowHistoricProcessInstanceService(eu.bcvsolutions.idm.core.workflow.service.WorkflowHistoricProcessInstanceService) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) Assert.assertNotNull(org.junit.Assert.assertNotNull) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmRoleService(eu.bcvsolutions.idm.core.api.service.IdmRoleService) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) RoleRequestState(eu.bcvsolutions.idm.core.api.domain.RoleRequestState) IdmIncompatibleRoleService(eu.bcvsolutions.idm.core.api.service.IdmIncompatibleRoleService) HttpStatus(org.springframework.http.HttpStatus) Assert.assertNull(org.junit.Assert.assertNull) ChronoUnit(java.time.temporal.ChronoUnit) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) WorkflowHistoricTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowHistoricTaskInstanceDto) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) ResolvedIncompatibleRoleDto(eu.bcvsolutions.idm.core.api.dto.ResolvedIncompatibleRoleDto) IdmRequestIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestIdentityRoleFilter) IdmGroupPermission(eu.bcvsolutions.idm.core.security.api.domain.IdmGroupPermission) Assert(org.junit.Assert) IdmIncompatibleRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIncompatibleRoleDto) ConceptRoleRequestOperation(eu.bcvsolutions.idm.core.api.domain.ConceptRoleRequestOperation) Assert.assertEquals(org.junit.Assert.assertEquals) Transactional(org.springframework.transaction.annotation.Transactional) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) WorkflowTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto) ZonedDateTime(java.time.ZonedDateTime) WorkflowFilterDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) AbstractCoreWorkflowIntegrationTest(eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest) Test(org.junit.Test)

Aggregations

Assert (org.junit.Assert)88 Assert.assertTrue (org.junit.Assert.assertTrue)88 Test (org.junit.Test)88 Assert.assertEquals (org.junit.Assert.assertEquals)84 List (java.util.List)82 Before (org.junit.Before)67 UUID (java.util.UUID)55 Assert.assertFalse (org.junit.Assert.assertFalse)54 Autowired (org.springframework.beans.factory.annotation.Autowired)53 Assert.assertNotNull (org.junit.Assert.assertNotNull)52 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)51 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)51 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)49 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)48 Transactional (org.springframework.transaction.annotation.Transactional)46 After (org.junit.After)44 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)42 ApplicationContext (org.springframework.context.ApplicationContext)38 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)37 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)36