Search in sources :

Example 1 with JsonFileReader

use of org.hisp.dhis.helpers.file.JsonFileReader in project dhis2-core by dhis2.

the class DataImportTest method dataValuesCanBeImportedForSingleDataSet.

@Test
public void dataValuesCanBeImportedForSingleDataSet() throws IOException {
    String orgUnit = "O6uvpzGd5pu";
    String period = "201911";
    String dataSet = "VEM58nY22sO";
    JsonObject importedPayload = new JsonFileReader(new File("src/test/resources/aggregate/dataValues_single_dataset.json")).get();
    ApiResponse response = dataValueSetActions.post(importedPayload);
    response.validate().statusCode(200).rootPath("response").body("status", equalTo("SUCCESS")).body("conflicts", empty()).body("importCount", notNullValue()).rootPath("response.importCount").body("ignored", not(greaterThan(0))).body("deleted", not(greaterThan(0)));
    ImportSummary importSummary = response.getImportSummaries().get(0);
    assertThat(importSummary, notNullValue());
    assertThat(response.getAsString(), importSummary.getImportCount().getImported() + importSummary.getImportCount().getUpdated(), greaterThanOrEqualTo(2));
    response = dataValueSetActions.get(String.format("?orgUnit=%s&period=%s&dataSet=%s", orgUnit, period, dataSet));
    response.validate().body("dataSet", equalTo(dataSet)).body("period", equalTo(period)).body("orgUnit", equalTo(orgUnit)).body("dataValues", hasSize(greaterThanOrEqualTo(2)));
    JsonArray dataValues = response.getBody().get("dataValues").getAsJsonArray();
    for (JsonElement j : dataValues) {
        JsonObject object = j.getAsJsonObject();
        response = dataValueActions.get(String.format("?ou=%s&pe=%s&de=%s&co=%s", orgUnit, period, object.get("dataElement").getAsString(), object.get("categoryOptionCombo").getAsString()));
        response.validate().statusCode(200).body(containsString(object.get("value").getAsString()));
    }
}
Also used : JsonArray(com.google.gson.JsonArray) ImportSummary(org.hisp.dhis.dto.ImportSummary) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) File(java.io.File) ApiResponse(org.hisp.dhis.dto.ApiResponse) JsonFileReader(org.hisp.dhis.helpers.file.JsonFileReader) Test(org.junit.jupiter.api.Test) ApiTest(org.hisp.dhis.ApiTest)

Example 2 with JsonFileReader

use of org.hisp.dhis.helpers.file.JsonFileReader in project dhis2-core by dhis2.

the class MetadataImportImportStrategyTests method shouldUpdateMetadataByIdentifier.

@ValueSource(strings = { "CODE", "UID" })
@ParameterizedTest
public void shouldUpdateMetadataByIdentifier(String identifier) throws IOException {
    JsonObject ob = new JsonFileReader(new File("src/test/resources/setup/metadata.json")).get(JsonObject.class);
    ApiResponse response = metadataActions.importMetadata(ob, "identifier=" + identifier);
    response.validate().statusCode(200).body("stats.updated", equalTo(response.extract("stats.total")));
}
Also used : JsonObject(com.google.gson.JsonObject) File(java.io.File) ApiResponse(org.hisp.dhis.dto.ApiResponse) JsonFileReader(org.hisp.dhis.helpers.file.JsonFileReader) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with JsonFileReader

use of org.hisp.dhis.helpers.file.JsonFileReader in project dhis2-core by dhis2.

the class PotentialDuplicatesEnrollmentsTests method shouldAutoMergeWithEnrollmentsAndEvents.

@Test
public void shouldAutoMergeWithEnrollmentsAndEvents() throws IOException {
    // arrange
    TrackerApiResponse originalTeiResponse = createTeiWithEnrollmentsAndEvents(Constants.ANOTHER_TRACKER_PROGRAM_ID, "PaOOjwLVW2X");
    String teiA = originalTeiResponse.extractImportedTeis().get(0);
    String enrollmentA = originalTeiResponse.extractImportedEnrollments().get(0);
    TrackerApiResponse duplicateTeiResponse = trackerActions.postAndGetJobReport(new JsonFileReader(new File("src/test/resources/tracker/importer/teis/teiWithEnrollmentAndEventsNested.json")).get());
    String teiB = duplicateTeiResponse.extractImportedTeis().get(0);
    String enrollmentB = duplicateTeiResponse.extractImportedEnrollments().get(0);
    String potentialDuplicate = potentialDuplicatesActions.createAndValidatePotentialDuplicate(teiA, teiB, "OPEN");
    // 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(2)).body("enrollments.enrollment", hasItems(enrollmentA, enrollmentB)).rootPath(String.format("enrollments.find{it.enrollment=='%s'}", enrollmentA)).body("events", hasSize(greaterThanOrEqualTo(1))).body("events.dataValues", hasSize(greaterThanOrEqualTo(1))).noRootPath().rootPath(String.format("enrollments.find{it.enrollment=='%s'}", enrollmentB)).body("events", hasSize(greaterThanOrEqualTo(1))).body("events.dataValues", hasSize(greaterThanOrEqualTo(1)));
    trackerActions.getTrackedEntity(teiB).validate().statusCode(404);
}
Also used : TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) File(java.io.File) JsonFileReader(org.hisp.dhis.helpers.file.JsonFileReader) PotentialDuplicatesApiTest(org.hisp.dhis.tracker.deduplication.PotentialDuplicatesApiTest) Test(org.junit.jupiter.api.Test)

Aggregations

File (java.io.File)3 JsonFileReader (org.hisp.dhis.helpers.file.JsonFileReader)3 JsonObject (com.google.gson.JsonObject)2 ApiResponse (org.hisp.dhis.dto.ApiResponse)2 Test (org.junit.jupiter.api.Test)2 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 ApiTest (org.hisp.dhis.ApiTest)1 ImportSummary (org.hisp.dhis.dto.ImportSummary)1 TrackerApiResponse (org.hisp.dhis.dto.TrackerApiResponse)1 PotentialDuplicatesApiTest (org.hisp.dhis.tracker.deduplication.PotentialDuplicatesApiTest)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 ValueSource (org.junit.jupiter.params.provider.ValueSource)1