Search in sources :

Example 11 with DataItem

use of org.hisp.dhis.dataitem.DataItem in project dhis2-core by dhis2.

the class DataItemServiceFacadeTest method testRetrieveDataItemEntities.

@Test
void testRetrieveDataItemEntities() {
    // Given
    final Class<? extends BaseIdentifiableObject> targetEntity = Indicator.class;
    final Set<Class<? extends BaseIdentifiableObject>> anyTargetEntities = new HashSet<>(asList(targetEntity));
    final List<DataItem> expectedItemsFound = asList(mockDataItem(INDICATOR), mockDataItem(INDICATOR));
    final Set<String> anyFilters = newHashSet("anyFilter");
    final WebOptions anyWebOptions = mockWebOptions(10, 1);
    final Set<String> anyOrdering = new HashSet<>(asList("name:desc"));
    final OrderParams anyOrderParams = new OrderParams(anyOrdering);
    final User currentUser = new User();
    // When
    when(currentUserService.getCurrentUser()).thenReturn(currentUser);
    when(queryExecutor.find(anySet(), any(MapSqlParameterSource.class))).thenReturn(expectedItemsFound);
    final List<DataItem> actualDimensionalItems = dataItemServiceFacade.retrieveDataItemEntities(anyTargetEntities, anyFilters, anyWebOptions, anyOrderParams);
    // Then
    assertThat(actualDimensionalItems, hasSize(2));
    assertThat(actualDimensionalItems.get(0).getDimensionItemType(), is(INDICATOR));
    assertThat(actualDimensionalItems.get(1).getDimensionItemType(), is(INDICATOR));
}
Also used : User(org.hisp.dhis.user.User) DataItem(org.hisp.dhis.dataitem.DataItem) WebOptions(org.hisp.dhis.webapi.webdomain.WebOptions) Indicator(org.hisp.dhis.indicator.Indicator) BaseIdentifiableObject(org.hisp.dhis.common.BaseIdentifiableObject) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) OrderParams(org.hisp.dhis.dxf2.common.OrderParams) HashSet(java.util.HashSet) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) Test(org.junit.jupiter.api.Test)

Example 12 with DataItem

use of org.hisp.dhis.dataitem.DataItem in project dhis2-core by dhis2.

the class ResponseHandlerTest method testAddResultsToNodeWithSuccess.

@Test
void testAddResultsToNodeWithSuccess() {
    // Given
    final RootNode anyRootNode = new RootNode("any");
    final DataItem anyDataItem = DataItem.builder().name("any").build();
    final List<DataItem> anyDimensionalItems = singletonList(anyDataItem);
    final Set<String> anyFields = newHashSet("name");
    final CollectionNode anyCollectionNode = new CollectionNode("any");
    // When
    when(fieldFilterService.toConcreteClassCollectionNode(any(), any(), any(), any())).thenReturn(anyCollectionNode);
    responseHandler.addResultsToNode(anyRootNode, anyDimensionalItems, anyFields);
    // Then
    assertThat(anyRootNode, is(notNullValue()));
    assertThat(anyRootNode.getName(), is(equalTo("any")));
    assertThat(anyRootNode.getChildren(), hasSize(1));
    assertThat(anyRootNode.getChildren().get(0).isCollection(), is(true));
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) DataItem(org.hisp.dhis.dataitem.DataItem) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CollectionNode(org.hisp.dhis.node.types.CollectionNode) Test(org.junit.jupiter.api.Test)

Example 13 with DataItem

use of org.hisp.dhis.dataitem.DataItem in project dhis2-core by dhis2.

the class PaginationHelperTest method testPaginateWhenDimensionalItemListIsEmpty.

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

Example 14 with DataItem

use of org.hisp.dhis.dataitem.DataItem 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)

Aggregations

DataItem (org.hisp.dhis.dataitem.DataItem)14 WebOptions (org.hisp.dhis.webapi.webdomain.WebOptions)11 Test (org.junit.jupiter.api.Test)11 BaseIdentifiableObject (org.hisp.dhis.common.BaseIdentifiableObject)5 HashSet (java.util.HashSet)4 OrderParams (org.hisp.dhis.dxf2.common.OrderParams)4 RootNode (org.hisp.dhis.node.types.RootNode)4 User (org.hisp.dhis.user.User)4 Indicator (org.hisp.dhis.indicator.Indicator)3 Sets.newHashSet (com.google.common.collect.Sets.newHashSet)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)2 CollectionNode (org.hisp.dhis.node.types.CollectionNode)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 ResponseEntity (org.springframework.http.ResponseEntity)1