Search in sources :

Example 41 with TrackerApiResponse

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

the class EventsTests method shouldImportEvents.

@Test
public void shouldImportEvents() throws Exception {
    JsonObject eventBody = new FileReaderUtils().readJsonAndGenerateData(new File("src/test/resources/tracker/importer/events/events.json"));
    TrackerApiResponse importResponse = trackerActions.postAndGetJobReport(eventBody);
    importResponse.validateSuccessfulImport().validateEvents().body("stats.created", Matchers.equalTo(4)).body("objectReports", notNullValue()).body("objectReports[0].errorReports", empty());
    eventBody.getAsJsonArray("events").forEach(event -> {
        String eventId = event.getAsJsonObject().get("event").getAsString();
        ApiResponse response = trackerActions.get("/events/" + eventId);
        response.validate().statusCode(200);
        assertThat(response.getBody(), matchesJSON(event));
    });
}
Also used : FileReaderUtils(org.hisp.dhis.helpers.file.FileReaderUtils) 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) TrackerNtiApiTest(org.hisp.dhis.tracker.TrackerNtiApiTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 42 with TrackerApiResponse

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

the class EventsTests method shouldImportToRepeatableStage.

@ParameterizedTest
@ValueSource(strings = { "true", "false" })
public void shouldImportToRepeatableStage(Boolean repeatableStage) throws Exception {
    // arrange
    String program = Constants.TRACKER_PROGRAM_ID;
    String programStage = new ProgramStageActions().get("", new QueryParamsBuilder().addAll("filter=program.id:eq:" + program, "filter=repeatable:eq:" + repeatableStage)).extractString("programStages.id[0]");
    TrackerApiResponse response = importTeiWithEnrollment(program);
    String teiId = response.extractImportedTeis().get(0);
    String enrollmentId = response.extractImportedEnrollments().get(0);
    JsonObject event = new EventDataBuilder().setEnrollment(enrollmentId).setTei(teiId).array(Constants.ORG_UNIT_IDS[0], program, programStage).getAsJsonArray("events").get(0).getAsJsonObject();
    JsonObject payload = new JsonObjectBuilder().addArray("events", event, event).build();
    // act
    response = trackerActions.postAndGetJobReport(payload);
    // assert
    if (repeatableStage) {
        response.validateSuccessfulImport().validate().body("stats.created", equalTo(2));
    } else {
        response.validateErrorReport().body("errorCode", hasItem("E1039"));
    }
}
Also used : EventDataBuilder(org.hisp.dhis.tracker.importer.databuilder.EventDataBuilder) QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) ProgramStageActions(org.hisp.dhis.actions.metadata.ProgramStageActions) JsonObject(com.google.gson.JsonObject) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) JsonObjectBuilder(org.hisp.dhis.helpers.JsonObjectBuilder) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 43 with TrackerApiResponse

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

the class EventsDataValueValidationTests method shouldNotValidateWhenDataValueExists.

@ParameterizedTest
@CsvSource({ "ON_COMPLETE,ACTIVE" })
public void shouldNotValidateWhenDataValueExists(String validationStrategy, String eventStatus) {
    programActions.programStageActions.setValidationStrategy(programStageId, validationStrategy);
    JsonObject events = createEventBodyWithStatus(eventStatus);
    TrackerApiResponse response = trackerActions.postAndGetJobReport(events);
    response.validateSuccessfulImport().validateEvents().body("stats.created", Matchers.equalTo(1)).body("objectReports", notNullValue()).body("objectReports[0].errorReports", empty());
}
Also used : JsonObject(com.google.gson.JsonObject) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 44 with TrackerApiResponse

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

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

the class TeiValidationTests method shouldReturnErrorWhenMandatoryAttributesMissing.

@Test
public void shouldReturnErrorWhenMandatoryAttributesMissing() {
    // arrange
    JsonObject trackedEntities = new TeiDataBuilder().array(trackedEntityType, Constants.ORG_UNIT_IDS[0]);
    // assert
    TrackerApiResponse response = trackerActions.postAndGetJobReport(trackedEntities);
    response.validateErrorReport().body("errorCode", hasItem("E1090"));
}
Also used : TeiDataBuilder(org.hisp.dhis.tracker.importer.databuilder.TeiDataBuilder) JsonObject(com.google.gson.JsonObject) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) Test(org.junit.jupiter.api.Test) TrackerNtiApiTest(org.hisp.dhis.tracker.TrackerNtiApiTest)

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