Search in sources :

Example 16 with DimensionalItemId

use of org.hisp.dhis.common.DimensionalItemId in project dhis2-core by dhis2.

the class DataDimensionExtractorTest method testGetAtomicIdsForProgramDataElement.

@Test
void testGetAtomicIdsForProgramDataElement() {
    // Given
    final DimensionalItemId programDataElementItem = new DimensionalItemId(PROGRAM_DATA_ELEMENT, "id0", "id1");
    final Set<DimensionalItemId> someItemIds = newHashSet(programDataElementItem);
    // When
    final SetMap<Class<? extends IdentifiableObject>, String> result = new DataDimensionExtractor(null).getAtomicIds(someItemIds);
    // Then
    assertThat(result.size(), is(equalTo(2)));
    assertThat(result.get(Program.class), containsInAnyOrder(programDataElementItem.getId0()));
    assertThat(result.get(DataElement.class), containsInAnyOrder(programDataElementItem.getId1()));
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) DimensionalItemId(org.hisp.dhis.common.DimensionalItemId) Program(org.hisp.dhis.program.Program) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) Test(org.junit.jupiter.api.Test)

Example 17 with DimensionalItemId

use of org.hisp.dhis.common.DimensionalItemId in project dhis2-core by dhis2.

the class DataDimensionExtractorTest method testGetAtomicIdsForReportingRate.

@Test
void testGetAtomicIdsForReportingRate() {
    // Given
    final DimensionalItemId reportingRateItem = new DimensionalItemId(REPORTING_RATE, "id0", "REPORTING_RATE");
    final Set<DimensionalItemId> someItemIds = newHashSet(reportingRateItem);
    // When
    final SetMap<Class<? extends IdentifiableObject>, String> result = new DataDimensionExtractor(null).getAtomicIds(someItemIds);
    // Then
    assertThat(result.size(), is(equalTo(1)));
    assertThat(result.get(DataSet.class), containsInAnyOrder(reportingRateItem.getId0()));
}
Also used : DimensionalItemId(org.hisp.dhis.common.DimensionalItemId) DataSet(org.hisp.dhis.dataset.DataSet) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) Test(org.junit.jupiter.api.Test)

Example 18 with DimensionalItemId

use of org.hisp.dhis.common.DimensionalItemId in project dhis2-core by dhis2.

the class CategoryOptionResolverTest method verifyExpressionIsNotResolvedWhenDimensionalItemIdHasNoItem.

@Test
void verifyExpressionIsNotResolvedWhenDimensionalItemIdHasNoItem() {
    // arrange
    dimensionalItemId = new DimensionalItemId(DimensionItemType.DATA_ELEMENT_OPERAND, uid1, CATEGORY_OPTION_PREFIX + uid2, uid3, createIndicatorExpression());
    String expression = createIndicatorExpression();
    when(expressionService.getExpressionDimensionalItemIds(expression, INDICATOR_EXPRESSION)).thenReturn(Sets.newHashSet(dimensionalItemId));
    // act
    String resolvedExpression = resolver.resolve(expression);
    // assert
    assertResolvedExpressionEquals(resolvedExpression, coc1.getUid(), coc2.getUid(), coc3.getUid());
}
Also used : DimensionalItemId(org.hisp.dhis.common.DimensionalItemId) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 19 with DimensionalItemId

use of org.hisp.dhis.common.DimensionalItemId in project dhis2-core by dhis2.

the class CategoryOptionResolverTest method verifyExpressionIsNotResolvedWhenCoPrefixNotInUid1.

@Test
void verifyExpressionIsNotResolvedWhenCoPrefixNotInUid1() {
    // arrange
    dimensionalItemId = new DimensionalItemId(DimensionItemType.DATA_ELEMENT_OPERAND, uid1, uid2, uid3, createIndicatorExpression());
    String expression = createIndicatorExpression();
    when(expressionService.getExpressionDimensionalItemIds(expression, INDICATOR_EXPRESSION)).thenReturn(Sets.newHashSet(dimensionalItemId));
    // act
    String resolvedExpression = resolver.resolve(expression);
    // assert
    assertEquals(expression, resolvedExpression);
}
Also used : DimensionalItemId(org.hisp.dhis.common.DimensionalItemId) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 20 with DimensionalItemId

use of org.hisp.dhis.common.DimensionalItemId in project dhis2-core by dhis2.

the class DataElementGroupResolverTest method verifyExpressionIsResolvedProperly.

@Test
void verifyExpressionIsResolvedProperly() {
    // arrange
    dimensionalItemId = new DimensionalItemId(DimensionItemType.DATA_ELEMENT_OPERAND, DATA_ELEMENT_GROUP_PREFIX + uid1, uid2, uid3, createIndicatorExpression());
    String expression = createIndicatorExpression();
    when(expressionService.getExpressionDimensionalItemIds(expression, INDICATOR_EXPRESSION)).thenReturn(Sets.newHashSet(dimensionalItemId));
    // act
    String resolvedExpression = resolver.resolve(expression);
    // assert
    assertResolvedExpressionEquals(resolvedExpression, de1.getUid(), de2.getUid(), de3.getUid());
}
Also used : DimensionalItemId(org.hisp.dhis.common.DimensionalItemId) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Aggregations

DimensionalItemId (org.hisp.dhis.common.DimensionalItemId)46 Test (org.junit.jupiter.api.Test)32 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)21 DhisSpringTest (org.hisp.dhis.DhisSpringTest)13 Indicator (org.hisp.dhis.indicator.Indicator)12 ProgramIndicator (org.hisp.dhis.program.ProgramIndicator)12 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)12 HashMap (java.util.HashMap)11 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)9 DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)9 IndicatorValue (org.hisp.dhis.indicator.IndicatorValue)8 IndicatorType (org.hisp.dhis.indicator.IndicatorType)6 DataElement (org.hisp.dhis.dataelement.DataElement)5 List (java.util.List)4 BaseDimensionalItemObject (org.hisp.dhis.common.BaseDimensionalItemObject)4 Period (org.hisp.dhis.period.Period)4 ArrayList (java.util.ArrayList)3 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3 AllArgsConstructor (lombok.AllArgsConstructor)3