Search in sources :

Example 41 with QueryParamsBuilder

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

the class TEIimportTest method teisShouldBeUpdatedAndDeletedInBulk.

@Test
public void teisShouldBeUpdatedAndDeletedInBulk() {
    // arrange
    JsonArray teis = object.getAsJsonArray("trackedEntityInstances");
    JsonObject tei1event = teis.get(0).getAsJsonObject().getAsJsonArray("enrollments").get(0).getAsJsonObject().getAsJsonArray("events").get(0).getAsJsonObject();
    JsonObject tei2enrollment = teis.get(1).getAsJsonObject().getAsJsonArray("enrollments").get(0).getAsJsonObject();
    tei1event.addProperty("deleted", true);
    tei2enrollment.addProperty("status", "COMPLETED");
    // act
    ApiResponse response = teiActions.post(object, new QueryParamsBuilder().addAll("strategy=SYNC"));
    // assert
    String eventId = response.validate().statusCode(200).body("response", notNullValue()).rootPath("response").body("updated", Matchers.greaterThanOrEqualTo(2)).appendRootPath("importSummaries[0]").body("importCount.updated", greaterThanOrEqualTo(1)).appendRootPath("enrollments.importSummaries[0].events.importSummaries[0]").body("status", Matchers.equalTo("SUCCESS"), "reference", notNullValue(), "importCount.deleted", Matchers.equalTo(1), "description", Matchers.stringContainsInOrder("Deletion of event", "was successful")).extract().path("response.importSummaries[0].enrollments.importSummaries[0].events.importSummaries[0].reference");
    String enrollmentId = response.validate().rootPath("response.importSummaries[1].enrollments.importSummaries[0]").body("status", Matchers.equalTo("SUCCESS"), "reference", notNullValue(), "importCount.updated", Matchers.equalTo(1)).extract().path("response.importSummaries[1].enrollments.importSummaries[0].reference");
    // check if updates on event and enrollment were done.
    response = enrollmentActions.get(enrollmentId);
    response.validate().statusCode(200).body("status", Matchers.equalTo("COMPLETED"));
    response = eventActions.get(eventId);
    response.validate().statusCode(404);
}
Also used : JsonArray(com.google.gson.JsonArray) 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 42 with QueryParamsBuilder

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

the class EnrollmentsUpdateTests method shouldNotUpdateImmutableProperties.

@Test
public void shouldNotUpdateImmutableProperties() throws Exception {
    String enrollmentId = importEnrollment();
    String program = new ProgramActions().createProgram("WITH_REGISTRATION").extractUid();
    JsonObject body = trackerActions.get("/enrollments/" + enrollmentId).getBody();
    body = JsonObjectBuilder.jsonObject(body).addProperty("enrollment", enrollmentId).addProperty("trackedEntity", importTei()).addProperty("program", program).wrapIntoArray("enrollments");
    trackerActions.postAndGetJobReport(body, new QueryParamsBuilder().add("importStrategy=UPDATE")).validateErrorReport().body("", hasSize(Matchers.greaterThanOrEqualTo(2))).body("errorCode", hasItems("E1127", "E1127")).body("message", Matchers.hasItem(Matchers.containsString("trackedEntity"))).body("message", Matchers.hasItem(Matchers.containsString("program")));
}
Also used : ProgramActions(org.hisp.dhis.actions.metadata.ProgramActions) QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) JsonObject(com.google.gson.JsonObject) Test(org.junit.jupiter.api.Test) TrackerNtiApiTest(org.hisp.dhis.tracker.TrackerNtiApiTest)

Example 43 with QueryParamsBuilder

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

the class EventsTests method eventsImportNewEventsFromFile.

@ParameterizedTest
@MethodSource("provideEventFilesTestArguments")
public void eventsImportNewEventsFromFile(String fileName, String contentType) throws Exception {
    Object obj = new FileReaderUtils().read(new File("src/test/resources/tracker/importer/events/" + fileName)).replacePropertyValuesWithIds("event").get();
    ApiResponse response = trackerActions.post("", contentType, obj, new QueryParamsBuilder().addAll("dryRun=false", "eventIdScheme=UID", "orgUnitIdScheme=UID"));
    response.validate().statusCode(200);
    String jobId = response.extractString("response.id");
    trackerActions.waitUntilJobIsCompleted(jobId);
    response = trackerActions.getJobReport(jobId, "FULL");
    response.validate().statusCode(200).body("status", equalTo("OK"));
}
Also used : FileReaderUtils(org.hisp.dhis.helpers.file.FileReaderUtils) QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) JsonObject(com.google.gson.JsonObject) File(java.io.File) ApiResponse(org.hisp.dhis.dto.ApiResponse) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 44 with QueryParamsBuilder

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

the class RelationshipsTests method shouldNotImportDuplicateRelationships.

@MethodSource("provideDuplicateRelationshipData")
@ParameterizedTest(name = "{index} {6}")
public void shouldNotImportDuplicateRelationships(String fromTei1, String toTei1, String fromTei2, String toTei2, boolean bidirectional, int expectedCount, String representation) {
    // arrange
    String relationshipTypeId = relationshipTypeActions.get("", new QueryParamsBuilder().addAll("filter=fromConstraint.relationshipEntity:eq:TRACKED_ENTITY_INSTANCE", "filter=toConstraint.relationshipEntity:eq:TRACKED_ENTITY_INSTANCE", "filter=bidirectional:eq:" + bidirectional, "filter=name:like:TA")).extractString("relationshipTypes.id[0]");
    JsonObject relationship1 = JsonObjectBuilder.jsonObject().addProperty("relationshipType", relationshipTypeId).addObject("from", JsonObjectBuilder.jsonObject().addProperty("trackedEntity", fromTei1)).addObject("to", JsonObjectBuilder.jsonObject().addProperty("trackedEntity", toTei1)).build();
    JsonObject relationship2 = JsonObjectBuilder.jsonObject().addProperty("relationshipType", relationshipTypeId).addObject("from", JsonObjectBuilder.jsonObject().addProperty("trackedEntity", fromTei2)).addObject("to", JsonObjectBuilder.jsonObject().addProperty("trackedEntity", toTei2)).build();
    JsonObject payload = JsonObjectBuilder.jsonObject().addArray("relationships", relationship1, relationship2).build();
    // act
    TrackerApiResponse response = trackerActions.postAndGetJobReport(payload);
    // assert
    response.validateSuccessfulImport().validate().body("stats.created", equalTo(expectedCount));
    createdRelationships = response.extractImportedRelationships();
}
Also used : QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) JsonObject(com.google.gson.JsonObject) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) MethodSource(org.junit.jupiter.params.provider.MethodSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 45 with QueryParamsBuilder

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

the class RelationshipsTests method shouldNotUpdateRelationship.

@Test
public void shouldNotUpdateRelationship() {
    // arrange
    String relationshipId = new IdGenerator().generateUniqueId();
    JsonObject relationship = JsonObjectBuilder.jsonObject().addProperty("relationship", relationshipId).addProperty("relationshipType", relationshipType).addObject("from", JsonObjectBuilder.jsonObject().addProperty("trackedEntity", teis.get(0))).addObject("to", JsonObjectBuilder.jsonObject().addProperty("trackedEntity", teis.get(1))).wrapIntoArray("relationships");
    trackerActions.postAndGetJobReport(relationship).validate().statusCode(200);
    JsonObject relationshipBody = trackerActions.get("/relationships/" + relationshipId).getBody();
    JsonObjectBuilder.jsonObject(relationship).addObjectByJsonPath("relationships[0]", "from", JsonObjectBuilder.jsonObject().addProperty("trackedEntity", teis.get(1)).build()).addObjectByJsonPath("relationships[0]", "to", JsonObjectBuilder.jsonObject().addProperty("trackedEntity", teis.get(0)).build()).build();
    // act
    TrackerApiResponse response = trackerActions.postAndGetJobReport(relationship, new QueryParamsBuilder().add("importStrategy=UPDATE"));
    // assert
    response.validateErrorReport();
    assertThat(trackerActions.get("/relationships/" + relationshipId).getBody(), matchesJSON(relationshipBody));
}
Also used : QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) JsonObject(com.google.gson.JsonObject) IdGenerator(org.hisp.dhis.actions.IdGenerator) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) TrackerNtiApiTest(org.hisp.dhis.tracker.TrackerNtiApiTest) Test(org.junit.jupiter.api.Test) 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