use of org.junit.Assert.assertTrue in project CzechIdMng by bcvsolutions.
the class DefaultFormServiceIntegrationTest method testMinMaxValidation.
@Test
public void testMinMaxValidation() {
// prepare form definition a test saving form values
IdmFormAttributeDto attributeDouble = new IdmFormAttributeDto();
String attributeDoubleName = getHelper().createName();
attributeDouble.setCode(attributeDoubleName);
attributeDouble.setName(attributeDoubleName);
attributeDouble.setPersistentType(PersistentType.DOUBLE);
attributeDouble.setMin(new BigDecimal("0.5"));
attributeDouble.setMax(new BigDecimal("0.7"));
IdmFormAttributeDto attributeLong = new IdmFormAttributeDto();
String attributeLongName = getHelper().createName();
attributeLong.setCode(attributeLongName);
attributeLong.setName(attributeLongName);
attributeLong.setPersistentType(PersistentType.LONG);
attributeLong.setMin(new BigDecimal("10"));
attributeLong.setMax(new BigDecimal("20"));
IdmFormAttributeDto attributeInt = new IdmFormAttributeDto();
String attributeIntName = getHelper().createName();
attributeInt.setCode(attributeIntName);
attributeInt.setName(attributeIntName);
attributeInt.setPersistentType(PersistentType.INT);
attributeInt.setMin(new BigDecimal("10.1"));
attributeInt.setMax(new BigDecimal("20"));
IdmFormDefinitionDto formDefinitionOne = formService.createDefinition(IdmIdentity.class.getCanonicalName(), getHelper().createName(), Lists.newArrayList(attributeDouble, attributeInt, attributeLong));
attributeDouble = formDefinitionOne.getMappedAttributeByCode(attributeDouble.getCode());
attributeInt = formDefinitionOne.getMappedAttributeByCode(attributeInt.getCode());
attributeLong = formDefinitionOne.getMappedAttributeByCode(attributeLong.getCode());
//
IdmFormValueDto valueDouble = new IdmFormValueDto(attributeDouble);
IdmFormValueDto valueInt = new IdmFormValueDto(attributeInt);
IdmFormValueDto valueLong = new IdmFormValueDto(attributeLong);
//
IdmFormInstanceDto formInstance = new IdmFormInstanceDto();
formInstance.setFormDefinition(formDefinitionOne);
formInstance.setValues(Lists.newArrayList(valueDouble, valueInt, valueLong));
//
List<InvalidFormAttributeDto> validationErrors = formService.validate(formInstance);
//
Assert.assertTrue(validationErrors.isEmpty());
//
valueDouble.setDoubleValue(new BigDecimal("0.4"));
valueInt.setLongValue(4L);
valueLong.setLongValue(4L);
//
validationErrors = formService.validate(formInstance);
Assert.assertEquals(3, validationErrors.size());
Assert.assertTrue(validationErrors.stream().allMatch(e -> e.getMinValue() != null));
Assert.assertTrue(validationErrors.stream().anyMatch(e -> e.getMinValue().equals(new BigDecimal("0.5")) && e.getAttributeCode().equals(attributeDoubleName)));
Assert.assertTrue(validationErrors.stream().anyMatch(e -> e.getMinValue().equals(new BigDecimal("10.1")) && e.getAttributeCode().equals(attributeIntName)));
Assert.assertTrue(validationErrors.stream().anyMatch(e -> e.getMinValue().equals(new BigDecimal("10")) && e.getAttributeCode().equals(attributeLongName)));
//
valueDouble.setDoubleValue(new BigDecimal("0.8"));
valueInt.setLongValue(40L);
valueLong.setLongValue(40L);
//
validationErrors = formService.validate(formInstance);
Assert.assertEquals(3, validationErrors.size());
Assert.assertTrue(validationErrors.stream().allMatch(e -> e.getMaxValue() != null));
Assert.assertTrue(validationErrors.stream().anyMatch(e -> e.getMaxValue().equals(new BigDecimal("0.7")) && e.getAttributeCode().equals(attributeDoubleName)));
Assert.assertTrue(validationErrors.stream().anyMatch(e -> e.getMaxValue().equals(new BigDecimal("20")) && e.getAttributeCode().equals(attributeIntName)));
Assert.assertTrue(validationErrors.stream().anyMatch(e -> e.getMaxValue().equals(new BigDecimal("20")) && e.getAttributeCode().equals(attributeLongName)));
//
valueDouble.setDoubleValue(new BigDecimal("0.5"));
valueInt.setLongValue(11L);
valueLong.setLongValue(10L);
//
validationErrors = formService.validate(formInstance);
Assert.assertTrue(validationErrors.isEmpty());
//
valueDouble.setDoubleValue(new BigDecimal("0.7"));
valueInt.setLongValue(20L);
valueLong.setLongValue(20L);
//
validationErrors = formService.validate(formInstance);
Assert.assertTrue(validationErrors.isEmpty());
//
valueDouble.setDoubleValue(new BigDecimal("0.6"));
valueInt.setLongValue(15L);
valueLong.setLongValue(15L);
//
validationErrors = formService.validate(formInstance);
Assert.assertTrue(validationErrors.isEmpty());
}
use of org.junit.Assert.assertTrue in project CzechIdMng by bcvsolutions.
the class IdentityFilterTest method testIdentifiers.
@Test
public void testIdentifiers() {
List<IdmIdentityDto> identities = createIdentities(10);
IdmIdentityDto identityOne = identities.get(1);
IdmIdentityDto identityTwo = identities.get(2);
IdmIdentityDto identityThree = identities.get(3);
IdmIdentityDto identityFive = identities.get(5);
IdmIdentityDto identityNine = identities.get(9);
identityOne.setExternalCode("identityOneExternalCode" + System.currentTimeMillis());
identityTwo.setUsername("identityTwoUsername" + System.currentTimeMillis());
identityThree.setLastName(getHelper().createName());
identityFive.setUsername("identityFiveUsername" + System.currentTimeMillis());
identityFive.setExternalCode("identityFiveExternalCode" + System.currentTimeMillis());
identityNine.setExternalCode("identityNineExternalCode" + System.currentTimeMillis());
identityNine.setUsername("identityNineUsername" + System.currentTimeMillis());
identityOne = identityService.save(identityOne);
UUID identityOneId = identityOne.getId();
identityTwo = identityService.save(identityTwo);
UUID identityTwoId = identityTwo.getId();
identityThree = identityService.save(identityThree);
UUID identityThreeId = identityThree.getId();
identityFive = identityService.save(identityFive);
UUID identityFiveId = identityFive.getId();
identityNine = identityService.save(identityNine);
UUID identityNineId = identityNine.getId();
IdmIdentityFilter filter = new IdmIdentityFilter();
List<String> identifiers = new ArrayList<>();
identifiers.add(identityOne.getExternalCode());
identifiers.add(identityTwo.getUsername());
identifiers.add(identityThree.getLastName());
identifiers.add(identityFive.getExternalCode());
identifiers.add(identityFive.getUsername());
identifiers.add(identityNine.getExternalCode());
identifiers.add(identityNine.getUsername());
filter.setIdentifiers(identifiers);
List<IdmIdentityDto> results = identityService.find(filter, null).getContent();
Assert.assertEquals(5, results.size());
Assert.assertTrue(results.stream().anyMatch(i -> i.getId().equals(identityOneId)));
Assert.assertTrue(results.stream().anyMatch(i -> i.getId().equals(identityTwoId)));
Assert.assertTrue(results.stream().anyMatch(i -> i.getId().equals(identityThreeId)));
Assert.assertTrue(results.stream().anyMatch(i -> i.getId().equals(identityFiveId)));
Assert.assertTrue(results.stream().anyMatch(i -> i.getId().equals(identityNineId)));
}
use of org.junit.Assert.assertTrue in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleRequestServiceIntegrationTest method testUpdateSubRoleByRequest.
@Test
@Transactional
public void testUpdateSubRoleByRequest() {
IdmRoleDto superior = getHelper().createRole();
IdmRoleDto sub = getHelper().createRole();
getHelper().createRoleComposition(superior, sub);
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
//
IdmRoleRequestDto request = getHelper().assignRoles(getHelper().getPrimeContract(identity), false, superior);
//
Assert.assertEquals(2, request.getConceptRoles().size());
List<IdmIdentityRoleDto> assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertEquals(2, assignedRoles.size());
Assert.assertTrue(assignedRoles.stream().allMatch(ir -> ir.getValidTill() == null));
IdmIdentityRoleDto directlyAssignedRole = assignedRoles.stream().filter(ir -> ir.getDirectRole() == null).findFirst().get();
Assert.assertEquals(superior.getId(), directlyAssignedRole.getRole());
//
// change superior role validity by concept
request = new IdmRoleRequestDto();
request.setApplicant(identity.getId());
request.setExecuteImmediately(true);
request.setRequestedByType(RoleRequestedByType.MANUALLY);
request.setState(RoleRequestState.EXECUTED);
request = roleRequestService.save(request);
Assert.assertEquals(RoleRequestState.CONCEPT, request.getState());
LocalDate validTill = LocalDate.now().plusMonths(1);
IdmConceptRoleRequestDto concept = new IdmConceptRoleRequestDto();
concept.setRoleRequest(request.getId());
concept.setState(RoleRequestState.EXECUTED);
concept.setOperation(ConceptRoleRequestOperation.UPDATE);
concept.setRole(superior.getId());
concept.setIdentityRole(directlyAssignedRole.getId());
concept.setValidTill(validTill);
concept.setIdentityContract(directlyAssignedRole.getIdentityContract());
concept = conceptRoleRequestService.save(concept);
Assert.assertEquals(RoleRequestState.CONCEPT, concept.getState());
getHelper().startRequestInternal(request, true, true);
request = roleRequestService.get(request.getId());
Assert.assertEquals(RoleRequestState.EXECUTED, request.getState());
//
assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertEquals(2, assignedRoles.size());
Assert.assertTrue(assignedRoles.stream().allMatch(ir -> ir.getValidTill().equals(validTill)));
//
// and remove
request = new IdmRoleRequestDto();
request.setApplicant(identity.getId());
request.setExecuteImmediately(true);
request.setRequestedByType(RoleRequestedByType.MANUALLY);
request.setState(RoleRequestState.EXECUTED);
request = roleRequestService.save(request);
Assert.assertEquals(RoleRequestState.CONCEPT, request.getState());
concept = new IdmConceptRoleRequestDto();
concept.setRoleRequest(request.getId());
concept.setState(RoleRequestState.EXECUTED);
concept.setOperation(ConceptRoleRequestOperation.REMOVE);
concept.setRole(superior.getId());
concept.setIdentityRole(directlyAssignedRole.getId());
concept.setIdentityContract(directlyAssignedRole.getIdentityContract());
concept = conceptRoleRequestService.save(concept);
Assert.assertEquals(RoleRequestState.CONCEPT, concept.getState());
getHelper().startRequestInternal(request, true, true);
request = roleRequestService.get(request.getId());
Assert.assertEquals(RoleRequestState.EXECUTED, request.getState());
assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertTrue(assignedRoles.isEmpty());
}
use of org.junit.Assert.assertTrue in project CzechIdMng by bcvsolutions.
the class DefaultProvisioningExecutorIntegrationTest method testAsynchronousQueueSynchronized.
@Test
public void testAsynchronousQueueSynchronized() throws Exception {
//
// schedule task to process queue async
Task task = new Task();
task.setInstanceId(configurationService.getInstanceId());
task.setTaskType(ProvisioningQueueTaskExecutor.class);
task = schedulerManager.createTask(task);
CronTaskTrigger trigger = new CronTaskTrigger();
trigger.setTaskId(task.getId());
trigger.setCron("0/5 * * * * ?");
//
schedulerManager.createTrigger(task.getId(), trigger);
//
// turn on async processing
getHelper().enableAsynchronousProcessing();
//
try {
int count = 50;
// system with asynchronous provisioning
SysSystemDto system = getHelper().createTestResourceSystem(true);
system.setQueue(true);
system = systemService.save(system);
//
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmRoleDto role = getHelper().createRole();
getHelper().createRoleSystem(role, system);
getHelper().createIdentityRole(identity, role);
//
for (int index = 0; index < count; index++) {
// async provisioning by the notify event
entityEventManager.changedEntity(identity);
Thread.sleep(25);
}
//
IdmEntityEventFilter eventFilter = new IdmEntityEventFilter();
eventFilter.setOwnerId(identity.getId());
eventFilter.setTransactionId(identity.getTransactionId());
eventFilter.setStates(Lists.newArrayList(OperationState.CREATED, OperationState.RUNNING));
getHelper().waitForResult(res -> {
return entityEventService.find(eventFilter, PageRequest.of(0, 1)).getTotalElements() != 0;
});
//
// check archive is executed
SysProvisioningOperationFilter filter = new SysProvisioningOperationFilter();
filter.setEntityIdentifier(identity.getId());
getHelper().waitForResult(res -> {
return provisioningArchiveService.find(filter, null).getContent().isEmpty();
});
List<SysProvisioningArchiveDto> archives = provisioningArchiveService.find(filter, null).getContent();
Assert.assertFalse(archives.isEmpty());
Assert.assertTrue(archives.stream().allMatch(a -> a.getResultState().isSuccessful()));
} finally {
schedulerManager.deleteTask(task.getId());
getHelper().disableAsynchronousProcessing();
}
}
use of org.junit.Assert.assertTrue in project CzechIdMng by bcvsolutions.
the class DefaultProvisioningExecutorIntegrationTest method testRetryProvisioning.
@Test
public void testRetryProvisioning() {
testProvisioningExceptionProcessor.setDisabled(false);
try {
SysSystemDto system = getHelper().createTestResourceSystem(true);
SysProvisioningOperationDto provisioningOperation = createProvisioningOperation(system, "firstname");
Map<ProvisioningAttributeDto, Object> accoutObject = provisioningOperation.getProvisioningContext().getAccountObject();
String uid = (String) accoutObject.get(getProvisioningAttribute(TestHelper.ATTRIBUTE_MAPPING_NAME));
ZonedDateTime now = ZonedDateTime.now();
//
// publish event
// 1 - create
provisioningExecutor.execute(provisioningOperation);
// is necessary to get again operation from service
SysProvisioningOperationFilter filter = new SysProvisioningOperationFilter();
filter.setSystemEntityUid(provisioningOperation.getSystemEntityUid());
filter.setSystemId(system.getId());
SysProvisioningOperationDto operation = provisioningOperationService.find(filter, null).getContent().get(0);
SysProvisioningBatchDto batch = provisioningBatchService.findBatch(operation.getSystemEntity());
Assert.assertEquals(OperationState.EXCEPTION, operation.getResultState());
Assert.assertEquals(AccResultCode.PROVISIONING_FAILED.name(), operation.getResult().getModel().getStatusEnum());
Assert.assertEquals(1, operation.getCurrentAttempt());
Assert.assertTrue(operation.getMaxAttempts() > 1);
Assert.assertTrue(batch.getNextAttempt().isAfter(now));
SysSystemEntityDto systemEntity = systemEntityService.getBySystemAndEntityTypeAndUid(system, SystemEntityType.IDENTITY, uid);
Assert.assertTrue(systemEntity.isWish());
Assert.assertNull(getHelper().findResource(uid));
// check failed operation is in archive too
List<SysProvisioningArchiveDto> archived = provisioningArchiveService.find(filter, PageRequest.of(0, 10, new Sort(Direction.DESC, SysProvisioningArchive_.created.getName()))).getContent();
Assert.assertEquals(1, archived.size());
Assert.assertEquals(OperationState.EXCEPTION, archived.get(0).getResultState());
Assert.assertEquals(AccResultCode.PROVISIONING_FAILED.name(), archived.get(0).getResult().getModel().getStatusEnum());
//
batch.setNextAttempt(ZonedDateTime.now());
provisioningBatchService.save(batch);
//
// retry - the same exception expected
RetryProvisioningTaskExecutor retryProvisioningTaskExecutor = new RetryProvisioningTaskExecutor();
Boolean result = longRunningTaskManager.executeSync(retryProvisioningTaskExecutor);
Assert.assertTrue(result);
operation = provisioningOperationService.get(operation.getId());
batch = provisioningBatchService.findBatch(systemEntity.getId());
Assert.assertEquals(2, operation.getCurrentAttempt());
Assert.assertNotNull(batch.getNextAttempt());
Assert.assertTrue(batch.getNextAttempt().isAfter(now));
archived = provisioningArchiveService.find(filter, PageRequest.of(0, 10, new Sort(Direction.DESC, SysProvisioningArchive_.created.getName()))).getContent();
Assert.assertEquals(2, archived.size());
Assert.assertEquals(OperationState.EXCEPTION, archived.get(0).getResultState());
Assert.assertEquals(AccResultCode.PROVISIONING_FAILED.name(), archived.get(0).getResult().getModel().getStatusEnum());
//
batch.setNextAttempt(ZonedDateTime.now());
provisioningBatchService.save(batch);
//
// retry - expected success now
testProvisioningExceptionProcessor.setDisabled(true);
retryProvisioningTaskExecutor = new RetryProvisioningTaskExecutor();
longRunningTaskManager.executeSync(retryProvisioningTaskExecutor);
//
systemEntity = systemEntityService.getBySystemAndEntityTypeAndUid(system, SystemEntityType.IDENTITY, uid);
Assert.assertFalse(systemEntity.isWish());
Assert.assertNotNull(getHelper().findResource(uid));
batch = provisioningBatchService.get(batch.getId());
Assert.assertNull(batch.getNextAttempt());
archived = provisioningArchiveService.find(filter, PageRequest.of(0, 10, new Sort(Direction.DESC, SysProvisioningArchive_.created.getName()))).getContent();
Assert.assertEquals(3, archived.size());
Assert.assertTrue(archived.stream().anyMatch(a -> a.getResultState() == OperationState.EXECUTED));
} finally {
testProvisioningExceptionProcessor.setDisabled(true);
}
}
Aggregations