use of eu.bcvsolutions.idm.core.scheduler.api.dto.IdmProcessedTaskItemDto in project CzechIdMng by bcvsolutions.
the class AbstractSchedulableStatefulExecutorUnitTest method testProcess.
@Test
public void testProcess() {
IdmScheduledTaskDto scheduledTask = new IdmScheduledTaskDto();
scheduledTask.setId(UUID.randomUUID());
IdmLongRunningTaskDto lrt = new IdmLongRunningTaskDto();
//
IdmIdentityDto dto1 = getTestIdentityDto();
IdmIdentityDto dto2 = getTestIdentityDto();
IdmIdentityDto dto3 = getTestIdentityDto();
// stubs
doReturn(Optional.of(new OperationResult.Builder(OperationState.EXECUTED).build())).when(executor).processItem(any(IdmIdentityDto.class));
doReturn(false).when(executor).isInProcessedQueue(any(IdmIdentityDto.class));
doNothing().when(itemService).deleteInternal(any(IdmProcessedTaskItemDto.class));
doReturn(Lists.newArrayList(UUID.randomUUID(), UUID.randomUUID())).when(executor).getProcessedItemRefsFromQueue();
doReturn(scheduledTask.getId()).when(executor).getScheduledTaskId();
// matchers
when(longRunningTaskService.get(any(UUID.class))).thenReturn(lrt);
when(scheduledTaskService.get(any(UUID.class))).thenReturn(scheduledTask);
when(executor.getItemsToProcess(any(Pageable.class))).thenReturn(new PageImpl<>(Lists.newArrayList(dto1, dto2), new PageRequest(0, 2), 6)).thenReturn(new PageImpl<>(Lists.newArrayList(dto3), new PageRequest(0, 2), 6)).thenReturn(new PageImpl<>(Lists.newArrayList()));
when(itemService.saveInternal(any(IdmProcessedTaskItemDto.class))).then(AdditionalAnswers.returnsFirstArg());
when(itemService.find(any(IdmProcessedTaskItemFilter.class), any(Pageable.class))).thenReturn(new PageImpl<>(Lists.newArrayList(new IdmProcessedTaskItemDto())));
//
//
Boolean processingResult = executor.process();
assertTrue(processingResult);
//
//
verify(scheduledTaskService, times(3)).get(any(UUID.class));
verify(longRunningTaskService, times(6)).get(any(UUID.class));
//
verify(executor, times(3)).getItemsToProcess(any(Pageable.class));
verify(executor, times(1)).isInProcessedQueue(dto1);
verify(executor, times(1)).isInProcessedQueue(dto2);
verify(executor, times(1)).isInProcessedQueue(dto3);
verify(executor, times(1)).getProcessedItemRefsFromQueue();
verify(executor, times(2)).removeFromProcessedQueue(any(UUID.class));
verify(executor, times(3)).addToProcessedQueue(any(IdmIdentityDto.class), any(OperationResult.class));
verify(executor, times(3)).logItemProcessed(any(IdmIdentityDto.class), any(OperationResult.class));
// 6x addToProcessQueue, 2x removeItemFromQueue, 2x stubbed
verify(executor, times(10)).getScheduledTaskId();
verify(executor, times(3)).processItem(any(IdmIdentityDto.class));
// 3x addToProcessQueue, 3x logItemProcessed
verify(itemService, times(2)).deleteInternal(any(IdmProcessedTaskItemDto.class));
verify(itemService, times(3)).createLogItem(any(AbstractDto.class), any(OperationResult.class), any(IdmLongRunningTaskDto.class));
verify(itemService, times(3)).createQueueItem(any(AbstractDto.class), any(OperationResult.class), any(IdmScheduledTaskDto.class));
// 2x from removeFromProcessedQueue, other invocations are stubbed
verify(itemService, times(2)).find(any(IdmProcessedTaskItemFilter.class), any(Pageable.class));
}
use of eu.bcvsolutions.idm.core.scheduler.api.dto.IdmProcessedTaskItemDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmProcessedTaskItemDtoServiceTest method testDeleteLogItemIntegrity.
@Test
public void testDeleteLogItemIntegrity() {
IdmScheduledTaskDto d = helper.createSchedulableTask();
IdmLongRunningTaskDto lrt = this.createLongRunningTask(d);
IdmProcessedTaskItemDto item = service.saveInternal(helper.prepareProcessedItem(lrt));
//
longrunningService.deleteInternal(lrt);
//
assertNull(longrunningService.get(lrt.getId()));
assertNull(service.get(item.getId()));
assertNotNull(scheduledTaskService.get(d.getId()));
}
use of eu.bcvsolutions.idm.core.scheduler.api.dto.IdmProcessedTaskItemDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmProcessedTaskItemDtoServiceTest method datesFilter.
@Test
public void datesFilter() {
IdmScheduledTaskDto d = helper.createSchedulableTask();
IdmProcessedTaskItemDto item = service.saveInternal(helper.prepareProcessedItem(d));
IdmProcessedTaskItemDto item2 = helper.prepareProcessedItem(d);
item2.setCreated(item.getCreated());
item2 = service.saveInternal(item2);
//
IdmProcessedTaskItemDto item3 = service.saveInternal(helper.prepareProcessedItem(d));
//
IdmProcessedTaskItemFilter filter = new IdmProcessedTaskItemFilter();
filter.setFrom(item.getCreated());
Page<IdmProcessedTaskItemDto> result = service.find(filter, null);
assertTrue("#1", result.getContent().contains(item));
assertTrue("#2", result.getContent().contains(item2));
filter.setFrom(null);
filter.setTill(item3.getCreated());
result = service.find(filter, null);
assertTrue("#4", result.getContent().contains(item3));
}
use of eu.bcvsolutions.idm.core.scheduler.api.dto.IdmProcessedTaskItemDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmProcessedTaskItemDtoServiceTest method textFilter.
@Test
public void textFilter() {
// find number of all processed items in old tests
IdmProcessedTaskItemFilter filter = new IdmProcessedTaskItemFilter();
filter.setText(IdmIdentityDto.class.getCanonicalName());
Page<IdmProcessedTaskItemDto> result = service.find(filter, null);
long count = result.getTotalElements();
//
IdmScheduledTaskDto d = helper.createSchedulableTask();
IdmProcessedTaskItemDto item = service.saveInternal(helper.prepareProcessedItem(d));
IdmProcessedTaskItemDto item2 = service.saveInternal(helper.prepareProcessedItem(d));
//
filter.setText(item.getReferencedDtoType());
result = service.find(filter, null);
assertEquals("Wrong number of items!", 2 + count, result.getTotalElements());
assertTrue(result.getContent().contains(item));
assertTrue(result.getContent().contains(item2));
}
use of eu.bcvsolutions.idm.core.scheduler.api.dto.IdmProcessedTaskItemDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmProcessedTaskItemDtoServiceTest method getLongRunningTaskIdFilter.
@Test
public void getLongRunningTaskIdFilter() {
IdmScheduledTaskDto d = helper.createSchedulableTask();
IdmLongRunningTaskDto lrt = this.createLongRunningTask(d);
IdmLongRunningTaskDto lrt2 = this.createLongRunningTask(d);
//
IdmProcessedTaskItemDto item = service.saveInternal(helper.prepareProcessedItem(lrt));
IdmProcessedTaskItemDto item2 = service.saveInternal(helper.prepareProcessedItem(lrt));
IdmProcessedTaskItemDto item3 = service.saveInternal(helper.prepareProcessedItem(lrt2));
//
IdmProcessedTaskItemFilter filter = new IdmProcessedTaskItemFilter();
filter.setLongRunningTaskId(lrt.getId());
Page<IdmProcessedTaskItemDto> result = service.find(filter, null);
assertEquals("Wrong number of items!", 2, result.getTotalElements());
assertTrue(result.getContent().contains(item));
assertTrue(result.getContent().contains(item2));
assertFalse(result.getContent().contains(item3));
}
Aggregations