diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java index 5ae65e907996..0abc0db2c80d 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java @@ -739,6 +739,14 @@ public void setPath(String path) { this.path = path; } + /** + * Note that the {@code path} is mapped with the "property access" mode. This method is for unit + * testing purposes only. + */ + public void updatePath() { + setPath(getPath()); + } + /** * Used by persistence layer. Purpose is to have a column for use in database queries. For * application use see {@link OrganisationUnit#getLevel()} which has better performance. diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/AnalyticsServiceMetadataTest.java b/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/AnalyticsServiceMetadataTest.java index 3512d14af20d..c82166da424e 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/AnalyticsServiceMetadataTest.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/AnalyticsServiceMetadataTest.java @@ -33,6 +33,7 @@ import static org.hamcrest.Matchers.hasProperty; import static org.hamcrest.Matchers.is; import static org.hisp.dhis.DhisConvenienceTest.createDataElement; +import static org.hisp.dhis.DhisConvenienceTest.createOrganisationUnit; import static org.hisp.dhis.analytics.DataQueryParams.DISPLAY_NAME_DATA_X; import static org.hisp.dhis.analytics.DataQueryParams.DISPLAY_NAME_ORGUNIT; import static org.hisp.dhis.period.RelativePeriodEnum.THIS_QUARTER; @@ -59,7 +60,6 @@ import org.hisp.dhis.dataelement.DataElementGroup; import org.hisp.dhis.indicator.Indicator; import org.hisp.dhis.indicator.IndicatorGroup; -import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.organisationunit.OrganisationUnitLevel; import org.hisp.dhis.period.MonthlyPeriodType; import org.hisp.dhis.period.Period; @@ -98,9 +98,7 @@ void metadataContainsOuLevelData() { DimensionType.ORGANISATION_UNIT, null, DISPLAY_NAME_ORGUNIT, - List.of( - new OrganisationUnit("aaa", "aaa", "OU_1", null, null, "c1"), - new OrganisationUnit("bbb", "bbb", "OU_2", null, null, "c2")), + List.of(createOrganisationUnit('A'), createOrganisationUnit('B')), new DimensionItemKeywords( Lists.newArrayList( buildOrgUnitLevel(2, "wjP19dkFeIk", "District", null), @@ -159,9 +157,7 @@ void metadataContainsIndicatorGroupMetadata() { DimensionType.ORGANISATION_UNIT, null, DISPLAY_NAME_ORGUNIT, - List.of( - new OrganisationUnit("aaa", "aaa", "OU_1", null, null, "c1"), - new OrganisationUnit("bbb", "bbb", "OU_2", null, null, "c2"))))) + List.of(createOrganisationUnit('A'), createOrganisationUnit('B'))))) .withIgnoreLimit(true) .withSkipData(true) .build(); @@ -197,9 +193,7 @@ void metadataContainsOuGroupData() { DimensionType.ORGANISATION_UNIT, null, DISPLAY_NAME_ORGUNIT, - List.of( - new OrganisationUnit("aaa", "aaa", "OU_1", null, null, "c1"), - new OrganisationUnit("bbb", "bbb", "OU_2", null, null, "c2")), + List.of(createOrganisationUnit('A'), createOrganisationUnit('B')), new DimensionItemKeywords( Lists.newArrayList( new BaseNameableObject("tTUf91fCytl", "OU_12345", "Chiefdom")))))) @@ -249,7 +243,7 @@ void metadataContainsDataElementGroupMetadata() { DimensionType.ORGANISATION_UNIT, null, DISPLAY_NAME_ORGUNIT, - List.of(new OrganisationUnit("aaa", "aaa", "OU_1", null, null, "c1"))))) + List.of(createOrganisationUnit('A'))))) .withIgnoreLimit(true) .withSkipData(true) .build(); diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/AnalyticsServiceProgramDataElementTest.java b/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/AnalyticsServiceProgramDataElementTest.java index 195b4c00d1f8..2156642ba004 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/AnalyticsServiceProgramDataElementTest.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/AnalyticsServiceProgramDataElementTest.java @@ -32,6 +32,7 @@ import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.is; import static org.hisp.dhis.DhisConvenienceTest.createDataElement; +import static org.hisp.dhis.DhisConvenienceTest.createOrganisationUnit; import static org.hisp.dhis.DhisConvenienceTest.createProgram; import static org.hisp.dhis.analytics.DataQueryParams.DISPLAY_NAME_ORGUNIT; import static org.mockito.ArgumentMatchers.any; @@ -50,7 +51,6 @@ import org.hisp.dhis.common.BaseDimensionalObject; import org.hisp.dhis.common.DimensionType; import org.hisp.dhis.dataelement.DataElement; -import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.period.Period; import org.hisp.dhis.period.YearlyPeriodType; import org.hisp.dhis.program.Program; @@ -89,7 +89,7 @@ void verifyProgramDataElementInQueryCallsEventsAnalytics() { DimensionType.ORGANISATION_UNIT, null, DISPLAY_NAME_ORGUNIT, - List.of(new OrganisationUnit("bbb", "bbb", "OU_2", null, null, "c2"))))) + List.of(createOrganisationUnit('A'))))) .build(); initMock(params); diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/AnalyticsServiceReportingRateTest.java b/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/AnalyticsServiceReportingRateTest.java index ed317f8f504e..8e5b5b4c5f8e 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/AnalyticsServiceReportingRateTest.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/AnalyticsServiceReportingRateTest.java @@ -32,6 +32,7 @@ import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.is; import static org.hisp.dhis.DhisConvenienceTest.createDataSet; +import static org.hisp.dhis.DhisConvenienceTest.createOrganisationUnit; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; import static org.mockito.ArgumentMatchers.any; @@ -88,7 +89,7 @@ void verifyReportingRatesValueWhenPeriodIsFilter() { periods.add( new MonthlyPeriodType().createPeriod(new DateTime(2014, x, 1, 0, 0).toDate()))); - OrganisationUnit ou = new OrganisationUnit("aaaa"); + OrganisationUnit ou = createOrganisationUnit('A'); DataQueryParams params = DataQueryParams.newBuilder() @@ -149,7 +150,7 @@ void verifyNullValueIsZeroForReportingRate() { List periods = new ArrayList<>(); periods.add(new MonthlyPeriodType().createPeriod(new DateTime(2014, 1, 1, 0, 0).toDate())); - OrganisationUnit ou = new OrganisationUnit("aaaa"); + OrganisationUnit ou = createOrganisationUnit('A'); DataQueryParams params = DataQueryParams.newBuilder() @@ -195,7 +196,7 @@ void verifyNullTargetIsNullForReportingRate() { List periods = new ArrayList<>(); periods.add(new MonthlyPeriodType().createPeriod(new DateTime(2014, 1, 1, 0, 0).toDate())); - OrganisationUnit ou = new OrganisationUnit("aaaa"); + OrganisationUnit ou = createOrganisationUnit('A'); DataQueryParams params = DataQueryParams.newBuilder() @@ -240,7 +241,7 @@ void verifyReportingRatesForMonthsWithLessThen30DaysAreComputedCorrectly() { List periods = new ArrayList<>(); periods.add(PeriodType.getPeriodFromIsoString("201902")); - OrganisationUnit ou = new OrganisationUnit("aaaa"); + OrganisationUnit ou = createOrganisationUnit('A'); // Create request DataQueryParams params = @@ -289,7 +290,7 @@ void verifyReportingRatesForMonthsWithMoreThen30DaysAreComputedCorrectly() { List periods = new ArrayList<>(); periods.add(PeriodType.getPeriodFromIsoString("201901")); - OrganisationUnit ou = new OrganisationUnit("aaaa"); + OrganisationUnit ou = createOrganisationUnit('A'); // Create request DataQueryParams params = diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/DataQueryServiceDimensionItemKeywordTest.java b/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/DataQueryServiceDimensionItemKeywordTest.java index a7224ccd5270..a09e3e76e0c4 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/DataQueryServiceDimensionItemKeywordTest.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/DataQueryServiceDimensionItemKeywordTest.java @@ -30,6 +30,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.is; +import static org.hisp.dhis.DhisConvenienceTest.createOrganisationUnit; import static org.hisp.dhis.common.DimensionalObject.PERIOD_DIM_ID; import static org.hisp.dhis.common.IdScheme.UID; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -149,7 +150,7 @@ public void setUp() { Mockito.lenient().when(i18nManager.getI18n()).thenReturn(i18n); Mockito.lenient().when(i18n.getString("LAST_12_MONTHS")).thenReturn("Last 12 months"); - rootOu = new OrganisationUnit("Sierra Leone"); + rootOu = createOrganisationUnit("Sierra Leone"); rootOu.setUid(CodeGenerator.generateUid()); rootOu.setCode("OU_525"); } @@ -171,7 +172,7 @@ void convertAnalyticsRequestWithOuLevelToDataQueryParam() { .thenReturn(getOrgUnitLevel(2, "level2UID", "District", null)); when(organisationUnitService.getOrganisationUnitLevelByLevelOrUid("2")).thenReturn(2); when(organisationUnitService.getOrganisationUnitsAtLevels(Mockito.anyList(), Mockito.anyList())) - .thenReturn(Lists.newArrayList(new OrganisationUnit(), new OrganisationUnit())); + .thenReturn(Lists.newArrayList(createOrganisationUnit('A'), createOrganisationUnit('B'))); rb.addOuFilter("LEVEL-2;ImspTQPwCqd"); rb.addDimension(concatenateUuid(DATA_ELEMENT_1, DATA_ELEMENT_2, DATA_ELEMENT_3)); @@ -206,7 +207,7 @@ void convertAnalyticsRequestWithMultipleOuLevelToDataQueryParam() { when(organisationUnitService.getOrganisationUnitLevelByLevelOrUid("3")).thenReturn(3); when(organisationUnitService.getOrganisationUnitLevelByLevelOrUid("2")).thenReturn(2); when(organisationUnitService.getOrganisationUnitsAtLevels(Mockito.anyList(), Mockito.anyList())) - .thenReturn(Lists.newArrayList(new OrganisationUnit(), new OrganisationUnit())); + .thenReturn(Lists.newArrayList(createOrganisationUnit('A'), createOrganisationUnit('B'))); rb.addOuFilter("LEVEL-2;LEVEL-3;ImspTQPwCqd"); rb.addDimension(concatenateUuid(DATA_ELEMENT_1, DATA_ELEMENT_2, DATA_ELEMENT_3)); @@ -247,9 +248,9 @@ void convertAnalyticsRequestWithIndicatorGroup() { when(idObjectManager.getObject(IndicatorGroup.class, UID, INDICATOR_GROUP_UID)) .thenReturn(indicatorGroup); when(idObjectManager.getObject(OrganisationUnit.class, UID, "goRUwCHPg1M")) - .thenReturn(new OrganisationUnit("aaa")); + .thenReturn(createOrganisationUnit('A')); when(idObjectManager.getObject(OrganisationUnit.class, UID, "fdc6uOvgoji")) - .thenReturn(new OrganisationUnit("bbb")); + .thenReturn(createOrganisationUnit('B')); rb.addOuFilter("goRUwCHPg1M;fdc6uOvgoji"); rb.addDimension("IN_GROUP-" + INDICATOR_GROUP_UID + ";cYeuwXTCPkU;Jtf34kNZhz"); @@ -314,8 +315,8 @@ void convertAnalyticsRequestWithOrgUnitGroupAsFilter() { @Test void convertAnalyticsRequestWithOrgUnitLevelAsFilter() { - OrganisationUnit level2OuA = new OrganisationUnit("Bo"); - OrganisationUnit level2OuB = new OrganisationUnit("Bombali"); + OrganisationUnit level2OuA = createOrganisationUnit('B'); + OrganisationUnit level2OuB = createOrganisationUnit('C'); mockDimensionService(); @@ -357,8 +358,8 @@ void convertAnalyticsRequestWithOrgUnitLevelAsFilter() { @Test void convertAnalyticsRequestWithOrgUnitLevelAndOrgUnitGroupAsFilter() { - OrganisationUnit level2OuA = new OrganisationUnit("Bo"); - OrganisationUnit level2OuB = new OrganisationUnit("Bombali"); + OrganisationUnit level2OuA = createOrganisationUnit('B'); + OrganisationUnit level2OuB = createOrganisationUnit('C'); OrganisationUnit ou1Group = new OrganisationUnit("ou1-group"); OrganisationUnit ou2Group = new OrganisationUnit("ou2-group"); @@ -431,9 +432,9 @@ void convertAnalyticsRequestWithDataElementGroup() { when(idObjectManager.getObject(DataElementGroup.class, UID, DATA_ELEMENT_GROUP_UID)) .thenReturn(dataElementGroup); when(idObjectManager.getObject(OrganisationUnit.class, UID, "goRUwCHPg1M")) - .thenReturn(new OrganisationUnit("aaa")); + .thenReturn(createOrganisationUnit('A')); when(idObjectManager.getObject(OrganisationUnit.class, UID, "fdc6uOvgoji")) - .thenReturn(new OrganisationUnit("bbb")); + .thenReturn(createOrganisationUnit('B')); rb.addOuFilter("goRUwCHPg1M;fdc6uOvgoji"); rb.addDimension("DE_GROUP-" + DATA_ELEMENT_GROUP_UID + ";cYeuwXTCPkU;Jtf34kNZhz"); @@ -480,9 +481,9 @@ void convertAnalyticsRequestWithDataElementGroupAndIndicatorGroup() { .thenReturn(indicatorGroup); when(idObjectManager.getObject(OrganisationUnit.class, UID, "goRUwCHPg1M")) - .thenReturn(new OrganisationUnit("aaa")); + .thenReturn(createOrganisationUnit('A')); when(idObjectManager.getObject(OrganisationUnit.class, UID, "fdc6uOvgoji")) - .thenReturn(new OrganisationUnit("bbb")); + .thenReturn(createOrganisationUnit('B')); rb.addOuFilter("goRUwCHPg1M;fdc6uOvgoji"); rb.addDimension( @@ -623,7 +624,7 @@ private void initOrgUnitGroup(String ouGroupUID) { when(idObjectManager.getObject(OrganisationUnit.class, UID, this.rootOu.getUid())) .thenReturn(rootOu); when(organisationUnitService.getOrganisationUnits(Mockito.anyList(), Mockito.anyList())) - .thenReturn(Lists.newArrayList(new OrganisationUnit(), new OrganisationUnit())); + .thenReturn(Lists.newArrayList(createOrganisationUnit('A'), createOrganisationUnit('B'))); } private void assertOrgUnitGroup(String ouGroupUID, DimensionalObject dimension) { diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/QueryPlannerGroupByAggregationTypeTest.java b/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/QueryPlannerGroupByAggregationTypeTest.java index d9b15b6cdd48..354d81e7de7a 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/QueryPlannerGroupByAggregationTypeTest.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/QueryPlannerGroupByAggregationTypeTest.java @@ -37,6 +37,7 @@ import static org.hisp.dhis.DhisConvenienceTest.createDataElement; import static org.hisp.dhis.DhisConvenienceTest.createIndicator; import static org.hisp.dhis.DhisConvenienceTest.createIndicatorType; +import static org.hisp.dhis.DhisConvenienceTest.createOrganisationUnit; import static org.hisp.dhis.analytics.DataQueryParams.DISPLAY_NAME_DATA_X; import static org.hisp.dhis.analytics.DataQueryParams.DISPLAY_NAME_ORGUNIT; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -58,7 +59,6 @@ import org.hisp.dhis.common.DimensionalItemObject; import org.hisp.dhis.common.ValueType; import org.hisp.dhis.dataelement.DataElementDomain; -import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.period.MonthlyPeriodType; import org.joda.time.DateTime; import org.junit.jupiter.api.BeforeEach; @@ -113,7 +113,7 @@ void verifyMultipleDataElementIsAggregatedWithTwoQueryGroupWhenDataTypeIsDiffere DimensionType.ORGANISATION_UNIT, null, DISPLAY_NAME_ORGUNIT, - List.of(new OrganisationUnit("bbb", "bbb", "OU_2", null, null, "c2"))))) + List.of(createOrganisationUnit('A'))))) .withAggregationType(AnalyticsAggregationType.AVERAGE) .build(); @@ -166,7 +166,7 @@ void verifySingleNonDataElementRetainAggregationTypeButNullDataType() { DimensionType.ORGANISATION_UNIT, null, DISPLAY_NAME_ORGUNIT, - List.of(new OrganisationUnit("bbb", "bbb", "OU_2", null, null, "c2"))))) + List.of(createOrganisationUnit('A'))))) .withAggregationType(AnalyticsAggregationType.AVERAGE) .build(); @@ -356,7 +356,7 @@ private DataQueryParams createDataQueryParams(BaseDimensionalObject filterDataEl DimensionType.ORGANISATION_UNIT, null, DISPLAY_NAME_ORGUNIT, - List.of(new OrganisationUnit("bbb", "bbb", "OU_2", null, null, "c2"))), + List.of(createOrganisationUnit('A'))), // DATA ELEMENT AS FILTER filterDataElements)) .build(); diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/event/data/AbstractJdbcEventAnalyticsManagerTest.java b/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/event/data/AbstractJdbcEventAnalyticsManagerTest.java index 98dfed515d59..7e0dd371d250 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/event/data/AbstractJdbcEventAnalyticsManagerTest.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/event/data/AbstractJdbcEventAnalyticsManagerTest.java @@ -47,7 +47,9 @@ import static org.hisp.dhis.common.QueryOperator.NEQ; import static org.hisp.dhis.common.QueryOperator.NIEQ; import static org.hisp.dhis.common.QueryOperator.NILIKE; -import static org.hisp.dhis.common.ValueType.*; +import static org.hisp.dhis.common.ValueType.BOOLEAN; +import static org.hisp.dhis.common.ValueType.NUMBER; +import static org.hisp.dhis.common.ValueType.TEXT; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -509,7 +511,7 @@ void testGetWhereClauseWithMultipleOrgUnitDescendantsAtSameLevel() { assertThat( whereClause, - containsString("and ax.\"uidlevel0\" in ('ouabcdefghA','ouabcdefghB','ouabcdefghC')")); + containsString("and ax.\"uidlevel1\" in ('ouabcdefghA','ouabcdefghB','ouabcdefghC')")); } @Test diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/orgunit/OrgUnitHelperTest.java b/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/orgunit/OrgUnitHelperTest.java index ab120d7e261c..5306b8b68a23 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/orgunit/OrgUnitHelperTest.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/orgunit/OrgUnitHelperTest.java @@ -27,6 +27,7 @@ */ package org.hisp.dhis.analytics.orgunit; +import static org.hisp.dhis.DhisConvenienceTest.createOrganisationUnit; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; @@ -48,9 +49,9 @@ void getActiveOrganisationUnits_returns_only_active_units() { // Given List rqOrgUnit = new ArrayList<>(); - rqOrgUnit.add(new OrganisationUnit("name1")); - rqOrgUnit.add(new OrganisationUnit("name2")); - rqOrgUnit.add(new OrganisationUnit("name3")); + rqOrgUnit.add(createOrganisationUnit('A')); + rqOrgUnit.add(createOrganisationUnit('B')); + rqOrgUnit.add(createOrganisationUnit('C')); rqOrgUnit.get(0).setUid(CodeGenerator.generateUid()); rqOrgUnit.get(1).setUid(CodeGenerator.generateUid()); @@ -75,9 +76,9 @@ void getActiveOrganisationUnits_returns_same_units() { // Given List rqOrgUnit = new ArrayList<>(); - rqOrgUnit.add(new OrganisationUnit("name1")); - rqOrgUnit.add(new OrganisationUnit("name2")); - rqOrgUnit.add(new OrganisationUnit("name3")); + rqOrgUnit.add(createOrganisationUnit('A')); + rqOrgUnit.add(createOrganisationUnit('B')); + rqOrgUnit.add(createOrganisationUnit('C')); rqOrgUnit.get(0).setUid(CodeGenerator.generateUid()); rqOrgUnit.get(1).setUid(CodeGenerator.generateUid()); diff --git a/dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityInstanceServiceTest.java b/dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityInstanceServiceTest.java index 5df443b30446..550d5073235a 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityInstanceServiceTest.java +++ b/dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityInstanceServiceTest.java @@ -27,15 +27,15 @@ */ package org.hisp.dhis.trackedentity; +import static org.hisp.dhis.DhisConvenienceTest.createOrganisationUnit; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.mockito.Mockito.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; import java.util.Set; import org.hisp.dhis.common.IllegalQueryException; import org.hisp.dhis.common.OrganisationUnitSelectionMode; -import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.organisationunit.OrganisationUnitService; import org.hisp.dhis.program.Program; import org.hisp.dhis.program.ProgramService; @@ -96,8 +96,8 @@ void setup() { attributeValueAuditService); User user = new User(); - user.setOrganisationUnits(Set.of(new OrganisationUnit("A"))); - user.setTeiSearchOrganisationUnits(Set.of(new OrganisationUnit("B"))); + user.setOrganisationUnits(Set.of(createOrganisationUnit('A'))); + user.setTeiSearchOrganisationUnits(Set.of(createOrganisationUnit('B'))); when(currentUserService.getCurrentUser()).thenReturn(user); params = new TrackedEntityInstanceQueryParams(); diff --git a/dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/trackedentity/DefaultTrackerAccessManagerTest.java b/dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/trackedentity/DefaultTrackerAccessManagerTest.java index 6ca37f424491..5d8d7f8aaaca 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/trackedentity/DefaultTrackerAccessManagerTest.java +++ b/dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/trackedentity/DefaultTrackerAccessManagerTest.java @@ -27,6 +27,8 @@ */ package org.hisp.dhis.trackedentity; +import static org.hisp.dhis.DhisConvenienceTest.createOrganisationUnit; +import static org.hisp.dhis.DhisConvenienceTest.createProgram; import static org.hisp.dhis.common.AccessLevel.CLOSED; import static org.hisp.dhis.common.AccessLevel.OPEN; import static org.hisp.dhis.common.AccessLevel.PROTECTED; @@ -38,6 +40,7 @@ import org.hisp.dhis.organisationunit.OrganisationUnitService; import org.hisp.dhis.program.Program; import org.hisp.dhis.user.User; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; @@ -51,12 +54,22 @@ class DefaultTrackerAccessManagerTest { @InjectMocks private DefaultTrackerAccessManager trackerAccessManager; + private Program program; + + private OrganisationUnit orgUnit; + + private User user; + + @BeforeEach + void before() { + program = createProgram('A'); + orgUnit = createOrganisationUnit('A'); + user = new User(); + } + @Test void shouldHaveAccessWhenProgramOpenAndSearchAccessAvailable() { - User user = new User(); - Program program = new Program(); program.setAccessLevel(OPEN); - OrganisationUnit orgUnit = new OrganisationUnit(); when(organisationUnitService.isInUserSearchHierarchy(user, orgUnit)).thenReturn(true); @@ -67,10 +80,7 @@ void shouldHaveAccessWhenProgramOpenAndSearchAccessAvailable() { @Test void shouldNotHaveAccessWhenProgramOpenAndSearchAccessNotAvailable() { - User user = new User(); - Program program = new Program(); program.setAccessLevel(OPEN); - OrganisationUnit orgUnit = new OrganisationUnit(); when(organisationUnitService.isInUserSearchHierarchy(user, orgUnit)).thenReturn(false); @@ -81,9 +91,6 @@ void shouldNotHaveAccessWhenProgramOpenAndSearchAccessNotAvailable() { @Test void shouldHaveAccessWhenProgramNullAndSearchAccessAvailable() { - User user = new User(); - OrganisationUnit orgUnit = new OrganisationUnit(); - when(organisationUnitService.isInUserSearchHierarchy(user, orgUnit)).thenReturn(true); assertTrue( @@ -93,9 +100,6 @@ void shouldHaveAccessWhenProgramNullAndSearchAccessAvailable() { @Test void shouldNotHaveAccessWhenProgramNullAndSearchAccessNotAvailable() { - User user = new User(); - OrganisationUnit orgUnit = new OrganisationUnit(); - when(organisationUnitService.isInUserSearchHierarchy(user, orgUnit)).thenReturn(false); assertFalse( @@ -105,10 +109,7 @@ void shouldNotHaveAccessWhenProgramNullAndSearchAccessNotAvailable() { @Test void shouldHaveAccessWhenProgramClosedAndCaptureAccessAvailable() { - User user = new User(); - Program program = new Program(); program.setAccessLevel(CLOSED); - OrganisationUnit orgUnit = new OrganisationUnit(); when(organisationUnitService.isInUserHierarchy(user, orgUnit)).thenReturn(true); @@ -119,10 +120,7 @@ void shouldHaveAccessWhenProgramClosedAndCaptureAccessAvailable() { @Test void shouldNotHaveAccessWhenProgramClosedAndCaptureAccessNotAvailable() { - User user = new User(); - Program program = new Program(); program.setAccessLevel(CLOSED); - OrganisationUnit orgUnit = new OrganisationUnit(); when(organisationUnitService.isInUserHierarchy(user, orgUnit)).thenReturn(false); @@ -133,10 +131,7 @@ void shouldNotHaveAccessWhenProgramClosedAndCaptureAccessNotAvailable() { @Test void shouldHaveAccessWhenProgramProtectedAndCaptureAccessAvailable() { - User user = new User(); - Program program = new Program(); program.setAccessLevel(PROTECTED); - OrganisationUnit orgUnit = new OrganisationUnit(); when(organisationUnitService.isInUserHierarchy(user, orgUnit)).thenReturn(true); @@ -147,12 +142,7 @@ void shouldHaveAccessWhenProgramProtectedAndCaptureAccessAvailable() { @Test void shouldNotHaveAccessWhenProgramProtectedAndCaptureAccessNotAvailable() { - User user = new User(); - Program program = new Program(); program.setAccessLevel(PROTECTED); - OrganisationUnit orgUnit = new OrganisationUnit(); - - when(organisationUnitService.isInUserHierarchy(user, orgUnit)).thenReturn(false); assertFalse( trackerAccessManager.canAccess(user, program, orgUnit), diff --git a/dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityAttributeServiceTest.java b/dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityAttributeServiceTest.java index 7baa4a55a102..aa80679fe614 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityAttributeServiceTest.java +++ b/dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityAttributeServiceTest.java @@ -27,6 +27,7 @@ */ package org.hisp.dhis.trackedentity; +import static org.hisp.dhis.DhisConvenienceTest.createOrganisationUnit; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -108,7 +109,7 @@ public void setUp() { programAttributeStore, organisationUnitService); - orgUnit = new OrganisationUnit("orgUnitA"); + orgUnit = createOrganisationUnit('A'); teiPassedInPayload = new TrackedEntityInstance(); teiPassedInPayload.setUid(identicalTeiUid); diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/TrackerCrudTest.java b/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/TrackerCrudTest.java index f682b80cedfd..7ea5e15f1000 100644 --- a/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/TrackerCrudTest.java +++ b/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/TrackerCrudTest.java @@ -27,12 +27,13 @@ */ package org.hisp.dhis.dxf2; +import static org.hisp.dhis.DhisConvenienceTest.createOrganisationUnit; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyList; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.CALLS_REAL_METHODS; -import static org.mockito.Mockito.any; -import static org.mockito.Mockito.anyBoolean; -import static org.mockito.Mockito.anyList; -import static org.mockito.Mockito.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -164,7 +165,7 @@ public void setUp() { TrackedEntityType.class, IdScheme.UID, trackedEntityTypeUid)) .thenReturn(new TrackedEntityType()); when(identifiableObjectManager.getObject(OrganisationUnit.class, IdScheme.UID, orgUnitUid)) - .thenReturn(new OrganisationUnit()); + .thenReturn(createOrganisationUnit('A')); when(trackerAccessManager.canWrite( any(), any(org.hisp.dhis.trackedentity.TrackedEntityInstance.class))) .thenReturn(new ArrayList<>()); diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/dataset/DefaultCompleteDataSetRegistrationExchangeServiceTest.java b/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/dataset/DefaultCompleteDataSetRegistrationExchangeServiceTest.java index e89edac7cc7f..71f4a3ef273a 100644 --- a/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/dataset/DefaultCompleteDataSetRegistrationExchangeServiceTest.java +++ b/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/dataset/DefaultCompleteDataSetRegistrationExchangeServiceTest.java @@ -292,7 +292,7 @@ void verifyUserHasNoWritePermissionOnCategoryOption() { void testValidateAssertMissingDataSet() { ExportParams params = new ExportParams() - .setOrganisationUnits(Sets.newHashSet(new OrganisationUnit())) + .setOrganisationUnits(Sets.newHashSet(createOrganisationUnit('A'))) .setPeriods(Sets.newHashSet(new Period())); assertIllegalQueryEx( diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetImportValidatorTest.java b/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetImportValidatorTest.java index da4b9bdfbceb..419c6881029c 100644 --- a/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetImportValidatorTest.java +++ b/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetImportValidatorTest.java @@ -29,6 +29,7 @@ import static java.util.Collections.emptySet; import static java.util.Collections.singleton; +import static org.hisp.dhis.DhisConvenienceTest.createOrganisationUnit; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -878,11 +879,9 @@ private DataValueContextBuilder createDataValueContext(DataValue dataValue) { builder.period(p); } if (ouId != null) { - OrganisationUnit ou = new OrganisationUnit(); + OrganisationUnit ou = createOrganisationUnit('A'); ou.setUid(ouId); - // we set the path here just for the tests. This is usually done by the persistence layer - // but there is no interaction with that in these tests. - ou.setPath(ou.getPath()); + ou.updatePath(); builder.orgUnit(ou); } if (coId != null) { diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/event/JdbcEventStoreTest.java b/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/event/JdbcEventStoreTest.java index 8366e813a283..20848d2630f5 100644 --- a/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/event/JdbcEventStoreTest.java +++ b/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/event/JdbcEventStoreTest.java @@ -29,6 +29,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.collection.IsCollectionWithSize.hasSize; +import static org.hisp.dhis.DhisConvenienceTest.createOrganisationUnit; import static org.hisp.dhis.utils.Assertions.assertNotEmpty; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; @@ -47,7 +48,6 @@ import org.hisp.dhis.dxf2.events.trackedentity.store.EventStore; import org.hisp.dhis.event.EventStatus; import org.hisp.dhis.jdbc.statementbuilder.PostgreSQLStatementBuilder; -import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.organisationunit.OrganisationUnitStore; import org.hisp.dhis.program.ProgramInstance; import org.hisp.dhis.program.ProgramStage; @@ -138,7 +138,8 @@ void verifyNullOrganisationUnitsIsHandled() throws SQLException { void shouldUpdateEventsWhenDateFieldsAreNotSet() { List programStageInstances = new ArrayList<>(); ProgramStageInstance psi = - new ProgramStageInstance(new ProgramInstance(), new ProgramStage(), new OrganisationUnit()); + new ProgramStageInstance( + new ProgramInstance(), new ProgramStage(), createOrganisationUnit('A')); psi.setStatus(EventStatus.ACTIVE); psi.setAttributeOptionCombo(new CategoryOptionCombo()); programStageInstances.add(psi); diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/importer/context/ProgramOrgUnitSupplierTest.java b/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/importer/context/ProgramOrgUnitSupplierTest.java index 42617aebeea6..ba581e0a4442 100644 --- a/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/importer/context/ProgramOrgUnitSupplierTest.java +++ b/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/importer/context/ProgramOrgUnitSupplierTest.java @@ -30,6 +30,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.hasSize; +import static org.hisp.dhis.DhisConvenienceTest.createOrganisationUnit; import static org.mockito.Mockito.when; import java.sql.SQLException; @@ -57,10 +58,10 @@ void setUp() { @Test void verifySupplier() throws SQLException { // Org Unit // - OrganisationUnit ou1 = new OrganisationUnit(); + OrganisationUnit ou1 = createOrganisationUnit('A'); ou1.setId(1); ou1.setUid("abcded"); - OrganisationUnit ou2 = new OrganisationUnit(); + OrganisationUnit ou2 = createOrganisationUnit('B'); ou2.setId(2); ou2.setUid("fgfgfg"); // create 2 events to import - each one pointing to a different org unit diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/importer/insert/validation/ProgramOrgUnitCheckTest.java b/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/importer/insert/validation/ProgramOrgUnitCheckTest.java index a3155db4433c..4adca816280b 100644 --- a/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/importer/insert/validation/ProgramOrgUnitCheckTest.java +++ b/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/importer/insert/validation/ProgramOrgUnitCheckTest.java @@ -27,6 +27,7 @@ */ package org.hisp.dhis.dxf2.events.importer.insert.validation; +import static org.hisp.dhis.DhisConvenienceTest.createOrganisationUnit; import static org.hisp.dhis.DhisConvenienceTest.createProgram; import static org.mockito.Mockito.when; @@ -76,7 +77,7 @@ private void verifySuccessWhenProgramHasOrgUnitMatchingEventOrgUnit( // Prepare data Program program = createProgram('P'); program.setId(1); - OrganisationUnit ou = new OrganisationUnit(); + OrganisationUnit ou = createOrganisationUnit('A'); ou.setId(1); ou.setUid(orgUnitId); when(workContext.getOrganisationUnitMap()).thenReturn(Map.of(event.getUid(), ou)); @@ -101,7 +102,7 @@ void failWhenProgramHasNoOrgUnitMatchingEventOrgUnit() { // Prepare data Program program = createProgram('P'); program.setId(1); - OrganisationUnit ou = new OrganisationUnit(); + OrganisationUnit ou = createOrganisationUnit('A'); ou.setId(1); ou.setUid(event.getOrgUnit()); when(workContext.getOrganisationUnitMap()).thenReturn(Map.of(event.getUid(), ou)); diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata/attribute/GeoJsonAttributesCheckTest.java b/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata/attribute/GeoJsonAttributesCheckTest.java index 662d20c41d2f..c84a229a2120 100644 --- a/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata/attribute/GeoJsonAttributesCheckTest.java +++ b/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata/attribute/GeoJsonAttributesCheckTest.java @@ -27,6 +27,7 @@ */ package org.hisp.dhis.dxf2.metadata.attribute; +import static org.hisp.dhis.DhisConvenienceTest.createOrganisationUnit; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -72,7 +73,7 @@ public class GeoJsonAttributesCheckTest { @BeforeEach public void setUpTest() { - organisationUnit = new OrganisationUnit(); + organisationUnit = createOrganisationUnit('A'); organisationUnit.setName("A"); attribute = new Attribute(); attribute.setUid("geoJson"); diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata/attribute/MetadataAttributeCheckTest.java b/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata/attribute/MetadataAttributeCheckTest.java index 65fc4dc9ee26..b74d03e589cd 100644 --- a/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata/attribute/MetadataAttributeCheckTest.java +++ b/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata/attribute/MetadataAttributeCheckTest.java @@ -27,7 +27,10 @@ */ package org.hisp.dhis.dxf2.metadata.attribute; -import static org.junit.jupiter.api.Assertions.*; +import static org.hisp.dhis.DhisConvenienceTest.createOrganisationUnit; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.when; import com.google.common.collect.Lists; @@ -85,7 +88,7 @@ class MetadataAttributeCheckTest { @BeforeEach void setUpTest() { - organisationUnit = new OrganisationUnit(); + organisationUnit = createOrganisationUnit('A'); organisationUnit.setName("A"); attribute = new Attribute(); attribute.setUid("attributeID"); @@ -456,7 +459,7 @@ void testAttributeOrganisationUnit() { organisationUnit.getAttributeValues().add(new AttributeValue(attribute, "OU-ID")); // OrganisationUnit exists - when(manager.get(OrganisationUnit.class, "OU-ID")).thenReturn(new OrganisationUnit()); + when(manager.get(OrganisationUnit.class, "OU-ID")).thenReturn(createOrganisationUnit('A')); List objectReportList = new ArrayList<>(); diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata/objectbundle/ObjectBundleHooksTest.java b/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata/objectbundle/ObjectBundleHooksTest.java index d2b417436b62..5cf54e556fe4 100644 --- a/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata/objectbundle/ObjectBundleHooksTest.java +++ b/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata/objectbundle/ObjectBundleHooksTest.java @@ -30,6 +30,7 @@ import static java.util.Arrays.asList; import static java.util.Collections.singletonList; import static java.util.stream.Collectors.toList; +import static org.hisp.dhis.DhisConvenienceTest.createOrganisationUnit; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -67,20 +68,20 @@ class ObjectBundleHooksTest { @Test void testMatchingClassBoundIsIncluded() { - assertHasHooksOfType(new OrganisationUnit(), OrganisationUnitObjectBundleHook.class); + assertHasHooksOfType(createOrganisationUnit('A'), OrganisationUnitObjectBundleHook.class); assertHasHooksOfType(new User(), UserObjectBundleHook.class); } @Test void testNonMatchingClassBoundIsNotIncluded() { - assertHasNotHooksOfType(new OrganisationUnit(), UserObjectBundleHook.class); + assertHasNotHooksOfType(createOrganisationUnit('A'), UserObjectBundleHook.class); assertHasNotHooksOfType(new User(), OrganisationUnitObjectBundleHook.class); } @Test void testMatchingInterfaceBoundIsIncluded() { assertHasHooksOfType( - new OrganisationUnit(), + createOrganisationUnit('A'), IdentifiableObjectBundleHook.class, VersionedObjectObjectBundleHook.class); assertHasHooksOfType( @@ -94,7 +95,7 @@ void testMatchingInterfaceBoundIsIncluded() { @Test void testNonMatchingInterfaceBoundIsNotIncluded() { - assertHasNotHooksOfType(new OrganisationUnit(), AnalyticalObjectObjectBundleHook.class); + assertHasNotHooksOfType(createOrganisationUnit('A'), AnalyticalObjectObjectBundleHook.class); assertHasNotHooksOfType(new User(), AnalyticalObjectObjectBundleHook.class); } diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata/objectbundle/hooks/ProgramStageWorkingListObjectBundleHookTest.java b/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata/objectbundle/hooks/ProgramStageWorkingListObjectBundleHookTest.java index c4ee5f57c0b3..c81c8b49b6c6 100644 --- a/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata/objectbundle/hooks/ProgramStageWorkingListObjectBundleHookTest.java +++ b/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata/objectbundle/hooks/ProgramStageWorkingListObjectBundleHookTest.java @@ -27,6 +27,7 @@ */ package org.hisp.dhis.dxf2.metadata.objectbundle.hooks; +import static org.hisp.dhis.DhisConvenienceTest.createOrganisationUnit; import static org.hisp.dhis.feedback.ErrorCode.E4062; import static org.hisp.dhis.feedback.ErrorCode.E4063; import static org.hisp.dhis.feedback.ErrorCode.E4064; @@ -50,7 +51,6 @@ import org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundle; import org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundleParams; import org.hisp.dhis.feedback.ErrorReport; -import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.organisationunit.OrganisationUnitService; import org.hisp.dhis.preheat.Preheat; import org.hisp.dhis.programstagefilter.DateFilterPeriod; @@ -136,7 +136,7 @@ void shouldReturnNoErrorsWhenQueryCriteriaSuppliedIsValid() { .build(); when(organisationUnitService.getOrganisationUnit(anyString())) - .thenReturn(new OrganisationUnit()); + .thenReturn(createOrganisationUnit('A')); when(dataElementService.getDataElement(anyString())).thenReturn(new DataElement()); when(attributeService.getTrackedEntityAttribute(anyString())) .thenReturn(new TrackedEntityAttribute()); diff --git a/dhis-2/dhis-services/dhis-service-reporting/src/test/java/org/hisp/dhis/visualization/VisualizationGridServiceTest.java b/dhis-2/dhis-services/dhis-service-reporting/src/test/java/org/hisp/dhis/visualization/VisualizationGridServiceTest.java index 0f8a20a7e7a1..a8dc296030ae 100644 --- a/dhis-2/dhis-services/dhis-service-reporting/src/test/java/org/hisp/dhis/visualization/VisualizationGridServiceTest.java +++ b/dhis-2/dhis-services/dhis-service-reporting/src/test/java/org/hisp/dhis/visualization/VisualizationGridServiceTest.java @@ -31,6 +31,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.hasSize; +import static org.hisp.dhis.DhisConvenienceTest.createOrganisationUnit; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -90,7 +91,7 @@ void getVisualizationGridByUserWhenItHasOrganisationUnitLevels() { final String anyOrganisationUnitUid = "ouiRzW5e"; final User userStub = userStub(); final List orgUnitLevels = asList(1, 2); - final List orgUnits = asList(new OrganisationUnit()); + final List orgUnits = asList(createOrganisationUnit('A')); final Map valueMap = valueMapStub(); final Visualization visualizationStub = visualizationStub("abc123xy"); @@ -124,7 +125,7 @@ void getVisualizationGridByUserWhenItHasItemOrganisationUnitGroups() { final Date anyRelativePeriodDate = new Date(); final String anyOrganisationUnitUid = "ouiRzW5e"; final User userStub = userStub(); - final List orgUnits = asList(new OrganisationUnit()); + final List orgUnits = asList(createOrganisationUnit('A')); final List orgUnitGroups = asList(new OrganisationUnitGroup()); final Map valueMap = valueMapStub(); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/preheat/mappers/OrganisationUnitMapperTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/preheat/mappers/OrganisationUnitMapperTest.java index 46d35b0c7511..476690e72b6f 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/preheat/mappers/OrganisationUnitMapperTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/preheat/mappers/OrganisationUnitMapperTest.java @@ -27,6 +27,7 @@ */ package org.hisp.dhis.tracker.preheat.mappers; +import static org.hisp.dhis.DhisConvenienceTest.createOrganisationUnit; import static org.hisp.dhis.tracker.preheat.mappers.AttributeCreator.attributeValue; import static org.hisp.dhis.tracker.preheat.mappers.AttributeCreator.attributeValues; import static org.hisp.dhis.tracker.preheat.mappers.AttributeCreator.setIdSchemeFields; @@ -45,7 +46,7 @@ void testIdSchemeRelatedFieldsAreMapped() { OrganisationUnit orgUnit = setIdSchemeFields( - new OrganisationUnit(), + createOrganisationUnit('A'), "HpSAvRWtdDR", "meet", "green", @@ -62,11 +63,11 @@ void testIdSchemeRelatedFieldsAreMapped() { @Test void testParentFieldsAreMapped() { - OrganisationUnit rootOrgUnit = new OrganisationUnit(); + OrganisationUnit rootOrgUnit = createOrganisationUnit('A'); rootOrgUnit.setUid("root"); - OrganisationUnit level1OrgUnit = new OrganisationUnit(); + OrganisationUnit level1OrgUnit = createOrganisationUnit('A'); level1OrgUnit.setUid("level1"); - OrganisationUnit level2OrgUnit = new OrganisationUnit(); + OrganisationUnit level2OrgUnit = createOrganisationUnit('A'); level2OrgUnit.setUid("level2"); level2OrgUnit.setParent(level1OrgUnit); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/preheat/mappers/TrackedEntityInstanceMapperTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/preheat/mappers/TrackedEntityInstanceMapperTest.java index d47e3fce7c08..0efe01599b77 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/preheat/mappers/TrackedEntityInstanceMapperTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/preheat/mappers/TrackedEntityInstanceMapperTest.java @@ -27,6 +27,7 @@ */ package org.hisp.dhis.tracker.preheat.mappers; +import static org.hisp.dhis.DhisConvenienceTest.createOrganisationUnit; import static org.hisp.dhis.tracker.preheat.mappers.AttributeCreator.attributeValue; import static org.hisp.dhis.tracker.preheat.mappers.AttributeCreator.attributeValues; import static org.hisp.dhis.tracker.preheat.mappers.AttributeCreator.setIdSchemeFields; @@ -57,7 +58,7 @@ void testIdSchemeRelatedFieldsAreMapped() { OrganisationUnit orgUnit = setIdSchemeFields( - new OrganisationUnit(), + createOrganisationUnit('A'), "HpSAvRWtdDR", "meet", "green", diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/validation/MessageFormatterTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/validation/MessageFormatterTest.java index 144b3678383d..e98d99dfc53f 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/validation/MessageFormatterTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/validation/MessageFormatterTest.java @@ -29,6 +29,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; +import static org.hisp.dhis.DhisConvenienceTest.createOrganisationUnit; import static org.hisp.dhis.utils.Assertions.assertContainsOnly; import static org.hisp.dhis.utils.Assertions.assertIsEmpty; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -102,7 +103,7 @@ void formatArgumentsShouldTurnIdentifiableObjectIntoArgument() { relationshipType.setUid("WTTYiPQDqh1"); Program program = new Program("friendship"); ProgramStage programStage = new ProgramStage("meet", program); - OrganisationUnit orgUnit = new OrganisationUnit(); + OrganisationUnit orgUnit = createOrganisationUnit('A'); orgUnit.setAttributeValues(attributeValues("HpSAvRWtdDR", "sunshine")); DataElement dataElement = new DataElement(); dataElement.setAttributeValues(attributeValues("m0GpPuMUfFW", "ice")); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/validation/validator/enrollment/MetaValidatorTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/validation/validator/enrollment/MetaValidatorTest.java index f519cd4e938a..70ed8ae6ef27 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/validation/validator/enrollment/MetaValidatorTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/validation/validator/enrollment/MetaValidatorTest.java @@ -27,6 +27,7 @@ */ package org.hisp.dhis.tracker.validation.validator.enrollment; +import static org.hisp.dhis.DhisConvenienceTest.createOrganisationUnit; import static org.hisp.dhis.tracker.validation.ValidationCode.E1068; import static org.hisp.dhis.tracker.validation.ValidationCode.E1069; import static org.hisp.dhis.tracker.validation.ValidationCode.E1070; @@ -36,7 +37,6 @@ import java.util.Optional; import org.hisp.dhis.common.CodeGenerator; -import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.program.Program; import org.hisp.dhis.trackedentity.TrackedEntityInstance; import org.hisp.dhis.tracker.TrackerIdSchemeParams; @@ -85,7 +85,7 @@ public void setUp() { void verifyEnrollmentValidationSuccess() { Enrollment enrollment = validEnrollment(); when(preheat.getOrganisationUnit(MetadataIdentifier.ofUid(ORG_UNIT_UID))) - .thenReturn(new OrganisationUnit()); + .thenReturn(createOrganisationUnit('A')); when(preheat.getTrackedEntity(TRACKED_ENTITY_UID)).thenReturn(new TrackedEntityInstance()); when(preheat.getProgram(MetadataIdentifier.ofUid(PROGRAM_UID))).thenReturn(new Program()); @@ -100,7 +100,7 @@ void verifyEnrollmentValidationSuccessWhenTeiIsInPayload() { when(bundle.findTrackedEntityByUid(TRACKED_ENTITY_UID)) .thenReturn(Optional.of(new TrackedEntity())); when(preheat.getOrganisationUnit(MetadataIdentifier.ofUid(ORG_UNIT_UID))) - .thenReturn(new OrganisationUnit()); + .thenReturn(createOrganisationUnit('A')); when(preheat.getProgram(MetadataIdentifier.ofUid(PROGRAM_UID))).thenReturn(new Program()); validator.validate(reporter, bundle, enrollment); @@ -123,7 +123,7 @@ void verifyEnrollmentValidationFailsWhenOrgUnitIsNotPresentInDb() { void verifyEnrollmentValidationFailsWhenTrackedEntityIsNotPresentInDbOrPayload() { Enrollment enrollment = validEnrollment(); when(preheat.getOrganisationUnit(MetadataIdentifier.ofUid(ORG_UNIT_UID))) - .thenReturn(new OrganisationUnit()); + .thenReturn(createOrganisationUnit('A')); when(preheat.getProgram(MetadataIdentifier.ofUid(PROGRAM_UID))).thenReturn(new Program()); validator.validate(reporter, bundle, enrollment); @@ -135,7 +135,7 @@ void verifyEnrollmentValidationFailsWhenTrackedEntityIsNotPresentInDbOrPayload() void verifyEnrollmentValidationFailsWhenProgramIsNotPresentInDb() { Enrollment enrollment = validEnrollment(); when(preheat.getOrganisationUnit(MetadataIdentifier.ofUid(ORG_UNIT_UID))) - .thenReturn(new OrganisationUnit()); + .thenReturn(createOrganisationUnit('A')); when(preheat.getTrackedEntity(TRACKED_ENTITY_UID)).thenReturn(new TrackedEntityInstance()); validator.validate(reporter, bundle, enrollment); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/validation/validator/event/MetaValidatorTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/validation/validator/event/MetaValidatorTest.java index 5d56b551b841..e18bced16c2f 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/validation/validator/event/MetaValidatorTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/validation/validator/event/MetaValidatorTest.java @@ -27,6 +27,7 @@ */ package org.hisp.dhis.tracker.validation.validator.event; +import static org.hisp.dhis.DhisConvenienceTest.createOrganisationUnit; import static org.hisp.dhis.tracker.validation.ValidationCode.E1010; import static org.hisp.dhis.tracker.validation.ValidationCode.E1011; import static org.hisp.dhis.tracker.validation.ValidationCode.E1013; @@ -35,7 +36,6 @@ import static org.mockito.Mockito.when; import org.hisp.dhis.common.CodeGenerator; -import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.program.Program; import org.hisp.dhis.program.ProgramStage; import org.hisp.dhis.tracker.TrackerIdSchemeParams; @@ -85,7 +85,7 @@ void verifyEventValidationSuccess() { Event event = validEvent(); when(preheat.getOrganisationUnit(MetadataIdentifier.ofUid(ORG_UNIT_UID))) - .thenReturn(new OrganisationUnit()); + .thenReturn(createOrganisationUnit('A')); when(preheat.getProgram(MetadataIdentifier.ofUid(PROGRAM_UID))).thenReturn(new Program()); when(preheat.getProgramStage(MetadataIdentifier.ofUid(PROGRAM_STAGE_UID))) .thenReturn(new ProgramStage()); @@ -100,7 +100,7 @@ void verifyEventValidationFailsWhenProgramIsNotPresentInDb() { Event event = validEvent(); when(preheat.getOrganisationUnit(MetadataIdentifier.ofUid(ORG_UNIT_UID))) - .thenReturn(new OrganisationUnit()); + .thenReturn(createOrganisationUnit('A')); when(preheat.getProgramStage(MetadataIdentifier.ofUid(PROGRAM_STAGE_UID))) .thenReturn(new ProgramStage()); @@ -114,7 +114,7 @@ void verifyEventValidationFailsWhenProgramStageIsNotPresentInDb() { Event event = validEvent(); when(preheat.getOrganisationUnit(MetadataIdentifier.ofUid(ORG_UNIT_UID))) - .thenReturn(new OrganisationUnit()); + .thenReturn(createOrganisationUnit('A')); when(preheat.getProgram(MetadataIdentifier.ofUid(PROGRAM_UID))).thenReturn(new Program()); validator.validate(reporter, bundle, event); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/validation/validator/trackedentity/MetaValidatorTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/validation/validator/trackedentity/MetaValidatorTest.java index fd09f6554c60..fc54ce4ec94b 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/validation/validator/trackedentity/MetaValidatorTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/validation/validator/trackedentity/MetaValidatorTest.java @@ -27,13 +27,13 @@ */ package org.hisp.dhis.tracker.validation.validator.trackedentity; +import static org.hisp.dhis.DhisConvenienceTest.createOrganisationUnit; import static org.hisp.dhis.tracker.validation.ValidationCode.E1005; import static org.hisp.dhis.tracker.validation.ValidationCode.E1049; import static org.hisp.dhis.tracker.validation.validator.AssertValidations.assertHasError; import static org.hisp.dhis.utils.Assertions.assertIsEmpty; import static org.mockito.Mockito.when; -import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.trackedentity.TrackedEntityType; import org.hisp.dhis.tracker.TrackerIdSchemeParams; import org.hisp.dhis.tracker.bundle.TrackerBundle; @@ -80,7 +80,7 @@ public void setUp() { void verifyTrackedEntityValidationSuccess() { TrackedEntity tei = validTei(); when(preheat.getOrganisationUnit(MetadataIdentifier.ofUid(ORG_UNIT_UID))) - .thenReturn(new OrganisationUnit()); + .thenReturn(createOrganisationUnit('A')); when(preheat.getTrackedEntityType(MetadataIdentifier.ofUid(TRACKED_ENTITY_TYPE_UID))) .thenReturn(new TrackedEntityType()); @@ -104,7 +104,7 @@ void verifyTrackedEntityValidationFailsWhenOrgUnitIsNotPresentInDb() { void verifyTrackedEntityValidationFailsWhenTrackedEntityTypeIsNotPresentInDb() { TrackedEntity tei = validTei(); when(preheat.getOrganisationUnit(MetadataIdentifier.ofUid(ORG_UNIT_UID))) - .thenReturn(new OrganisationUnit()); + .thenReturn(createOrganisationUnit('A')); validator.validate(reporter, bundle, tei); diff --git a/dhis-2/dhis-services/dhis-service-validation/src/test/java/org/hisp/dhis/validation/ValidationResultServiceTest.java b/dhis-2/dhis-services/dhis-service-validation/src/test/java/org/hisp/dhis/validation/ValidationResultServiceTest.java index 8639a8e0ba3f..c9da516a9a1c 100644 --- a/dhis-2/dhis-services/dhis-service-validation/src/test/java/org/hisp/dhis/validation/ValidationResultServiceTest.java +++ b/dhis-2/dhis-services/dhis-service-validation/src/test/java/org/hisp/dhis/validation/ValidationResultServiceTest.java @@ -30,6 +30,7 @@ import static java.util.Arrays.asList; import static java.util.Collections.emptyList; import static java.util.Collections.singletonList; +import static org.hisp.dhis.DhisConvenienceTest.createOrganisationUnit; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; @@ -82,7 +83,7 @@ void setUp() { List units = new ArrayList<>(); for (String uid : uids) { if (CodeGenerator.isValidUid(uid)) { - OrganisationUnit unit = new OrganisationUnit(); + OrganisationUnit unit = createOrganisationUnit('A'); unit.setUid(uid); units.add(unit); } diff --git a/dhis-2/dhis-services/dhis-service-validation/src/test/java/org/hisp/dhis/validation/ValidationResultStoreHqlTest.java b/dhis-2/dhis-services/dhis-service-validation/src/test/java/org/hisp/dhis/validation/ValidationResultStoreHqlTest.java index 3f6c27fdb764..e6e5631075bb 100644 --- a/dhis-2/dhis-services/dhis-service-validation/src/test/java/org/hisp/dhis/validation/ValidationResultStoreHqlTest.java +++ b/dhis-2/dhis-services/dhis-service-validation/src/test/java/org/hisp/dhis/validation/ValidationResultStoreHqlTest.java @@ -32,6 +32,7 @@ import static java.util.Collections.emptySet; import static java.util.Collections.singleton; import static java.util.Collections.singletonList; +import static org.hisp.dhis.DhisConvenienceTest.createOrganisationUnit; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -123,7 +124,7 @@ private void setUpUser(String orgUnitUid, Category category, CategoryOptionGroup User user = new User(); when(currentUserService.getCurrentUser()).thenReturn(user); user.setGroups(emptySet()); - OrganisationUnit unit = new OrganisationUnit(); + OrganisationUnit unit = createOrganisationUnit('A'); unit.setUid(orgUnitUid); user.setDataViewOrganisationUnits(singleton(unit)); // categories diff --git a/dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/filter/OrganisationUnitPolygonCoveringCoordinateFilterTest.java b/dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/filter/OrganisationUnitPolygonCoveringCoordinateFilterTest.java index e0bb5cdced46..5cdf1154036b 100644 --- a/dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/filter/OrganisationUnitPolygonCoveringCoordinateFilterTest.java +++ b/dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/filter/OrganisationUnitPolygonCoveringCoordinateFilterTest.java @@ -27,6 +27,7 @@ */ package org.hisp.dhis.system.filter; +import static org.hisp.dhis.DhisConvenienceTest.createOrganisationUnit; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -51,7 +52,7 @@ class OrganisationUnitPolygonCoveringCoordinateFilterTest { @BeforeEach void setUp() throws IOException { - organisationUnit = new OrganisationUnit(); + organisationUnit = createOrganisationUnit('A'); DOWNTOWN_OSLO = TestResourceUtils.getFileContent("gis/downtownOslo.json"); } diff --git a/dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/SmsUtilsTest.java b/dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/SmsUtilsTest.java index a39bd21091ea..c41a52411d6e 100644 --- a/dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/SmsUtilsTest.java +++ b/dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/SmsUtilsTest.java @@ -27,6 +27,7 @@ */ package org.hisp.dhis.system.util; +import static org.hisp.dhis.DhisConvenienceTest.createOrganisationUnit; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -87,18 +88,18 @@ void setup() { userA.setAutoFields(); userA.setPhoneNumber(phoneNumber); userA.setEmail(email); - organisationUnitA = new OrganisationUnit(); + organisationUnitA = createOrganisationUnit('A'); organisationUnitA.setAutoFields(); organisationUnitA.setId(1); organisationUnitA.setCode("TESTORGA"); userA.addOrganisationUnit(organisationUnitA); userB = new User(); - organisationUnitB = new OrganisationUnit(); + organisationUnitB = createOrganisationUnit('B'); organisationUnitB.setAutoFields(); organisationUnitB.setId(2); organisationUnitB.setCode("TESTORGB"); userB.addOrganisationUnit(organisationUnitB); - organisationUnitC = new OrganisationUnit(); + organisationUnitC = createOrganisationUnit('C'); organisationUnitC.setAutoFields(); organisationUnitC.setId(3); organisationUnitC.setCode("TESTORGC"); diff --git a/dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java b/dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java index 262f163aa59a..6b060aad62e6 100644 --- a/dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java +++ b/dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java @@ -951,22 +951,19 @@ public static DataEntryForm createDataEntryForm(char uniqueCharacter, String htm public static OrganisationUnit createOrganisationUnit(char uniqueCharacter) { OrganisationUnit unit = new OrganisationUnit(); unit.setAutoFields(); - unit.setUid(BASE_OU_UID + uniqueCharacter); unit.setName("OrganisationUnit" + uniqueCharacter); unit.setShortName("OrganisationUnitShort" + uniqueCharacter); unit.setCode("OrganisationUnitCode" + uniqueCharacter); unit.setOpeningDate(date); unit.setComment("Comment" + uniqueCharacter); - + unit.updatePath(); return unit; } public static OrganisationUnit createOrganisationUnit(char uniqueCharacter, Geometry geometry) { OrganisationUnit unit = createOrganisationUnit(uniqueCharacter); - unit.setGeometry(geometry); - return unit; } @@ -977,10 +974,8 @@ public static OrganisationUnit createOrganisationUnit(char uniqueCharacter, Geom public static OrganisationUnit createOrganisationUnit( char uniqueCharacter, OrganisationUnit parent) { OrganisationUnit unit = createOrganisationUnit(uniqueCharacter); - unit.setParent(parent); parent.getChildren().add(unit); - return unit; } @@ -990,14 +985,13 @@ public static OrganisationUnit createOrganisationUnit( public static OrganisationUnit createOrganisationUnit(String name) { OrganisationUnit unit = new OrganisationUnit(); unit.setAutoFields(); - unit.setUid(CodeGenerator.generateUid()); unit.setName(name); unit.setShortName(name); unit.setCode(name); unit.setOpeningDate(date); unit.setComment("Comment " + name); - + unit.updatePath(); return unit; } diff --git a/dhis-2/dhis-web-api/src/test/java/org/hisp/dhis/webapi/controller/SharingControllerTest.java b/dhis-2/dhis-web-api/src/test/java/org/hisp/dhis/webapi/controller/SharingControllerTest.java index 1391d6a2d5a4..851e33ed805e 100644 --- a/dhis-2/dhis-web-api/src/test/java/org/hisp/dhis/webapi/controller/SharingControllerTest.java +++ b/dhis-2/dhis-web-api/src/test/java/org/hisp/dhis/webapi/controller/SharingControllerTest.java @@ -29,9 +29,10 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.StringContains.containsString; +import static org.hisp.dhis.DhisConvenienceTest.createOrganisationUnit; import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.eq; import static org.mockito.Mockito.when; import org.hisp.dhis.category.Category; @@ -68,7 +69,7 @@ class SharingControllerTest { @Test void notSystemDefaultMetadataNoAccess() { - final OrganisationUnit organisationUnit = new OrganisationUnit(); + final OrganisationUnit organisationUnit = createOrganisationUnit('A'); doReturn(OrganisationUnit.class).when(aclService).classForType(eq("organisationUnit")); when(aclService.isClassShareable(eq(OrganisationUnit.class))).thenReturn(true); diff --git a/dhis-2/dhis-web-api/src/test/java/org/hisp/dhis/webapi/controller/event/EnrollmentCriteriaMapperTest.java b/dhis-2/dhis-web-api/src/test/java/org/hisp/dhis/webapi/controller/event/EnrollmentCriteriaMapperTest.java index 3a52ee6efc11..e153ca09b509 100644 --- a/dhis-2/dhis-web-api/src/test/java/org/hisp/dhis/webapi/controller/event/EnrollmentCriteriaMapperTest.java +++ b/dhis-2/dhis-web-api/src/test/java/org/hisp/dhis/webapi/controller/event/EnrollmentCriteriaMapperTest.java @@ -27,6 +27,7 @@ */ package org.hisp.dhis.webapi.controller.event; +import static org.hisp.dhis.DhisConvenienceTest.createOrganisationUnit; import static org.hisp.dhis.common.OrganisationUnitSelectionMode.CHILDREN; import static org.hisp.dhis.common.OrganisationUnitSelectionMode.DESCENDANTS; import static org.hisp.dhis.common.OrganisationUnitSelectionMode.SELECTED; @@ -105,12 +106,14 @@ void setUp() { program = new Program(); program.setUid(PROGRAM_UID); - organisationUnit1 = new OrganisationUnit(); + organisationUnit1 = createOrganisationUnit('A'); organisationUnit1.setUid(ORG_UNIT1); + organisationUnit1.updatePath(); orgUnits = Set.of(ORG_UNIT1); - organisationUnit2 = new OrganisationUnit(); + organisationUnit2 = createOrganisationUnit('B'); organisationUnit2.setUid(ORG_UNIT2); + organisationUnit2.updatePath(); user = new User(); when(currentUserService.getCurrentUser()).thenReturn(user); diff --git a/dhis-2/dhis-web-api/src/test/java/org/hisp/dhis/webapi/controller/event/EventRequestToSearchParamsMapperTest.java b/dhis-2/dhis-web-api/src/test/java/org/hisp/dhis/webapi/controller/event/EventRequestToSearchParamsMapperTest.java index 8a8fad776763..4fbd08c41300 100644 --- a/dhis-2/dhis-web-api/src/test/java/org/hisp/dhis/webapi/controller/event/EventRequestToSearchParamsMapperTest.java +++ b/dhis-2/dhis-web-api/src/test/java/org/hisp/dhis/webapi/controller/event/EventRequestToSearchParamsMapperTest.java @@ -27,6 +27,7 @@ */ package org.hisp.dhis.webapi.controller.event; +import static org.hisp.dhis.DhisConvenienceTest.createOrganisationUnit; import static org.hisp.dhis.DhisConvenienceTest.getDate; import static org.hisp.dhis.common.AccessLevel.CLOSED; import static org.hisp.dhis.common.AccessLevel.OPEN; @@ -141,7 +142,7 @@ public void setUp() { Program program = new Program(); User user = new User(); - OrganisationUnit ou = new OrganisationUnit(); + OrganisationUnit ou = createOrganisationUnit('A'); user.setOrganisationUnits(Set.of(ou)); TrackedEntityInstance tei = new TrackedEntityInstance(); DataElement de = new DataElement(); @@ -445,9 +446,10 @@ void shouldNotManipulateDates() { } private OrganisationUnit createOrgUnit(String name, String uid) { - OrganisationUnit orgUnit = new OrganisationUnit(name); - orgUnit.setUid(uid); - return orgUnit; + OrganisationUnit ou = createOrganisationUnit(name); + ou.setUid(uid); + ou.updatePath(); + return ou; } private User createSearchInAllOrgUnitsUser() { diff --git a/dhis-2/dhis-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/export/TrackerEnrollmentCriteriaMapperTest.java b/dhis-2/dhis-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/export/TrackerEnrollmentCriteriaMapperTest.java index 82fcb32ea616..9831cd574278 100644 --- a/dhis-2/dhis-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/export/TrackerEnrollmentCriteriaMapperTest.java +++ b/dhis-2/dhis-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/export/TrackerEnrollmentCriteriaMapperTest.java @@ -27,6 +27,7 @@ */ package org.hisp.dhis.webapi.controller.tracker.export; +import static org.hisp.dhis.DhisConvenienceTest.createOrganisationUnit; import static org.hisp.dhis.common.OrganisationUnitSelectionMode.ALL; import static org.hisp.dhis.utils.Assertions.assertContainsOnly; import static org.hisp.dhis.utils.Assertions.assertIsEmpty; @@ -106,14 +107,16 @@ void setUp() { user = new User(); when(currentUserService.getCurrentUser()).thenReturn(user); - orgUnit1 = new OrganisationUnit("orgUnit1"); + orgUnit1 = createOrganisationUnit('A'); orgUnit1.setUid(ORG_UNIT_1_UID); + orgUnit1.updatePath(); when(organisationUnitService.getOrganisationUnit(orgUnit1.getUid())).thenReturn(orgUnit1); when(organisationUnitService.isInUserHierarchy( orgUnit1.getUid(), user.getTeiSearchOrganisationUnitsWithFallback())) .thenReturn(true); - orgUnit2 = new OrganisationUnit("orgUnit2"); + orgUnit2 = createOrganisationUnit('B'); orgUnit2.setUid(ORG_UNIT_2_UID); + orgUnit2.updatePath(); when(organisationUnitService.getOrganisationUnit(orgUnit2.getUid())).thenReturn(orgUnit2); when(organisationUnitService.isInUserHierarchy( orgUnit2.getUid(), user.getTeiSearchOrganisationUnitsWithFallback()))