Search in sources :

Example 31 with TrackerApiResponse

use of org.hisp.dhis.dto.TrackerApiResponse in project dhis2-core by dhis2.

the class EventValidationTests method eventImportShouldValidateReferences.

@ParameterizedTest
@MethodSource("provideValidationArguments")
public void eventImportShouldValidateReferences(String ouId, String programId, String programStageId, String errorCode) {
    JsonObject jsonObject = new EventDataBuilder().array(ouId, programId, programStageId);
    TrackerApiResponse response = trackerActions.postAndGetJobReport(jsonObject);
    response.validateErrorReport().body("errorCode", hasItem(equalTo(errorCode)));
}
Also used : EventDataBuilder(org.hisp.dhis.tracker.importer.databuilder.EventDataBuilder) JsonObject(com.google.gson.JsonObject) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 32 with TrackerApiResponse

use of org.hisp.dhis.dto.TrackerApiResponse in project dhis2-core by dhis2.

the class EventValidationTests method shouldNotImportDeletedEvents.

@Test
public void shouldNotImportDeletedEvents() throws Exception {
    JsonObject eventBody = new FileReaderUtils().readJsonAndGenerateData(new File("src/test/resources/tracker/importer/events/event.json"));
    String eventId = trackerActions.postAndGetJobReport(eventBody).validateSuccessfulImport().extractImportedEvents().get(0);
    eventActions.softDelete(eventId);
    TrackerApiResponse response = trackerActions.postAndGetJobReport(eventBody);
    response.validateErrorReport().body("errorCode", hasItem("E1082"));
}
Also used : FileReaderUtils(org.hisp.dhis.helpers.file.FileReaderUtils) JsonObject(com.google.gson.JsonObject) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) File(java.io.File) Test(org.junit.jupiter.api.Test) TrackerNtiApiTest(org.hisp.dhis.tracker.TrackerNtiApiTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 33 with TrackerApiResponse

use of org.hisp.dhis.dto.TrackerApiResponse in project dhis2-core by dhis2.

the class EventsTests method shouldAddEventsToExistingTei.

@Test
public void shouldAddEventsToExistingTei() throws Exception {
    String programId = Constants.TRACKER_PROGRAM_ID;
    String programStageId = "nlXNK4b7LVr";
    TrackerApiResponse response = importTeiWithEnrollment(programId);
    String enrollmentId = response.extractImportedEnrollments().get(0);
    JsonObject event = new EventDataBuilder().setEnrollment(enrollmentId).array(Constants.ORG_UNIT_IDS[1], programId, programStageId);
    response = trackerActions.postAndGetJobReport(event).validateSuccessfulImport();
    String eventId = response.extractImportedEvents().get(0);
    trackerActions.get("/events/" + eventId + "?fields=*").validate().statusCode(200).body("enrollment", equalTo(enrollmentId));
}
Also used : EventDataBuilder(org.hisp.dhis.tracker.importer.databuilder.EventDataBuilder) JsonObject(com.google.gson.JsonObject) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) TrackerNtiApiTest(org.hisp.dhis.tracker.TrackerNtiApiTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 34 with TrackerApiResponse

use of org.hisp.dhis.dto.TrackerApiResponse 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 35 with TrackerApiResponse

use of org.hisp.dhis.dto.TrackerApiResponse 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

TrackerApiResponse (org.hisp.dhis.dto.TrackerApiResponse)53 JsonObject (com.google.gson.JsonObject)44 Test (org.junit.jupiter.api.Test)35 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)34 TrackerNtiApiTest (org.hisp.dhis.tracker.TrackerNtiApiTest)32 QueryParamsBuilder (org.hisp.dhis.helpers.QueryParamsBuilder)17 EventDataBuilder (org.hisp.dhis.tracker.importer.databuilder.EventDataBuilder)15 File (java.io.File)14 FileReaderUtils (org.hisp.dhis.helpers.file.FileReaderUtils)11 ApiResponse (org.hisp.dhis.dto.ApiResponse)9 TeiDataBuilder (org.hisp.dhis.tracker.importer.databuilder.TeiDataBuilder)8 JsonObjectBuilder (org.hisp.dhis.helpers.JsonObjectBuilder)5 CsvSource (org.junit.jupiter.params.provider.CsvSource)5 ValueSource (org.junit.jupiter.params.provider.ValueSource)5 MethodSource (org.junit.jupiter.params.provider.MethodSource)4 PotentialDuplicatesApiTest (org.hisp.dhis.tracker.deduplication.PotentialDuplicatesApiTest)3 EnrollmentDataBuilder (org.hisp.dhis.tracker.importer.databuilder.EnrollmentDataBuilder)3 IdGenerator (org.hisp.dhis.actions.IdGenerator)2 ProgramStageActions (org.hisp.dhis.actions.metadata.ProgramStageActions)2 JsonFileReader (org.hisp.dhis.helpers.file.JsonFileReader)1