Search in sources :

Example 11 with JsonResponse

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

the class EventReportControllerTest method testThatGetEventVisualizationsContainsLegacyEventReports.

@Test
void testThatGetEventVisualizationsContainsLegacyEventReports() {
    // Given
    final String body = "{'name': 'Name Test', 'type':'LINE_LIST', 'program':{'id':'" + mockProgram.getUid() + "'}}";
    // 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("name").toString(), containsString("Name Test"));
    assertThat(nodeMap.get("type").toString(), containsString("LINE_LIST"));
}
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 12 with JsonResponse

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

the class AbstractCrudControllerTest method testUpdateObjectProperty.

@Test
void testUpdateObjectProperty() {
    String peter = "{'name': 'Peter', 'firstName':'Peter', 'surname':'Pan', 'username':'peter47'}";
    String peterUserId = assertStatus(HttpStatus.CREATED, POST("/users", peter));
    JsonResponse roles = GET("/userRoles?fields=id").content();
    String roleId = roles.getArray("userRoles").getObject(0).getString("id").string();
    assertStatus(HttpStatus.NO_CONTENT, POST("/userRoles/" + roleId + "/users/" + peterUserId));
    JsonUser oldPeter = GET("/users/{id}", peterUserId).content().as(JsonUser.class);
    assertEquals("Peter", oldPeter.getFirstName());
    assertEquals(1, oldPeter.getArray("userRoles").size());
    List<User> allUsers2 = userService.getAllUsers();
    Set<UserAuthorityGroup> g1 = allUsers2.get(0).getUserAuthorityGroups();
    Set<UserAuthorityGroup> g2 = allUsers2.get(1).getUserAuthorityGroups();
    assertStatus(HttpStatus.NO_CONTENT, PATCH("/users/" + peterUserId + "/firstName", Body("{'firstName': 'Fry'}"), ContentType(MediaType.APPLICATION_JSON)));
    List<User> allUsers3 = userService.getAllUsers();
    Set<UserAuthorityGroup> g3 = allUsers3.get(0).getUserAuthorityGroups();
    Set<UserAuthorityGroup> g4 = allUsers3.get(1).getUserAuthorityGroups();
    JsonUser newPeter = GET("/users/{id}", peterUserId).content().as(JsonUser.class);
    assertEquals("Fry", newPeter.getFirstName());
    // are user roles still there?
    assertEquals(1, newPeter.getArray("userRoles").size());
}
Also used : JsonUser(org.hisp.dhis.webapi.json.domain.JsonUser) User(org.hisp.dhis.user.User) JsonUser(org.hisp.dhis.webapi.json.domain.JsonUser) UserAuthorityGroup(org.hisp.dhis.user.UserAuthorityGroup) JsonResponse(org.hisp.dhis.jsontree.JsonResponse) DhisControllerConvenienceTest(org.hisp.dhis.webapi.DhisControllerConvenienceTest) Test(org.junit.jupiter.api.Test)

Example 13 with JsonResponse

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

the class EventVisualizationControllerTest 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': 'STACKED_COLUMN', 'program': {'id':'" + mockProgram.getUid() + "'}, 'columns': [" + dimensionBody + "]}";
    // 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("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 14 with JsonResponse

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

the class EventVisualizationControllerTest method testPostRepetitionForRow.

@Test
void testPostRepetitionForRow() {
    // Given
    final String dimension = "pe";
    final String indexes = "[1,2,0]";
    final String repetition = "'repetition': {'indexes': " + indexes + "}";
    final String body = "{'name': 'Name Test', 'type': 'STACKED_COLUMN', 'program': {'id':'" + mockProgram.getUid() + "'}, 'rows': [{'dimension': '" + dimension + "', " + repetition + "}]}";
    // When
    final String uid = assertStatus(CREATED, POST("/eventVisualizations/", body));
    // Then
    final String getParams = "?fields=:all,rows[: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("ROW"));
    assertThat(nodeMap.get("repetitions").toString(), containsString(indexes));
    assertThat(nodeMap.get("repetitions").toString(), containsString(dimension));
    assertThat(nodeMap.get("rows").toString(), containsString(indexes));
    assertThat(nodeMap.get("columns").toString(), not(containsString(indexes)));
    assertThat(nodeMap.get("filters").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 15 with JsonResponse

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

the class EventVisualizationControllerTest method testPostRepetitionForColumn.

@Test
void testPostRepetitionForColumn() {
    // Given
    final String dimension = "pe";
    final String indexes = "[1,0,-1]";
    final String repetition = "'repetition': {'indexes': " + indexes + "}";
    final String body = "{'name': 'Name Test', 'type': 'STACKED_COLUMN', 'program': {'id':'" + mockProgram.getUid() + "'}, 'columns': [{'dimension': '" + dimension + "', " + repetition + "}]}";
    // When
    final String uid = assertStatus(CREATED, POST("/eventVisualizations/", body));
    // Then
    final String getParams = "?fields=:all,columns[: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("COLUMN"));
    assertThat(nodeMap.get("repetitions").toString(), containsString(indexes));
    assertThat(nodeMap.get("repetitions").toString(), containsString(dimension));
    assertThat(nodeMap.get("columns").toString(), containsString(indexes));
    assertThat(nodeMap.get("rows").toString(), not(containsString(indexes)));
    assertThat(nodeMap.get("filters").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)

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