use of org.springframework.data.domain.PageImpl in project CzechIdMng by bcvsolutions.
the class EntityEventProcessorController method find.
@ResponseBody
@RequestMapping(method = RequestMethod.GET)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.MODULE_READ + "')")
@ApiOperation(value = "Find all processors", nickname = "findAllEntityEventProcessors", tags = { EntityEventProcessorController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.MODULE_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.MODULE_READ, description = "") }) }, notes = "Returns all registered entity event processors with state properties (disabled, order)")
@SuppressWarnings({ "unchecked", "rawtypes" })
public Resources<?> find(@RequestParam(required = false) MultiValueMap<String, Object> parameters) {
List<EntityEventProcessorDto> records = entityEventManager.find(toFilter(parameters));
PageImpl page = new PageImpl(records, new PageRequest(0, records.size() == 0 ? 10 : records.size()), records.size());
if (page.getContent().isEmpty()) {
return pagedResourcesAssembler.toEmptyResource(page, EntityEventProcessorDto.class, null);
}
return pagedResourcesAssembler.toResource(page);
}
use of org.springframework.data.domain.PageImpl 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 org.springframework.data.domain.PageImpl in project uplace.es by Uplace.
the class PaginationUtilUnitTest method generatePaginationHttpHeadersTest.
@Test
public void generatePaginationHttpHeadersTest() {
String baseUrl = "/api/_search/example";
List<String> content = new ArrayList<>();
Page<String> page = new PageImpl<>(content, new PageRequest(6, 50), 400L);
HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, baseUrl);
List<String> strHeaders = headers.get(HttpHeaders.LINK);
assertNotNull(strHeaders);
assertTrue(strHeaders.size() == 1);
String headerData = strHeaders.get(0);
assertTrue(headerData.split(",").length == 4);
String expectedData = "</api/_search/example?page=7&size=50>; rel=\"next\"," + "</api/_search/example?page=5&size=50>; rel=\"prev\"," + "</api/_search/example?page=7&size=50>; rel=\"last\"," + "</api/_search/example?page=0&size=50>; rel=\"first\"";
assertEquals(expectedData, headerData);
List<String> xTotalCountHeaders = headers.get("X-Total-Count");
assertTrue(xTotalCountHeaders.size() == 1);
assertTrue(Long.valueOf(xTotalCountHeaders.get(0)).equals(400L));
}
Aggregations