use of org.hisp.dhis.tracker.importer.databuilder.TeiDataBuilder 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.tracker.importer.databuilder.TeiDataBuilder in project dhis2-core by dhis2.
the class RuleEngineTests method shouldImportWhenWarnings.
@Test
public void shouldImportWhenWarnings() {
// arrange
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("message[0]", containsString("TA warning")).body("warningCode", everyItem(equalTo("E1300")));
response.validateSuccessfulImport();
}
use of org.hisp.dhis.tracker.importer.databuilder.TeiDataBuilder in project dhis2-core by dhis2.
the class SideEffectsTests method shouldSendNotificationIfNotSkipSideEffects.
@ParameterizedTest
@ValueSource(strings = { "true", "false" })
public void shouldSendNotificationIfNotSkipSideEffects(Boolean shouldSkipSideEffects) {
JsonObject object = new TeiDataBuilder().buildWithEnrollmentAndEvent(Constants.TRACKED_ENTITY_TYPE, Constants.ORG_UNIT_IDS[0], trackerProgramId, trackerProgramStageId, "COMPLETED");
ApiResponse response = new RestApiActions("/messageConversations").get("", new QueryParamsBuilder().add("fields=*"));
int size = response.getBody().getAsJsonArray("messageConversations").size();
trackerActions.postAndGetJobReport(object, new QueryParamsBuilder().add("skipSideEffects=" + shouldSkipSideEffects)).validateSuccessfulImport();
int expectedCount = (shouldSkipSideEffects) ? size : size + 1;
response = messageConversationsActions.waitForNotification(expectedCount);
response.validate().statusCode(200).body("messageConversations", hasSize(expectedCount));
if (shouldSkipSideEffects) {
return;
}
response.validate().body("messageConversations.subject", hasItem("TA program stage completion"));
}
use of org.hisp.dhis.tracker.importer.databuilder.TeiDataBuilder in project dhis2-core by dhis2.
the class TeiValidationTests method shouldValidateUniqueness.
@Test
public void shouldValidateUniqueness() {
String value = DataGenerator.randomString();
JsonObject payload = new TeiDataBuilder().addAttribute(uniqueTetAttribute, value).addAttribute(mandatoryTetAttribute, value).array(trackedEntityType, Constants.ORG_UNIT_IDS[0]);
trackerActions.postAndGetJobReport(payload).validateSuccessfulImport();
trackerActions.postAndGetJobReport(payload).validateErrorReport().body("", hasSize(greaterThanOrEqualTo(1))).body("errorCode", hasItem("E1064")).body("message", hasItem(containsStringIgnoringCase("non-unique")));
}
use of org.hisp.dhis.tracker.importer.databuilder.TeiDataBuilder in project dhis2-core by dhis2.
the class PotentialDuplicatesEnrollmentsTests method shouldMergeWithNonSuperUser.
@Test
public void shouldMergeWithNonSuperUser() {
// arrange
String teiB = createTeiWithoutEnrollment(Constants.ORG_UNIT_IDS[0]);
TrackerApiResponse imported = trackerActions.postAndGetJobReport(new TeiDataBuilder().buildWithEnrollmentAndEvent(Constants.TRACKED_ENTITY_TYPE, Constants.ORG_UNIT_IDS[0], TRACKER_PROGRAM_ID, TRACKER_PROGRAM_STAGE_ID)).validateSuccessfulImport();
String teiA = imported.extractImportedTeis().get(0);
String enrollment = imported.extractImportedEnrollments().get(0);
assertThat(enrollment, notNullValue());
String potentialDuplicate = potentialDuplicatesActions.createAndValidatePotentialDuplicate(teiA, teiB, "OPEN");
String username = createUserWithAccessToMerge();
loginActions.loginAsUser(username, USER_PASSWORD);
// act
potentialDuplicatesActions.autoMergePotentialDuplicate(potentialDuplicate).validate().statusCode(200);
// assert
potentialDuplicatesActions.get(potentialDuplicate).validate().statusCode(200).body("status", equalTo("MERGED"));
trackerActions.getTrackedEntity(teiA + "?fields=*").validate().statusCode(200).body("enrollments", hasSize(1)).body("enrollments.enrollment", hasItems(enrollment)).body(String.format("enrollments.find{it.enrollment=='%s'}.events", enrollment), hasSize(1));
trackerActions.getTrackedEntity(teiB).validate().statusCode(404);
}
Aggregations