Search in sources :

Example 36 with JsonObjectBuilder

use of org.hisp.dhis.helpers.JsonObjectBuilder in project dhis2-core by dhis2.

the class OrgUnitProfileTests method shouldApplyGroupSets.

@Test
public void shouldApplyGroupSets() {
    // arrange
    MetadataApiResponse response = new MetadataActions().importAndValidateMetadata(new File("src/test/resources/metadata/orgunits/ou_with_group_and_set.json"));
    String groupSet = response.extractObjectUid("OrganisationUnitGroupSet").get(0);
    String ou = response.extractObjectUid("OrganisationUnit").get(0);
    JsonArray array = new JsonArray();
    array.add(groupSet);
    JsonObject profileBody = new JsonObjectBuilder().addArray("groupSets", array).build();
    // act
    orgUnitProfileActions.post(profileBody).validate().statusCode(200);
    // assert
    orgUnitProfileActions.get().validate().body("groupSets", hasSize(greaterThanOrEqualTo(1)));
    orgUnitProfileActions.get("/" + ou + "/data").validate().statusCode(200).body("groupSets", hasSize(1)).rootPath("groupSets[0]").body("id", equalTo(groupSet)).body("label", notNullValue()).body("value", notNullValue());
}
Also used : JsonArray(com.google.gson.JsonArray) MetadataApiResponse(org.hisp.dhis.dto.MetadataApiResponse) JsonObject(com.google.gson.JsonObject) MetadataActions(org.hisp.dhis.actions.metadata.MetadataActions) JsonObjectBuilder(org.hisp.dhis.helpers.JsonObjectBuilder) File(java.io.File) Test(org.junit.jupiter.api.Test) ApiTest(org.hisp.dhis.ApiTest)

Example 37 with JsonObjectBuilder

use of org.hisp.dhis.helpers.JsonObjectBuilder in project dhis2-core by dhis2.

the class OrgUnitProfileTests method shouldApplyDataItems.

@Test
public void shouldApplyDataItems() {
    List<String> datItems = new DataItemActions().get("", new QueryParamsBuilder().add("filter=dimensionItemType:in:[DATA_ELEMENT,PROGRAM_INDICATOR]")).extractList("dataItems.id");
    JsonArray array = new JsonArray();
    datItems.forEach(p -> array.add(p));
    orgUnitProfileActions.post(new JsonObjectBuilder().addArray("dataItems", array).build()).validate().statusCode(200);
    orgUnitProfileActions.get().validate().body("dataItems", hasSize(greaterThanOrEqualTo(1)));
// todo add validation for organisationUnitProfile/id/data
}
Also used : JsonArray(com.google.gson.JsonArray) DataItemActions(org.hisp.dhis.actions.dataitem.DataItemActions) QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) JsonObjectBuilder(org.hisp.dhis.helpers.JsonObjectBuilder) Test(org.junit.jupiter.api.Test) ApiTest(org.hisp.dhis.ApiTest)

Example 38 with JsonObjectBuilder

use of org.hisp.dhis.helpers.JsonObjectBuilder in project dhis2-core by dhis2.

the class OrgUnitProfileTests method shouldApplyProfileAttributes.

@Test
public void shouldApplyProfileAttributes() {
    // arrange
    String attributeId = attributeActions.createAttribute("TEXT", false, "organisationUnit");
    String attributeValue = DataGenerator.randomString();
    new OrgUnitActions().addAttributeValue(orgUnitId, attributeId, attributeValue);
    JsonArray array = new JsonArray();
    array.add(attributeId);
    JsonObject profileBody = orgUnitProfileActions.get().getBody();
    // act
    orgUnitProfileActions.post(new JsonObjectBuilder(profileBody).addArray("attributes", array).build()).validate().statusCode(200);
    // assert
    orgUnitProfileActions.get().validate().body("attributes", hasSize(greaterThanOrEqualTo(1)));
    orgUnitProfileActions.get("/" + orgUnitId + "/data").validate().statusCode(200).body("attributes", hasSize(1)).rootPath("attributes[0]").body("value", equalTo(attributeValue)).body("id", equalTo(attributeId)).body("label", notNullValue());
}
Also used : JsonArray(com.google.gson.JsonArray) OrgUnitActions(org.hisp.dhis.actions.metadata.OrgUnitActions) JsonObject(com.google.gson.JsonObject) JsonObjectBuilder(org.hisp.dhis.helpers.JsonObjectBuilder) Test(org.junit.jupiter.api.Test) ApiTest(org.hisp.dhis.ApiTest)

Aggregations

JsonObjectBuilder (org.hisp.dhis.helpers.JsonObjectBuilder)38 JsonObject (com.google.gson.JsonObject)29 Test (org.junit.jupiter.api.Test)18 ApiResponse (org.hisp.dhis.dto.ApiResponse)11 QueryParamsBuilder (org.hisp.dhis.helpers.QueryParamsBuilder)9 TrackerNtiApiTest (org.hisp.dhis.tracker.TrackerNtiApiTest)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 ApiTest (org.hisp.dhis.ApiTest)6 File (java.io.File)5 TrackerApiResponse (org.hisp.dhis.dto.TrackerApiResponse)5 PotentialDuplicatesApiTest (org.hisp.dhis.tracker.deduplication.PotentialDuplicatesApiTest)5 JsonArray (com.google.gson.JsonArray)4 IdGenerator (org.hisp.dhis.actions.IdGenerator)4 ProgramStageActions (org.hisp.dhis.actions.metadata.ProgramStageActions)3 FileReaderUtils (org.hisp.dhis.helpers.file.FileReaderUtils)3 EnrollmentDataBuilder (org.hisp.dhis.tracker.importer.databuilder.EnrollmentDataBuilder)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 RestApiActions (org.hisp.dhis.actions.RestApiActions)2 MetadataActions (org.hisp.dhis.actions.metadata.MetadataActions)2 TeiDataBuilder (org.hisp.dhis.tracker.importer.databuilder.TeiDataBuilder)2