Search in sources :

Example 61 with JsonObject

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

the class DataSetControllerTest method testGetFormJson.

@Test
void testGetFormJson() {
    String ouId = assertStatus(HttpStatus.CREATED, POST("/organisationUnits/", "{'name':'My Unit', 'shortName':'OU1', 'openingDate': '2020-01-01'}"));
    JsonObject info = GET("/dataSets/{id}/form?ou={ou}", dsId, ouId).content(HttpStatus.OK);
    assertTrue(info.isObject());
    assertTrue(info.has("label", "options", "groups"));
    assertEquals("My data set", info.getString("label").string());
    JsonObject options = info.getObject("options");
    assertEquals(0, options.getNumber("openPeriodsAfterCoEndDate").intValue());
    assertEquals(0, options.getNumber("openFuturePeriods").intValue());
    assertEquals(0, options.getNumber("expiryDays").intValue());
    assertEquals("Monthly", options.getString("periodType").string());
    JsonArray groups = info.getArray("groups");
    assertTrue(groups.isArray());
    assertEquals(1, groups.size());
}
Also used : JsonArray(org.hisp.dhis.jsontree.JsonArray) JsonObject(org.hisp.dhis.jsontree.JsonObject) Test(org.junit.jupiter.api.Test) DhisControllerConvenienceTest(org.hisp.dhis.webapi.DhisControllerConvenienceTest)

Example 62 with JsonObject

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

the class AttributeControllerTest method testObjectTypes.

/**
 * Tests that each type only sets the property the type relates to
 */
@Test
void testObjectTypes() {
    for (ObjectType testedType : ObjectType.values()) {
        String propertyName = testedType.getPropertyName();
        String uid = assertStatus(HttpStatus.CREATED, POST("/attributes", "{" + "'name':'" + testedType + "', " + "'valueType':'INTEGER', " + "'" + propertyName + "':true}"));
        JsonObject attr = GET("/attributes/{uid}", uid).content();
        for (ObjectType otherType : ObjectType.values()) {
            assertEquals(testedType == otherType, attr.getBoolean(otherType.getPropertyName()).booleanValue());
        }
    }
}
Also used : ObjectType(org.hisp.dhis.attribute.Attribute.ObjectType) JsonObject(org.hisp.dhis.jsontree.JsonObject) Test(org.junit.jupiter.api.Test) DhisControllerConvenienceTest(org.hisp.dhis.webapi.DhisControllerConvenienceTest)

Example 63 with JsonObject

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

the class DataApprovalControllerTest method testGetMultipleApprovalPermissions_Approvals.

@Test
void testGetMultipleApprovalPermissions_Approvals() {
    JsonArray statuses = GET("/dataApprovals/approvals?ou={ou}&pe=202101&wf={wf}", ouId, wfId).content(HttpStatus.OK);
    assertEquals(1, statuses.size());
    JsonObject status = statuses.getObject(0);
    assertTrue(status.has("wf", "pe", "ou", "aoc"));
    assertEquals(ouId, status.getString("ou").string());
    assertEquals(wfId, status.getString("wf").string());
    assertEquals("202101", status.getString("pe").string());
}
Also used : JsonArray(org.hisp.dhis.jsontree.JsonArray) JsonObject(org.hisp.dhis.jsontree.JsonObject) DhisControllerConvenienceTest(org.hisp.dhis.webapi.DhisControllerConvenienceTest) Test(org.junit.jupiter.api.Test)

Example 64 with JsonObject

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

the class DataIntegrityReportControllerTest method getDataIntegrityReport.

private JsonDataIntegrityReport getDataIntegrityReport(String url) {
    HttpResponse httpResponse = POST(url);
    assertTrue(httpResponse.location().startsWith("http://localhost/dataIntegrity/details?checks="));
    JsonObject response = httpResponse.content().getObject("response");
    String id = response.getString("id").string();
    String jobType = response.getString("jobType").string();
    return GET("/system/taskSummaries/{type}/{id}", jobType, id).content().as(JsonDataIntegrityReport.class);
}
Also used : JsonObject(org.hisp.dhis.jsontree.JsonObject) JsonString(org.hisp.dhis.jsontree.JsonString)

Example 65 with JsonObject

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

the class InterpretationControllerTest method testUpdateComment.

@Test
void testUpdateComment() {
    String cuid = assertStatus(HttpStatus.CREATED, POST("/interpretations/" + uid + "/comments", "text/plain:comment"));
    assertStatus(HttpStatus.NO_CONTENT, PUT("/interpretations/" + uid + "/comments/" + cuid, "text/plain:new comment"));
    JsonObject comments = GET("/interpretations/{uid}/comments/", uid).content();
    assertEquals("new comment", comments.getArray("comments").getObject(0).getString("text").string());
}
Also used : JsonObject(org.hisp.dhis.jsontree.JsonObject) DhisControllerConvenienceTest(org.hisp.dhis.webapi.DhisControllerConvenienceTest) Test(org.junit.jupiter.api.Test)

Aggregations

JsonObject (org.hisp.dhis.jsontree.JsonObject)106 Test (org.junit.jupiter.api.Test)92 DhisControllerConvenienceTest (org.hisp.dhis.webapi.DhisControllerConvenienceTest)51 JsonArray (org.hisp.dhis.jsontree.JsonArray)16 ProgramInstance (org.hisp.dhis.program.ProgramInstance)6 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)6 Relationship (org.hisp.dhis.relationship.Relationship)5 RelationshipType (org.hisp.dhis.relationship.RelationshipType)5 GeoJsonObject (org.geojson.GeoJsonObject)3 JsonString (org.hisp.dhis.jsontree.JsonString)3 HttpStatus (org.springframework.http.HttpStatus)3 ObjectType (org.hisp.dhis.attribute.Attribute.ObjectType)2 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)2 Arrays.stream (java.util.Arrays.stream)1 Date (java.util.Date)1 JsonResponse (org.hisp.dhis.jsontree.JsonResponse)1 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)1 Program (org.hisp.dhis.program.Program)1 ApiToken (org.hisp.dhis.security.apikey.ApiToken)1 SettingKey (org.hisp.dhis.setting.SettingKey)1