Search in sources :

Example 51 with TrackerApiResponse

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

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

Example 53 with TrackerApiResponse

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

the class RuleEngineTests method shouldAddErrorForEnrollmentsAndEventsWhenRuleHasNoStage.

@Test
public void shouldAddErrorForEnrollmentsAndEventsWhenRuleHasNoStage() {
    JsonObject object = new TeiDataBuilder().buildWithEnrollmentAndEvent(Constants.TRACKED_ENTITY_TYPE, Constants.ORG_UNIT_IDS[0], trackerProgramId, "yKg8CY252Yk");
    JsonObjectBuilder.jsonObject(object).addPropertyByJsonPath("trackedEntities[0].enrollments[0].enrolledAt", Instant.now().minus(1, ChronoUnit.DAYS).toString());
    // act
    TrackerApiResponse response = trackerActions.postAndGetJobReport(object);
    response.validateWarningReport().body("", hasSize(greaterThanOrEqualTo(1))).body("trackerType", hasItems("ENROLLMENT")).body("warningCode", everyItem(equalTo("E1300")));
}
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) 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