Search in sources :

Example 26 with IdmProcessedTaskItemDto

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));
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) PageRequest(org.springframework.data.domain.PageRequest) Pageable(org.springframework.data.domain.Pageable) IdmScheduledTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmScheduledTaskDto) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) IdmProcessedTaskItemFilter(eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmProcessedTaskItemFilter) IdmProcessedTaskItemDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmProcessedTaskItemDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) AbstractVerifiableUnitTest(eu.bcvsolutions.idm.test.api.AbstractVerifiableUnitTest) Test(org.junit.Test)

Example 27 with IdmProcessedTaskItemDto

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()));
}
Also used : IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) IdmScheduledTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmScheduledTaskDto) IdmProcessedTaskItemDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmProcessedTaskItemDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 28 with IdmProcessedTaskItemDto

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));
}
Also used : IdmScheduledTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmScheduledTaskDto) IdmProcessedTaskItemFilter(eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmProcessedTaskItemFilter) IdmProcessedTaskItemDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmProcessedTaskItemDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 29 with IdmProcessedTaskItemDto

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));
}
Also used : IdmScheduledTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmScheduledTaskDto) IdmProcessedTaskItemFilter(eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmProcessedTaskItemFilter) IdmProcessedTaskItemDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmProcessedTaskItemDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 30 with IdmProcessedTaskItemDto

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));
}
Also used : IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) IdmScheduledTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmScheduledTaskDto) IdmProcessedTaskItemFilter(eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmProcessedTaskItemFilter) IdmProcessedTaskItemDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmProcessedTaskItemDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

IdmProcessedTaskItemDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmProcessedTaskItemDto)42 Test (org.junit.Test)32 IdmScheduledTaskDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmScheduledTaskDto)22 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)16 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)13 IdmLongRunningTaskDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto)12 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)11 IdmProcessedTaskItemFilter (eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmProcessedTaskItemFilter)9 IdmPasswordDto (eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto)4 OperationResult (eu.bcvsolutions.idm.core.api.entity.OperationResult)4 AbstractVerifiableUnitTest (eu.bcvsolutions.idm.test.api.AbstractVerifiableUnitTest)4 UUID (java.util.UUID)4 LocalDate (org.joda.time.LocalDate)4 AbstractDto (eu.bcvsolutions.idm.core.api.dto.AbstractDto)3 AbstractRestTest (eu.bcvsolutions.idm.test.api.AbstractRestTest)2 PageImpl (org.springframework.data.domain.PageImpl)2 PageRequest (org.springframework.data.domain.PageRequest)2 Pageable (org.springframework.data.domain.Pageable)2 Transactional (org.springframework.transaction.annotation.Transactional)2 CoreException (eu.bcvsolutions.idm.core.api.exception.CoreException)1