use of eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto in project CzechIdMng by bcvsolutions.
the class DefaultSchedulerManagerIntegrationTest method testDependentTaskExecution.
@Test
@SuppressWarnings("unchecked")
public void testDependentTaskExecution() throws Exception {
helper.setConfigurationValue(SchedulerConfiguration.PROPERTY_TASK_ASYNCHRONOUS_ENABLED, false);
try {
String resultValue = "dependent-task-initiator";
//
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());
// execute first task
LongRunningFutureTask<String> futureTask = (LongRunningFutureTask<String>) longRunningTaskManager.processCreated(createdLrts.get(0).getId());
Assert.assertEquals(resultValue, futureTask.getFutureTask().get());
//
helper.waitForResult(getContinueFunction());
createdLrts = longRunningTaskService.find(filter, null).getContent();
Assert.assertEquals(1L, longRunningTaskService.find(filter, null).getTotalElements());
//
longRunningTaskManager.cancel(createdLrts.get(0).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.IdmLongRunningTaskDto in project CzechIdMng by bcvsolutions.
the class DefaultSchedulerManagerIntegrationTest method testDependentTaskInDryModeExecution.
@Test
@SuppressWarnings("unchecked")
public void testDependentTaskInDryModeExecution() throws Exception {
helper.setConfigurationValue(SchedulerConfiguration.PROPERTY_TASK_ASYNCHRONOUS_ENABLED, false);
try {
String resultValue = "dependent-task-initiator-dry-run";
//
IdmLongRunningTaskFilter filter = new IdmLongRunningTaskFilter();
filter.setOperationState(OperationState.CREATED);
filter.setTaskType(TestSchedulableDryRunTask.class.getCanonicalName());
filter.setFrom(new DateTime());
List<IdmLongRunningTaskDto> createdLrts = longRunningTaskService.find(filter, null).getContent();
Assert.assertEquals(0L, createdLrts.size());
//
Task task = createDryRunTask(resultValue);
DependentTaskTrigger trigger = new DependentTaskTrigger();
trigger.setInitiatorTaskId(task.getId());
//
// initiator = dependent task => circular execution
manager.createTrigger(task.getId(), trigger);
manager.runTask(task.getId(), true);
helper.waitForResult(getContinueFunction());
createdLrts = longRunningTaskService.find(filter, null).getContent();
Assert.assertEquals(1L, createdLrts.size());
Assert.assertTrue(createdLrts.get(0).isDryRun());
UUID firstTaskId = createdLrts.get(0).getId();
// execute first task
LongRunningFutureTask<String> futureTask = (LongRunningFutureTask<String>) longRunningTaskManager.processCreated(createdLrts.get(0).getId());
Assert.assertEquals(resultValue, futureTask.getFutureTask().get());
//
helper.waitForResult(getContinueFunction());
createdLrts = longRunningTaskService.find(filter, null).getContent();
Assert.assertEquals(1L, longRunningTaskService.find(filter, null).getTotalElements());
Assert.assertTrue(createdLrts.get(0).isDryRun());
Assert.assertNotEquals(firstTaskId, createdLrts.get(0).getId());
//
longRunningTaskManager.cancel(createdLrts.get(0).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.IdmLongRunningTaskDto in project CzechIdMng by bcvsolutions.
the class PasswordExpirationWarningIntegrationTest method testSimpleWarningMessageDry.
@Test
public void testSimpleWarningMessageDry() {
// prepare date
IdmIdentityDto identity = helper.createIdentity();
//
try {
IdmPasswordDto password = passwordService.findOneByIdentity(identity.getId());
password.setValidTill(new LocalDate().plusDays(1));
passwordService.save(password);
// prepare task
IdmScheduledTaskDto scheduledTask = scheduledTaskService.save(SchedulerTestUtils.createIdmScheduledTask(UUID.randomUUID().toString()));
IdmLongRunningTaskDto longRunningTask = longRunningService.save(SchedulerTestUtils.createIdmLongRunningTask(scheduledTask, PasswordExpirationWarningTaskExecutor.class));
PasswordExpirationWarningTaskExecutor executor = AutowireHelper.autowireBean(new PasswordExpirationWarningTaskExecutor());
executor.setLongRunningTaskId(longRunningTask.getId());
executor.init(ImmutableMap.of(PasswordExpirationWarningTaskExecutor.PARAMETER_DAYS_BEFORE, "2"));
// first process
Boolean result = executor.process();
Page<IdmProcessedTaskItemDto> queueItems = itemService.findQueueItems(scheduledTask, null);
Page<IdmProcessedTaskItemDto> logItems = itemService.findLogItems(longRunningTask, null);
// first check
Assert.assertTrue(result);
Assert.assertTrue(executor.getCount() > 0);
Assert.assertTrue(queueItems.getTotalElements() > 0);
Assert.assertTrue(logItems.getTotalElements() > 0);
Assert.assertTrue(logItems.getContent().stream().map(IdmProcessedTaskItemDto::getReferencedEntityId).anyMatch(password.getId()::equals));
// second process
longRunningTask = longRunningService.save(SchedulerTestUtils.createIdmLongRunningTask(scheduledTask, PasswordExpirationWarningTaskExecutor.class));
executor.setLongRunningTaskId(longRunningTask.getId());
executor.init(ImmutableMap.of(PasswordExpirationWarningTaskExecutor.PARAMETER_DAYS_BEFORE, "2"));
result = executor.process();
itemService.findQueueItems(scheduledTask, null);
logItems = itemService.findLogItems(longRunningTask, null);
// second check
Assert.assertTrue(result);
Assert.assertEquals(Long.valueOf(0), executor.getCount());
Assert.assertTrue(queueItems.getTotalElements() > 0);
Assert.assertEquals(0, logItems.getTotalElements());
} finally {
identityService.delete(identity);
}
}
use of eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto in project CzechIdMng by bcvsolutions.
the class PasswordExpiredIntegrationTest method testNotSendWarningMessageToDisabledIdentity.
@Test
public void testNotSendWarningMessageToDisabledIdentity() {
// prepare date
IdmIdentityDto identity = helper.createIdentity();
//
try {
IdmPasswordDto password = passwordService.findOneByIdentity(identity.getId());
password.setValidTill(new LocalDate().minusDays(1));
passwordService.save(password);
// disable identity
identity.setDisabled(true);
identityService.save(identity);
// prepare task
IdmScheduledTaskDto scheduledTask = scheduledTaskService.save(SchedulerTestUtils.createIdmScheduledTask(UUID.randomUUID().toString()));
IdmLongRunningTaskDto longRunningTask = longRunningService.save(SchedulerTestUtils.createIdmLongRunningTask(scheduledTask, PasswordExpiredTaskExecutor.class));
PasswordExpiredTaskExecutor executor = AutowireHelper.autowireBean(new PasswordExpiredTaskExecutor());
executor.setLongRunningTaskId(longRunningTask.getId());
executor.init(ImmutableMap.of(PasswordExpirationWarningTaskExecutor.PARAMETER_DAYS_BEFORE, "2"));
// first process
Boolean result = executor.process();
Page<IdmProcessedTaskItemDto> logItems = itemService.findLogItems(longRunningTask, null);
// check
Assert.assertTrue(result);
Assert.assertFalse(logItems.getContent().stream().map(IdmProcessedTaskItemDto::getReferencedEntityId).anyMatch(password.getId()::equals));
} finally {
identityService.delete(identity);
}
}
use of eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto in project CzechIdMng by bcvsolutions.
the class AbstractReportExecutor method process.
@Override
public RptReportDto process() {
if (event != null) {
// generate report
return generate(event.getContent());
}
// event is empty - publish new event and stop current LRT process (event has to be initialized at first)
if (getLongRunningTaskId() != null) {
IdmLongRunningTaskDto task = getLongRunningTaskService().get(getLongRunningTaskId());
if (task != null) {
task.setRunning(false);
getLongRunningTaskService().save(task);
}
}
// executed from scheduler => we propagate new event for creating report
RptReportDto report = new RptReportDto();
report.setExecutorName(getName());
report.setLongRunningTask(getLongRunningTaskId());
reportManager.generate(report);
return report;
}
Aggregations