Search in sources :

Example 1 with ObjectReport

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

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

the class MetadataImportTest method shouldReturnObjectReportsWhenSomeMetadataWasIgnoredAndAtomicModeFalse.

@Test
public void shouldReturnObjectReportsWhenSomeMetadataWasIgnoredAndAtomicModeFalse() throws Exception {
    // arrange
    QueryParamsBuilder queryParamsBuilder = new QueryParamsBuilder();
    queryParamsBuilder.addAll("async=false", "importReportMode=DEBUG", "importStrategy=CREATE", "atomicMode=NONE");
    JsonObject object = new FileReaderUtils().readJsonAndGenerateData(new File("src/test/resources/metadata/uniqueMetadata.json"));
    // act
    ApiResponse response = metadataActions.post(object, queryParamsBuilder);
    response.validate().statusCode(200);
    JsonObject newObj = new FileReaderUtils().readJsonAndGenerateData(new File("src/test/resources/metadata/uniqueMetadata.json"));
    // add one of the orgunits from already imported metadata to get it
    // ignored
    newObj.get("organisationUnits").getAsJsonArray().add(object.get("organisationUnits").getAsJsonArray().get(0));
    response = metadataActions.post(newObj, queryParamsBuilder);
    // assert
    response.validate().statusCode(409).rootPath("response").body("stats", notNullValue()).body("stats.total", greaterThan(1)).body("stats.ignored", equalTo(1)).body("stats.created", equalTo((Integer) response.extract("response.stats.total") - 1));
    int total = (int) response.extract("response.stats.total");
    List<ObjectReport> objectReports = getObjectReports(response.getTypeReports());
    assertNotNull(objectReports);
    validateCreatedEntities(objectReports);
    assertThat(objectReports, hasItems(hasProperty("errorReports", notNullValue())));
    assertEquals(total, objectReports.size(), "Not all imported entities had object reports");
}
Also used : 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)

Aggregations

JsonObject (com.google.gson.JsonObject)2 File (java.io.File)2 ApiTest (org.hisp.dhis.ApiTest)2 ApiResponse (org.hisp.dhis.dto.ApiResponse)2 ObjectReport (org.hisp.dhis.dto.ObjectReport)2 QueryParamsBuilder (org.hisp.dhis.helpers.QueryParamsBuilder)2 FileReaderUtils (org.hisp.dhis.helpers.file.FileReaderUtils)2 Test (org.junit.jupiter.api.Test)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 HashMap (java.util.HashMap)1