Search in sources :

Example 1 with TeiDataBuilder

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

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();
}
Also used : TeiDataBuilder(org.hisp.dhis.tracker.importer.databuilder.TeiDataBuilder) JsonObject(com.google.gson.JsonObject) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) Test(org.junit.jupiter.api.Test) TrackerNtiApiTest(org.hisp.dhis.tracker.TrackerNtiApiTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with TeiDataBuilder

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"));
}
Also used : TeiDataBuilder(org.hisp.dhis.tracker.importer.databuilder.TeiDataBuilder) RestApiActions(org.hisp.dhis.actions.RestApiActions) QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) JsonObject(com.google.gson.JsonObject) ApiResponse(org.hisp.dhis.dto.ApiResponse) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with TeiDataBuilder

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")));
}
Also used : TeiDataBuilder(org.hisp.dhis.tracker.importer.databuilder.TeiDataBuilder) JsonObject(com.google.gson.JsonObject) Test(org.junit.jupiter.api.Test) TrackerNtiApiTest(org.hisp.dhis.tracker.TrackerNtiApiTest)

Example 5 with TeiDataBuilder

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);
}
Also used : TeiDataBuilder(org.hisp.dhis.tracker.importer.databuilder.TeiDataBuilder) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) PotentialDuplicatesApiTest(org.hisp.dhis.tracker.deduplication.PotentialDuplicatesApiTest) Test(org.junit.jupiter.api.Test)

Aggregations

TeiDataBuilder (org.hisp.dhis.tracker.importer.databuilder.TeiDataBuilder)13 JsonObject (com.google.gson.JsonObject)11 Test (org.junit.jupiter.api.Test)9 TrackerApiResponse (org.hisp.dhis.dto.TrackerApiResponse)8 TrackerNtiApiTest (org.hisp.dhis.tracker.TrackerNtiApiTest)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 QueryParamsBuilder (org.hisp.dhis.helpers.QueryParamsBuilder)5 JsonObjectBuilder (org.hisp.dhis.helpers.JsonObjectBuilder)2 Matchers.containsString (org.hamcrest.Matchers.containsString)1 RestApiActions (org.hisp.dhis.actions.RestApiActions)1 UserActions (org.hisp.dhis.actions.UserActions)1 OrgUnitActions (org.hisp.dhis.actions.metadata.OrgUnitActions)1 ProgramStageActions (org.hisp.dhis.actions.metadata.ProgramStageActions)1 TrackerActions (org.hisp.dhis.actions.tracker.importer.TrackerActions)1 ApiResponse (org.hisp.dhis.dto.ApiResponse)1 PotentialDuplicatesApiTest (org.hisp.dhis.tracker.deduplication.PotentialDuplicatesApiTest)1 CsvSource (org.junit.jupiter.params.provider.CsvSource)1 ValueSource (org.junit.jupiter.params.provider.ValueSource)1