From 032b7398e668df9b93c89159329762fdb305ed00 Mon Sep 17 00:00:00 2001 From: maikelarabori Date: Wed, 1 Nov 2023 15:35:43 -0300 Subject: [PATCH] test: Fix test assertions in Event Vis. --- .../EventVisualizationControllerTest.java | 153 +++++++++++++----- 1 file changed, 113 insertions(+), 40 deletions(-) diff --git a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/EventVisualizationControllerTest.java b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/EventVisualizationControllerTest.java index 2f37756ec32a..525a039d7ef5 100644 --- a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/EventVisualizationControllerTest.java +++ b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/EventVisualizationControllerTest.java @@ -39,10 +39,12 @@ import static org.hisp.dhis.web.HttpStatus.OK; import static org.hisp.dhis.web.WebClientUtils.assertStatus; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import org.hisp.dhis.dataelement.DataElement; +import org.hisp.dhis.jsontree.JsonNode; import org.hisp.dhis.jsontree.JsonObject; import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.program.Program; @@ -52,7 +54,6 @@ import org.hisp.dhis.webapi.DhisControllerConvenienceTest; import org.hisp.dhis.webapi.json.domain.JsonError; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -571,7 +572,6 @@ void testPost() { } @Test - @Disabled void testPostMultiPrograms() { // Given String body = @@ -585,16 +585,13 @@ void testPostMultiPrograms() { "direction": "ASC" }, { - "dimension": "deabcdefghP.deabcdefghS.deabcdefghB", + "dimension": "deabcdefghP.deabcdefghB", "direction": "DESC" } ], "columns": [ { "dimension": "deabcdefghB", - "programStage": { - "id": "deabcdefghS" - }, "program": { "id": "deabcdefghP" } @@ -673,41 +670,54 @@ void testPostMultiPrograms() { is(equalTo(""" {"id":"nEenWmSyUEp"}"""))); + JsonNode simpleDimensionNode0 = response.get("simpleDimensions").node().element(0); + assertThat(simpleDimensionNode0.get("parent").value().toString(), is(equalTo("COLUMN"))); + assertThat(simpleDimensionNode0.get("dimension").value().toString(), is(equalTo("eventDate"))); + assertThat(simpleDimensionNode0.get("program").value().toString(), is(equalTo("deabcdefghP"))); + assertThat( + simpleDimensionNode0.get("values").value().toString(), + is(equalTo(""" +["2023-07-21_2023-08-01","2023-01-21_2023-02-01"]"""))); + assertThat(simpleDimensionNode0.get("parent").value().toString(), is(equalTo("COLUMN"))); + + JsonNode sortingNode0 = response.get("sorting").node().element(0); assertThat( - response.get("simpleDimensions").node().value().toString(), - is( - equalTo( - """ -[{"parent":"COLUMN","dimension":"eventDate","program":"deabcdefghP","values":["2023-07-21_2023-08-01","2023-01-21_2023-02-01"]}]"""))); + sortingNode0.get("dimension").value().toString(), + is(equalTo("deabcdefghP[-1].deabcdefghS[0].deabcdefghB"))); + assertThat(sortingNode0.get("direction").value().toString(), is(equalTo("ASC"))); + JsonNode sortingNode1 = response.get("sorting").node().element(1); assertThat( - response.get("sorting").node().value().toString(), - is( - equalTo( - """ -[{"dimension":"deabcdefghP[-1].deabcdefghS[0].deabcdefghB","direction":"ASC"},{"dimension":"deabcdefghP.deabcdefghS.deabcdefghB","direction":"DESC"}]"""))); + sortingNode1.get("dimension").value().toString(), is(equalTo("deabcdefghP.deabcdefghB"))); + assertThat(sortingNode1.get("direction").value().toString(), is(equalTo("DESC"))); assertThat(response.get("rows").node().value().toString(), is(equalTo("[]"))); assertThat(response.get("rowDimensions").node().value().toString(), is(equalTo("[]"))); assertThat( response.get("columnDimensions").node().value().toString(), - is( - equalTo( - """ -["deabcdefghP.deabcdefghS.deabcdefghB","deabcdefghC","deabcdefghP.eventDate"]"""))); + is(equalTo(""" +["deabcdefghP.deabcdefghB","deabcdefghC","deabcdefghP.eventDate"]"""))); assertThat( response.get("filterDimensions").node().value().toString(), is(equalTo(""" ["deabcdefghP.deabcdefghS.ou","deabcdefghE"]"""))); + JsonNode dataElementDimensionsNode0 = response.get("dataElementDimensions").node().element(0); assertThat( - response.get("dataElementDimensions").node().value().toString(), - is( - equalTo( - """ -[{"dataElement":{"id":"deabcdefghC"},"filter":"IN:Female"},{"dataElement":{"id":"deabcdefghE"}}]"""))); + dataElementDimensionsNode0.get("dataElement").value().toString(), + is(equalTo(""" +{"id":"deabcdefghC"}"""))); + assertThat( + dataElementDimensionsNode0.get("filter").value().toString(), is(equalTo("IN:Female"))); + + JsonNode dataElementDimensionsNode1 = response.get("dataElementDimensions").node().element(1); + assertThat( + dataElementDimensionsNode1.get("dataElement").value().toString(), + is(equalTo(""" +{"id":"deabcdefghE"}"""))); + assertFalse(dataElementDimensionsNode1.isMember("filter")); assertThat( response.get("programIndicatorDimensions").node().value().toString(), @@ -719,26 +729,89 @@ void testPostMultiPrograms() { is(equalTo(""" [{"id":"ImspTQPwCqd"}]"""))); + JsonNode repetitionsNode0 = response.get("repetitions").node().element(0); + assertThat(repetitionsNode0.get("parent").value().toString(), is(equalTo("FILTER"))); + assertThat(repetitionsNode0.get("dimension").value().toString(), is(equalTo("ou"))); + assertThat(repetitionsNode0.get("program").value().toString(), is(equalTo("deabcdefghP"))); + assertThat(repetitionsNode0.get("programStage").value().toString(), is(equalTo("deabcdefghS"))); + assertThat(repetitionsNode0.get("indexes").value().toString(), is(equalTo("[1,2,3,-2,-1,0]"))); + + JsonNode repetitionsNode1 = response.get("repetitions").node().element(1); + assertThat(repetitionsNode1.get("parent").value().toString(), is(equalTo("FILTER"))); + assertThat(repetitionsNode1.get("dimension").value().toString(), is(equalTo("deabcdefghE"))); + assertFalse(repetitionsNode1.isMember("program")); + assertFalse(repetitionsNode1.isMember("programStage")); + assertThat(repetitionsNode1.get("indexes").value().toString(), is(equalTo("[1,2,0]"))); + + JsonNode columnsNode0 = response.get("columns").node().element(0); + assertThat(columnsNode0.get("items").value().toString(), is(equalTo("[]"))); + assertThat( + columnsNode0.get("program").value().toString(), is(equalTo(""" +{"id":"deabcdefghP"}"""))); + assertThat(columnsNode0.get("dimension").value().toString(), is(equalTo("deabcdefghB"))); + + JsonNode columnsNode1 = response.get("columns").node().element(1); + assertThat(columnsNode1.get("items").value().toString(), is(equalTo("[]"))); + assertFalse(columnsNode1.isMember("program")); + assertThat(columnsNode1.get("dimension").value().toString(), is(equalTo("deabcdefghC"))); + + JsonNode columnsNode2 = response.get("columns").node().element(2); assertThat( - response.get("repetitions").node().value().toString(), - is( - equalTo( - """ -[{"parent":"FILTER","dimension":"ou","program":"deabcdefghP","programStage":"deabcdefghS","indexes":[1,2,3,-2,-1,0]},{"parent":"FILTER","dimension":"deabcdefghE","indexes":[1,2,0]}]"""))); + columnsNode2.get("items").value().toString(), + is(equalTo(""" +[{"id":"2023-07-21_2023-08-01"},{"id":"2023-01-21_2023-02-01"}]"""))); + assertThat( + columnsNode2.get("program").value().toString(), is(equalTo(""" +{"id":"deabcdefghP"}"""))); + assertThat(columnsNode2.get("dimension").value().toString(), is(equalTo("eventDate"))); + JsonNode filtersNode0 = response.get("filters").node().element(0); + assertThat( + filtersNode0.get("items").element(0).get("code").value().toString(), + is(equalTo("OrganisationUnitCodeA"))); + assertThat( + filtersNode0.get("items").element(0).get("name").value().toString(), + is(equalTo("OrganisationUnitA"))); assertThat( - response.get("columns").node().value().toString(), - is( - equalTo( - """ -[{"items":[],"program":{"id":"deabcdefghP"},"dimension":"deabcdefghB"},{"items":[],"dimension":"deabcdefghC"},{"items":[{"id":"2023-07-21_2023-08-01"},{"id":"2023-01-21_2023-02-01"}],"program":{"id":"deabcdefghP"},"dimension":"eventDate"}]"""))); + filtersNode0.get("items").element(0).get("dimensionItemType").value().toString(), + is(equalTo("ORGANISATION_UNIT"))); + assertThat( + filtersNode0.get("items").element(0).get("dimensionItem").value().toString(), + is(equalTo("ImspTQPwCqd"))); + assertThat( + filtersNode0.get("items").element(0).get("id").value().toString(), + is(equalTo("ImspTQPwCqd"))); + assertThat( + filtersNode0.get("programStage").value().toString(), + is(equalTo(""" +{"id":"deabcdefghS"}"""))); + assertThat(filtersNode0.get("dimension").value().toString(), is(equalTo("ou"))); + assertThat( + filtersNode0.get("repetition").get("parent").value().toString(), is(equalTo("FILTER"))); + assertThat( + filtersNode0.get("repetition").get("dimension").value().toString(), is(equalTo("ou"))); + assertThat( + filtersNode0.get("repetition").get("program").value().toString(), + is(equalTo("deabcdefghP"))); + assertThat( + filtersNode0.get("repetition").get("programStage").value().toString(), + is(equalTo("deabcdefghS"))); + assertThat( + filtersNode0.get("repetition").get("indexes").value().toString(), + is(equalTo("[1,2,3,-2,-1,0]"))); + JsonNode filtersNode1 = response.get("filters").node().element(1); + assertThat(filtersNode1.get("items").value().toString(), is(equalTo("[]"))); + assertThat(filtersNode1.get("dimension").value().toString(), is(equalTo("deabcdefghE"))); + assertThat( + filtersNode1.get("repetition").get("parent").value().toString(), is(equalTo("FILTER"))); + assertThat( + filtersNode1.get("repetition").get("dimension").value().toString(), + is(equalTo("deabcdefghE"))); + assertFalse(filtersNode1.get("repetition").isMember("program")); + assertFalse(filtersNode1.get("repetition").isMember("programStage")); assertThat( - response.get("filters").node().value().toString(), - is( - equalTo( - """ -[{"items":[{"code":"OrganisationUnitCodeA","name":"OrganisationUnitA","dimensionItemType":"ORGANISATION_UNIT","dimensionItem":"ImspTQPwCqd","id":"ImspTQPwCqd"}],"programStage":{"id":"deabcdefghS"},"dimension":"ou","repetition":{"parent":"FILTER","dimension":"ou","program":"deabcdefghP","programStage":"deabcdefghS","indexes":[1,2,3,-2,-1,0]}},{"items":[],"dimension":"deabcdefghE","repetition":{"parent":"FILTER","dimension":"deabcdefghE","indexes":[1,2,0]}}]"""))); + filtersNode1.get("repetition").get("indexes").value().toString(), is(equalTo("[1,2,0]"))); } @Test