use of org.hisp.dhis.helpers.file.FileReaderUtils in project dhis2-core by dhis2.
the class MetadataImportTest method shouldReturnImportSummariesWhenImportingInvalidMetadataAsync.
@Test
public void shouldReturnImportSummariesWhenImportingInvalidMetadataAsync() throws Exception {
// arrange
QueryParamsBuilder queryParamsBuilder = new QueryParamsBuilder();
queryParamsBuilder.addAll("async=true", "importReportMode=DEBUG", "importStrategy=CREATE_AND_UPDATE", "atomicMode=NONE");
JsonObject metadata = new FileReaderUtils().readJsonAndGenerateData(new File("src/test/resources/metadata/uniqueMetadata.json"));
metadata.getAsJsonArray("organisationUnits").get(0).getAsJsonObject().addProperty("shortName", RandomStringUtils.random(51));
// act
ApiResponse response = metadataActions.post(metadata, queryParamsBuilder);
response.validate().statusCode(200).body(notNullValue()).body("response.name", equalTo("metadataImport")).body("response.jobType", equalTo("METADATA_IMPORT"));
String taskId = response.extractString("response.id");
// Validate that job was successful
systemActions.waitUntilTaskCompleted("METADATA_IMPORT", taskId).validate().body("message", hasItem(containsString("Import:Start"))).body("message", hasItem(containsString("Import:Done")));
// validate task summaries were created
systemActions.waitForTaskSummaries("METADATA_IMPORT", taskId).validate().body(notNullValue()).body("status", equalTo("WARNING")).body("typeReports", notNullValue()).rootPath("typeReports").body("stats.total", everyItem(greaterThan(0))).body("stats.ignored", hasSize(greaterThanOrEqualTo(1))).body("objectReports", notNullValue()).body("objectReports", hasSize(greaterThanOrEqualTo(1))).body("objectReports.errorReports", notNullValue());
}
use of org.hisp.dhis.helpers.file.FileReaderUtils in project dhis2-core by dhis2.
the class MetadataImportTest method shouldImportUniqueMetadataAndReturnObjectReports.
@Test
public void shouldImportUniqueMetadataAndReturnObjectReports() throws Exception {
// arrange
JsonObject object = new FileReaderUtils().readJsonAndGenerateData(new File("src/test/resources/metadata/uniqueMetadata.json"));
// act
ApiResponse response = metadataActions.post(object, new QueryParamsBuilder().addAll("async=false", "importReportMode=DEBUG", "importStrategy=CREATE"));
// assert
response.validate().statusCode(200).rootPath("response").body("stats", notNullValue()).body("stats.total", greaterThan(0)).body("typeReports", notNullValue()).body("typeReports.stats", notNullValue()).body("typeReports.objectReports", Matchers.notNullValue());
List<HashMap> stats = response.extractList("response.typeReports.stats");
stats.forEach(x -> {
assertEquals(x.get("total"), x.get("created"));
});
List<ObjectReport> objectReports = getObjectReports(response.getTypeReports());
assertNotNull(objectReports);
validateCreatedEntities(objectReports);
}
use of org.hisp.dhis.helpers.file.FileReaderUtils in project dhis2-core by dhis2.
the class ImportStrategyTests method shouldDeleteReferencingDataWhenTeiIsDeleted.
@Test
public void shouldDeleteReferencingDataWhenTeiIsDeleted() throws Exception {
// arrange
JsonObject body = new FileReaderUtils().readJsonAndGenerateData(new File("src/test/resources/tracker/importer/teis/teiAndEnrollment.json"));
TrackerApiResponse response = trackerActions.postAndGetJobReport(body).validateSuccessfulImport();
String teiId = response.extractImportedTeis().get(0);
String enrollmentId = response.extractImportedEnrollments().get(0);
body.remove("enrollments");
// act
response = trackerActions.postAndGetJobReport(body, new QueryParamsBuilder().add("importStrategy=DELETE")).validateSuccessfulImport();
// assert
response.validateSuccessfulImport().validate().body("stats.deleted", Matchers.equalTo(1));
trackerActions.getTrackedEntity(teiId).validate().statusCode(404);
trackerActions.get("/enrollments/" + enrollmentId).validate().statusCode(404);
}
use of org.hisp.dhis.helpers.file.FileReaderUtils in project dhis2-core by dhis2.
the class ImportStrategyTests method shouldDeleteWithDeleteStrategy.
@ParameterizedTest
@ValueSource(strings = { "src/test/resources/tracker/importer/teis/teisWithEnrollmentsAndEvents.json", "src/test/resources/tracker/importer/teis/teiAndEnrollment.json", "src/test/resources/tracker/importer/teis/teis.json", "src/test/resources/tracker/importer/events/events.json" })
public void shouldDeleteWithDeleteStrategy(String fileName) throws Exception {
// arrange
JsonObject teiBody = new FileReaderUtils().readJsonAndGenerateData(new File(fileName));
trackerActions.postAndGetJobReport(teiBody).validateSuccessfulImport();
teiBody = new FileReaderUtils().readJsonAndGenerateData(new File(fileName));
// act
ApiResponse response = trackerActions.postAndGetJobReport(teiBody, new QueryParamsBuilder().add("importStrategy=DELETE"));
// assert
response.validate().statusCode(200).body("status", equalTo("OK")).body("stats.deleted", Matchers.greaterThanOrEqualTo(1));
}
use of org.hisp.dhis.helpers.file.FileReaderUtils in project dhis2-core by dhis2.
the class SideEffectsTests method setupData.
private void setupData() throws Exception {
ProgramStageActions programStageActions = new ProgramStageActions();
JsonArray array = new FileReaderUtils().read(new File("src/test/resources/tracker/notificationTemplates.json")).get(JsonObject.class).getAsJsonArray("programNotificationTemplates");
array.forEach(nt -> {
String programNotificationTemplate = new RestApiActions("/programNotificationTemplates").post(nt.getAsJsonObject()).extractUid();
JsonObject programStage = JsonObjectBuilder.jsonObject(programStageActions.get(trackerProgramStageId).getBody()).addOrAppendToArray("notificationTemplates", new JsonObjectBuilder().addProperty("id", programNotificationTemplate).build()).build();
programStageActions.update(trackerProgramStageId, programStage).validate().statusCode(200);
programStageActions.get(trackerProgramStageId).validate().body("notificationTemplates.id", hasItem(programNotificationTemplate));
});
}
Aggregations