use of org.hisp.dhis.dto.TrackerApiResponse in project dhis2-core by dhis2.
the class EventsTests method shouldImportEvents.
@Test
public void shouldImportEvents() throws Exception {
JsonObject eventBody = new FileReaderUtils().readJsonAndGenerateData(new File("src/test/resources/tracker/importer/events/events.json"));
TrackerApiResponse importResponse = trackerActions.postAndGetJobReport(eventBody);
importResponse.validateSuccessfulImport().validateEvents().body("stats.created", Matchers.equalTo(4)).body("objectReports", notNullValue()).body("objectReports[0].errorReports", empty());
eventBody.getAsJsonArray("events").forEach(event -> {
String eventId = event.getAsJsonObject().get("event").getAsString();
ApiResponse response = trackerActions.get("/events/" + eventId);
response.validate().statusCode(200);
assertThat(response.getBody(), matchesJSON(event));
});
}
use of org.hisp.dhis.dto.TrackerApiResponse 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"));
}
}
use of org.hisp.dhis.dto.TrackerApiResponse in project dhis2-core by dhis2.
the class EventsDataValueValidationTests method shouldNotValidateWhenDataValueExists.
@ParameterizedTest
@CsvSource({ "ON_COMPLETE,ACTIVE" })
public void shouldNotValidateWhenDataValueExists(String validationStrategy, String eventStatus) {
programActions.programStageActions.setValidationStrategy(programStageId, validationStrategy);
JsonObject events = createEventBodyWithStatus(eventStatus);
TrackerApiResponse response = trackerActions.postAndGetJobReport(events);
response.validateSuccessfulImport().validateEvents().body("stats.created", Matchers.equalTo(1)).body("objectReports", notNullValue()).body("objectReports[0].errorReports", empty());
}
use of org.hisp.dhis.dto.TrackerApiResponse in project dhis2-core by dhis2.
the class TeiImportTests method shouldImportTei.
@Test
public void shouldImportTei() {
// arrange
JsonObject trackedEntities = new JsonObjectBuilder().addProperty("trackedEntityType", "Q9GufDoplCL").addProperty("orgUnit", Constants.ORG_UNIT_IDS[0]).wrapIntoArray("trackedEntities");
// act
TrackerApiResponse response = trackerActions.postAndGetJobReport(trackedEntities);
response.validateSuccessfulImport().validateTeis().body("stats.created", equalTo(1)).body("objectReports", notNullValue()).body("objectReports[0].errorReports", empty());
// assert that the tei was imported
String teiId = response.extractImportedTeis().get(0);
ApiResponse teiResponse = trackerActions.getTrackedEntity(teiId);
teiResponse.validate().statusCode(200);
assertThat(teiResponse.getBody(), matchesJSON(trackedEntities.get("trackedEntities").getAsJsonArray().get(0)));
}
use of org.hisp.dhis.dto.TrackerApiResponse in project dhis2-core by dhis2.
the class TeiValidationTests method shouldReturnErrorWhenMandatoryAttributesMissing.
@Test
public void shouldReturnErrorWhenMandatoryAttributesMissing() {
// arrange
JsonObject trackedEntities = new TeiDataBuilder().array(trackedEntityType, Constants.ORG_UNIT_IDS[0]);
// assert
TrackerApiResponse response = trackerActions.postAndGetJobReport(trackedEntities);
response.validateErrorReport().body("errorCode", hasItem("E1090"));
}
Aggregations