use of eu.bcvsolutions.idm.core.scheduler.api.dto.IdmScheduledTaskDto in project CzechIdMng by bcvsolutions.
the class AbstractSchedulableStatefulExecutorUnitTest method testIsInProcessedQueue.
@Test
public void testIsInProcessedQueue() {
IdmScheduledTaskDto scheduledTask = new IdmScheduledTaskDto();
UUID randomId = UUID.randomUUID();
scheduledTask.setId(randomId);
when(scheduledTaskService.findByLongRunningTaskId(randomId)).thenReturn(scheduledTask);
//
List<IdmProcessedTaskItemDto> items = Lists.newArrayList(new IdmProcessedTaskItemDto());
//
when(itemService.find(any(IdmProcessedTaskItemFilter.class), any(Pageable.class))).thenReturn(new PageImpl<>(items));
//
when(executor.getLongRunningTaskId()).thenReturn(randomId);
//
boolean inProcessedQueue = executor.isInProcessedQueue(getTestIdentityDto());
assertTrue(inProcessedQueue);
//
when(itemService.find(any(IdmProcessedTaskItemFilter.class), any(Pageable.class))).thenReturn(new PageImpl<>(Lists.newArrayList()));
//
inProcessedQueue = executor.isInProcessedQueue(getTestIdentityDto());
assertFalse(inProcessedQueue);
//
verify(executor, times(2)).isInProcessedQueue(any(IdmIdentityDto.class));
verify(scheduledTaskService, times(1)).findByLongRunningTaskId(randomId);
verify(itemService, times(2)).find(any(IdmProcessedTaskItemFilter.class), any(Pageable.class));
}
use of eu.bcvsolutions.idm.core.scheduler.api.dto.IdmScheduledTaskDto in project CzechIdMng by bcvsolutions.
the class AbstractSchedulableStatefulExecutorUnitTest method testAddToProcessedQueue.
@Test
public void testAddToProcessedQueue() {
IdmScheduledTaskDto scheduledTask = new IdmScheduledTaskDto();
scheduledTask.setId(UUID.randomUUID());
when(scheduledTaskService.findByLongRunningTaskId(any(UUID.class))).thenReturn(scheduledTask);
when(scheduledTaskService.get(any(UUID.class))).thenReturn(scheduledTask);
when(itemService.saveInternal(any(IdmProcessedTaskItemDto.class))).then(AdditionalAnswers.returnsFirstArg());
when(itemService.createQueueItem(any(AbstractDto.class), any(OperationResult.class), any(IdmScheduledTaskDto.class))).thenCallRealMethod();
//
IdmIdentityDto dto = getTestIdentityDto();
OperationResult opResult = new OperationResult.Builder(OperationState.EXCEPTION).build();
IdmProcessedTaskItemDto qItem = executor.addToProcessedQueue(dto, opResult);
//
assertEquals(scheduledTask.getId(), qItem.getScheduledTaskQueueOwner());
assertEquals(opResult, qItem.getOperationResult());
assertEquals(dto.getClass().getCanonicalName(), qItem.getReferencedDtoType());
assertEquals(dto.getId(), qItem.getReferencedEntityId());
assertNull(qItem.getLongRunningTask());
//
verify(itemService, times(1)).saveInternal(any(IdmProcessedTaskItemDto.class));
verify(executor, times(1)).addToProcessedQueue(any(IdmIdentityDto.class), any(OperationResult.class));
verify(scheduledTaskService, times(1)).findByLongRunningTaskId(any(UUID.class));
verify(scheduledTaskService, times(1)).get(any(UUID.class));
verify(itemService, times(1)).createQueueItem(any(AbstractDto.class), any(OperationResult.class), any(IdmScheduledTaskDto.class));
}
use of eu.bcvsolutions.idm.core.scheduler.api.dto.IdmScheduledTaskDto in project CzechIdMng by bcvsolutions.
the class AbstractSchedulableStatefulExecutorUnitTest method testDontTouchProcessed.
@Test
public void testDontTouchProcessed() {
IdmLongRunningTaskDto lrt = new IdmLongRunningTaskDto();
IdmScheduledTaskDto scheduledTask = new IdmScheduledTaskDto();
scheduledTask.setId(UUID.randomUUID());
//
IdmIdentityDto dto1 = getTestIdentityDto();
IdmIdentityDto dto2 = getTestIdentityDto();
// stubs
doReturn(true).when(executor).isInProcessedQueue(any(IdmIdentityDto.class));
doReturn(Lists.newArrayList(dto1.getId(), dto2.getId())).when(executor).getProcessedItemRefsFromQueue();
doReturn(scheduledTask.getId()).when(executor).getScheduledTaskId();
// matchers
when(longRunningTaskService.get(any(UUID.class))).thenReturn(lrt);
when(executor.getItemsToProcess(any(Pageable.class))).thenReturn(new PageImpl<>(Lists.newArrayList(dto1, dto2))).thenReturn(new PageImpl<>(Lists.newArrayList()));
//
//
Boolean processingResult = executor.process();
assertTrue(processingResult);
//
//
verify(longRunningTaskService, times(2)).get(any(UUID.class));
//
verify(executor, times(1)).getItemsToProcess(any(Pageable.class));
verify(executor, times(1)).isInProcessedQueue(dto1);
verify(executor, times(1)).isInProcessedQueue(dto2);
verify(executor, times(1)).getProcessedItemRefsFromQueue();
verify(executor, never()).getScheduledTaskId();
verify(executor, never()).removeFromProcessedQueue(any(UUID.class));
verify(executor, never()).addToProcessedQueue(any(IdmIdentityDto.class), any(OperationResult.class));
verify(executor, never()).processItem(any(IdmIdentityDto.class));
verify(itemService, never()).saveInternal(any(IdmProcessedTaskItemDto.class));
verify(itemService, never()).deleteInternal(any(IdmProcessedTaskItemDto.class));
verify(itemService, never()).find(any(IdmProcessedTaskItemFilter.class), any(Pageable.class));
}
use of eu.bcvsolutions.idm.core.scheduler.api.dto.IdmScheduledTaskDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmProcessedTaskItemDtoServiceTest method testDeleteQueueItemIntegrity.
@Test
public void testDeleteQueueItemIntegrity() {
IdmScheduledTaskDto d = helper.createSchedulableTask();
IdmProcessedTaskItemDto item = service.saveInternal(helper.prepareProcessedItem(d));
//
scheduledTaskService.deleteInternal(d);
//
assertNull(scheduledTaskService.get(d.getId()));
assertNull(service.get(item.getId()));
}
use of eu.bcvsolutions.idm.core.scheduler.api.dto.IdmScheduledTaskDto 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);
}
}
Aggregations