use of org.hisp.dhis.webapi.webdomain.WebOptions in project dhis2-core by dhis2.
the class PaginationHelperTest method testPaginateWhenPageIsZero.
@Test
void testPaginateWhenPageIsZero() {
// Given
final int pageSize = 5;
final int currentPage = 0;
final WebOptions theWebOptions = mockWebOptions(pageSize, currentPage);
final List<DataItem> emptyDimensionalItems = emptyList();
// When
assertThrows(IllegalStateException.class, () -> paginate(theWebOptions, emptyDimensionalItems), "Current page must be greater than zero.");
}
use of org.hisp.dhis.webapi.webdomain.WebOptions in project dhis2-core by dhis2.
the class DimensionItemPageHandlerTest method testAddPaginationToNodeWithSuccess.
@Test
void testAddPaginationToNodeWithSuccess() {
// Given
final RootNode anyRootNode = new RootNode("any");
final WebOptions anyWebOptions = mockWebOptions(10, 1);
final String anyUid = "LFsZ8v5v7rq";
final int anyTotals = 12;
// When
dimensionItemPageHandler.addPaginationToNodeIfEnabled(anyRootNode, anyWebOptions, anyUid, anyTotals);
// Then
assertThat(anyRootNode, is(notNullValue()));
assertThat(anyRootNode.getName(), is(equalTo("any")));
assertThat(anyRootNode.getChildren(), hasSize(1));
assertThat(anyRootNode.getChildren().get(0).isComplex(), is(true));
verify(linkService, times(1)).generatePagerLinks(any(Pager.class), anyString());
}
use of org.hisp.dhis.webapi.webdomain.WebOptions in project dhis2-core by dhis2.
the class DimensionItemPageHandlerTest method testAddPaginationToNodeWhenNoPagingIsSet.
@Test
void testAddPaginationToNodeWhenNoPagingIsSet() {
// Given
final RootNode anyRootNode = new RootNode("any");
final WebOptions webOptionsNoPaging = mockWebOptionsWithNoPagingFlagSet();
final String anyUid = "LFsZ8v5v7rq";
final int anyTotals = 12;
// When
dimensionItemPageHandler.addPaginationToNodeIfEnabled(anyRootNode, webOptionsNoPaging, anyUid, anyTotals);
// Then
assertThat(anyRootNode, is(notNullValue()));
assertThat(anyRootNode.getName(), is(equalTo("any")));
assertThat(anyRootNode.getChildren(), is(empty()));
verify(linkService, never()).generatePagerLinks(any(Pager.class), anyString());
}
use of org.hisp.dhis.webapi.webdomain.WebOptions in project dhis2-core by dhis2.
the class PaginationUtilsTest method verifyPaginationStartsAtZero.
@Test
void verifyPaginationStartsAtZero() {
Map<String, String> options = new HashMap<>();
options.put(WebOptions.PAGING, "true");
options.put(WebOptions.PAGE, "1");
options.put(WebOptions.PAGE_SIZE, "20");
WebOptions webOptions = new WebOptions(options);
Pagination paginationData = PaginationUtils.getPaginationData(webOptions);
assertThat(paginationData.getFirstResult(), is(0));
assertThat(paginationData.getSize(), is(20));
}
use of org.hisp.dhis.webapi.webdomain.WebOptions in project dhis2-core by dhis2.
the class PaginationUtilsTest method verifyPaginationCalculation.
@Test
void verifyPaginationCalculation() {
Map<String, String> options = new HashMap<>();
options.put(WebOptions.PAGING, "true");
options.put(WebOptions.PAGE, "14");
options.put(WebOptions.PAGE_SIZE, "200");
WebOptions webOptions = new WebOptions(options);
Pagination paginationData = PaginationUtils.getPaginationData(webOptions);
assertThat(paginationData.getFirstResult(), is(2600));
assertThat(paginationData.getSize(), is(200));
}
Aggregations