Search in sources :

Example 26 with TrackerApiResponse

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

the class EventIdSchemeTests method eventsShouldBeImportedWithProgramScheme.

@ParameterizedTest
@MethodSource("provideIdSchemeArguments")
public void eventsShouldBeImportedWithProgramScheme(String scheme, String property) throws Exception {
    // arrange
    String programPropertyValue = programActions.get(PROGRAM_ID).extractString(property);
    assertNotNull(programPropertyValue, String.format("Program property %s was not present.", property));
    JsonObject object = new FileReaderUtils().read(new File("src/test/resources/tracker/importer/events/event.json")).replacePropertyValuesWithIds("event").replacePropertyValuesWith("orgUnit", orgUnitId).replacePropertyValuesWith("program", programPropertyValue).replacePropertyValuesWith("programStage", PROGRAM_STAGE_ID).get(JsonObject.class);
    // act
    TrackerApiResponse response = trackerActions.postAndGetJobReport(object, new QueryParamsBuilder().add("programIdScheme=" + scheme));
    // assert
    String eventId = response.validateSuccessfulImport().extractImportedEvents().get(0);
    assertNotNull("Event was not created", eventId);
    trackerActions.get("/events/" + eventId).validate().statusCode(200).body("program", equalTo(PROGRAM_ID));
}
Also used : FileReaderUtils(org.hisp.dhis.helpers.file.FileReaderUtils) QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) JsonObject(com.google.gson.JsonObject) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) File(java.io.File) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 27 with TrackerApiResponse

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

the class EventIdSchemeTests method eventsShouldBeImportedWithOrgUnitScheme.

@ParameterizedTest
@MethodSource("provideIdSchemeArguments")
public void eventsShouldBeImportedWithOrgUnitScheme(String ouScheme, String ouProperty) throws Exception {
    String ouPropertyValue = orgUnitActions.get(orgUnitId).extractString(ouProperty);
    assertNotNull(ouPropertyValue, String.format("Org unit property %s was not present.", ouProperty));
    JsonObject object = new FileReaderUtils().read(new File("src/test/resources/tracker/importer/events/event.json")).replacePropertyValuesWith("orgUnit", ouPropertyValue).replacePropertyValuesWithIds("event").get(JsonObject.class);
    TrackerApiResponse response = trackerActions.postAndGetJobReport(object, new QueryParamsBuilder().add("orgUnitIdScheme=" + ouScheme));
    String eventId = response.validateSuccessfulImport().extractImportedEvents().get(0);
    trackerActions.get("/events/" + eventId).validate().statusCode(200).body("orgUnit", equalTo(orgUnitId));
}
Also used : FileReaderUtils(org.hisp.dhis.helpers.file.FileReaderUtils) QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) JsonObject(com.google.gson.JsonObject) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) File(java.io.File) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 28 with TrackerApiResponse

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

the class TeiValidationTests method shouldReturnErrorReportsWhenTeiIncorrect.

@Test
public void shouldReturnErrorReportsWhenTeiIncorrect() {
    // arrange
    JsonObject trackedEntities = new TeiDataBuilder().array("", Constants.ORG_UNIT_IDS[0]);
    // act
    TrackerApiResponse response = trackerActions.postAndGetJobReport(trackedEntities);
    // assert
    response.validateErrorReport().body("errorCode", hasItem("E1121"));
}
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)

Example 29 with TrackerApiResponse

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

the class EventNotesTests method shouldUpdateEventWithANote.

@Test
public void shouldUpdateEventWithANote() {
    // arrange
    JsonObject ob = buildEventWithNote();
    String eventId = trackerActions.postAndGetJobReport(ob).validateSuccessfulImport().extractImportedEvents().get(0);
    JsonObjectBuilder.jsonObject(ob).addPropertyByJsonPath("events[0]", "event", eventId);
    // act
    TrackerApiResponse response = trackerActions.postAndGetJobReport(ob);
    // assert
    response.validateSuccessfulImport().validate().body("stats.updated", equalTo(1));
    trackerActions.getEvent(eventId + "?fields=notes").validate().statusCode(200).body("notes", hasSize(2)).body("notes.storedBy", CoreMatchers.everyItem(equalTo("taadmin")));
}
Also used : JsonObject(com.google.gson.JsonObject) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) Test(org.junit.jupiter.api.Test) TrackerNtiApiTest(org.hisp.dhis.tracker.TrackerNtiApiTest)

Example 30 with TrackerApiResponse

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

the class EventNotesTests method shouldNotAddAnotherNote.

@Test
public void shouldNotAddAnotherNote() {
    // arrange
    JsonObject ob = buildEventWithNote();
    String eventId = trackerActions.postAndGetJobReport(ob).validateSuccessfulImport().extractImportedEvents().get(0);
    ob = trackerActions.get("/events/" + eventId).getBody();
    ob = JsonObjectBuilder.jsonObject(ob).wrapIntoArray("events");
    // act
    TrackerApiResponse response = trackerActions.postAndGetJobReport(ob);
    // assert
    response.validateSuccessfulImport().validateWarningReport().body("trackerType", everyItem(equalTo("EVENT"))).body("warningCode", hasItem("E1119"));
}
Also used : JsonObject(com.google.gson.JsonObject) 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