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));
}
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));
}
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));
}
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.");
}
Aggregations