use of org.hisp.dhis.tracker.importer.databuilder.TeiDataBuilder in project dhis2-core by dhis2.
the class EventExportTests method setupTrackerEvents.
private void setupTrackerEvents() {
Arrays.asList(captureOu, dataReadOu, searchOu, rootOu).forEach(ou -> {
JsonObject object = new TeiDataBuilder().buildWithEnrollmentAndEvent(Constants.TRACKED_ENTITY_TYPE, ou, withRegistrationProgram, withRegistrationProgramStage);
String eventId = new TrackerActions().postAndGetJobReport(object).validateSuccessfulImport().extractImportedEvents().get(0);
trackerEvents.put(ou, eventId);
// closed program events
object = new TeiDataBuilder().buildWithEnrollmentAndEvent(Constants.TRACKED_ENTITY_TYPE, ou, closedProgramId, closedProgramProgramStageId);
eventId = new TrackerActions().postAndGetJobReport(object, new QueryParamsBuilder().add("async", "false")).validateSuccessfulImport().extractImportedEvents().get(0);
closedProgramEvents.put(ou, eventId);
});
}
use of org.hisp.dhis.tracker.importer.databuilder.TeiDataBuilder in project dhis2-core by dhis2.
the class ImportStrategyTests method shouldDeleteReferencingEventsWhenEnrollmentIsDeleted.
@Test
public void shouldDeleteReferencingEventsWhenEnrollmentIsDeleted() {
// arrange
JsonObject body = new TeiDataBuilder().buildWithEnrollmentAndEvent(Constants.TRACKED_ENTITY_TYPE, Constants.ORG_UNIT_IDS[0], Constants.TRACKER_PROGRAM_ID, "PaOOjwLVW23");
TrackerApiResponse response = trackerActions.postAndGetJobReport(body).validateSuccessfulImport();
String teiId = response.extractImportedTeis().get(0);
String enrollmentId = response.extractImportedEnrollments().get(0);
String eventId1 = response.extractImportedEvents().get(0);
body = trackerActions.getEnrollment(enrollmentId).validateStatus(200).getBodyAsJsonBuilder().wrapIntoArray("enrollments");
// act
response = trackerActions.postAndGetJobReport(body, new QueryParamsBuilder().add("importStrategy=DELETE")).validateSuccessfulImport();
// assert
response.validateSuccessfulImport().validate().body("stats.deleted", Matchers.equalTo(1));
trackerActions.getTrackedEntity(teiId + "?fields=*").validate().statusCode(200).body("enrollments", hasSize(0));
trackerActions.get("/enrollments/" + enrollmentId).validate().statusCode(404);
trackerActions.get("/events/" + eventId1).validate().statusCode(404);
}
use of org.hisp.dhis.tracker.importer.databuilder.TeiDataBuilder 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")));
}
Aggregations