use of eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter in project CzechIdMng by bcvsolutions.
the class DefaultIdmLongRunningTaskServiceTest method operationStateFilterTest.
@Test
public void operationStateFilterTest() {
IdmLongRunningTaskFilter filter = new IdmLongRunningTaskFilter();
String expectedResult = "TEST_SUCCESS_06_M";
// set tasks
LongRunningTaskExecutor<String> taskExecutor = new TestSimpleLongRunningTaskExecutor(expectedResult);
assertNull(taskExecutor.getLongRunningTaskId());
manager.executeSync(taskExecutor);
IdmLongRunningTaskDto task1 = idmLongRunningTaskService.get(taskExecutor.getLongRunningTaskId());
// set filter
filter.setOperationState(task1.getResultState());
Page<IdmLongRunningTaskDto> result = idmLongRunningTaskService.find(filter, null);
assertEquals("Wrong operationState id", true, result.getContent().contains(task1));
}
use of eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter in project CzechIdMng by bcvsolutions.
the class DefaultSchedulerManagerIntegrationTest method testDependentTaskNoExecutionAfterInitiatorFails.
@Test
public void testDependentTaskNoExecutionAfterInitiatorFails() throws Exception {
helper.setConfigurationValue(SchedulerConfiguration.PROPERTY_TASK_ASYNCHRONOUS_ENABLED, false);
try {
LongRunningTaskExecuteDependentProcessor processor = context.getBean(LongRunningTaskExecuteDependentProcessor.class);
//
IdmLongRunningTaskFilter filter = new IdmLongRunningTaskFilter();
filter.setOperationState(OperationState.CREATED);
filter.setTaskType(TestSchedulableTask.class.getCanonicalName());
filter.setFrom(new DateTime());
List<IdmLongRunningTaskDto> createdLrts = longRunningTaskService.find(filter, null).getContent();
Assert.assertEquals(0L, createdLrts.size());
//
Task task = createTask("dependent-task-initiator");
DependentTaskTrigger trigger = new DependentTaskTrigger();
trigger.setInitiatorTaskId(task.getId());
//
// initiator = dependent task => circular execution
manager.createTrigger(task.getId(), trigger);
manager.runTask(task.getId());
helper.waitForResult(getContinueFunction());
createdLrts = longRunningTaskService.find(filter, null).getContent();
Assert.assertEquals(1L, createdLrts.size());
IdmLongRunningTaskDto lrt = createdLrts.get(0);
lrt.setResult(new OperationResult(OperationState.EXCEPTION));
// not executed
EventResult<IdmLongRunningTaskDto> result = processor.process(new LongRunningTaskEvent(LongRunningTaskEventType.END, lrt));
Assert.assertEquals(OperationState.NOT_EXECUTED, result.getResults().get(0).getState());
lrt.setResult(new OperationResult(OperationState.BLOCKED));
result = processor.process(new LongRunningTaskEvent(LongRunningTaskEventType.END, lrt));
Assert.assertEquals(OperationState.NOT_EXECUTED, result.getResults().get(0).getState());
lrt.setResult(new OperationResult(OperationState.NOT_EXECUTED));
result = processor.process(new LongRunningTaskEvent(LongRunningTaskEventType.END, lrt));
Assert.assertEquals(OperationState.NOT_EXECUTED, result.getResults().get(0).getState());
lrt.setResult(new OperationResult(OperationState.CANCELED));
result = processor.process(new LongRunningTaskEvent(LongRunningTaskEventType.END, lrt));
Assert.assertEquals(OperationState.NOT_EXECUTED, result.getResults().get(0).getState());
lrt.setResult(new OperationResult(OperationState.CREATED));
result = processor.process(new LongRunningTaskEvent(LongRunningTaskEventType.END, lrt));
Assert.assertEquals(OperationState.NOT_EXECUTED, result.getResults().get(0).getState());
lrt.setResult(new OperationResult(OperationState.RUNNING));
result = processor.process(new LongRunningTaskEvent(LongRunningTaskEventType.END, lrt));
Assert.assertEquals(OperationState.NOT_EXECUTED, result.getResults().get(0).getState());
//
longRunningTaskManager.cancel(lrt.getId());
//
longRunningTaskService.find(filter, null).getContent();
// cancel - clean up
Assert.assertEquals(0L, longRunningTaskService.find(filter, null).getTotalElements());
} finally {
helper.setConfigurationValue(SchedulerConfiguration.PROPERTY_TASK_ASYNCHRONOUS_ENABLED, true);
}
}
use of eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter in project CzechIdMng by bcvsolutions.
the class IdentityUsernameExportBulkActionTest method processBulkAction.
@Test
public void processBulkAction() throws IOException {
IdmBulkActionDto exampleAction = findBulkAction(IdmIdentity.class, IdentityUsernameExportBulkAction.BULK_ACTION_NAME);
assertNotNull(exampleAction);
IdmIdentityDto identity = getHelper().createIdentity();
IdmIdentityDto identity2 = getHelper().createIdentity();
IdmIdentityDto identity3 = getHelper().createIdentity();
exampleAction.setIdentifiers(Sets.newHashSet(identity.getId(), identity2.getId(), identity3.getId()));
IdmBulkActionDto processAction = bulkActionManager.processAction(exampleAction);
assertNotNull(processAction.getLongRunningTaskId());
IdmLongRunningTaskFilter context = new IdmLongRunningTaskFilter();
context.setIncludeItemCounts(true);
IdmLongRunningTaskDto longRunningTask = longRunningTaskService.get(processAction.getLongRunningTaskId(), context);
assertEquals(Long.valueOf(3), longRunningTask.getCount());
assertEquals(Long.valueOf(3), longRunningTask.getSuccessItemCount());
assertEquals(Long.valueOf(0), longRunningTask.getFailedItemCount());
assertEquals(Long.valueOf(0), longRunningTask.getWarningItemCount());
OperationResult result = longRunningTask.getResult();
ResultModel model = result.getModel();
assertNotNull(model);
assertEquals(206, model.getStatusCode());
assertEquals(CoreResultCode.LONG_RUNNING_TASK_PARTITIAL_DOWNLOAD.getCode(), model.getStatusEnum());
UUID fromString = attachmentManager.getAttachments(longRunningTask, null).getContent().get(0).getId();
assertNotNull(fromString);
IdmAttachmentDto attachmentDto = attachmentManager.get(fromString);
assertNotNull(attachmentDto);
assertEquals(longRunningTask.getId(), attachmentDto.getOwnerId());
IdmAttachmentDto attachmentForLongRunningTask = longRunningTaskManager.getAttachment(longRunningTask.getId(), attachmentDto.getId());
assertNotNull(attachmentForLongRunningTask);
assertEquals(attachmentDto.getId(), attachmentForLongRunningTask.getId());
InputStream is = attachmentManager.getAttachmentData(attachmentDto.getId());
try {
String string = IOUtils.toString(is);
assertTrue(string.contains(identity.getUsername()));
assertTrue(string.contains(identity2.getUsername()));
assertTrue(string.contains(identity3.getUsername()));
assertTrue(string.contains(IdmIdentity_.username.getName().toUpperCase()));
assertTrue(string.contains(IdmIdentity_.externalCode.getName().toUpperCase()));
assertTrue(string.contains(IdmIdentity_.state.getName().toUpperCase()));
} finally {
IOUtils.closeQuietly(is);
}
}
use of eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter in project CzechIdMng by bcvsolutions.
the class DefaultTestHelper method createRoleComposition.
@Override
public IdmRoleCompositionDto createRoleComposition(IdmRoleDto superior, IdmRoleDto sub) {
IdmRoleCompositionDto roleComposition = new IdmRoleCompositionDto();
roleComposition.setSuperior(superior.getId());
roleComposition.setSub(sub.getId());
// create role composition
roleComposition = roleCompositionService.save(roleComposition);
// wait for role composition is completely processed
UUID transactionId = roleComposition.getTransactionId();
//
waitForResult(res -> {
IdmLongRunningTaskFilter filter = new IdmLongRunningTaskFilter();
filter.setOperationStates(Lists.newArrayList(OperationState.CREATED, OperationState.RUNNING));
filter.setTransactionId(transactionId);
//
List<IdmLongRunningTaskDto> tasks = taskManager.findLongRunningTasks(filter, null).getContent();
// use this to debug, if needed ...
tasks.forEach(task -> {
System.out.println("Task: " + task.getTaskType() + ", " + task.getResultState() + ", TID: " + transactionId + " ~ " + task.getTransactionId());
});
//
return !tasks.isEmpty();
}, 500, // ~ 40s max
80);
//
return roleComposition;
}
use of eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter in project CzechIdMng by bcvsolutions.
the class IdentityLogExampleBulkActionTest method processBulkAction.
@Test
public void processBulkAction() {
IdmBulkActionDto exampleAction = findBulkAction(IdmIdentity.class, IdentityLogExampleBulkAction.BULK_ACTION_NAME);
assertNotNull(exampleAction);
Assert.assertEquals(NotificationLevel.INFO, exampleAction.getLevel());
IdmIdentityDto identity = getHelper().createIdentity();
IdmIdentityDto identity2 = getHelper().createIdentity();
IdmIdentityDto identity3 = getHelper().createIdentity();
exampleAction.setIdentifiers(Sets.newHashSet(identity.getId(), identity2.getId(), identity3.getId()));
IdmBulkActionDto processAction = bulkActionManager.processAction(exampleAction);
assertNotNull(processAction.getLongRunningTaskId());
IdmLongRunningTaskFilter context = new IdmLongRunningTaskFilter();
context.setIncludeItemCounts(true);
IdmLongRunningTaskDto longRunningTask = longRunningTaskService.get(processAction.getLongRunningTaskId(), context);
assertEquals(Long.valueOf(3), longRunningTask.getCount());
assertEquals(Long.valueOf(3), longRunningTask.getSuccessItemCount());
assertEquals(Long.valueOf(0), longRunningTask.getFailedItemCount());
assertEquals(Long.valueOf(0), longRunningTask.getWarningItemCount());
List<IdmProcessedTaskItemDto> items = getItemsForLrt(longRunningTask);
assertEquals(3, items.size());
boolean identitySuccess = false;
boolean identitySuccess2 = false;
boolean identitySuccess3 = false;
for (IdmProcessedTaskItemDto item : items) {
if (item.getOperationResult().getState() != OperationState.EXECUTED) {
fail("Identity " + item.getReferencedEntityId() + ", failed.");
}
if (item.getReferencedEntityId().equals(identity.getId())) {
identitySuccess = true;
}
if (item.getReferencedEntityId().equals(identity2.getId())) {
identitySuccess2 = true;
}
if (item.getReferencedEntityId().equals(identity3.getId())) {
identitySuccess3 = true;
}
}
assertTrue(identitySuccess);
assertTrue(identitySuccess2);
assertTrue(identitySuccess3);
}
Aggregations