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));
}
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())));
}
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);
}
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)));
});
}
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())));
}
Aggregations