use of org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundleParams in project dhis2-core by dhis2.
the class ObjectBundleServiceTest method testCreatePreheatValidationsInvalidObjects.
@Test
void testCreatePreheatValidationsInvalidObjects() throws IOException {
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/de_validate2.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);
assertTrue(validate.hasErrorReports());
assertEquals(5, validate.getErrorReportsCountByCode(DataElement.class, ErrorCode.E5002));
assertEquals(3, validate.getErrorReportsCountByCode(DataElement.class, ErrorCode.E4000));
}
use of org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundleParams in project dhis2-core by dhis2.
the class ObjectBundleServiceTest method testUpdateWithPersistedObjectsRequiresValidReferencesUID.
@Test
void testUpdateWithPersistedObjectsRequiresValidReferencesUID() throws IOException {
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/de_validate7.json").getInputStream(), RenderFormat.JSON);
defaultSetup();
ObjectBundleParams params = new ObjectBundleParams();
params.setObjectBundleMode(ObjectBundleMode.VALIDATE);
params.setPreheatIdentifier(PreheatIdentifier.UID);
params.setImportStrategy(ImportStrategy.UPDATE);
params.setAtomicMode(NONE);
params.setObjects(metadata);
ObjectBundle bundle = objectBundleService.create(params);
ObjectBundleValidationReport validate = objectBundleValidationService.validate(bundle);
assertEquals(1, validate.getErrorReportsCountByCode(DataElement.class, ErrorCode.E5001));
assertNotEquals(0, validate.getErrorReportsCountByCode(DataElement.class, ErrorCode.E4000));
assertEquals(0, bundle.getObjectsCount(DataElement.class));
}
use of org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundleParams in project dhis2-core by dhis2.
the class OptionObjectBundleHookTest method preCreateOptionSetAvailable.
@Test
void preCreateOptionSetAvailable() {
OptionSet optionSet = new OptionSet();
optionSet.setUid("jadhjSHdhs");
Option option = new Option();
option.setOptionSet(optionSet);
OptionSet persistedOptionSet = new OptionSet();
persistedOptionSet.setUid("jadhjSHdhs");
preheat.put(PreheatIdentifier.UID, persistedOptionSet);
ObjectBundleParams objectBundleParams = new ObjectBundleParams();
objectBundleParams.setPreheatIdentifier(PreheatIdentifier.UID);
ObjectBundle bundle = new ObjectBundle(objectBundleParams, preheat, Collections.singletonMap(OptionSet.class, Collections.singletonList(optionSet)));
hook.preCreate(option, bundle);
Assertions.assertEquals(0, persistedOptionSet.getOptions().size());
}
use of org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundleParams in project dhis2-core by dhis2.
the class OptionObjectBundleHookTest method preCreate.
@Test
void preCreate() {
OptionSet optionSet = new OptionSet();
optionSet.setUid("jadhjSHdhs");
Option option = new Option();
option.setOptionSet(optionSet);
OptionSet persistedOptionSet = new OptionSet();
persistedOptionSet.setUid("jadhjSHdhs");
preheat.put(PreheatIdentifier.UID, persistedOptionSet);
ObjectBundleParams objectBundleParams = new ObjectBundleParams();
objectBundleParams.setPreheatIdentifier(PreheatIdentifier.UID);
ObjectBundle bundle = new ObjectBundle(objectBundleParams, preheat, Collections.emptyMap());
hook.preCreate(option, bundle);
Assertions.assertEquals(1, persistedOptionSet.getOptions().size());
Assertions.assertSame(option, persistedOptionSet.getOptions().get(0));
}
use of org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundleParams in project dhis2-core by dhis2.
the class ValidatingEventCheckerTest method createObjectBundle.
private ObjectBundle createObjectBundle() {
Attribute attribute1 = new Attribute();
attribute1.setUid("u1");
ObjectBundleParams objectBundleParams = new ObjectBundleParams();
Preheat preheat = new Preheat();
final Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> objectMap = new HashMap<>();
objectMap.put(Attribute.class, new ArrayList<>());
objectMap.get(Attribute.class).add(attribute1);
preheat.put(PreheatIdentifier.UID, attribute1);
return new ObjectBundle(objectBundleParams, preheat, objectMap);
}
Aggregations