Search in sources :

Example 11 with TrackerApiResponse

use of org.hisp.dhis.dto.TrackerApiResponse in project dhis2-core by dhis2.

the class AtomicModeTests method shouldNotImportWhenErrorsWithoutAtomicMode.

@Test
public void shouldNotImportWhenErrorsWithoutAtomicMode() throws Exception {
    TrackerApiResponse response = trackerActions.postAndGetJobReport(createWrongPayload(), new QueryParamsBuilder().add("atomicMode=ALL"));
    response.validate().body("status", equalTo("ERROR")).body("stats.ignored", equalTo(3));
    response.validateErrorReport().body("", hasSize(2)).body("trackerType", contains("TRACKED_ENTITY", "RELATIONSHIP"));
}
Also used : QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) Test(org.junit.jupiter.api.Test) TrackerNtiApiTest(org.hisp.dhis.tracker.TrackerNtiApiTest)

Example 12 with TrackerApiResponse

use of org.hisp.dhis.dto.TrackerApiResponse in project dhis2-core by dhis2.

the class EventsDataValueValidationTests method shouldImportEventsWithCompulsoryDataValues.

@Test
public void shouldImportEventsWithCompulsoryDataValues() {
    JsonObject events = new EventDataBuilder().addDataValue(mandatoryDataElementId, "TEXT value").array(OU_ID, programId, programStageId);
    TrackerApiResponse response = trackerActions.postAndGetJobReport(events);
    response.validateSuccessfulImport().validateEvents().body("stats.created", Matchers.equalTo(1)).body("objectReports", notNullValue()).body("objectReports[0].errorReports", empty());
    String eventId = response.extractImportedEvents().get(0);
    trackerActions.get("/events/" + eventId).validate().statusCode(200).body("dataValues", not(Matchers.emptyArray()));
}
Also used : EventDataBuilder(org.hisp.dhis.tracker.importer.databuilder.EventDataBuilder) 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 13 with TrackerApiResponse

use of org.hisp.dhis.dto.TrackerApiResponse in project dhis2-core by dhis2.

the class EventsDataValueValidationTests method shouldValidateWhenNoDataValue.

@ParameterizedTest
@CsvSource({ "ON_COMPLETE,COMPLETED", "ON_UPDATE_AND_INSERT,ACTIVE", "ON_UPDATE_AND_INSERT,COMPLETED" })
public void shouldValidateWhenNoDataValue(String validationStrategy, String eventStatus) {
    programActions.programStageActions.setValidationStrategy(programStageId, validationStrategy);
    JsonObject event = createEventBodyWithStatus(eventStatus);
    TrackerApiResponse response = trackerActions.postAndGetJobReport(event);
    response.validate().body("status", equalTo("ERROR")).body("bundleReport.typeReportMap.EVENT", nullValue());
    response.validateErrorReport().body("errorCode", hasItem("E1303"));
}
Also used : JsonObject(com.google.gson.JsonObject) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 14 with TrackerApiResponse

use of org.hisp.dhis.dto.TrackerApiResponse in project dhis2-core by dhis2.

the class UserAssignmentTests method createEvents.

private TrackerApiResponse createEvents(String programId, String programStageId, String assignedUserId) {
    JsonObject jsonObject = new EventDataBuilder().setAssignedUser(assignedUserId).array(Constants.ORG_UNIT_IDS[0], programId, programStageId);
    TrackerApiResponse eventResponse = trackerActions.postAndGetJobReport(jsonObject);
    eventResponse.validateSuccessfulImport();
    return eventResponse;
}
Also used : EventDataBuilder(org.hisp.dhis.tracker.importer.databuilder.EventDataBuilder) JsonObject(com.google.gson.JsonObject) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse)

Example 15 with TrackerApiResponse

use of org.hisp.dhis.dto.TrackerApiResponse in project dhis2-core by dhis2.

the class TeiImportTests method shouldImportTeiWithAttributes.

@Test
public void shouldImportTeiWithAttributes() throws Exception {
    JsonObject teiBody = new FileReaderUtils().readJsonAndGenerateData(new File("src/test/resources/tracker/importer/teis/tei.json"));
    // act
    TrackerApiResponse response = trackerActions.postAndGetJobReport(teiBody);
    // assert
    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(teiBody.get("trackedEntities").getAsJsonArray().get(0)));
}
Also used : FileReaderUtils(org.hisp.dhis.helpers.file.FileReaderUtils) JsonObject(com.google.gson.JsonObject) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) File(java.io.File) ApiResponse(org.hisp.dhis.dto.ApiResponse) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) Test(org.junit.jupiter.api.Test) TrackerNtiApiTest(org.hisp.dhis.tracker.TrackerNtiApiTest)

Aggregations

TrackerApiResponse (org.hisp.dhis.dto.TrackerApiResponse)53 JsonObject (com.google.gson.JsonObject)44 Test (org.junit.jupiter.api.Test)35 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)34 TrackerNtiApiTest (org.hisp.dhis.tracker.TrackerNtiApiTest)32 QueryParamsBuilder (org.hisp.dhis.helpers.QueryParamsBuilder)17 EventDataBuilder (org.hisp.dhis.tracker.importer.databuilder.EventDataBuilder)15 File (java.io.File)14 FileReaderUtils (org.hisp.dhis.helpers.file.FileReaderUtils)11 ApiResponse (org.hisp.dhis.dto.ApiResponse)9 TeiDataBuilder (org.hisp.dhis.tracker.importer.databuilder.TeiDataBuilder)8 JsonObjectBuilder (org.hisp.dhis.helpers.JsonObjectBuilder)5 CsvSource (org.junit.jupiter.params.provider.CsvSource)5 ValueSource (org.junit.jupiter.params.provider.ValueSource)5 MethodSource (org.junit.jupiter.params.provider.MethodSource)4 PotentialDuplicatesApiTest (org.hisp.dhis.tracker.deduplication.PotentialDuplicatesApiTest)3 EnrollmentDataBuilder (org.hisp.dhis.tracker.importer.databuilder.EnrollmentDataBuilder)3 IdGenerator (org.hisp.dhis.actions.IdGenerator)2 ProgramStageActions (org.hisp.dhis.actions.metadata.ProgramStageActions)2 JsonFileReader (org.hisp.dhis.helpers.file.JsonFileReader)1