Search in sources :

Example 6 with EventDataBuilder

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

the class EventsDataValueValidationTests method shouldImportEventsWithCompulsoryDataValues.

@Test
public void shouldImportEventsWithCompulsoryDataValues() {
    JsonObject events = new EventDataBuilder().addDataValue(mandatoryDataElementId, "TEXT value").array(OU_ID, programId, programStageId);
    TrackerApiResponse response = trackerActions.postAndGetJobReport(events);
    response.validateSuccessfulImport().validateEvents().body("stats.created", Matchers.equalTo(1)).body("objectReports", notNullValue()).body("objectReports[0].errorReports", empty());
    String eventId = response.extractImportedEvents().get(0);
    trackerActions.get("/events/" + eventId).validate().statusCode(200).body("dataValues", not(Matchers.emptyArray()));
}
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 7 with EventDataBuilder

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

the class UserAssignmentTests method createEvents.

private TrackerApiResponse createEvents(String programId, String programStageId, String assignedUserId) {
    JsonObject jsonObject = new EventDataBuilder().setAssignedUser(assignedUserId).array(Constants.ORG_UNIT_IDS[0], programId, programStageId);
    TrackerApiResponse eventResponse = trackerActions.postAndGetJobReport(jsonObject);
    eventResponse.validateSuccessfulImport();
    return eventResponse;
}
Also used : EventDataBuilder(org.hisp.dhis.tracker.importer.databuilder.EventDataBuilder) JsonObject(com.google.gson.JsonObject) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse)

Example 8 with EventDataBuilder

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

the class EnrollmentsTests method shouldAllowFutureEnrollments.

@ParameterizedTest
@ValueSource(strings = { "true", "false " })
public void shouldAllowFutureEnrollments(String shouldAddFutureDays) throws Exception {
    // arrange
    JsonObject object = programActions.get(multipleEnrollmentsProgram).getBodyAsJsonBuilder().addProperty("selectEnrollmentDatesInFuture", shouldAddFutureDays).build();
    programActions.update(multipleEnrollmentsProgram, object).validateStatus(200);
    String teiId = importTei();
    // act
    JsonObject enrollment = new EnrollmentDataBuilder().setTei(teiId).setEnrollmentDate(Instant.now().plus(2, ChronoUnit.DAYS).toString()).addEvent(new EventDataBuilder().setProgram(multipleEnrollmentsProgram).setOu(Constants.ORG_UNIT_IDS[0]).setProgramStage(multipleEnrollmentsProgramStage)).array(multipleEnrollmentsProgram, Constants.ORG_UNIT_IDS[0]);
    // assert
    TrackerApiResponse response = trackerActions.postAndGetJobReport(enrollment, new QueryParamsBuilder().add("async", "false"));
    if (Boolean.parseBoolean(shouldAddFutureDays)) {
        response.validateSuccessfulImport();
        return;
    }
    response.validateErrorReport().body("errorCode", hasSize(1)).body("errorCode", hasItems("E1020"));
}
Also used : EventDataBuilder(org.hisp.dhis.tracker.importer.databuilder.EventDataBuilder) QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) JsonObject(com.google.gson.JsonObject) EnrollmentDataBuilder(org.hisp.dhis.tracker.importer.databuilder.EnrollmentDataBuilder) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 9 with EventDataBuilder

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

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

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