Search in sources :

Example 11 with EventDataBuilder

use of org.hisp.dhis.tracker.importer.databuilder.EventDataBuilder in project dhis2-core by dhis2.

the class EventValidationTests method shouldValidateEventProperties.

@CsvSource({ "ACTIVE,,OccurredAt date is missing.", "SCHEDULE,,ScheduledAt date is missing." })
@ParameterizedTest
public void shouldValidateEventProperties(String status, String occurredAt, String error) {
    JsonObject object = new EventDataBuilder().setStatus(status).setEventDate(occurredAt).setEnrollment(enrollment).array(OU_ID, trackerProgramId, trackerProgramStageId);
    TrackerApiResponse response = trackerActions.postAndGetJobReport(object);
    response.validateErrorReport().body("message[0]", containsStringIgnoringCase(error));
}
Also used : EventDataBuilder(org.hisp.dhis.tracker.importer.databuilder.EventDataBuilder) 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 12 with EventDataBuilder

use of org.hisp.dhis.tracker.importer.databuilder.EventDataBuilder in project dhis2-core by dhis2.

the class EventValidationTests method eventImportShouldPassValidationWhenOnlyEventProgramIsDefined.

@Test
public void eventImportShouldPassValidationWhenOnlyEventProgramIsDefined() {
    JsonObject jsonObject = new EventDataBuilder().array(OU_ID, eventProgramId, null);
    TrackerApiResponse response = trackerActions.postAndGetJobReport(jsonObject);
    response.validateSuccessfulImport();
}
Also used : EventDataBuilder(org.hisp.dhis.tracker.importer.databuilder.EventDataBuilder) JsonObject(com.google.gson.JsonObject) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) Test(org.junit.jupiter.api.Test) TrackerNtiApiTest(org.hisp.dhis.tracker.TrackerNtiApiTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 13 with EventDataBuilder

use of org.hisp.dhis.tracker.importer.databuilder.EventDataBuilder in project dhis2-core by dhis2.

the class EventValidationTests method eventImportShouldValidateProgramFromProgramStage.

@Test
public void eventImportShouldValidateProgramFromProgramStage() {
    JsonObject jsonObject = new EventDataBuilder().setEnrollment(enrollment).array(OU_ID, anotherTrackerProgramId, trackerProgramStageId);
    TrackerApiResponse response = trackerActions.postAndGetJobReport(jsonObject);
    response.validateErrorReport().body("errorCode", hasItem(equalTo("E1079")));
}
Also used : EventDataBuilder(org.hisp.dhis.tracker.importer.databuilder.EventDataBuilder) JsonObject(com.google.gson.JsonObject) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) Test(org.junit.jupiter.api.Test) TrackerNtiApiTest(org.hisp.dhis.tracker.TrackerNtiApiTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 14 with EventDataBuilder

use of org.hisp.dhis.tracker.importer.databuilder.EventDataBuilder in project dhis2-core by dhis2.

the class EventValidationTests method shouldSetDueDate.

@Test
public void shouldSetDueDate() {
    JsonObject eventBody = new EventDataBuilder().setEnrollment(enrollment).array(OU_ID, trackerProgramId, trackerProgramStageId);
    TrackerApiResponse response = trackerActions.postAndGetJobReport(eventBody);
    String eventId = response.validateSuccessfulImport().extractImportedEvents().get(0);
    JsonObject event = trackerActions.get("/events/" + eventId).getBody();
    assertEquals(event.get("eventDate"), event.get("dueDate"));
}
Also used : EventDataBuilder(org.hisp.dhis.tracker.importer.databuilder.EventDataBuilder) JsonObject(com.google.gson.JsonObject) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) Test(org.junit.jupiter.api.Test) TrackerNtiApiTest(org.hisp.dhis.tracker.TrackerNtiApiTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 15 with EventDataBuilder

use of org.hisp.dhis.tracker.importer.databuilder.EventDataBuilder 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)

Aggregations

JsonObject (com.google.gson.JsonObject)17 EventDataBuilder (org.hisp.dhis.tracker.importer.databuilder.EventDataBuilder)17 TrackerApiResponse (org.hisp.dhis.dto.TrackerApiResponse)16 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)16 TrackerNtiApiTest (org.hisp.dhis.tracker.TrackerNtiApiTest)11 Test (org.junit.jupiter.api.Test)11 QueryParamsBuilder (org.hisp.dhis.helpers.QueryParamsBuilder)6 EnrollmentDataBuilder (org.hisp.dhis.tracker.importer.databuilder.EnrollmentDataBuilder)3 CsvSource (org.junit.jupiter.params.provider.CsvSource)2 ValueSource (org.junit.jupiter.params.provider.ValueSource)2 RestApiActions (org.hisp.dhis.actions.RestApiActions)1 ProgramStageActions (org.hisp.dhis.actions.metadata.ProgramStageActions)1 ApiResponse (org.hisp.dhis.dto.ApiResponse)1 JsonObjectBuilder (org.hisp.dhis.helpers.JsonObjectBuilder)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1