Search in sources :

Example 61 with QueryParamsBuilder

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

the class PotentialDuplicatesTests method shouldGetDuplicatesByTei.

@Test
public void shouldGetDuplicatesByTei() {
    String teiA = createTei();
    String teiB = createTei();
    String teiC = createTei();
    String teiD = createTei();
    potentialDuplicatesActions.createPotentialDuplicate(teiA, teiB, "OPEN").validate().statusCode(200);
    potentialDuplicatesActions.createPotentialDuplicate(teiC, teiA, "INVALID").validate().statusCode(200);
    potentialDuplicatesActions.createPotentialDuplicate(teiD, teiA, "OPEN").validate().statusCode(200);
    potentialDuplicatesActions.get("", new QueryParamsBuilder().add("teis=" + teiA)).validate().statusCode(200).body("identifiableObjects", hasSize(2));
    potentialDuplicatesActions.get("", new QueryParamsBuilder().addAll("teis=" + teiB + "," + teiC, "status=ALL")).validate().statusCode(200).body("identifiableObjects", hasSize(2));
    potentialDuplicatesActions.get("", new QueryParamsBuilder().addAll("teis=" + teiA, "status=INVALID")).validate().statusCode(200).body("identifiableObjects", hasSize(1));
    potentialDuplicatesActions.get("", new QueryParamsBuilder().addAll("teis=" + teiA, "status=OPEN")).validate().statusCode(200).body("identifiableObjects", hasSize(2));
    potentialDuplicatesActions.get("", new QueryParamsBuilder().addAll("teis=" + teiA, "status=MERGED")).validate().statusCode(200).body("identifiableObjects", hasSize(0));
    potentialDuplicatesActions.get("", new QueryParamsBuilder().addAll("teis=" + teiA, "status=ALL")).validate().statusCode(200).body("identifiableObjects", hasSize(3));
}
Also used : QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 62 with QueryParamsBuilder

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

the class EventImportDataValueValidationTests method shouldValidateCompletedOnInsert.

@Test
public void shouldValidateCompletedOnInsert() {
    programActions.programStageActions.setValidationStrategy(programStageId, "ON_UPDATE_AND_INSERT");
    JsonObject event = eventActions.createEventBody(OU_ID, programId, programStageId);
    event.addProperty("status", "COMPLETED");
    ApiResponse response = eventActions.post(event, new QueryParamsBuilder().add("skipCache=true"));
    response.validate().statusCode(409).body("status", equalTo("ERROR")).rootPath("response").body("ignored", equalTo(1)).body("imported", equalTo(0)).body("importSummaries[0].conflicts[0].value", equalTo("value_required_but_not_provided"));
}
Also used : QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) JsonObject(com.google.gson.JsonObject) ApiResponse(org.hisp.dhis.dto.ApiResponse) Test(org.junit.jupiter.api.Test) ApiTest(org.hisp.dhis.ApiTest)

Example 63 with QueryParamsBuilder

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

the class EnrollmentAttributeTests method shouldAddAttributeValue.

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

Example 64 with QueryParamsBuilder

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

the class RelationshipsTests method shouldImportObjectsWithRelationship.

@ParameterizedTest
@ValueSource(strings = { "src/test/resources/tracker/importer/teis/teisAndRelationship.json", "src/test/resources/tracker/importer/teis/teisWithRelationship.json" })
public void shouldImportObjectsWithRelationship(String file) throws Exception {
    JsonObject jsonObject = new FileReaderUtils().read(new File(file)).get(JsonObject.class);
    TrackerApiResponse response = trackerActions.postAndGetJobReport(jsonObject).validateSuccessfulImport();
    response.validate().body("stats.total", equalTo(3));
    createdRelationships = response.extractImportedRelationships();
    ApiResponse relationshipResponse = trackerActions.get("/relationships/" + createdRelationships.get(0));
    relationshipResponse.validate().statusCode(200).body("from.trackedEntity", notNullValue()).body("to.trackedEntity", notNullValue());
    response.extractImportedTeis().forEach(tei -> {
        teiActions.get(tei, new QueryParamsBuilder().add("fields=relationships")).validate().statusCode(200).body("relationships.relationship", contains(createdRelationships.get(0)));
    });
}
Also used : FileReaderUtils(org.hisp.dhis.helpers.file.FileReaderUtils) QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) JsonObject(com.google.gson.JsonObject) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) File(java.io.File) ApiResponse(org.hisp.dhis.dto.ApiResponse) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 65 with QueryParamsBuilder

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

the class TeiUpdateTests method shouldNotUpdateImmutableProperties.

@Test
public void shouldNotUpdateImmutableProperties() throws Exception {
    // arrange
    String tei = importTei();
    String trackedEntityType = new TrackedEntityTypeActions().create();
    JsonObject body = trackerActions.getTrackedEntity(tei).getBodyAsJsonBuilder().addProperty("trackedEntity", tei).addProperty("trackedEntityType", trackedEntityType).wrapIntoArray("trackedEntities");
    // assert
    trackerActions.postAndGetJobReport(body, new QueryParamsBuilder().add("importStrategy=UPDATE")).validateErrorReport().body("errorCode", Matchers.hasItem("E1126")).body("message", Matchers.hasItem(Matchers.containsString("trackedEntityType")));
}
Also used : TrackedEntityTypeActions(org.hisp.dhis.actions.metadata.TrackedEntityTypeActions) QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) JsonObject(com.google.gson.JsonObject) Test(org.junit.jupiter.api.Test) TrackerNtiApiTest(org.hisp.dhis.tracker.TrackerNtiApiTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

QueryParamsBuilder (org.hisp.dhis.helpers.QueryParamsBuilder)90 JsonObject (com.google.gson.JsonObject)54 Test (org.junit.jupiter.api.Test)51 ApiResponse (org.hisp.dhis.dto.ApiResponse)49 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)43 ApiTest (org.hisp.dhis.ApiTest)27 TrackerApiResponse (org.hisp.dhis.dto.TrackerApiResponse)21 File (java.io.File)20 TrackerNtiApiTest (org.hisp.dhis.tracker.TrackerNtiApiTest)20 FileReaderUtils (org.hisp.dhis.helpers.file.FileReaderUtils)14 MethodSource (org.junit.jupiter.params.provider.MethodSource)13 ValueSource (org.junit.jupiter.params.provider.ValueSource)9 JsonObjectBuilder (org.hisp.dhis.helpers.JsonObjectBuilder)8 EventDataBuilder (org.hisp.dhis.tracker.importer.databuilder.EventDataBuilder)6 TeiDataBuilder (org.hisp.dhis.tracker.importer.databuilder.TeiDataBuilder)5 ProgramActions (org.hisp.dhis.actions.metadata.ProgramActions)4 JsonArray (com.google.gson.JsonArray)3 HashMap (java.util.HashMap)3 ProgramStageActions (org.hisp.dhis.actions.metadata.ProgramStageActions)3 ImportSummary (org.hisp.dhis.dto.ImportSummary)3