use of org.junit.Assert.assertNotNull in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleFormAttributeServiceIntegrationTest method testSubDefinitionOverrideValidationReqex.
@Test
public void testSubDefinitionOverrideValidationReqex() {
String regex = "regex";
// 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 regex 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.assertNull(roleFormAttributeDto.getRegex());
roleFormAttributeDto.setRegex(regex);
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(regex, ipFormAttribute.getRegex());
}
use of org.junit.Assert.assertNotNull 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.assertNotNull in project CzechIdMng by bcvsolutions.
the class IdentityPasswordProvisioningTest method testSendPasswordNotificationGreenLine.
@Test
public void testSendPasswordNotificationGreenLine() {
SysSystemDto system = initSystem();
IdmRoleDto role = initRole(system);
IdmIdentityDto identity = helper.createIdentity();
IdmIdentityRoleDto identityRole = helper.createIdentityRole(identity, role);
checkIdentityAccount(identity, identityRole, 1);
AccAccountDto account = accountService.getAccount(identity.getUsername(), system.getId());
Assert.assertNotNull(account);
Assert.assertFalse(account.isInProtection());
TestResource entityOnSystem = helper.findResource(account.getUid());
assertNotNull(entityOnSystem);
assertEquals(DEFAULT_PASSWORD, entityOnSystem.getPassword());
// 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 -> "email".equals(notification.getType())).collect(Collectors.toList());
assertEquals(1, notifications.size());
}
use of org.junit.Assert.assertNotNull 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.assertNotNull in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityContractServiceIntegrationTest method testChangeContractPositionAndValidityWithAutomaticRolesAssigned.
@Test
public void testChangeContractPositionAndValidityWithAutomaticRolesAssigned() {
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());
//
// => role A is the same => down recursion
contract.setWorkPosition(nodeB.getId());
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(automaticRole.getId()) && // validity is changed
newValidTill.equals(ir.getValidTill());
}));
}
Aggregations