Search in sources :

Example 31 with JsonObject

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

the class MetadataWorkflowControllerTest method testGetProposals.

@Test
void testGetProposals() {
    String proposalId = postAddProposal("My Unit", "OU1");
    assertNotNull(proposalId);
    JsonObject page = GET("/metadata/proposals/").content();
    assertTrue(page.has("pager", "proposals"));
    assertEquals(1, page.getArray("proposals").size());
    assertEquals(proposalId, page.getArray("proposals").getObject(0).getString("id").string());
}
Also used : JsonObject(org.hisp.dhis.jsontree.JsonObject) DhisControllerConvenienceTest(org.hisp.dhis.webapi.DhisControllerConvenienceTest) Test(org.junit.jupiter.api.Test)

Example 32 with JsonObject

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

the class AbstractDataValueControllerTest method setUp.

@BeforeEach
void setUp() {
    orgUnitId = assertStatus(HttpStatus.CREATED, POST("/organisationUnits/", "{'name':'My Unit', 'shortName':'OU1', 'openingDate': '2020-01-01'}"));
    // add OU to users hierarchy
    assertStatus(HttpStatus.OK, POST("/users/{id}/organisationUnits", getCurrentUser().getUid(), Body("{'additions':[{'id':'" + orgUnitId + "'}]}")));
    JsonObject ccDefault = GET("/categoryCombos/gist?fields=id,categoryOptionCombos::ids&pageSize=1&headless=true&filter=name:eq:default").content().getObject(0);
    categoryComboId = ccDefault.getString("id").string();
    categoryOptionId = ccDefault.getArray("categoryOptionCombos").getString(0).string();
    dataElementId = assertStatus(HttpStatus.CREATED, POST("/dataElements/", "{'name':'My data element', 'shortName':'DE1', 'code':'DE1', 'valueType':'INTEGER', " + "'aggregationType':'SUM', 'zeroIsSignificant':false, 'domainType':'AGGREGATE', " + "'categoryCombo': {'id': '" + categoryComboId + "'}}"));
}
Also used : JsonObject(org.hisp.dhis.jsontree.JsonObject) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 33 with JsonObject

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

the class AbstractGistControllerTest method assertHasPager.

static void assertHasPager(JsonObject response, int page, int pageSize, Integer total) {
    JsonObject pager = response.getObject("pager");
    assertTrue(pager.exists(), "Pager is missing");
    assertEquals(page, pager.getNumber("page").intValue());
    assertEquals(pageSize, pager.getNumber("pageSize").intValue());
    if (total != null) {
        assertEquals(total.intValue(), pager.getNumber("total").intValue());
        assertEquals((int) Math.ceil(total / (double) pageSize), pager.getNumber("pageCount").intValue());
    }
}
Also used : JsonObject(org.hisp.dhis.jsontree.JsonObject)

Example 34 with JsonObject

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

the class AbstractCrudControllerTest method testPutJsonObject_skipSharing.

@Test
void testPutJsonObject_skipSharing() {
    String groupId = assertStatus(HttpStatus.CREATED, POST("/userGroups/", "{'name':'My Group'}"));
    JsonObject group = GET("/userGroups/{id}", groupId).content();
    String groupWithoutSharing = group.getObject("sharing").node().replaceWith("null").toString();
    assertStatus(HttpStatus.OK, PUT("/userGroups/" + groupId + "?skipSharing=true", groupWithoutSharing));
    assertEquals("rw------", GET("/userGroups/{id}", groupId).content().as(JsonGeoMap.class).getSharing().getPublic().string());
}
Also used : JsonObject(org.hisp.dhis.jsontree.JsonObject) DhisControllerConvenienceTest(org.hisp.dhis.webapi.DhisControllerConvenienceTest) Test(org.junit.jupiter.api.Test)

Example 35 with JsonObject

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

the class DataSetControllerTest method testGetVersion.

@Test
void testGetVersion() {
    JsonObject info = GET("/dataSets/{id}/version", dsId).content(HttpStatus.OK);
    assertTrue(info.isObject());
    assertEquals(1, info.size());
    assertEquals(0, info.getNumber("version").intValue());
}
Also used : JsonObject(org.hisp.dhis.jsontree.JsonObject) Test(org.junit.jupiter.api.Test) DhisControllerConvenienceTest(org.hisp.dhis.webapi.DhisControllerConvenienceTest)

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