use of org.hisp.dhis.dataelement.DataElementGroup in project dhis2-core by dhis2.
the class PreheatServiceTest method testCollectReferenceCodeDEG1.
@Test
void testCollectReferenceCodeDEG1() {
DataElementGroup dataElementGroup = createDataElementGroup('A');
DataElement de1 = createDataElement('A');
DataElement de2 = createDataElement('B');
DataElement de3 = createDataElement('C');
User user = createUser('A');
dataElementGroup.addDataElement(de1);
dataElementGroup.addDataElement(de2);
dataElementGroup.addDataElement(de3);
dataElementGroup.setCreatedBy(user);
Map<Class<? extends IdentifiableObject>, Set<String>> references = preheatService.collectReferences(dataElementGroup).get(PreheatIdentifier.CODE);
assertTrue(references.containsKey(DataElement.class));
assertTrue(references.containsKey(User.class));
assertEquals(3, references.get(DataElement.class).size());
assertEquals(1, references.get(User.class).size());
assertTrue(references.get(DataElement.class).contains(de1.getCode()));
assertTrue(references.get(DataElement.class).contains(de2.getCode()));
assertTrue(references.get(DataElement.class).contains(de3.getCode()));
assertTrue(references.get(User.class).contains(user.getCode()));
}
use of org.hisp.dhis.dataelement.DataElementGroup in project dhis2-core by dhis2.
the class PreheatServiceTest method testCollectReferenceUidDEG1.
@Test
void testCollectReferenceUidDEG1() {
DataElementGroup deg1 = createDataElementGroup('A');
DataElement de1 = createDataElement('A');
DataElement de2 = createDataElement('B');
DataElement de3 = createDataElement('C');
User user = createUser('A');
deg1.addDataElement(de1);
deg1.addDataElement(de2);
deg1.addDataElement(de3);
deg1.setCreatedBy(user);
Map<Class<? extends IdentifiableObject>, Set<String>> references = preheatService.collectReferences(deg1).get(PreheatIdentifier.UID);
assertTrue(references.containsKey(DataElement.class));
assertTrue(references.containsKey(User.class));
assertEquals(3, references.get(DataElement.class).size());
assertEquals(1, references.get(User.class).size());
assertTrue(references.get(DataElement.class).contains(de1.getUid()));
assertTrue(references.get(DataElement.class).contains(de2.getUid()));
assertTrue(references.get(DataElement.class).contains(de3.getUid()));
assertTrue(references.get(User.class).contains(user.getUid()));
}
use of org.hisp.dhis.dataelement.DataElementGroup in project dhis2-core by dhis2.
the class PreheatServiceTest method testPreheatReferenceWithScanUID.
@Test
void testPreheatReferenceWithScanUID() {
DataElementGroup dataElementGroup = fromJson("preheat/degAUidRef.json", DataElementGroup.class);
defaultSetup();
PreheatParams params = new PreheatParams();
params.setPreheatMode(PreheatMode.REFERENCE);
params.getObjects().put(DataElementGroup.class, Lists.newArrayList(dataElementGroup));
preheatService.validate(params);
Preheat preheat = preheatService.preheat(params);
assertFalse(preheat.isEmpty());
assertFalse(preheat.isEmpty(PreheatIdentifier.UID));
assertFalse(preheat.isEmpty(PreheatIdentifier.UID, DataElement.class));
assertFalse(preheat.isEmpty(PreheatIdentifier.UID, DataElementGroup.class));
assertFalse(preheat.isEmpty(PreheatIdentifier.UID, User.class));
assertTrue(preheat.containsKey(PreheatIdentifier.UID, DataElement.class, "deabcdefghA"));
assertTrue(preheat.containsKey(PreheatIdentifier.UID, DataElement.class, "deabcdefghB"));
assertTrue(preheat.containsKey(PreheatIdentifier.UID, DataElement.class, "deabcdefghC"));
assertTrue(preheat.containsKey(PreheatIdentifier.UID, User.class, "userabcdefA"));
}
use of org.hisp.dhis.dataelement.DataElementGroup in project dhis2-core by dhis2.
the class PatchServiceTest method testSimpleIdObjectCollectionDiff.
@Test
void testSimpleIdObjectCollectionDiff() {
DataElement deA = createDataElement('A');
DataElement deB = createDataElement('B');
DataElementGroup degA = createDataElementGroup('C');
DataElementGroup degB = createDataElementGroup('D');
manager.save(degA);
manager.save(degB);
deA.getGroups().add(degA);
manager.update(degA);
deB.getGroups().add(degB);
deA.getAggregationLevels().add(1);
deA.getAggregationLevels().add(2);
deB.getAggregationLevels().add(2);
deB.getAggregationLevels().add(3);
deB.getAggregationLevels().add(4);
Patch patch = patchService.diff(new PatchParams(deA, deB));
checkCount(patch, "dataElementGroups", Mutation.Operation.ADDITION, 1);
checkCount(patch, "dataElementGroups", Mutation.Operation.DELETION, 1);
checkCount(patch, "aggregationLevels", Mutation.Operation.ADDITION, 2);
checkCount(patch, "aggregationLevels", Mutation.Operation.DELETION, 1);
patchService.apply(patch, deA);
assertEquals(deA.getName(), deB.getName());
assertEquals(deA.getShortName(), deB.getShortName());
assertEquals(deA.getDescription(), deB.getDescription());
assertEquals(deA.getAggregationLevels(), deB.getAggregationLevels());
assertEquals(deA.getGroups(), deB.getGroups());
}
use of org.hisp.dhis.dataelement.DataElementGroup in project dhis2-core by dhis2.
the class PatchServiceTest method testDeleteDataElementFromGroup.
@Test
void testDeleteDataElementFromGroup() {
DataElementGroup dataElementGroup = createDataElementGroup('A');
DataElement deA = createDataElement('A');
DataElement deB = createDataElement('B');
manager.save(deA);
manager.save(deB);
dataElementGroup.addDataElement(deA);
dataElementGroup.addDataElement(deB);
assertEquals(2, dataElementGroup.getMembers().size());
Patch patch = new Patch().addMutation(new Mutation("name", "Updated Name")).addMutation(new Mutation("dataElements", Lists.newArrayList(deA.getUid()), Mutation.Operation.DELETION));
patchService.apply(patch, dataElementGroup);
assertEquals("Updated Name", dataElementGroup.getName());
assertEquals(1, dataElementGroup.getMembers().size());
patch = new Patch().addMutation(new Mutation("dataElements", Lists.newArrayList(deB.getUid()), Mutation.Operation.DELETION));
patchService.apply(patch, dataElementGroup);
assertTrue(dataElementGroup.getMembers().isEmpty());
}
Aggregations