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();
}
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));
});
}
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"));
}
}
Aggregations