Search in sources :

Example 1 with ImportSummary

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

the class DataImportTest method dataValuesCanBeImportedInBulk.

@Test
public void dataValuesCanBeImportedInBulk() {
    ApiResponse response = dataValueSetActions.postFile(new File("src/test/resources/aggregate/dataValues_bulk.json"), new QueryParamsBuilder().add("importReportMode=FULL"));
    response.validate().statusCode(200).rootPath("response").body("status", equalTo("SUCCESS")).body("conflicts", empty()).body("importCount", notNullValue()).rootPath("importCount").body("ignored", not(greaterThan(0))).body("deleted", not(greaterThan(0)));
    ImportSummary importSummary = response.getImportSummaries().get(0);
    assertThat(response.getAsString(), importSummary.getImportCount().getImported() + importSummary.getImportCount().getUpdated(), greaterThan(0));
}
Also used : ImportSummary(org.hisp.dhis.dto.ImportSummary) QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) File(java.io.File) ApiResponse(org.hisp.dhis.dto.ApiResponse) Test(org.junit.jupiter.api.Test) ApiTest(org.hisp.dhis.ApiTest)

Example 2 with ImportSummary

use of org.hisp.dhis.dto.ImportSummary 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 3 with ImportSummary

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

the class DataImportTest method dataValuesCanBeImportedAsync.

@Test
public void dataValuesCanBeImportedAsync() {
    ApiResponse response = dataValueSetActions.postFile(new File("src/test/resources/aggregate/dataValues_bulk.json"), new QueryParamsBuilder().addAll("reportMode=DEBUG", "async=true")).validateStatus(200);
    String taskId = response.extractString("response.id");
    // Validate that job was successful
    systemActions.waitUntilTaskCompleted("DATAVALUE_IMPORT", taskId).validate().body("message", Matchers.containsInAnyOrder("Process started", "Importing data values", "Import done"));
    // validate task summaries were created
    ApiResponse taskSummariesResponse = systemActions.waitForTaskSummaries("DATAVALUE_IMPORT", taskId);
    taskSummariesResponse.validate().statusCode(200).body("status", equalTo("SUCCESS")).rootPath("importCount").body("deleted", equalTo(0)).body("ignored", equalTo(0));
    ImportSummary importSummary = taskSummariesResponse.getImportSummaries().get(0);
    assertThat(taskSummariesResponse.getAsString(), importSummary.getImportCount().getImported() + importSummary.getImportCount().getUpdated(), greaterThan(0));
}
Also used : ImportSummary(org.hisp.dhis.dto.ImportSummary) QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) File(java.io.File) ApiResponse(org.hisp.dhis.dto.ApiResponse) Test(org.junit.jupiter.api.Test) ApiTest(org.hisp.dhis.ApiTest)

Example 4 with ImportSummary

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

the class EventImportTests method eventsImportDeletedEventShouldFail.

@Test
public void eventsImportDeletedEventShouldFail() {
    ApiResponse response = post("events.json", false);
    response.validate().statusCode(200);
    createdEvents = response.getImportSummaries().stream().map(p -> {
        return p.getReference();
    }).collect(toList());
    assertThat("Expected 4 events created", createdEvents, hasSize(4));
    eventActions.softDelete(createdEvents);
    response = post("events.json", true);
    String taskId = response.extractString("response.id");
    assertNotNull(taskId, "Task id was not returned");
    systemActions.waitUntilTaskCompleted("EVENT_IMPORT", taskId);
    List<ImportSummary> importSummaryList = systemActions.getTaskSummaries("EVENT_IMPORT", taskId);
    assertThat(importSummaryList, Matchers.everyItem(hasProperty("status", Matchers.equalTo("ERROR"))));
    assertThat(importSummaryList, everyItem(hasProperty("description", Matchers.containsString("This event can not be modified."))));
}
Also used : ImportSummary(org.hisp.dhis.dto.ImportSummary) ApiResponse(org.hisp.dhis.dto.ApiResponse) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ApiTest(org.hisp.dhis.ApiTest)

Example 5 with ImportSummary

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

the class EventImportTests method eventsImportNewEventsFromFile.

@ParameterizedTest
@MethodSource("provideEventFilesTestArguments")
public void eventsImportNewEventsFromFile(String fileName, String contentType) throws Exception {
    Object obj = new FileReaderUtils().read(new File("src/test/resources/tracker/events/" + fileName)).replacePropertyValuesWithIds("event").get();
    ApiResponse response = eventActions.post("", contentType, obj, new QueryParamsBuilder().addAll("dryRun=false", "eventIdScheme=UID", "orgUnitIdScheme=UID", "skipFirst=true", "async=true"));
    response.validate().statusCode(200);
    String taskId = response.extractString("response.id");
    assertNotNull(taskId, "Task id was not returned");
    systemActions.waitUntilTaskCompleted("EVENT_IMPORT", taskId);
    List<ImportSummary> importSummaries = systemActions.getTaskSummaries("EVENT_IMPORT", taskId);
    assertThat("Wrong import summaries size", importSummaries.size(), Matchers.greaterThan(0));
    createdEvents.addAll(importSummaries.stream().map(ImportSummary::getReference).collect(toList()));
    assertThat(importSummaries, Matchers.everyItem(hasProperty("status", Matchers.equalTo("SUCCESS"))));
}
Also used : FileReaderUtils(org.hisp.dhis.helpers.file.FileReaderUtils) ImportSummary(org.hisp.dhis.dto.ImportSummary) QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) File(java.io.File) ApiResponse(org.hisp.dhis.dto.ApiResponse) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

ApiResponse (org.hisp.dhis.dto.ApiResponse)5 ImportSummary (org.hisp.dhis.dto.ImportSummary)5 File (java.io.File)4 ApiTest (org.hisp.dhis.ApiTest)4 Test (org.junit.jupiter.api.Test)4 QueryParamsBuilder (org.hisp.dhis.helpers.QueryParamsBuilder)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 FileReaderUtils (org.hisp.dhis.helpers.file.FileReaderUtils)1 JsonFileReader (org.hisp.dhis.helpers.file.JsonFileReader)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1