Search in sources :

Example 6 with JsonResponse

use of org.hisp.dhis.jsontree.JsonResponse in project dhis2-core by dhis2.

the class EventVisualizationControllerTest method testPostRepetitionForFilter.

@Test
void testPostRepetitionForFilter() {
    // Given
    final String dimension = "ou";
    final String indexes = "[1,2,3,-2,-1,0]";
    final String repetition = "'repetition': {'indexes': " + indexes + "}";
    final String body = "{'name': 'Name Test', 'type': 'STACKED_COLUMN', 'program': {'id':'" + mockProgram.getUid() + "'}, 'filters': [{'dimension': '" + dimension + "', " + repetition + "}]}";
    // When
    final String uid = assertStatus(CREATED, POST("/eventVisualizations/", body));
    // Then
    final String getParams = "?fields=:all,filters[:all,items,repetitions]";
    final JsonResponse response = GET("/eventVisualizations/" + uid + getParams).content();
    final Map<String, JsonNode> nodeMap = (Map<String, JsonNode>) response.node().value();
    assertThat(nodeMap.get("repetitions").toString(), containsString("FILTER"));
    assertThat(nodeMap.get("repetitions").toString(), containsString(indexes));
    assertThat(nodeMap.get("repetitions").toString(), containsString(dimension));
    assertThat(nodeMap.get("filters").toString(), containsString(indexes));
    assertThat(nodeMap.get("columns").toString(), not(containsString(indexes)));
    assertThat(nodeMap.get("rows").toString(), not(containsString(indexes)));
}
Also used : JsonNode(org.hisp.dhis.jsontree.JsonNode) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Map(java.util.Map) JsonResponse(org.hisp.dhis.jsontree.JsonResponse) DhisControllerConvenienceTest(org.hisp.dhis.webapi.DhisControllerConvenienceTest) Test(org.junit.jupiter.api.Test)

Example 7 with JsonResponse

use of org.hisp.dhis.jsontree.JsonResponse in project dhis2-core by dhis2.

the class EventVisualizationControllerTest method testPostForMultiEventDates.

@Test
void testPostForMultiEventDates() {
    // Given
    final String eventDateDimension = "eventDate";
    final String incidentDateDimension = "incidentDate";
    final String eventDate = "2021-07-21_2021-08-01";
    final String incidentDate = "2021-07-21_2021-08-01";
    final String eventDateBody = "{'dimension': '" + eventDateDimension + "', 'items': [{'id': '" + eventDate + "'}]}";
    final String incidentDateBody = "{'dimension': '" + incidentDateDimension + "', 'items': [{'id': '" + incidentDate + "'}]}";
    final String body = "{'name': 'Name Test', 'type': 'STACKED_COLUMN', 'program': {'id':'" + mockProgram.getUid() + "'}, 'rows': [" + eventDateBody + "," + incidentDateBody + "]}";
    // When
    final String uid = assertStatus(CREATED, POST("/eventVisualizations/", body));
    // Then
    final JsonResponse response = GET("/eventVisualizations/" + uid).content();
    final Map<String, JsonNode> nodeMap = (Map<String, JsonNode>) response.node().value();
    assertThat(nodeMap.get("simpleDimensions").toString(), containsString("ROW"));
    assertThat(nodeMap.get("simpleDimensions").toString(), containsString(eventDate));
    assertThat(nodeMap.get("simpleDimensions").toString(), containsString(incidentDate));
    assertThat(nodeMap.get("rows").toString(), containsString(eventDateDimension));
    assertThat(nodeMap.get("rows").toString(), containsString(incidentDateDimension));
    assertThat(nodeMap.get("columns").toString(), not(containsString(eventDateDimension)));
    assertThat(nodeMap.get("columns").toString(), not(containsString(incidentDateDimension)));
    assertThat(nodeMap.get("filters").toString(), not(containsString(eventDateDimension)));
    assertThat(nodeMap.get("filters").toString(), not(containsString(incidentDateDimension)));
}
Also used : JsonNode(org.hisp.dhis.jsontree.JsonNode) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Map(java.util.Map) JsonResponse(org.hisp.dhis.jsontree.JsonResponse) DhisControllerConvenienceTest(org.hisp.dhis.webapi.DhisControllerConvenienceTest) Test(org.junit.jupiter.api.Test)

Example 8 with JsonResponse

use of org.hisp.dhis.jsontree.JsonResponse in project dhis2-core by dhis2.

the class FollowupAnalysisControllerTest method assertFollowupValues.

private void assertFollowupValues(HttpResponse response, String... expectedComments) {
    JsonResponse body = response.content();
    JsonList<JsonFollowupValue> values = body.getList("followupValues", JsonFollowupValue.class);
    assertEquals(expectedComments.length, values.size());
    assertEquals(Arrays.stream(expectedComments).collect(toSet()), values.stream().map(JsonFollowupValue::getComment).collect(toSet()));
    JsonObject metadata = body.getObject("metadata");
    assertTrue(metadata.exists());
    assertEquals(asList("de", "coc", "ou", "startDate", "endDate", "maxResults"), metadata.names());
}
Also used : JsonFollowupValue(org.hisp.dhis.webapi.json.domain.JsonFollowupValue) JsonObject(org.hisp.dhis.jsontree.JsonObject) JsonResponse(org.hisp.dhis.jsontree.JsonResponse)

Example 9 with JsonResponse

use of org.hisp.dhis.jsontree.JsonResponse in project dhis2-core by dhis2.

the class EventChartControllerTest method testThatGetEventChartsDoesNotContainNewEventVisualizations.

@Test
void testThatGetEventChartsDoesNotContainNewEventVisualizations() {
    // Given
    final String body = "{'name': 'Name Test', 'type':'GAUGE', 'program':{'id':'" + mockProgram.getUid() + "'}}";
    // When
    final String uid = assertStatus(CREATED, POST("/eventVisualizations/", body));
    // Then
    final JsonResponse response = GET("/eventCharts/" + uid).content();
    final Map<String, JsonNode> nodeMap = (Map<String, JsonNode>) response.node().value();
    assertThat(nodeMap.values(), is(empty()));
}
Also used : JsonNode(org.hisp.dhis.jsontree.JsonNode) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Map(java.util.Map) JsonResponse(org.hisp.dhis.jsontree.JsonResponse) DhisControllerConvenienceTest(org.hisp.dhis.webapi.DhisControllerConvenienceTest) Test(org.junit.jupiter.api.Test)

Example 10 with JsonResponse

use of org.hisp.dhis.jsontree.JsonResponse in project dhis2-core by dhis2.

the class EventReportControllerTest method testPostForMultiEventDates.

@Test
void testPostForMultiEventDates() {
    // Given
    final String eventDateDimension = "eventDate";
    final String incidentDateDimension = "incidentDate";
    final String eventDate = "2021-07-21_2021-08-01";
    final String incidentDate = "2021-07-21_2021-08-01";
    final String eventDateBody = "{'dimension': '" + eventDateDimension + "', 'items': [{'id': '" + eventDate + "'}]}";
    final String incidentDateBody = "{'dimension': '" + incidentDateDimension + "', 'items': [{'id': '" + incidentDate + "'}]}";
    final String body = "{'name': 'Name Test', 'type':'LINE_LIST', 'program':{'id':'" + mockProgram.getUid() + "'}, 'rows': [" + eventDateBody + "," + incidentDateBody + "]}";
    // When
    final String uid = assertStatus(CREATED, POST("/eventReports/", body));
    // Then
    final JsonResponse response = GET("/eventReports/" + uid).content();
    final Map<String, JsonNode> nodeMap = (Map<String, JsonNode>) response.node().value();
    assertThat(nodeMap.get("simpleDimensions").toString(), containsString("ROW"));
    assertThat(nodeMap.get("simpleDimensions").toString(), containsString(eventDate));
    assertThat(nodeMap.get("simpleDimensions").toString(), containsString(incidentDate));
    assertThat(nodeMap.get("rows").toString(), containsString(eventDateDimension));
    assertThat(nodeMap.get("rows").toString(), containsString(incidentDateDimension));
    assertThat(nodeMap.get("columns").toString(), not(containsString(eventDateDimension)));
    assertThat(nodeMap.get("columns").toString(), not(containsString(incidentDateDimension)));
    assertThat(nodeMap.get("filters").toString(), not(containsString(eventDateDimension)));
    assertThat(nodeMap.get("filters").toString(), not(containsString(incidentDateDimension)));
}
Also used : JsonNode(org.hisp.dhis.jsontree.JsonNode) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Map(java.util.Map) JsonResponse(org.hisp.dhis.jsontree.JsonResponse) DhisControllerConvenienceTest(org.hisp.dhis.webapi.DhisControllerConvenienceTest) Test(org.junit.jupiter.api.Test)

Aggregations

JsonResponse (org.hisp.dhis.jsontree.JsonResponse)21 DhisControllerConvenienceTest (org.hisp.dhis.webapi.DhisControllerConvenienceTest)18 Test (org.junit.jupiter.api.Test)18 Map (java.util.Map)11 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)11 JsonNode (org.hisp.dhis.jsontree.JsonNode)11 SQLException (java.sql.SQLException)2 JsonString (org.hisp.dhis.jsontree.JsonString)2 JsonValue (org.hisp.dhis.jsontree.JsonValue)2 JsonUser (org.hisp.dhis.webapi.json.domain.JsonUser)2 JsonArray (org.hisp.dhis.jsontree.JsonArray)1 JsonObject (org.hisp.dhis.jsontree.JsonObject)1 User (org.hisp.dhis.user.User)1 UserAuthorityGroup (org.hisp.dhis.user.UserAuthorityGroup)1 JsonFollowupValue (org.hisp.dhis.webapi.json.domain.JsonFollowupValue)1 JsonTranslation (org.hisp.dhis.webapi.json.domain.JsonTranslation)1