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