use of org.junit.Assert.assertTrue in project CzechIdMng by bcvsolutions.
the class IdentityPasswordProvisioningTest method testSendPasswordNotificationCreateCancelled.
@Test
public void testSendPasswordNotificationCreateCancelled() {
// init readOnly system
SysSystemDto system = initSystem();
system.setReadonly(true);
system = systemService.save(system);
IdmRoleDto role = initRole(system);
IdmIdentityDto identity = helper.createIdentity();
// CREATE operation
IdmIdentityRoleDto identityRole = helper.createIdentityRole(identity, role);
checkIdentityAccount(identity, identityRole, 1);
// => new password is sent for valid identity only
identity.setState(IdentityState.VALID);
identity.setFirstName(getHelper().createName());
// UPDATE operation
identityService.save(identity);
//
AccAccountDto account = accountService.getAccount(identity.getUsername(), system.getId());
Assert.assertNotNull(account);
TestResource entityOnSystem = helper.findResource(account.getUid());
Assert.assertNull(entityOnSystem);
//
// Check for send password notification
IdmNotificationFilter notificationFilter = new IdmNotificationFilter();
notificationFilter.setTopic(AccModuleDescriptor.TOPIC_NEW_PASSWORD);
notificationFilter.setRecipient(identity.getUsername());
List<IdmNotificationLogDto> notifications = //
notificationLogService.find(notificationFilter, null).getContent().stream().filter(//
notification -> IdmEmailLog.NOTIFICATION_TYPE.equals(notification.getType())).collect(Collectors.toList());
Assert.assertTrue(notifications.isEmpty());
//
// cancel the first provisioning operation
SysProvisioningOperationFilter filter = new SysProvisioningOperationFilter();
filter.setEntityType(SystemEntityType.IDENTITY);
filter.setEntityIdentifier(identity.getId());
List<SysProvisioningOperationDto> operations = provisioningOperationService.find(filter, null).getContent();
Assert.assertEquals(2, operations.size());
// ~ readonly
Assert.assertTrue(operations.stream().allMatch(o -> o.getResultState() == OperationState.NOT_EXECUTED));
SysProvisioningOperationDto createOperation = operations.stream().filter(o -> o.getOperationType() == ProvisioningEventType.CREATE).findFirst().get();
SysProvisioningOperationDto updateOperation = operations.stream().filter(o -> o.getOperationType() == ProvisioningEventType.UPDATE).findFirst().get();
//
// active system
system.setReadonly(false);
system = systemService.save(system);
//
// cancel the first operation
provisioningExecutor.cancel(createOperation);
operations = provisioningOperationService.find(filter, null).getContent();
Assert.assertEquals(1, operations.size());
notifications = //
notificationLogService.find(notificationFilter, null).getContent().stream().filter(//
notification -> IdmEmailLog.NOTIFICATION_TYPE.equals(notification.getType())).collect(Collectors.toList());
Assert.assertTrue(notifications.isEmpty());
//
provisioningExecutor.execute(updateOperation);
operations = provisioningOperationService.find(filter, null).getContent();
Assert.assertTrue(operations.isEmpty());
notifications = //
notificationLogService.find(notificationFilter, null).getContent().stream().filter(//
notification -> IdmEmailLog.NOTIFICATION_TYPE.equals(notification.getType())).collect(Collectors.toList());
Assert.assertEquals(1, notifications.size());
}
use of org.junit.Assert.assertTrue in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityContractServiceIntegrationTest method testSkipAndAssignAutomaticRoleOnContractAfterChange.
@Test
public void testSkipAndAssignAutomaticRoleOnContractAfterChange() {
IdmTreeNodeDto otherNode = getHelper().createTreeNode();
IdmTreeNodeDto node = getHelper().createTreeNode();
// define automatic role for parent
IdmRoleDto role = getHelper().createRole();
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, otherNode);
// no role should be assigned now
List<IdmIdentityRoleDto> assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertTrue(assignedRoles.isEmpty());
//
contract.setWorkPosition(node.getId());
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.getCode());
filter.setOwnerType(entityStateManager.getOwnerType(IdmIdentityContractDto.class));
List<IdmEntityStateDto> skippedStates = entityStateManager.findStates(filter, null).getContent();
Assert.assertFalse(skippedStates.isEmpty());
Assert.assertTrue(skippedStates.stream().anyMatch(s -> s.getOwnerId().equals(contractId)));
//
assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertTrue(assignedRoles.isEmpty());
//
// 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.assertEquals(1, assignedRoles.size());
Assert.assertEquals(automaticRole.getId(), assignedRoles.get(0).getAutomaticRole());
}
use of org.junit.Assert.assertTrue in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityContractServiceIntegrationTest method testChangeContractPositionWithAutomaticRolesAssigned.
@Test
public void testChangeContractPositionWithAutomaticRolesAssigned() {
prepareAutomaticRoles();
//
// prepare identity and contract
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmIdentityContractDto contract = new IdmIdentityContractDto();
contract.setIdentity(identity.getId());
contract.setWorkPosition(nodeD.getId());
contract = service.save(contract);
//
// test after create
List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByContract(contract.getId());
assertEquals(3, identityRoles.size());
Assert.assertTrue(identityRoles.stream().anyMatch(ir -> {
return roleA.getId().equals(ir.getRole());
}));
Assert.assertTrue(identityRoles.stream().anyMatch(ir -> {
return roleB.getId().equals(ir.getRole());
}));
Assert.assertTrue(identityRoles.stream().anyMatch(ir -> {
return roleC.getId().equals(ir.getRole());
}));
//
contract.setWorkPosition(nodeE.getId());
contract = service.save(contract);
//
// test after change
identityRoles = identityRoleService.findAllByContract(contract.getId());
assertEquals(3, identityRoles.size());
Assert.assertTrue(identityRoles.stream().anyMatch(ir -> {
return roleA.getId().equals(ir.getRole());
}));
Assert.assertTrue(identityRoles.stream().anyMatch(ir -> {
return roleB.getId().equals(ir.getRole());
}));
Assert.assertTrue(identityRoles.stream().anyMatch(ir -> {
return roleD.getId().equals(ir.getRole());
}));
}
use of org.junit.Assert.assertTrue in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityContractServiceIntegrationTest method testFindContractByOrPermissions.
@Test
public void testFindContractByOrPermissions() {
IdmIdentityDto identity = getHelper().createIdentity();
IdmIdentityContractDto contractOne = getHelper().createContract(identity);
IdmIdentityContractDto contractTwo = getHelper().createContract(identity);
// other - without permission
getHelper().createContract(identity);
//
IdmRoleDto role = getHelper().createRole();
getHelper().createUuidPolicy(role, contractOne, ContractBasePermission.CANBEREQUESTED);
getHelper().createUuidPolicy(role, contractTwo, ContractBasePermission.CHANGEPERMISSION);
//
IdmIdentityDto manager = getHelper().createIdentity();
getHelper().createIdentityRole(manager, role);
//
IdmIdentityContractFilter filter = new IdmIdentityContractFilter();
filter.setIdentity(identity.getId());
filter.setEvaluatePermissionOperator(PermissionContext.OPERATOR_OR);
//
// without login => empty
List<IdmIdentityContractDto> contracts = service.find(filter, null, ContractBasePermission.CANBEREQUESTED, ContractBasePermission.CHANGEPERMISSION).getContent();
Assert.assertTrue(contracts.isEmpty());
//
try {
getHelper().login(manager);
//
contracts = service.find(filter, null, ContractBasePermission.CANBEREQUESTED, ContractBasePermission.CHANGEPERMISSION).getContent();
Assert.assertEquals(2, contracts.size());
Assert.assertTrue(contracts.stream().anyMatch(c -> c.getId().equals(contractOne.getId())));
Assert.assertTrue(contracts.stream().anyMatch(c -> c.getId().equals(contractTwo.getId())));
//
contracts = service.find(filter, null, ContractBasePermission.CANBEREQUESTED).getContent();
Assert.assertEquals(1, contracts.size());
Assert.assertTrue(contracts.stream().anyMatch(c -> c.getId().equals(contractOne.getId())));
//
contracts = service.find(filter, null, ContractBasePermission.CHANGEPERMISSION).getContent();
Assert.assertEquals(1, contracts.size());
Assert.assertTrue(contracts.stream().anyMatch(c -> c.getId().equals(contractTwo.getId())));
//
filter.setEvaluatePermissionOperator(null);
contracts = service.find(filter, null, ContractBasePermission.CANBEREQUESTED, ContractBasePermission.CHANGEPERMISSION).getContent();
Assert.assertTrue(contracts.isEmpty());
//
filter.setEvaluatePermissionOperator(PermissionContext.OPERATOR_AND);
contracts = service.find(filter, null, ContractBasePermission.CANBEREQUESTED, ContractBasePermission.CHANGEPERMISSION).getContent();
Assert.assertTrue(contracts.isEmpty());
} finally {
getHelper().logout();
}
}
use of org.junit.Assert.assertTrue in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityContractServiceIntegrationTest method testCRUDContractWithAutomaticRoles.
@Test
public void testCRUDContractWithAutomaticRoles() {
prepareAutomaticRoles();
//
// prepare identity and contract
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmIdentityContractDto contractToCreate = service.getPrimeContract(identity.getId());
contractToCreate.setIdentity(identity.getId());
contractToCreate.setValidFrom(LocalDate.now().minusDays(1));
contractToCreate.setValidTill(LocalDate.now().plusMonths(1));
contractToCreate.setWorkPosition(nodeD.getId());
contractToCreate.setMain(true);
contractToCreate.setDescription("test-node-d");
service.save(contractToCreate);
//
IdmIdentityContractDto contract = service.getPrimeContract(identity.getId());
//
// test after create
Assert.assertEquals(nodeD.getId(), contract.getWorkPosition());
Assert.assertEquals("test-node-d", contract.getDescription());
List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByContract(contract.getId());
Assert.assertEquals(3, identityRoles.size());
Assert.assertTrue(identityRoles.stream().allMatch(ir -> contract.getValidFrom().equals(ir.getValidFrom())));
Assert.assertTrue(identityRoles.stream().allMatch(ir -> contract.getValidTill().equals(ir.getValidTill())));
Assert.assertTrue(identityRoles.stream().anyMatch(ir -> {
return roleA.getId().equals(ir.getRole());
}));
Assert.assertTrue(identityRoles.stream().anyMatch(ir -> {
return roleB.getId().equals(ir.getRole());
}));
Assert.assertTrue(identityRoles.stream().anyMatch(ir -> {
return roleC.getId().equals(ir.getRole());
}));
//
identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(3, identityRoles.size());
//
// test after delete
service.delete(contract);
assertTrue(identityRoleService.findAllByIdentity(identity.getId()).isEmpty());
}
Aggregations