use of org.hisp.dhis.fieldfilter.FieldFilterParams in project dhis2-core by dhis2.
the class DataElementOperandControllerTest method verifyPaginationGetFirstPage.
@Test
void verifyPaginationGetFirstPage() throws Exception {
int pageSize = 15;
long totalSize = 150;
// Given
final List<DataElement> dataElements = rnd.objects(DataElement.class, 1).collect(Collectors.toList());
when(manager.getAllSorted(DataElement.class)).thenReturn(dataElements);
final List<DataElementOperand> dataElementOperands = rnd.objects(DataElementOperand.class, (int) totalSize).collect(Collectors.toList());
when(dataElementCategoryService.getOperands(dataElements, true)).thenReturn(rnd.objects(DataElementOperand.class, (int) totalSize).collect(Collectors.toList()));
final List<DataElementOperand> first50elements = dataElementOperands.subList(0, pageSize);
ArgumentCaptor<FieldFilterParams> filterParamsArgumentCaptor = ArgumentCaptor.forClass(FieldFilterParams.class);
when(fieldFilterService.toCollectionNode(eq(DataElementOperand.class), filterParamsArgumentCaptor.capture())).thenReturn(buildResponse(first50elements));
doReturn(totalSize).when(queryService).count(any(Query.class));
// Then
ResultActions resultActions = mockMvc.perform(get(ENDPOINT).param("totals", "true").param("pageSize", Integer.toString(pageSize))).andExpect(status().isOk()).andExpect(content().contentType("application/json")).andExpect(jsonPath("$.pager.pageSize").value(Integer.toString(pageSize))).andExpect(jsonPath("$.pager.page").value("1")).andExpect(jsonPath("$.pager.total").value(Long.toString(totalSize))).andExpect(jsonPath("$.pager.pageCount").value(Long.toString(totalSize / pageSize))).andExpect(jsonPath("$.dataElementOperands", hasSize(pageSize)));
final FieldFilterParams fieldFilterParams = filterParamsArgumentCaptor.getValue();
assertThat(fieldFilterParams.getObjects(), hasSize(pageSize));
assertThat(fieldFilterParams.getFields(), Matchers.is(Lists.newArrayList("*")));
// Make sure that the first and last element in the page matches with
// the
// original list
List<Map<String, Object>> jsonDataElementOperands = convertResponse(resultActions);
assertThat(jsonDataElementOperands.get(0).get("id"), Matchers.is(dataElementOperands.get(0).getDimensionItem()));
assertThat(jsonDataElementOperands.get(pageSize - 1).get("id"), Matchers.is(dataElementOperands.get(pageSize - 1).getDimensionItem()));
}
use of org.hisp.dhis.fieldfilter.FieldFilterParams in project dhis2-core by dhis2.
the class DataElementOperandControllerTest method verifyPaginationGetThirdPage.
@Test
void verifyPaginationGetThirdPage() throws Exception {
int pageSize = 25;
long totalSize = 100;
// Given
final List<DataElement> dataElements = rnd.objects(DataElement.class, 1).collect(Collectors.toList());
when(manager.getAllSorted(DataElement.class)).thenReturn(dataElements);
final List<DataElementOperand> dataElementOperands = rnd.objects(DataElementOperand.class, (int) totalSize).collect(Collectors.toList());
when(dataElementCategoryService.getOperands(dataElements, true)).thenReturn(rnd.objects(DataElementOperand.class, (int) totalSize).collect(Collectors.toList()));
final List<DataElementOperand> thirdPageElements = dataElementOperands.subList(50, 50 + pageSize);
ArgumentCaptor<FieldFilterParams> filterParamsArgumentCaptor = ArgumentCaptor.forClass(FieldFilterParams.class);
when(fieldFilterService.toCollectionNode(eq(DataElementOperand.class), filterParamsArgumentCaptor.capture())).thenReturn(buildResponse(thirdPageElements));
doReturn(totalSize).when(queryService).count(any(Query.class));
// Then
ResultActions resultActions = mockMvc.perform(get(ENDPOINT).param("totals", "true").param("pageSize", Integer.toString(pageSize)).param("page", Integer.toString(3))).andExpect(status().isOk()).andExpect(content().contentType("application/json")).andExpect(jsonPath("$.pager.pageSize").value(Integer.toString(pageSize))).andExpect(jsonPath("$.pager.page").value("3")).andExpect(jsonPath("$.pager.total").value(Long.toString(totalSize))).andExpect(jsonPath("$.pager.pageCount").value(Long.toString(totalSize / pageSize))).andExpect(jsonPath("$.dataElementOperands", hasSize(pageSize)));
final FieldFilterParams fieldFilterParams = filterParamsArgumentCaptor.getValue();
assertThat(fieldFilterParams.getObjects(), hasSize(pageSize));
assertThat(fieldFilterParams.getFields(), Matchers.is(Lists.newArrayList("*")));
// Make sure that the first and last element in the page matches with
// the
// original list
List<Map<String, Object>> jsonDataElementOperands = convertResponse(resultActions);
assertThat(jsonDataElementOperands.get(0).get("id"), Matchers.is(dataElementOperands.get(50).getDimensionItem()));
assertThat(jsonDataElementOperands.get(pageSize - 1).get("id"), Matchers.is(dataElementOperands.get(74).getDimensionItem()));
}
Aggregations