Search in sources :

Example 11 with JsonObjectBuilder

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

the class PotentialDuplicatesEnrollmentsTests method shouldBeManuallyMerged.

@Test
public void shouldBeManuallyMerged() {
    String teiA = createTeiWithEnrollmentsAndEvents(TRACKER_PROGRAM_ID, TRACKER_PROGRAM_STAGE_ID).extractImportedTeis().get(0);
    TrackerApiResponse teiBResponse = createTeiWithEnrollmentsAndEvents(Constants.ANOTHER_TRACKER_PROGRAM_ID, "PaOOjwLVW2X");
    String teiB = teiBResponse.extractImportedTeis().get(0);
    String enrollmentToMerge = teiBResponse.extractImportedEnrollments().get(0);
    String potentialDuplicate = potentialDuplicatesActions.createPotentialDuplicate(teiA, teiB, "OPEN").validateStatus(200).extractString("id");
    potentialDuplicatesActions.manualMergePotentialDuplicate(potentialDuplicate, new JsonObjectBuilder().addArray("enrollments", Arrays.asList(enrollmentToMerge)).build()).validate().statusCode(200);
    trackerActions.getTrackedEntity(teiA + "?fields=enrollments").validate().statusCode(200).body("enrollments", hasSize(2));
}
Also used : TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) JsonObjectBuilder(org.hisp.dhis.helpers.JsonObjectBuilder) PotentialDuplicatesApiTest(org.hisp.dhis.tracker.deduplication.PotentialDuplicatesApiTest) Test(org.junit.jupiter.api.Test)

Example 12 with JsonObjectBuilder

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

the class PotentialDuplicatesRelationshipTests method shouldManuallyMergeRelationship.

@Test
public void shouldManuallyMergeRelationship() {
    String teiA = createTei();
    String teiB = createTei();
    String teiC = createTei();
    String relationship = createRelationship(teiB, teiC).extractImportedRelationships().get(0);
    String potentialDuplicate = potentialDuplicatesActions.createAndValidatePotentialDuplicate(teiA, teiB, "OPEN");
    potentialDuplicatesActions.manualMergePotentialDuplicate(potentialDuplicate, new JsonObjectBuilder().addArray("relationships", Arrays.asList(relationship)).build()).validate().statusCode(200);
    trackerActions.getTrackedEntity(teiA + "?fields=*").validate().statusCode(200).body("relationships", hasSize(1)).body("relationships.relationship", hasItems(relationship));
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) JsonObjectBuilder(org.hisp.dhis.helpers.JsonObjectBuilder) PotentialDuplicatesApiTest(org.hisp.dhis.tracker.deduplication.PotentialDuplicatesApiTest) Test(org.junit.jupiter.api.Test)

Example 13 with JsonObjectBuilder

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

the class EventImportDataValueValidationTests method setupData.

private void setupData() throws Exception {
    programId = new IdGenerator().generateUniqueId();
    programStageId = new IdGenerator().generateUniqueId();
    JsonObject jsonObject = new JsonObjectBuilder(new FileReaderUtils().readJsonAndGenerateData(new File("src/test/resources/tracker/eventProgram.json"))).addPropertyByJsonPath("programStages[0].program.id", programId).addPropertyByJsonPath("programs[0].id", programId).addPropertyByJsonPath("programs[0].programStages[0].id", programStageId).addPropertyByJsonPath("programStages[0].id", programStageId).addPropertyByJsonPath("programStages[0].programStageDataElements", null).build();
    new MetadataActions().importAndValidateMetadata(jsonObject);
    String dataElementId = dataElementActions.get("?fields=id&filter=domainType:eq:TRACKER&filter=valueType:eq:TEXT&pageSize=1").extractString("dataElements.id[0]");
    assertNotNull(dataElementId, "Failed to create data elements");
    mandatoryDataElementId = dataElementId;
    programActions.addDataElement(programStageId, dataElementId, true).validate().statusCode(200);
}
Also used : FileReaderUtils(org.hisp.dhis.helpers.file.FileReaderUtils) JsonObject(com.google.gson.JsonObject) MetadataActions(org.hisp.dhis.actions.metadata.MetadataActions) IdGenerator(org.hisp.dhis.actions.IdGenerator) JsonObjectBuilder(org.hisp.dhis.helpers.JsonObjectBuilder) File(java.io.File)

Example 14 with JsonObjectBuilder

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

the class ProgramRemovalTest method setupData.

private void setupData() throws Exception {
    programId = programActions.createProgram("WITH_REGISTRATION").extractUid();
    assertNotNull(programId, "Failed to create program");
    JsonObject relationshipType = new FileReaderUtils().read(new File("src/test/resources/tracker/relationshipTypes.json")).replacePropertyValuesWithIds("id").get(JsonObject.class).getAsJsonArray("relationshipTypes").get(0).getAsJsonObject();
    new JsonObjectBuilder(relationshipType).addObject("toConstraint", new JsonObjectBuilder().addProperty("relationshipEntity", "PROGRAM_STAGE_INSTANCE").addObject("program", new JsonObjectBuilder().addProperty("id", programId))).build();
    relationshipTypeId = relationshipTypeActions.create(relationshipType);
    assertNotNull(relationshipTypeId, "Failed to create relationshipType");
}
Also used : FileReaderUtils(org.hisp.dhis.helpers.file.FileReaderUtils) JsonObject(com.google.gson.JsonObject) JsonObjectBuilder(org.hisp.dhis.helpers.JsonObjectBuilder) File(java.io.File)

Example 15 with JsonObjectBuilder

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

the class EnrollmentsTests method shouldAddNote.

@Test
public void shouldAddNote() {
    String enrollmentId = trackerActions.postAndGetJobReport(new TeiDataBuilder().buildWithEnrollment(Constants.ORG_UNIT_IDS[0], Constants.TRACKER_PROGRAM_ID)).extractImportedEnrollments().get(0);
    JsonObject payload = trackerActions.getEnrollment(enrollmentId).getBodyAsJsonBuilder().addOrAppendToArray("notes", new JsonObjectBuilder().addProperty("value", DataGenerator.randomString()).build()).wrapIntoArray("enrollments");
    trackerActions.postAndGetJobReport(payload).validateSuccessfulImport().validate().body("stats.updated", equalTo(1));
    trackerActions.getEnrollment(enrollmentId + "?fields=notes").validate().statusCode(200).rootPath("notes").body("note", notNullValue()).body("storedAt", notNullValue()).body("updatedAt", notNullValue()).body("value", notNullValue()).body("storedBy", CoreMatchers.everyItem(equalTo("taadmin")));
}
Also used : TeiDataBuilder(org.hisp.dhis.tracker.importer.databuilder.TeiDataBuilder) JsonObject(com.google.gson.JsonObject) JsonObjectBuilder(org.hisp.dhis.helpers.JsonObjectBuilder) TrackerNtiApiTest(org.hisp.dhis.tracker.TrackerNtiApiTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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