use of org.hisp.dhis.deduplication.PotentialDuplicate in project dhis2-core by dhis2.
the class DeduplicationControllerMvcTest method shouldPostPotentialDuplicate.
@Test
void shouldPostPotentialDuplicate() throws Exception {
PotentialDuplicate potentialDuplicate = new PotentialDuplicate(teiA, teiB);
mockMvc.perform(post(ENDPOINT).content(objectMapper.writeValueAsString(potentialDuplicate)).contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andExpect(content().contentType("application/json"));
}
use of org.hisp.dhis.deduplication.PotentialDuplicate in project dhis2-core by dhis2.
the class DeduplicationControllerMvcTest method shouldManualMergePotentialDuplicate.
@Test
void shouldManualMergePotentialDuplicate() throws Exception {
String uid = "uid";
PotentialDuplicate potentialDuplicate = new PotentialDuplicate(teiA, teiB);
when(deduplicationService.getPotentialDuplicateByUid(uid)).thenReturn(potentialDuplicate);
MergeObject mergeObject = MergeObject.builder().build();
mockMvc.perform(post(ENDPOINT + "/" + uid + "/merge").content(objectMapper.writeValueAsString(mergeObject)).param("mergeStrategy", MergeStrategy.MANUAL.name()).contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk());
verify(deduplicationService, times(0)).autoMerge(deduplicationMergeParams);
verify(deduplicationService).manualMerge(deduplicationMergeParams);
}
use of org.hisp.dhis.deduplication.PotentialDuplicate in project dhis2-core by dhis2.
the class DeduplicationControllerMvcTest method shouldThrowAutoMergeForbiddenException.
@Test
void shouldThrowAutoMergeForbiddenException() throws Exception {
String uid = "uid";
PotentialDuplicate potentialDuplicate = new PotentialDuplicate(teiA, teiB);
when(deduplicationService.getPotentialDuplicateByUid(uid)).thenReturn(potentialDuplicate);
doThrow(new PotentialDuplicateForbiddenException("Forbidden")).when(deduplicationService).autoMerge(deduplicationMergeParams);
MergeObject mergeObject = MergeObject.builder().build();
mockMvc.perform(post(ENDPOINT + "/" + uid + "/merge").content(objectMapper.writeValueAsString(mergeObject)).param("mergeStrategy", MergeStrategy.AUTO.name()).contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)).andExpect(result -> assertTrue(result.getResolvedException() instanceof PotentialDuplicateForbiddenException));
verify(deduplicationService).autoMerge(deduplicationMergeParams);
verify(deduplicationService, times(0)).manualMerge(deduplicationMergeParams);
}
use of org.hisp.dhis.deduplication.PotentialDuplicate in project dhis2-core by dhis2.
the class DeduplicationControllerMvcTest method shouldThrowUpdatePotentialDuplicateToMergedStatus.
@Test
void shouldThrowUpdatePotentialDuplicateToMergedStatus() throws Exception {
String uid = "uid";
PotentialDuplicate potentialDuplicate = new PotentialDuplicate(teiA, teiB);
when(deduplicationService.getPotentialDuplicateByUid(uid)).thenReturn(potentialDuplicate);
mockMvc.perform(put(ENDPOINT + "/" + uid).param("status", DeduplicationStatus.MERGED.name()).content(objectMapper.writeValueAsString(potentialDuplicate)).contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)).andExpect(result -> assertTrue(result.getResolvedException() instanceof BadRequestException));
verify(deduplicationService).getPotentialDuplicateByUid(uid);
}
use of org.hisp.dhis.deduplication.PotentialDuplicate in project dhis2-core by dhis2.
the class DeduplicationControllerTest method postPotentialDuplicateAlreadyExists.
@Test
void postPotentialDuplicateAlreadyExists() throws PotentialDuplicateConflictException {
PotentialDuplicate pd = new PotentialDuplicate(teiA, teiB);
when(trackerAccessManager.canRead(any(), eq(trackedEntityInstanceA))).thenReturn(Lists.newArrayList());
when(trackerAccessManager.canRead(any(), eq(trackedEntityInstanceB))).thenReturn(Lists.newArrayList());
when(deduplicationService.exists(pd)).thenReturn(true);
try {
deduplicationController.postPotentialDuplicate(pd);
} catch (OperationNotAllowedException | ConflictException | NotFoundException | BadRequestException | PotentialDuplicateConflictException e) {
assertTrue(e instanceof ConflictException);
}
verify(deduplicationService, times(0)).addPotentialDuplicate(any());
verify(trackerAccessManager).canRead(user, trackedEntityInstanceA);
verify(trackerAccessManager).canRead(user, trackedEntityInstanceB);
verify(deduplicationService).exists(pd);
}
Aggregations