Search in sources :

Example 26 with JsonObjectBuilder

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

the class UserAssignmentTests method shouldRemoveUserAssignment.

@Test
public void shouldRemoveUserAssignment() throws Exception {
    // arrange
    String loggedInUser = loginActions.getLoggedInUserId();
    programActions.programStageActions.enableUserAssignment(programStageId, true);
    createEvents(programId, programStageId, loggedInUser);
    JsonObject eventBody = trackerActions.get("/events?program=" + programId + "&assignedUserMode=CURRENT&ouMode=ACCESSIBLE").validateStatus(200).extractJsonObject("instances[0]");
    assertNotNull(eventBody, "no events matching the query.");
    String eventId = eventBody.get("event").getAsString();
    // act
    eventBody.add("assignedUser", null);
    trackerActions.postAndGetJobReport(new JsonObjectBuilder(eventBody).wrapIntoArray("events"), new QueryParamsBuilder().addAll("importStrategy=UPDATE")).validateSuccessfulImport();
    // assert
    trackerActions.getEvent(eventId).validate().body("assignedUser", nullValue());
}
Also used : QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) JsonObject(com.google.gson.JsonObject) JsonObjectBuilder(org.hisp.dhis.helpers.JsonObjectBuilder) Test(org.junit.jupiter.api.Test) TrackerNtiApiTest(org.hisp.dhis.tracker.TrackerNtiApiTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 27 with JsonObjectBuilder

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

the class TeiImportTests method shouldImportTei.

@Test
public void shouldImportTei() {
    // arrange
    JsonObject trackedEntities = new JsonObjectBuilder().addProperty("trackedEntityType", "Q9GufDoplCL").addProperty("orgUnit", Constants.ORG_UNIT_IDS[0]).wrapIntoArray("trackedEntities");
    // act
    TrackerApiResponse response = trackerActions.postAndGetJobReport(trackedEntities);
    response.validateSuccessfulImport().validateTeis().body("stats.created", equalTo(1)).body("objectReports", notNullValue()).body("objectReports[0].errorReports", empty());
    // assert that the tei was imported
    String teiId = response.extractImportedTeis().get(0);
    ApiResponse teiResponse = trackerActions.getTrackedEntity(teiId);
    teiResponse.validate().statusCode(200);
    assertThat(teiResponse.getBody(), matchesJSON(trackedEntities.get("trackedEntities").getAsJsonArray().get(0)));
}
Also used : JsonObject(com.google.gson.JsonObject) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) JsonObjectBuilder(org.hisp.dhis.helpers.JsonObjectBuilder) ApiResponse(org.hisp.dhis.dto.ApiResponse) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) Test(org.junit.jupiter.api.Test) TrackerNtiApiTest(org.hisp.dhis.tracker.TrackerNtiApiTest)

Example 28 with JsonObjectBuilder

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

the class PotentialDuplicatesTests method shouldUpdateStatus.

@CsvSource({ "MERGED,INVALID,false", "OPEN,INVALID,true", "OPEN,MERGED,false", "INVALID,OPEN,true", "MERGED,OPEN,false" })
@ParameterizedTest
public void shouldUpdateStatus(String status, String newStatus, boolean shouldUpdate) {
    String duplicateId = potentialDuplicatesActions.createAndValidatePotentialDuplicate(createTei(), createTei(), status);
    ApiResponse response = potentialDuplicatesActions.update(duplicateId + "?status=" + newStatus, new JsonObjectBuilder().build());
    if (shouldUpdate) {
        response.validate().statusCode(200);
        potentialDuplicatesActions.get(duplicateId).validate().statusCode(200).body("status", equalTo(newStatus));
        return;
    }
    response.validate().statusCode(400).body("status", equalTo("ERROR"));
}
Also used : JsonObjectBuilder(org.hisp.dhis.helpers.JsonObjectBuilder) ApiResponse(org.hisp.dhis.dto.ApiResponse) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 29 with JsonObjectBuilder

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

the class PotentialDuplicatesRelationshipTests method shouldNotMergeManuallyWhenThereAreDuplicateRelationships.

@Test
public void shouldNotMergeManuallyWhenThereAreDuplicateRelationships() {
    String teiA = createTei();
    String teiB = createTei();
    String relationship = createRelationship(teiA, teiB).extractImportedRelationships().get(0);
    String potentialDuplicate = potentialDuplicatesActions.createAndValidatePotentialDuplicate(teiA, teiB, "OPEN");
    potentialDuplicatesActions.manualMergePotentialDuplicate(potentialDuplicate, new JsonObjectBuilder().addArray("relationships", Arrays.asList(relationship)).build()).validate().statusCode(409).body("message", containsString("A similar relationship already exists on original"));
}
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 30 with JsonObjectBuilder

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

the class EventDataBuilder method addDataValue.

public EventDataBuilder addDataValue(String dataElementId, String value) {
    JsonObject dataValue = new JsonObjectBuilder().addProperty("dataElement", dataElementId).addProperty("value", value).build();
    this.builder.addOrAppendToArray("dataValues", dataValue);
    return this;
}
Also used : JsonObject(com.google.gson.JsonObject) JsonObjectBuilder(org.hisp.dhis.helpers.JsonObjectBuilder)

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