use of eu.bcvsolutions.idm.acc.dto.SysProvisioningBatchDto in project CzechIdMng by bcvsolutions.
the class DefaultProvisioningExecutorIntegrationTest method testRetryProvisioningAfterPrepareConnectorObjectFailed.
@Test
public void testRetryProvisioningAfterPrepareConnectorObjectFailed() {
SysSystemDto system = getHelper().createTestResourceSystem(true);
// set the wrong password
IdmFormDefinitionDto savedFormDefinition = systemService.getConnectorFormDefinition(system);
List<IdmFormValueDto> values = new ArrayList<>();
IdmFormValueDto password = new IdmFormValueDto(savedFormDefinition.getMappedAttributeByCode("password"));
password.setValue("wrong");
values.add(password);
formService.saveValues(system, savedFormDefinition, values);
//
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
// publish event
// 1 - create
provisioningExecutor.execute(provisioningOperation);
// is necessary to get again operation from service
SysProvisioningOperationFilter filter = new SysProvisioningOperationFilter();
filter.setSystemEntity(provisioningOperation.getSystemEntity());
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));
//
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));
//
batch.setNextAttempt(ZonedDateTime.now());
provisioningBatchService.save(batch);
//
// retry - expected success now - set the good password
password.setValue(((HikariDataSource) dataSource).getPassword());
formService.saveValues(system, savedFormDefinition, values);
//
retryProvisioningTaskExecutor = new RetryProvisioningTaskExecutor();
result = longRunningTaskManager.executeSync(retryProvisioningTaskExecutor);
Assert.assertTrue(result);
//
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());
}
use of eu.bcvsolutions.idm.acc.dto.SysProvisioningBatchDto 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);
}
}
use of eu.bcvsolutions.idm.acc.dto.SysProvisioningBatchDto in project CzechIdMng by bcvsolutions.
the class DefaultProvisioningExecutorIntegrationTest method testRunningOperationInQueue.
@Test
public void testRunningOperationInQueue() {
SysSystemDto system = getHelper().createTestResourceSystem(true);
system.setQueue(true);
system = systemService.save(system);
//
// create test provisioning context
SysProvisioningOperationDto provisioningOperation = createProvisioningOperation(system, "firstname");
Map<ProvisioningAttributeDto, Object> accoutObject = provisioningOperation.getProvisioningContext().getAccountObject();
String uid = (String) accoutObject.get(getProvisioningAttribute(TestHelper.ATTRIBUTE_MAPPING_NAME));
//
// publish event
provisioningExecutor.execute(provisioningOperation);
// is necessary to get again operation from service
SysProvisioningOperationFilter filter = new SysProvisioningOperationFilter();
filter.setSystemEntity(provisioningOperation.getSystemEntity());
filter.setSystemId(system.getId());
SysProvisioningOperationDto operation = provisioningOperationService.find(filter, null).getContent().get(0);
assertEquals(OperationState.CREATED, operation.getResultState());
SysSystemEntityDto systemEntity = systemEntityService.getBySystemAndEntityTypeAndUid(system, SystemEntityType.IDENTITY, uid);
assertTrue(systemEntity.isWish());
assertNull(getHelper().findResource(uid));
SysProvisioningBatchDto batch = DtoUtils.getEmbedded(operation, SysProvisioningOperation_.batch);
Assert.assertNull(batch.getNextAttempt());
//
// set operation state to running manually
operation.getResult().setState(OperationState.RUNNING);
operation = provisioningOperationService.save(operation);
//
// created the second operation
ProvisioningContext context = new ProvisioningContext();
String firstname = "firstname2";
accoutObject = createAccountObject(systemEntity, firstname);
context.setAccountObject(accoutObject);
//
// prepare provisioning operation
SysSystemMappingDto systemMapping = getHelper().getDefaultMapping(system);
IcObjectClass objectClass = new IcObjectClassImpl(schemaObjectClassService.get(systemMapping.getObjectClass()).getObjectClassName());
IcConnectorObject connectorObject = new IcConnectorObjectImpl(null, objectClass, null);
SysProvisioningOperationDto.Builder operationBuilder = new SysProvisioningOperationDto.Builder().setOperationType(ProvisioningOperationType.CREATE).setSystemEntity(systemEntity).setProvisioningContext(new ProvisioningContext(accoutObject, connectorObject));
SysProvisioningOperationDto secondOperation = operationBuilder.build();
// for quick search
secondOperation.setId(UUID.randomUUID());
//
// publish event
provisioningExecutor.execute(secondOperation);
//
secondOperation = provisioningOperationService.get(secondOperation);
batch = provisioningBatchService.get(batch);
Assert.assertNotNull(batch.getNextAttempt());
//
// retry - the operation is still running
RetryProvisioningTaskExecutor retryProvisioningTaskExecutor = new RetryProvisioningTaskExecutor();
Boolean result = longRunningTaskManager.executeSync(retryProvisioningTaskExecutor);
Assert.assertTrue(result);
operation = provisioningOperationService.get(operation);
secondOperation = provisioningOperationService.get(secondOperation);
//
Assert.assertEquals(OperationState.RUNNING, operation.getResultState());
Assert.assertEquals(OperationState.NOT_EXECUTED, secondOperation.getResultState());
//
operation.getResult().setState(OperationState.EXECUTED);
operation = provisioningOperationService.save(operation);
// Account cannot exist now
TestResource resource = getHelper().findResource(uid);
Assert.assertNull(resource);
//
// retry - expected success now
retryProvisioningTaskExecutor = new RetryProvisioningTaskExecutor();
result = longRunningTaskManager.executeSync(retryProvisioningTaskExecutor);
Assert.assertTrue(result);
//
systemEntity = systemEntityService.getBySystemAndEntityTypeAndUid(system, SystemEntityType.IDENTITY, uid);
Assert.assertFalse(systemEntity.isWish());
resource = getHelper().findResource(uid);
Assert.assertNotNull(resource);
Assert.assertEquals(firstname, resource.getFirstname());
batch = provisioningBatchService.get(batch.getId());
Assert.assertNull(batch.getNextAttempt());
}
use of eu.bcvsolutions.idm.acc.dto.SysProvisioningBatchDto in project CzechIdMng by bcvsolutions.
the class DefaultSysProvisioningBatchServiceTest method emptyFilterTest.
@Test
public void emptyFilterTest() {
IdmBasePermission permission = IdmBasePermission.ADMIN;
SysSystemDto system = getHelper().createSystem(TestResource.TABLE_NAME);
SysSystemEntityDto systemEntity = getHelper().createSystemEntity(system);
//
SysProvisioningBatchDto provisioningBatch = new SysProvisioningBatchDto();
provisioningBatch.setId(UUID.randomUUID());
provisioningBatch.setSystemEntity(systemEntity.getId());
batchService.save(provisioningBatch);
EmptyFilter filter = new EmptyFilter();
Page<SysProvisioningBatchDto> result = batchService.find(filter, null, permission);
assertTrue(result.getContent().contains(provisioningBatch));
}
Aggregations