Search in sources :

Example 1 with ProgramStageActions

use of org.hisp.dhis.actions.metadata.ProgramStageActions in project dhis2-core by dhis2.

the class RuleEngineTests method shouldShowErrorsBasedOnValidationStrategy.

@ParameterizedTest
@CsvSource({ "ON_COMPLETE,COMPLETED,true", "ON_COMPLETE,ACTIVE,false", "ON_UPDATE_AND_INSERT,ACTIVE,true" })
public void shouldShowErrorsBasedOnValidationStrategy(String validationStrategy, String eventStatus, boolean shouldFail) {
    String programStage = new ProgramStageActions().get("", new QueryParamsBuilder().addAll("filter=program.id:eq:" + trackerProgramId, "filter=validationStrategy:eq:" + validationStrategy)).extractString("programStages.id[0]");
    JsonObject payload = new TeiDataBuilder().buildWithEnrollmentAndEvent(Constants.TRACKED_ENTITY_TYPE, Constants.ORG_UNIT_IDS[0], trackerProgramId, programStage);
    // program rule is triggered for events with date earlier than today
    new JsonObjectBuilder(payload).addPropertyByJsonPath("trackedEntities[0].enrollments[0].events[0].occurredAt", Instant.now().minus(1, ChronoUnit.DAYS).toString()).addPropertyByJsonPath("trackedEntities[0].enrollments[0].events[0].status", eventStatus);
    TrackerApiResponse response = trackerActions.postAndGetJobReport(payload);
    if (shouldFail) {
        response.validateErrorReport();
        return;
    }
    response.validateSuccessfulImport();
}
Also used : TeiDataBuilder(org.hisp.dhis.tracker.importer.databuilder.TeiDataBuilder) 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) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with ProgramStageActions

use of org.hisp.dhis.actions.metadata.ProgramStageActions in project dhis2-core by dhis2.

the class SideEffectsTests method setupData.

private void setupData() throws Exception {
    ProgramStageActions programStageActions = new ProgramStageActions();
    JsonArray array = new FileReaderUtils().read(new File("src/test/resources/tracker/notificationTemplates.json")).get(JsonObject.class).getAsJsonArray("programNotificationTemplates");
    array.forEach(nt -> {
        String programNotificationTemplate = new RestApiActions("/programNotificationTemplates").post(nt.getAsJsonObject()).extractUid();
        JsonObject programStage = JsonObjectBuilder.jsonObject(programStageActions.get(trackerProgramStageId).getBody()).addOrAppendToArray("notificationTemplates", new JsonObjectBuilder().addProperty("id", programNotificationTemplate).build()).build();
        programStageActions.update(trackerProgramStageId, programStage).validate().statusCode(200);
        programStageActions.get(trackerProgramStageId).validate().body("notificationTemplates.id", hasItem(programNotificationTemplate));
    });
}
Also used : JsonArray(com.google.gson.JsonArray) RestApiActions(org.hisp.dhis.actions.RestApiActions) FileReaderUtils(org.hisp.dhis.helpers.file.FileReaderUtils) ProgramStageActions(org.hisp.dhis.actions.metadata.ProgramStageActions) JsonObject(com.google.gson.JsonObject) JsonObjectBuilder(org.hisp.dhis.helpers.JsonObjectBuilder) File(java.io.File)

Example 3 with ProgramStageActions

use of org.hisp.dhis.actions.metadata.ProgramStageActions 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)3 ProgramStageActions (org.hisp.dhis.actions.metadata.ProgramStageActions)3 JsonObjectBuilder (org.hisp.dhis.helpers.JsonObjectBuilder)3 TrackerApiResponse (org.hisp.dhis.dto.TrackerApiResponse)2 QueryParamsBuilder (org.hisp.dhis.helpers.QueryParamsBuilder)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 JsonArray (com.google.gson.JsonArray)1 File (java.io.File)1 RestApiActions (org.hisp.dhis.actions.RestApiActions)1 FileReaderUtils (org.hisp.dhis.helpers.file.FileReaderUtils)1 EventDataBuilder (org.hisp.dhis.tracker.importer.databuilder.EventDataBuilder)1 TeiDataBuilder (org.hisp.dhis.tracker.importer.databuilder.TeiDataBuilder)1 CsvSource (org.junit.jupiter.params.provider.CsvSource)1 ValueSource (org.junit.jupiter.params.provider.ValueSource)1