Search in sources :

Example 16 with JsonObjectBuilder

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

the class EventDataBuilder method addNote.

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

Example 17 with JsonObjectBuilder

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

the class EnrollmentAttributeTests method shouldValidateUniquenessWithinThePayload.

@Test
public void shouldValidateUniquenessWithinThePayload() throws Exception {
    String tei = importTei();
    String teiB = importTei();
    String value = DataGenerator.randomString();
    Function<String, JsonObject> singleEnrollment = (teiId) -> {
        return new EnrollmentDataBuilder().setId(new IdGenerator().generateUniqueId()).setTei(teiId).addAttribute(uniqueAttributeId, value).setProgram(programId).setOu(Constants.ORG_UNIT_IDS[1]).single();
    };
    JsonObject payload = new JsonObjectBuilder().addOrAppendToArray("enrollments", singleEnrollment.apply(tei), singleEnrollment.apply(teiB)).build();
    trackerActions.postAndGetJobReport(payload).validateErrorReport();
}
Also used : JsonObject(com.google.gson.JsonObject) DataGenerator(org.hisp.dhis.utils.DataGenerator) BeforeEach(org.junit.jupiter.api.BeforeEach) Constants(org.hisp.dhis.Constants) Arrays(java.util.Arrays) CoreMatchers.hasItem(org.hamcrest.CoreMatchers.hasItem) IdGenerator(org.hisp.dhis.actions.IdGenerator) ProgramActions(org.hisp.dhis.actions.metadata.ProgramActions) Matchers(org.hamcrest.Matchers) Disabled(org.junit.jupiter.api.Disabled) Function(java.util.function.Function) JsonObjectBuilder(org.hisp.dhis.helpers.JsonObjectBuilder) QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) Test(org.junit.jupiter.api.Test) TrackerNtiApiTest(org.hisp.dhis.tracker.TrackerNtiApiTest) EnrollmentDataBuilder(org.hisp.dhis.tracker.importer.databuilder.EnrollmentDataBuilder) TrackedEntityAttributeActions(org.hisp.dhis.actions.metadata.TrackedEntityAttributeActions) JsonObject(com.google.gson.JsonObject) EnrollmentDataBuilder(org.hisp.dhis.tracker.importer.databuilder.EnrollmentDataBuilder) IdGenerator(org.hisp.dhis.actions.IdGenerator) JsonObjectBuilder(org.hisp.dhis.helpers.JsonObjectBuilder) Test(org.junit.jupiter.api.Test) TrackerNtiApiTest(org.hisp.dhis.tracker.TrackerNtiApiTest)

Example 18 with JsonObjectBuilder

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

the class EnrollmentAttributeTests method shouldRemoveAttributeValue.

@Test
public void shouldRemoveAttributeValue() throws Exception {
    String tei = importTei();
    JsonObject payload = new EnrollmentDataBuilder().setId(new IdGenerator().generateUniqueId()).setTei(tei).addAttribute(optionSetAttributeId, "TA_YES").array(programId, Constants.ORG_UNIT_IDS[1]);
    trackerActions.postAndGetJobReport(payload).validateSuccessfulImport();
    payload = new JsonObjectBuilder(payload).addPropertyByJsonPath("enrollments[0].attributes[0].value", null).build();
    trackerActions.postAndGetJobReport(payload).validateSuccessfulImport();
    trackerActions.getTrackedEntity(tei + "?program=" + programId).validateStatus(200).validate().statusCode(200).body("attributes", hasSize(greaterThanOrEqualTo(1))).body("attributes.attribute", not(hasItem(optionSetAttributeId))).body("attributes.value", not(hasItem("TA_YES")));
}
Also used : JsonObject(com.google.gson.JsonObject) EnrollmentDataBuilder(org.hisp.dhis.tracker.importer.databuilder.EnrollmentDataBuilder) IdGenerator(org.hisp.dhis.actions.IdGenerator) JsonObjectBuilder(org.hisp.dhis.helpers.JsonObjectBuilder) Test(org.junit.jupiter.api.Test) TrackerNtiApiTest(org.hisp.dhis.tracker.TrackerNtiApiTest)

Example 19 with JsonObjectBuilder

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

the class RelationshipsTests method shouldDeleteRelationshipWithDeleteStrategy.

@Test
public void shouldDeleteRelationshipWithDeleteStrategy() {
    // arrage
    TrackerApiResponse response = trackerActions.postAndGetJobReport(new File("src/test/resources/tracker/importer/teis/teisAndRelationship.json")).validateSuccessfulImport();
    List<String> teis = response.extractImportedTeis();
    String relationship = response.extractImportedRelationships().get(0);
    JsonObject obj = new JsonObjectBuilder().addObject("from", JsonObjectBuilder.jsonObject().addProperty("trackedEntity", teis.get(0))).addObject("to", JsonObjectBuilder.jsonObject().addProperty("trackedEntity", teis.get(1))).addProperty("relationshipType", relationshipType).addProperty("relationship", relationship).wrapIntoArray("relationships");
    // act
    response = trackerActions.postAndGetJobReport(obj, new QueryParamsBuilder().add("importStrategy=DELETE"));
    // assert
    response.validate().body("status", equalTo("OK")).body("stats.deleted", equalTo(1));
    trackerActions.get("/relationships/" + relationship).validate().statusCode(404);
    trackerActions.getTrackedEntity(teis.get(0) + "?fields=relationships").validate().body("relationships", Matchers.empty());
}
Also used : QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) JsonObject(com.google.gson.JsonObject) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) JsonObjectBuilder(org.hisp.dhis.helpers.JsonObjectBuilder) File(java.io.File) TrackerNtiApiTest(org.hisp.dhis.tracker.TrackerNtiApiTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 20 with JsonObjectBuilder

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

the class UserActions method addUser.

public String addUser(final String firstName, final String surname, final String username, final String password) {
    String id = idGenerator.generateUniqueId();
    JsonObject user = new JsonObjectBuilder().addProperty("id", id).addProperty("firstName", firstName).addProperty("surname", surname).addProperty("username", username).addProperty("password", password).build();
    ApiResponse response = this.post(user);
    response.validate().statusCode(201);
    TestRunStorage.addCreatedEntity(endpoint, id);
    return id;
}
Also used : JsonObject(com.google.gson.JsonObject) JsonObjectBuilder(org.hisp.dhis.helpers.JsonObjectBuilder) ApiResponse(org.hisp.dhis.dto.ApiResponse)

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