Search in sources :

Example 16 with EventDataBuilder

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

the class RuleEngineTests method shouldShowErrorOnEventWhenProgramRuleStageMatches.

@ParameterizedTest
@CsvSource({ "nH8zfPSUSN1,true", "yKg8CY252Yk,false" })
public void shouldShowErrorOnEventWhenProgramRuleStageMatches(String programStage, boolean shouldReturnError) throws Exception {
    // arrange
    String tei = importTei();
    String enrollment = trackerActions.postAndGetJobReport(new EnrollmentDataBuilder().setTei(tei).setEnrollmentDate(Instant.now().plus(1, ChronoUnit.DAYS).toString()).array(trackerProgramId, Constants.ORG_UNIT_IDS[0])).extractImportedEnrollments().get(0);
    JsonObject payload = new EventDataBuilder().setEnrollment(enrollment).array(Constants.ORG_UNIT_IDS[0], trackerProgramId, programStage);
    // act
    TrackerApiResponse response = trackerActions.postAndGetJobReport(payload);
    if (!shouldReturnError) {
        response.validateSuccessfulImport();
        return;
    }
    response.validateErrorReport().body("trackerType", Matchers.everyItem(equalTo("EVENT"))).body("message", Matchers.contains(containsString("TA on stage error")));
    response.validate().body("stats.created", equalTo(0));
}
Also used : EventDataBuilder(org.hisp.dhis.tracker.importer.databuilder.EventDataBuilder) EnrollmentDataBuilder(org.hisp.dhis.tracker.importer.databuilder.EnrollmentDataBuilder) 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 17 with EventDataBuilder

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

the class RuleEngineTests method shouldSetMandatoryField.

@Test
public void shouldSetMandatoryField() {
    JsonObject payload = new EventDataBuilder().addDataValue("ILRgzHhzFkg", "true").array(Constants.ORG_UNIT_IDS[0], eventProgramId, "Mt6Ac5brjoK");
    TrackerApiResponse response = trackerActions.postAndGetJobReport(payload);
    response.validateErrorReport().body("errorCode", hasItem("E1301")).body("message", hasItem(stringContainsInOrder("Mandatory DataElement", "is not present")));
}
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)

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