Search in sources :

Example 31 with JsonObjectBuilder

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

the class PotentialDuplicatesAttributeMergeTests method shouldManuallyMergeAttributeWithDifferentValues.

@Test
public void shouldManuallyMergeAttributeWithDifferentValues() {
    String teiA = createTeiWithAttributes(createAttribute(attributes.get(0), "attribute 1"));
    String teiB = createTeiWithAttributes(createAttribute(attributes.get(0), "attribute 2"));
    String potentialDuplicate = potentialDuplicatesActions.createAndValidatePotentialDuplicate(teiA, teiB, "OPEN");
    potentialDuplicatesActions.manualMergePotentialDuplicate(potentialDuplicate, new JsonObjectBuilder().addArray("trackedEntityAttributes", Arrays.asList(attributes.get(0))).build()).validate().statusCode(200);
    trackerActions.getTrackedEntity(teiA).validate().body("attributes", hasSize(1)).body("attributes[0].value", equalTo("attribute 2"));
}
Also used : JsonObjectBuilder(org.hisp.dhis.helpers.JsonObjectBuilder) PotentialDuplicatesApiTest(org.hisp.dhis.tracker.deduplication.PotentialDuplicatesApiTest) Test(org.junit.jupiter.api.Test)

Example 32 with JsonObjectBuilder

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

the class PotentialDuplicatesAttributeMergeTests method shouldMoveChangelogs.

@Test
public void shouldMoveChangelogs() {
    String teiA = createTeiWithAttributes(createAttribute(attributes.get(0), "attribute A"));
    String teiB = createTeiWithAttributes(createAttribute(attributes.get(0), "attribute A - changed"), createAttribute(attributes.get(1), "attribute B"));
    String potentialDuplicate = potentialDuplicatesActions.createAndValidatePotentialDuplicate(teiA, teiB, "OPEN");
    potentialDuplicatesActions.manualMergePotentialDuplicate(potentialDuplicate, new JsonObjectBuilder().addArray("trackedEntityAttributes", Arrays.asList(attributes.get(0), attributes.get(1))).build()).validate().statusCode(200);
    new AuditActions().getTrackedEntityAttributeValueAudits(teiA).validate().statusCode(200).rootPath("trackedEntityAttributeValueAudits").body("", hasSize(greaterThanOrEqualTo(2))).appendRootPath(String.format("find{it.trackedEntityAttribute.id=='%s'}", attributes.get(1))).body("value", equalTo("attribute B")).body("auditType", equalTo("CREATE")).rootPath(String.format("trackedEntityAttributeValueAudits.find{it.trackedEntityAttribute.id=='%s'}", attributes.get(0))).body("value", equalTo("attribute A - changed")).body("auditType", equalTo("UPDATE"));
}
Also used : AuditActions(org.hisp.dhis.actions.AuditActions) JsonObjectBuilder(org.hisp.dhis.helpers.JsonObjectBuilder) PotentialDuplicatesApiTest(org.hisp.dhis.tracker.deduplication.PotentialDuplicatesApiTest) Test(org.junit.jupiter.api.Test)

Example 33 with JsonObjectBuilder

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

the class ProgramStagesTest method shouldAddProgramStageToProgram.

@Test
public void shouldAddProgramStageToProgram() {
    // arrange
    JsonObject programBody = programActions.get(programId).getBodyAsJsonBuilder().addArray("programStages", new JsonObjectBuilder().addProperty("id", programStageId).build()).build();
    // act
    ApiResponse response = programActions.update(programId, programBody);
    // assert
    ResponseValidationHelper.validateObjectUpdate(response, 200);
    response = programActions.get(programId);
    response.validate().statusCode(200).body("programStages", not(emptyArray())).body("programStages.id", not(emptyArray())).body("programStages.id", hasItem(programStageId));
    response = programStageActions.get(programStageId);
    response.validate().statusCode(200).body("program", notNullValue()).body("program.id", equalTo(programId));
}
Also used : JsonObject(com.google.gson.JsonObject) JsonObjectBuilder(org.hisp.dhis.helpers.JsonObjectBuilder) ApiResponse(org.hisp.dhis.dto.ApiResponse) Test(org.junit.jupiter.api.Test) ApiTest(org.hisp.dhis.ApiTest)

Example 34 with JsonObjectBuilder

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

the class MetadataPatchTests method shouldAddToArrays.

@Test
public void shouldAddToArrays() {
    JsonObject operation = buildOperation("add", "/dataElements/-", new JsonObjectBuilder().addProperty("id", dataElementId).build());
    dataElementGroupActions.patch(dataElementGroupId, Arrays.asList(operation)).validate().statusCode(200);
    dataElementActions.get(dataElementId).validate().body("dataElementGroups.id", Matchers.contains(dataElementGroupId));
}
Also used : JsonObject(com.google.gson.JsonObject) JsonObjectBuilder(org.hisp.dhis.helpers.JsonObjectBuilder) Test(org.junit.jupiter.api.Test) ApiTest(org.hisp.dhis.ApiTest)

Example 35 with JsonObjectBuilder

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

the class MetadataImportImportStrategyTests method shouldCreateMetadataWithCodeIdentifier.

@Test
public void shouldCreateMetadataWithCodeIdentifier() {
    JsonObject object = JsonObjectBuilder.jsonObject(DataGenerator.generateObjectForEndpoint("/dataElementGroup")).addProperty("code", "TA_CODE_DATAELEMENT_GROUP").addArray("userGroupAccesses", new JsonObjectBuilder().addProperty("access", "rw------").addProperty("code", "TA_USER_GROUP").build()).wrapIntoArray("dataElementGroups");
    ApiResponse response = metadataActions.importMetadata(object, "identifier=CODE");
    response.validate().statusCode(200).body("response.stats.created", equalTo(1));
    response = metadataActions.importMetadata(object, "identifier=CODE");
    response.validate().statusCode(200).body("response.stats.updated", equalTo(1));
}
Also used : JsonObject(com.google.gson.JsonObject) JsonObjectBuilder(org.hisp.dhis.helpers.JsonObjectBuilder) ApiResponse(org.hisp.dhis.dto.ApiResponse) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) 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