use of org.junit.Assert.assertTrue in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityContractServiceIntegrationTest method testSkipAndRemoveAutomaticRoleOnInvalidContract.
@Test
public void testSkipAndRemoveAutomaticRoleOnInvalidContract() {
IdmTreeNodeDto node = getHelper().createTreeNode();
// define automatic role for parent
IdmRoleDto role = getHelper().createRole();
IdmRoleDto subRole = getHelper().createRole();
getHelper().createRoleComposition(role, subRole);
IdmRoleTreeNodeDto automaticRole = getHelper().createRoleTreeNode(role, node, RecursionType.NO, true);
// create identity with contract on node
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmIdentityContractDto contract = getHelper().createContract(identity, node);
// role should be assigned now
List<IdmIdentityRoleDto> assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertEquals(2, assignedRoles.size());
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> automaticRole.getId().equals(ir.getAutomaticRole())));
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getDirectRole() != null));
//
contract.setValidTill(LocalDate.now().minusDays(2));
EntityEvent<IdmIdentityContractDto> event = new IdentityContractEvent(IdentityContractEventType.UPDATE, contract);
event.getProperties().put(AutomaticRoleManager.SKIP_RECALCULATION, Boolean.TRUE);
contract = service.publish(event).getContent();
UUID contractId = contract.getId();
IdmEntityStateFilter filter = new IdmEntityStateFilter();
filter.setStates(Lists.newArrayList(OperationState.BLOCKED));
filter.setResultCode(CoreResultCode.AUTOMATIC_ROLE_SKIPPED_INVALID_CONTRACT.getCode());
filter.setOwnerType(entityStateManager.getOwnerType(IdmIdentityContractDto.class));
List<IdmEntityStateDto> skippedStates = entityStateManager.findStates(filter, null).getContent();
Assert.assertTrue(skippedStates.stream().anyMatch(s -> s.getOwnerId().equals(contractId)));
//
assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertEquals(2, assignedRoles.size());
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> automaticRole.getId().equals(ir.getAutomaticRole())));
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getDirectRole() != null));
//
// recount skipped automatic roles
longRunningTaskManager.execute(new ProcessSkippedAutomaticRoleByTreeForContractTaskExecutor());
skippedStates = entityStateManager.findStates(filter, null).getContent();
Assert.assertFalse(skippedStates.stream().anyMatch(s -> s.getOwnerId().equals(automaticRole.getId())));
//
assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertTrue(assignedRoles.isEmpty());
}
use of org.junit.Assert.assertTrue in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityContractServiceIntegrationTest method testFindExcludedContracts.
@Test
public void testFindExcludedContracts() {
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
//
IdmIdentityContractDto contract = getHelper().getPrimeContract(identity.getId());
contract.setState(ContractState.EXCLUDED);
contract = service.save(contract);
IdmIdentityContractDto disabled = getHelper().createContract(identity);
disabled.setState(ContractState.DISABLED);
contract = service.save(contract);
IdmIdentityContractDto valid = getHelper().createContract(identity);
//
IdmIdentityContractFilter filter = new IdmIdentityContractFilter();
filter.setIdentity(identity.getId());
filter.setExcluded(Boolean.TRUE);
List<IdmIdentityContractDto> contracts = service.find(filter, null).getContent();
//
Assert.assertEquals(1, contracts.size());
Assert.assertEquals(contract.getId(), contracts.get(0).getId());
//
filter.setExcluded(Boolean.FALSE);
contracts = service.find(filter, null).getContent();
Assert.assertEquals(2, contracts.size());
Assert.assertTrue(contracts.stream().anyMatch(c -> c.getId().equals(disabled.getId())));
Assert.assertTrue(contracts.stream().anyMatch(c -> c.getId().equals(valid.getId())));
}
use of org.junit.Assert.assertTrue in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityContractServiceIntegrationTest method testAssignAutomaticRoleToExistIdentityAsync.
@Test
public void testAssignAutomaticRoleToExistIdentityAsync() {
IdmIdentityDto identityOne = getHelper().createIdentityOnly();
IdmIdentityDto identityTwo = getHelper().createIdentityOnly();
IdmIdentityDto identityThree = getHelper().createIdentityOnly();
IdmTreeNodeDto treeNode = getHelper().createTreeNode();
IdmIdentityContractDto contractOne = getHelper().createContract(identityOne, treeNode);
IdmIdentityContractDto contractTwo = getHelper().createContract(identityTwo, treeNode);
IdmIdentityContractDto contractThree = getHelper().createContract(identityThree, treeNode);
IdmRoleDto role = getHelper().createRole();
//
List<IdmLongRunningTaskDto> lrts = null;
getHelper().setConfigurationValue(EventConfiguration.PROPERTY_EVENT_ASYNCHRONOUS_ENABLED, true);
getHelper().setConfigurationValue(SchedulerConfiguration.PROPERTY_TASK_ASYNCHRONOUS_ENABLED, true);
try {
IdmRoleTreeNodeDto automaticRole = getHelper().createAutomaticRole(role, treeNode);
//
getHelper().waitForResult(res -> {
return identityRoleService.findByAutomaticRole(automaticRole.getId(), null).getTotalElements() != 3;
}, 500, 30);
getHelper().waitForResult(res -> {
IdmLongRunningTaskFilter filter = new IdmLongRunningTaskFilter();
filter.setRunning(Boolean.TRUE);
//
return taskManager.findLongRunningTasks(filter, null).getTotalElements() != 0;
});
//
List<IdmIdentityRoleDto> assignedRoles = identityRoleService.findByAutomaticRole(automaticRole.getId(), null).getContent();
Assert.assertEquals(3, assignedRoles.size());
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getIdentityContract().equals(contractOne.getId())));
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getIdentityContract().equals(contractTwo.getId())));
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getIdentityContract().equals(contractThree.getId())));
//
// check asynchronous LRT
IdmLongRunningTaskFilter filter = new IdmLongRunningTaskFilter();
filter.setTransactionId(assignedRoles.get(0).getTransactionId());
lrts = taskManager.findLongRunningTasks(filter, null).getContent();
Assert.assertFalse(lrts.isEmpty());
Assert.assertTrue(lrts.stream().allMatch(lrt -> lrt.getResultState() == OperationState.EXECUTED));
//
// and check lrt start event is properly created and ended
IdmEntityEventFilter eventFilter = new IdmEntityEventFilter();
eventFilter.setOwnerType(entityEventManager.getOwnerType(IdmLongRunningTaskDto.class));
eventFilter.setTransactionId(assignedRoles.get(0).getTransactionId());
List<IdmEntityEventDto> events = entityEventManager.findEvents(eventFilter, null).getContent();
Assert.assertFalse(events.isEmpty());
Assert.assertTrue(events.stream().allMatch(event -> event.getResult().getState() == OperationState.EXECUTED));
Assert.assertTrue(events.stream().allMatch(event -> event.getEventStarted() != null));
Assert.assertTrue(events.stream().allMatch(event -> event.getEventEnded() != null));
Assert.assertTrue(events.stream().anyMatch(event -> event.getEventType().equals(LongRunningTaskEventType.START.name())));
} finally {
getHelper().setConfigurationValue(EventConfiguration.PROPERTY_EVENT_ASYNCHRONOUS_ENABLED, false);
getHelper().setConfigurationValue(SchedulerConfiguration.PROPERTY_TASK_ASYNCHRONOUS_ENABLED, false);
//
if (lrts != null) {
lrts.forEach(lrt -> {
if (lrt.isRunning() || lrt.getResultState() == OperationState.RUNNING) {
taskManager.cancel(lrt.getId());
}
});
}
}
}
use of org.junit.Assert.assertTrue in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleAttributeServiceIntegrationTest method testRecalculationWithManyIdentities.
@Test
@Ignore
public void testRecalculationWithManyIdentities() {
String description = getHelper().createName();
List<IdmIdentityDto> identities = new ArrayList<IdmIdentityDto>();
try {
//
for (int index = 0; index < 187; index++) {
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
identity.setDescription(description);
identityService.save(identity);
identities.add(identity);
}
assertEquals(187, identities.size());
IdmRoleDto role = getHelper().createRole();
IdmRoleDto subRole = getHelper().createRole();
getHelper().createRoleComposition(role, subRole);
IdmAutomaticRoleAttributeDto automaticRole = getHelper().createAutomaticRole(role.getId());
getHelper().createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY, IdmIdentity_.description.getName(), null, description);
// turn on async processing
getHelper().setConfigurationValue(EventConfiguration.PROPERTY_EVENT_ASYNCHRONOUS_ENABLED, true);
//
// execute recalculation
automaticRoleAttributeService.recalculate(automaticRole.getId());
//
// wait for result
IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
filter.setAutomaticRoleId(automaticRole.getId());
getHelper().waitForResult(res -> {
return identityRoleService.count(filter) != 187;
}, 1000, 300);
List<IdmIdentityRoleDto> identityRoles = identityRoleService.find(filter, null).getContent();
Assert.assertEquals(187, identityRoles.size());
for (IdmIdentityDto identity : identities) {
List<IdmIdentityRoleDto> allByIdentity = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertEquals(2, allByIdentity.size());
Assert.assertTrue(allByIdentity.stream().anyMatch(ir -> automaticRole.getId().equals(ir.getAutomaticRole()) && ir.getRole().equals(role.getId())));
Assert.assertTrue(allByIdentity.stream().anyMatch(ir -> ir.getDirectRole() != null && ir.getRole().equals(subRole.getId())));
}
} finally {
// turn off async processing
getHelper().setConfigurationValue(EventConfiguration.PROPERTY_EVENT_ASYNCHRONOUS_ENABLED, false);
identityService.deleteAll(identities);
}
}
use of org.junit.Assert.assertTrue 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());
}));
}
Aggregations