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