Search in sources :

Example 36 with TrackerApiResponse

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

the class RelationshipsTests method shouldDeleteRelationshipWithDeleteStrategy.

@Test
public void shouldDeleteRelationshipWithDeleteStrategy() {
    // arrage
    TrackerApiResponse response = trackerActions.postAndGetJobReport(new File("src/test/resources/tracker/importer/teis/teisAndRelationship.json")).validateSuccessfulImport();
    List<String> teis = response.extractImportedTeis();
    String relationship = response.extractImportedRelationships().get(0);
    JsonObject obj = new JsonObjectBuilder().addObject("from", JsonObjectBuilder.jsonObject().addProperty("trackedEntity", teis.get(0))).addObject("to", JsonObjectBuilder.jsonObject().addProperty("trackedEntity", teis.get(1))).addProperty("relationshipType", relationshipType).addProperty("relationship", relationship).wrapIntoArray("relationships");
    // act
    response = trackerActions.postAndGetJobReport(obj, new QueryParamsBuilder().add("importStrategy=DELETE"));
    // assert
    response.validate().body("status", equalTo("OK")).body("stats.deleted", equalTo(1));
    trackerActions.get("/relationships/" + relationship).validate().statusCode(404);
    trackerActions.getTrackedEntity(teis.get(0) + "?fields=relationships").validate().body("relationships", Matchers.empty());
}
Also used : QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) JsonObject(com.google.gson.JsonObject) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) JsonObjectBuilder(org.hisp.dhis.helpers.JsonObjectBuilder) File(java.io.File) TrackerNtiApiTest(org.hisp.dhis.tracker.TrackerNtiApiTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 37 with TrackerApiResponse

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

the class EventValidationTests method shouldValidateEventProperties.

@CsvSource({ "ACTIVE,,OccurredAt date is missing.", "SCHEDULE,,ScheduledAt date is missing." })
@ParameterizedTest
public void shouldValidateEventProperties(String status, String occurredAt, String error) {
    JsonObject object = new EventDataBuilder().setStatus(status).setEventDate(occurredAt).setEnrollment(enrollment).array(OU_ID, trackerProgramId, trackerProgramStageId);
    TrackerApiResponse response = trackerActions.postAndGetJobReport(object);
    response.validateErrorReport().body("message[0]", containsStringIgnoringCase(error));
}
Also used : EventDataBuilder(org.hisp.dhis.tracker.importer.databuilder.EventDataBuilder) 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 38 with TrackerApiResponse

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

the class EventValidationTests method eventImportShouldPassValidationWhenOnlyEventProgramIsDefined.

@Test
public void eventImportShouldPassValidationWhenOnlyEventProgramIsDefined() {
    JsonObject jsonObject = new EventDataBuilder().array(OU_ID, eventProgramId, null);
    TrackerApiResponse response = trackerActions.postAndGetJobReport(jsonObject);
    response.validateSuccessfulImport();
}
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 39 with TrackerApiResponse

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

the class EventValidationTests method eventImportShouldValidateProgramFromProgramStage.

@Test
public void eventImportShouldValidateProgramFromProgramStage() {
    JsonObject jsonObject = new EventDataBuilder().setEnrollment(enrollment).array(OU_ID, anotherTrackerProgramId, trackerProgramStageId);
    TrackerApiResponse response = trackerActions.postAndGetJobReport(jsonObject);
    response.validateErrorReport().body("errorCode", hasItem(equalTo("E1079")));
}
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 40 with TrackerApiResponse

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

the class EventValidationTests method shouldSetDueDate.

@Test
public void shouldSetDueDate() {
    JsonObject eventBody = new EventDataBuilder().setEnrollment(enrollment).array(OU_ID, trackerProgramId, trackerProgramStageId);
    TrackerApiResponse response = trackerActions.postAndGetJobReport(eventBody);
    String eventId = response.validateSuccessfulImport().extractImportedEvents().get(0);
    JsonObject event = trackerActions.get("/events/" + eventId).getBody();
    assertEquals(event.get("eventDate"), event.get("dueDate"));
}
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)

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