Search in sources :

Example 16 with WebOptions

use of org.hisp.dhis.webapi.webdomain.WebOptions in project dhis2-core by dhis2.

the class PaginationHelperTest method testPaginateWhenIntermediatePage.

@Test
void testPaginateWhenIntermediatePage() {
    // Given
    final int pageSize = 5;
    final int secondPage = 2;
    final int totalOfItems = 13;
    final WebOptions theWebOptions = mockWebOptions(pageSize, secondPage);
    final List<DataItem> anyDimensionalItems = mockDimensionalItems(totalOfItems);
    // When
    final List<DataItem> resultingList = paginate(theWebOptions, anyDimensionalItems);
    // Then
    assertThat(resultingList, hasSize(5));
}
Also used : DataItem(org.hisp.dhis.dataitem.DataItem) WebOptions(org.hisp.dhis.webapi.webdomain.WebOptions) Test(org.junit.jupiter.api.Test)

Example 17 with WebOptions

use of org.hisp.dhis.webapi.webdomain.WebOptions in project dhis2-core by dhis2.

the class PaginationHelperTest method testPaginateWhenLastPage.

@Test
void testPaginateWhenLastPage() {
    // Given
    final int pageSize = 5;
    final int lastPage = 3;
    final int totalOfItems = 13;
    final WebOptions theWebOptions = mockWebOptions(pageSize, lastPage);
    final List<DataItem> anyDimensionalItems = mockDimensionalItems(totalOfItems);
    // When
    final List<DataItem> resultingList = paginate(theWebOptions, anyDimensionalItems);
    // Then
    assertThat(resultingList, hasSize(3));
}
Also used : DataItem(org.hisp.dhis.dataitem.DataItem) WebOptions(org.hisp.dhis.webapi.webdomain.WebOptions) Test(org.junit.jupiter.api.Test)

Example 18 with WebOptions

use of org.hisp.dhis.webapi.webdomain.WebOptions in project dhis2-core by dhis2.

the class PaginationHelperTest method testPaginateWhenPageSizeIsZero.

@Test
void testPaginateWhenPageSizeIsZero() {
    // Given
    final int pageSize = 0;
    final int lastPage = 3;
    final int totalOfItems = 13;
    final WebOptions theWebOptions = mockWebOptions(pageSize, lastPage);
    final List<DataItem> anyDimensionalItems = mockDimensionalItems(totalOfItems);
    // When
    assertThrows(IllegalStateException.class, () -> paginate(theWebOptions, anyDimensionalItems), "Page size 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 19 with WebOptions

use of org.hisp.dhis.webapi.webdomain.WebOptions in project dhis2-core by dhis2.

the class PaginationHelperTest method testPaginateWhenFirstPage.

@Test
void testPaginateWhenFirstPage() {
    // Given
    final int pageSize = 5;
    final int firstPage = 1;
    final int totalOfItems = 13;
    final WebOptions theWebOptions = mockWebOptions(pageSize, firstPage);
    final List<DataItem> anyDimensionalItems = mockDimensionalItems(totalOfItems);
    // When
    final List<DataItem> resultingList = paginate(theWebOptions, anyDimensionalItems);
    // Then
    assertThat(resultingList, hasSize(5));
}
Also used : DataItem(org.hisp.dhis.dataitem.DataItem) WebOptions(org.hisp.dhis.webapi.webdomain.WebOptions) Test(org.junit.jupiter.api.Test)

Example 20 with WebOptions

use of org.hisp.dhis.webapi.webdomain.WebOptions in project dhis2-core by dhis2.

the class DimensionItemPageHandlerTest method testAddPaginationToNodeWhenPagingIsFalse.

@Test
void testAddPaginationToNodeWhenPagingIsFalse() {
    // Given
    final RootNode anyRootNode = new RootNode("any");
    final WebOptions webOptionsNoPaging = mockWebOptionsWithPagingFlagFalse();
    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)

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