use of org.hisp.dhis.common.IdentifiableObject in project dhis2-core by dhis2.
the class ObjectBundleServiceAttributesTest method testValidateMetadataAttributeValuesUniqueFromPayload.
@Test
public void testValidateMetadataAttributeValuesUniqueFromPayload() throws IOException {
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/metadata_with_unique_attributes_from_payload.json").getInputStream(), RenderFormat.JSON);
ObjectBundleParams params = new ObjectBundleParams();
params.setObjectBundleMode(ObjectBundleMode.VALIDATE);
params.setObjects(metadata);
ObjectBundle bundle = objectBundleService.create(params);
ObjectBundleValidationReport validationReport = objectBundleValidationService.validate(bundle);
List<ObjectReport> objectReports = validationReport.getObjectReports(DataElement.class);
assertFalse(objectReports.isEmpty());
assertEquals(2, validationReport.getErrorReportsByCode(DataElement.class, ErrorCode.E4009).size());
}
use of org.hisp.dhis.common.IdentifiableObject in project dhis2-core by dhis2.
the class ObjectBundleServiceAttributesTest method testValidateMetadataAttributeValuesMandatory.
@Test
public void testValidateMetadataAttributeValuesMandatory() throws IOException {
defaultSetupWithAttributes();
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/metadata_with_mandatory_attributes.json").getInputStream(), RenderFormat.JSON);
ObjectBundleParams params = new ObjectBundleParams();
params.setObjectBundleMode(ObjectBundleMode.VALIDATE);
params.setObjects(metadata);
ObjectBundle bundle = objectBundleService.create(params);
ObjectBundleValidationReport validationReport = objectBundleValidationService.validate(bundle);
List<ObjectReport> objectReports = validationReport.getObjectReports(DataElement.class);
assertFalse(objectReports.isEmpty());
assertEquals(4, objectReports.size());
objectReports.forEach(objectReport -> assertEquals(2, objectReport.getErrorReports().size()));
}
use of org.hisp.dhis.common.IdentifiableObject in project dhis2-core by dhis2.
the class ObjectBundleServiceTest method testPreheatValidationsIncludingMerge.
@Test
public void testPreheatValidationsIncludingMerge() throws IOException {
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/de_validate3.json").getInputStream(), RenderFormat.JSON);
defaultSetup();
ObjectBundleParams params = new ObjectBundleParams();
params.setObjectBundleMode(ObjectBundleMode.VALIDATE);
params.setMergeMode(MergeMode.REPLACE);
params.setObjects(metadata);
ObjectBundle bundle = objectBundleService.create(params);
ObjectBundleValidationReport validate = objectBundleValidationService.validate(bundle);
assertNotNull(validate);
}
use of org.hisp.dhis.common.IdentifiableObject in project dhis2-core by dhis2.
the class ObjectBundleServiceTest method testCreateOrgUnitWithLevels.
@Test
public void testCreateOrgUnitWithLevels() throws IOException {
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/ou_with_levels.json").getInputStream(), RenderFormat.JSON);
ObjectBundleParams params = new ObjectBundleParams();
params.setObjectBundleMode(ObjectBundleMode.COMMIT);
params.setImportStrategy(ImportStrategy.CREATE_AND_UPDATE);
params.setAtomicMode(AtomicMode.ALL);
params.setObjects(metadata);
ObjectBundle bundle = objectBundleService.create(params);
assertTrue(objectBundleValidationService.validate(bundle).getErrorReports().isEmpty());
objectBundleService.commit(bundle);
OrganisationUnit root = manager.get(OrganisationUnit.class, "inVD5SdytkT");
assertNull(root.getParent());
assertEquals(3, root.getChildren().size());
}
use of org.hisp.dhis.common.IdentifiableObject in project dhis2-core by dhis2.
the class ObjectBundleServiceTest method testPreheatValidations.
@Test
public void testPreheatValidations() throws IOException {
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/de_validate1.json").getInputStream(), RenderFormat.JSON);
ObjectBundleParams params = new ObjectBundleParams();
params.setObjectBundleMode(ObjectBundleMode.VALIDATE);
params.setImportStrategy(ImportStrategy.CREATE);
params.setObjects(metadata);
ObjectBundle bundle = objectBundleService.create(params);
ObjectBundleValidationReport validate = objectBundleValidationService.validate(bundle);
assertFalse(validate.isEmpty());
List<ObjectReport> objectReports = validate.getObjectReports(DataElement.class);
assertFalse(objectReports.isEmpty());
for (ObjectReport objectReport : objectReports) {
for (ErrorCode errorCode : objectReport.getErrorCodes()) {
List<ErrorReport> errorReports = objectReport.getErrorReportsByCode().get(errorCode);
assertFalse(errorReports.isEmpty());
for (ErrorReport errorReport : errorReports) {
assertTrue(PreheatErrorReport.class.isInstance(errorReport));
PreheatErrorReport preheatErrorReport = (PreheatErrorReport) errorReport;
assertEquals(PreheatIdentifier.UID, preheatErrorReport.getPreheatIdentifier());
if (DataElementCategoryCombo.class.isInstance(preheatErrorReport.getValue())) {
assertEquals("p0KPaWEg3cf", preheatErrorReport.getObjectReference().getUid());
} else if (User.class.isInstance(preheatErrorReport.getValue())) {
assertEquals("GOLswS44mh8", preheatErrorReport.getObjectReference().getUid());
} else if (OptionSet.class.isInstance(preheatErrorReport.getValue())) {
assertEquals("pQYCiuosBnZ", preheatErrorReport.getObjectReference().getUid());
}
}
}
}
}
Aggregations