Search in sources :

Example 16 with JsonResponse

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

the class GeoFeatureControllerTest method testGetWithCoordinateField.

@Test
public void testGetWithCoordinateField() {
    POST("/metadata", "{\"organisationUnits\": [" + "{\"id\":\"rXnqqH2Pu6N\",\"name\": \"My Unit 1\",\"shortName\": \"OU1\",\"openingDate\": \"2020-01-01\"," + "\"attributeValues\": [{\"value\":  \"{\\\"type\\\": \\\"Polygon\\\"," + "\\\"coordinates\\\":  [[[100,0],[101,0],[101,1],[100,1],[100,0]]] }\"," + "\"attribute\": {\"id\": \"RRH9IFiZZYN\"}}]}," + "{\"id\":\"NBfMnCrwlQc\",\"name\": \"My Unit 3\",\"shortName\": \"OU3\",\"openingDate\": \"2020-01-01\"}" + "]," + "\"attributes\":[{\"id\":\"RRH9IFiZZYN\",\"valueType\":\"GEOJSON\",\"organisationUnitAttribute\":true,\"name\":\"testgeojson\"}]}").content(HttpStatus.OK);
    JsonResponse response = GET("/geoFeatures?ou=ou:LEVEL-1&&coordinateField=RRH9IFiZZYN").content(HttpStatus.OK);
    assertEquals(1, response.size());
    assertEquals("[[[100.0,0.0],[101.0,0.0],[101.0,1.0],[100.0,1.0],[100.0,0.0]]]", response.getObject(0).get("co").node().value().toString());
}
Also used : JsonResponse(org.hisp.dhis.jsontree.JsonResponse) Test(org.junit.jupiter.api.Test) DhisControllerConvenienceTest(org.hisp.dhis.webapi.DhisControllerConvenienceTest)

Example 17 with JsonResponse

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

the class EventChartControllerTest method testThatGetEventVisualizationsContainsLegacyEventCharts.

@Test
void testThatGetEventVisualizationsContainsLegacyEventCharts() {
    // Given
    final String body = "{'name': 'Name Test', 'type':'GAUGE', 'program':{'id':'" + mockProgram.getUid() + "'}}";
    // When
    final String uid = assertStatus(CREATED, POST("/eventCharts/", body));
    // Then
    final JsonResponse response = GET("/eventVisualizations/" + uid).content();
    final Map<String, JsonNode> nodeMap = (Map<String, JsonNode>) response.node().value();
    assertThat(nodeMap.get("name").toString(), containsString("Name Test"));
    assertThat(nodeMap.get("type").toString(), containsString("GAUGE"));
}
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 18 with JsonResponse

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

the class EventReportControllerTest method testPostForSingleEventDate.

@Test
void testPostForSingleEventDate() {
    // Given
    final String eventDateDimension = "eventDate";
    final String eventDate = "2021-07-21_2021-08-01";
    final String dimensionBody = "{'dimension': '" + eventDateDimension + "', 'items': [{'id': '" + eventDate + "'}]}";
    final String body = "{'name': 'Name Test', 'type':'LINE_LIST', 'program':{'id':'" + mockProgram.getUid() + "'}, 'columns': [" + dimensionBody + "]}";
    // When
    final String uid = assertStatus(CREATED, POST("/eventReports/", 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("COLUMN"));
    assertThat(nodeMap.get("simpleDimensions").toString(), containsString(eventDateDimension));
    assertThat(nodeMap.get("simpleDimensions").toString(), containsString(eventDate));
    assertThat(nodeMap.get("columns").toString(), containsString(eventDateDimension));
    assertThat(nodeMap.get("rows").toString(), not(containsString(eventDateDimension)));
    assertThat(nodeMap.get("filters").toString(), not(containsString(eventDateDimension)));
}
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 19 with JsonResponse

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

the class EventReportControllerTest method testThatGetEventReportsDoesNotContainNewEventVisualizations.

@Test
void testThatGetEventReportsDoesNotContainNewEventVisualizations() {
    // Given
    final String body = "{'name': 'Name Test', 'type':'LINE_LIST', 'program':{'id':'" + mockProgram.getUid() + "'}}";
    // When
    final String uid = assertStatus(CREATED, POST("/eventVisualizations/", body));
    // Then
    final JsonResponse response = GET("/eventReports/" + 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 20 with JsonResponse

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

the class ProgramStageControllerTest method testCreateProgramStageOk.

@Test
void testCreateProgramStageOk() {
    POST("/programs/", "{'name':'test program', 'id':'VoZMWi7rBgj', 'shortName':'test program','programType':'WITH_REGISTRATION' }").content(HttpStatus.CREATED);
    String programStageId = assertStatus(HttpStatus.CREATED, POST("/programStages/", "{'name':'test programStage', 'program':{'id':'VoZMWi7rBgj'}}"));
    JsonResponse programStage = GET("/programStages/{id}", programStageId).content();
    assertEquals("VoZMWi7rBgj", programStage.getString("program.id").string());
    JsonResponse program = GET("/programs/{id}", "VoZMWi7rBgj").content();
    assertEquals(programStageId, program.getJsonDocument().get("$.programStages[0].id").value());
}
Also used : JsonResponse(org.hisp.dhis.jsontree.JsonResponse) Test(org.junit.jupiter.api.Test) DhisControllerConvenienceTest(org.hisp.dhis.webapi.DhisControllerConvenienceTest)

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