Search in sources :

Example 11 with EnrollmentDataBuilder

use of org.hisp.dhis.tracker.importer.databuilder.EnrollmentDataBuilder in project dhis2-core by dhis2.

the class EnrollmentAttributeTests method shouldAddAttributeValue.

@Test
public void shouldAddAttributeValue() throws Exception {
    String tei = importTei();
    JsonObject payload = new EnrollmentDataBuilder().setTei(tei).addAttribute(optionSetAttributeId, "TA_YES").array(programId, Constants.ORG_UNIT_IDS[1]);
    trackerActions.postAndGetJobReport(payload, new QueryParamsBuilder().add("async=false")).validateSuccessfulImport();
    trackerActions.getTrackedEntity(tei + "?program=" + programId).validateStatus(200).validate().statusCode(200).body("attributes", hasSize(greaterThanOrEqualTo(1))).body("attributes.attribute", hasItem(optionSetAttributeId)).body("attributes.value", hasItem("TA_YES"));
}
Also used : QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) JsonObject(com.google.gson.JsonObject) EnrollmentDataBuilder(org.hisp.dhis.tracker.importer.databuilder.EnrollmentDataBuilder) Test(org.junit.jupiter.api.Test) TrackerNtiApiTest(org.hisp.dhis.tracker.TrackerNtiApiTest)

Example 12 with EnrollmentDataBuilder

use of org.hisp.dhis.tracker.importer.databuilder.EnrollmentDataBuilder in project dhis2-core by dhis2.

the class RuleEngineTests method shouldShowErrorOnEventWhenProgramRuleStageMatches.

@ParameterizedTest
@CsvSource({ "nH8zfPSUSN1,true", "yKg8CY252Yk,false" })
public void shouldShowErrorOnEventWhenProgramRuleStageMatches(String programStage, boolean shouldReturnError) throws Exception {
    // arrange
    String tei = importTei();
    String enrollment = trackerActions.postAndGetJobReport(new EnrollmentDataBuilder().setTei(tei).setEnrollmentDate(Instant.now().plus(1, ChronoUnit.DAYS).toString()).array(trackerProgramId, Constants.ORG_UNIT_IDS[0])).extractImportedEnrollments().get(0);
    JsonObject payload = new EventDataBuilder().setEnrollment(enrollment).array(Constants.ORG_UNIT_IDS[0], trackerProgramId, programStage);
    // act
    TrackerApiResponse response = trackerActions.postAndGetJobReport(payload);
    if (!shouldReturnError) {
        response.validateSuccessfulImport();
        return;
    }
    response.validateErrorReport().body("trackerType", Matchers.everyItem(equalTo("EVENT"))).body("message", Matchers.contains(containsString("TA on stage error")));
    response.validate().body("stats.created", equalTo(0));
}
Also used : EventDataBuilder(org.hisp.dhis.tracker.importer.databuilder.EventDataBuilder) EnrollmentDataBuilder(org.hisp.dhis.tracker.importer.databuilder.EnrollmentDataBuilder) JsonObject(com.google.gson.JsonObject) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

EnrollmentDataBuilder (org.hisp.dhis.tracker.importer.databuilder.EnrollmentDataBuilder)12 JsonObject (com.google.gson.JsonObject)11 TrackerNtiApiTest (org.hisp.dhis.tracker.TrackerNtiApiTest)9 Test (org.junit.jupiter.api.Test)9 IdGenerator (org.hisp.dhis.actions.IdGenerator)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 QueryParamsBuilder (org.hisp.dhis.helpers.QueryParamsBuilder)4 TrackerApiResponse (org.hisp.dhis.dto.TrackerApiResponse)3 JsonObjectBuilder (org.hisp.dhis.helpers.JsonObjectBuilder)3 EventDataBuilder (org.hisp.dhis.tracker.importer.databuilder.EventDataBuilder)3 ValueSource (org.junit.jupiter.params.provider.ValueSource)2 Arrays (java.util.Arrays)1 Function (java.util.function.Function)1 CoreMatchers.hasItem (org.hamcrest.CoreMatchers.hasItem)1 Matchers (org.hamcrest.Matchers)1 Constants (org.hisp.dhis.Constants)1 ProgramActions (org.hisp.dhis.actions.metadata.ProgramActions)1 TrackedEntityAttributeActions (org.hisp.dhis.actions.metadata.TrackedEntityAttributeActions)1 DataGenerator (org.hisp.dhis.utils.DataGenerator)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1