Search in sources :

Example 1 with FileReaderUtils

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());
}
Also used : FileReaderUtils(org.hisp.dhis.helpers.file.FileReaderUtils) QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) JsonObject(com.google.gson.JsonObject) File(java.io.File) ApiResponse(org.hisp.dhis.dto.ApiResponse) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ApiTest(org.hisp.dhis.ApiTest)

Example 2 with FileReaderUtils

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);
}
Also used : HashMap(java.util.HashMap) FileReaderUtils(org.hisp.dhis.helpers.file.FileReaderUtils) QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) JsonObject(com.google.gson.JsonObject) ObjectReport(org.hisp.dhis.dto.ObjectReport) File(java.io.File) ApiResponse(org.hisp.dhis.dto.ApiResponse) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ApiTest(org.hisp.dhis.ApiTest)

Example 3 with FileReaderUtils

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);
}
Also used : FileReaderUtils(org.hisp.dhis.helpers.file.FileReaderUtils) QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) JsonObject(com.google.gson.JsonObject) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) File(java.io.File) Test(org.junit.jupiter.api.Test) TrackerNtiApiTest(org.hisp.dhis.tracker.TrackerNtiApiTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with FileReaderUtils

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));
}
Also used : FileReaderUtils(org.hisp.dhis.helpers.file.FileReaderUtils) QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) JsonObject(com.google.gson.JsonObject) File(java.io.File) ApiResponse(org.hisp.dhis.dto.ApiResponse) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with FileReaderUtils

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));
    });
}
Also used : JsonArray(com.google.gson.JsonArray) RestApiActions(org.hisp.dhis.actions.RestApiActions) FileReaderUtils(org.hisp.dhis.helpers.file.FileReaderUtils) ProgramStageActions(org.hisp.dhis.actions.metadata.ProgramStageActions) JsonObject(com.google.gson.JsonObject) JsonObjectBuilder(org.hisp.dhis.helpers.JsonObjectBuilder) File(java.io.File)

Aggregations

File (java.io.File)28 FileReaderUtils (org.hisp.dhis.helpers.file.FileReaderUtils)28 JsonObject (com.google.gson.JsonObject)27 ApiResponse (org.hisp.dhis.dto.ApiResponse)18 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)17 QueryParamsBuilder (org.hisp.dhis.helpers.QueryParamsBuilder)14 TrackerApiResponse (org.hisp.dhis.dto.TrackerApiResponse)13 Test (org.junit.jupiter.api.Test)12 TrackerNtiApiTest (org.hisp.dhis.tracker.TrackerNtiApiTest)7 MethodSource (org.junit.jupiter.params.provider.MethodSource)6 ApiTest (org.hisp.dhis.ApiTest)5 RestApiActions (org.hisp.dhis.actions.RestApiActions)3 JsonObjectBuilder (org.hisp.dhis.helpers.JsonObjectBuilder)3 ValueSource (org.junit.jupiter.params.provider.ValueSource)3 LoginActions (org.hisp.dhis.actions.LoginActions)2 MetadataActions (org.hisp.dhis.actions.metadata.MetadataActions)2 EventActions (org.hisp.dhis.actions.tracker.EventActions)2 ObjectReport (org.hisp.dhis.dto.ObjectReport)2 BeforeAll (org.junit.jupiter.api.BeforeAll)2 JsonArray (com.google.gson.JsonArray)1