Search in sources :

Example 41 with WebOptions

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.");
}
Also used : DataItem(org.hisp.dhis.dataitem.DataItem) WebOptions(org.hisp.dhis.webapi.webdomain.WebOptions) Test(org.junit.jupiter.api.Test)

Example 42 with WebOptions

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());
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) Pager(org.hisp.dhis.common.Pager) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) WebOptions(org.hisp.dhis.webapi.webdomain.WebOptions) Test(org.junit.jupiter.api.Test)

Example 43 with WebOptions

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());
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) Pager(org.hisp.dhis.common.Pager) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) WebOptions(org.hisp.dhis.webapi.webdomain.WebOptions) Test(org.junit.jupiter.api.Test)

Example 44 with WebOptions

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));
}
Also used : Pagination(org.hisp.dhis.query.Pagination) HashMap(java.util.HashMap) WebOptions(org.hisp.dhis.webapi.webdomain.WebOptions) Test(org.junit.jupiter.api.Test)

Example 45 with WebOptions

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));
}
Also used : Pagination(org.hisp.dhis.query.Pagination) HashMap(java.util.HashMap) WebOptions(org.hisp.dhis.webapi.webdomain.WebOptions) Test(org.junit.jupiter.api.Test)

Aggregations

WebOptions (org.hisp.dhis.webapi.webdomain.WebOptions)45 RootNode (org.hisp.dhis.node.types.RootNode)21 Test (org.junit.jupiter.api.Test)18 Pager (org.hisp.dhis.common.Pager)16 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)14 BaseIdentifiableObject (org.hisp.dhis.common.BaseIdentifiableObject)13 GetMapping (org.springframework.web.bind.annotation.GetMapping)13 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)12 DataItem (org.hisp.dhis.dataitem.DataItem)10 FieldFilterParams (org.hisp.dhis.fieldfilter.FieldFilterParams)10 User (org.hisp.dhis.user.User)9 WebMetadata (org.hisp.dhis.webapi.webdomain.WebMetadata)9 List (java.util.List)8 UpdateAccessDeniedException (org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException)7 Order (org.hisp.dhis.query.Order)7 Query (org.hisp.dhis.query.Query)7 ArrayList (java.util.ArrayList)6 CollectionNode (org.hisp.dhis.node.types.CollectionNode)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 HashMap (java.util.HashMap)5