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));
}
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()));
}
}
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));
}
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."))));
}
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"))));
}
Aggregations