use of org.hisp.dhis.merge.orgunit.OrgUnitMergeRequest in project dhis2-core by dhis2.
the class UserMetadataOrgUnitMergeHandlerTest method testMergeUsers.
@Test
void testMergeUsers() {
User userA = createUser('A');
userA.addOrganisationUnit(ouA);
userA.getDataViewOrganisationUnits().add(ouA);
userA.getTeiSearchOrganisationUnits().add(ouA);
User userB = createUser('B');
userB.addOrganisationUnit(ouB);
userB.getDataViewOrganisationUnits().add(ouB);
userB.getTeiSearchOrganisationUnits().add(ouB);
userService.addUser(userA);
userService.addUser(userB);
assertTrue(ouA.getUsers().contains(userA));
assertTrue(userA.getOrganisationUnits().contains(ouA));
assertTrue(ouB.getUsers().contains(userB));
assertTrue(userB.getOrganisationUnits().contains(ouB));
OrgUnitMergeRequest request = new OrgUnitMergeRequest.Builder().addSource(ouA).addSource(ouB).withTarget(ouC).build();
handler.mergeUsers(request);
assertTrue(ouA.getUsers().isEmpty());
assertFalse(userA.getOrganisationUnits().contains(ouA));
assertFalse(userA.getDataViewOrganisationUnits().contains(ouA));
assertFalse(userA.getTeiSearchOrganisationUnits().contains(ouA));
assertTrue(ouB.getUsers().isEmpty());
assertFalse(userB.getOrganisationUnits().contains(ouB));
assertFalse(userB.getDataViewOrganisationUnits().contains(ouB));
assertFalse(userB.getTeiSearchOrganisationUnits().contains(ouB));
assertTrue(ouC.getUsers().contains(userA));
assertTrue(ouC.getUsers().contains(userB));
assertContainsOnly(userA.getOrganisationUnits(), ouC);
assertContainsOnly(userA.getDataViewOrganisationUnits(), ouC);
assertContainsOnly(userA.getTeiSearchOrganisationUnits(), ouC);
assertContainsOnly(userB.getOrganisationUnits(), ouC);
assertContainsOnly(userB.getDataViewOrganisationUnits(), ouC);
assertContainsOnly(userB.getTeiSearchOrganisationUnits(), ouC);
}
use of org.hisp.dhis.merge.orgunit.OrgUnitMergeRequest in project dhis2-core by dhis2.
the class InterpretationDataOrgUnitMergeHandlerTest method testMigrate.
@Test
void testMigrate() {
interpretationService.saveInterpretation(ipA);
interpretationService.saveInterpretation(ipB);
interpretationService.saveInterpretation(ipC);
assertEquals(1, getInterpretationCount(ouA));
assertEquals(1, getInterpretationCount(ouB));
assertEquals(1, getInterpretationCount(ouC));
OrgUnitMergeRequest request = new OrgUnitMergeRequest.Builder().addSource(ouA).addSource(ouB).withTarget(ouC).build();
mergeHandler.mergeInterpretations(request);
assertEquals(0, getInterpretationCount(ouA));
assertEquals(0, getInterpretationCount(ouB));
assertEquals(3, getInterpretationCount(ouC));
}
use of org.hisp.dhis.merge.orgunit.OrgUnitMergeRequest in project dhis2-core by dhis2.
the class DataOrgUnitMergeHandlerTest method testMergeDataApprovals.
@Test
void testMergeDataApprovals() {
addDataApprovals(new DataApproval(dlA, dwA, peA, ouA, cocA, false, date(2021, 1, 1), usA), new DataApproval(dlA, dwA, peA, ouB, cocA, false, date(2021, 2, 1), usA), new DataApproval(dlA, dwA, peB, ouA, cocA, false, date(2021, 3, 1), usA), new DataApproval(dlA, dwA, peB, ouB, cocA, false, date(2021, 4, 1), usA));
assertEquals(2, getDataApprovalCount(ouA));
assertEquals(2, getDataApprovalCount(ouB));
assertEquals(0, getDataApprovalCount(ouC));
OrgUnitMergeRequest request = new OrgUnitMergeRequest.Builder().addSource(ouA).addSource(ouB).withTarget(ouC).withDataApprovalMergeStrategy(DataMergeStrategy.LAST_UPDATED).build();
handler.mergeDataApprovals(request);
assertEquals(0, getDataApprovalCount(ouA));
assertEquals(0, getDataApprovalCount(ouB));
assertEquals(2, getDataApprovalCount(ouC));
}
use of org.hisp.dhis.merge.orgunit.OrgUnitMergeRequest in project dhis2-core by dhis2.
the class MetadataOrgUnitMergeHandlerTest method testMergeOrgUnitGroups.
@Test
void testMergeOrgUnitGroups() {
OrganisationUnitGroup ougA = createOrganisationUnitGroup('A');
ougA.addOrganisationUnit(ouA);
ougA.addOrganisationUnit(ouB);
OrganisationUnitGroup ougB = createOrganisationUnitGroup('B');
ougB.addOrganisationUnit(ouA);
OrgUnitMergeRequest request = new OrgUnitMergeRequest.Builder().addSource(ouA).addSource(ouB).withTarget(ouC).build();
assertEquals(2, ouA.getGroups().size());
assertEquals(1, ouB.getGroups().size());
assertEquals(0, ouC.getGroups().size());
handler.mergeOrgUnitGroups(request);
assertEquals(0, ouA.getGroups().size());
assertEquals(0, ouB.getGroups().size());
assertEquals(2, ouC.getGroups().size());
}
Aggregations