Search in sources :

Example 6 with MergeObject

use of org.hisp.dhis.deduplication.MergeObject in project dhis2-core by dhis2.

the class DeduplicationControllerMvcTest method shouldThrowAutoMergeConflictException.

@Test
void shouldThrowAutoMergeConflictException() throws Exception {
    String uid = "uid";
    PotentialDuplicate potentialDuplicate = new PotentialDuplicate(teiA, teiB);
    when(deduplicationService.getPotentialDuplicateByUid(uid)).thenReturn(potentialDuplicate);
    doThrow(new PotentialDuplicateConflictException("Conflict")).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 PotentialDuplicateConflictException));
    verify(deduplicationService).autoMerge(deduplicationMergeParams);
    verify(deduplicationService, times(0)).manualMerge(deduplicationMergeParams);
}
Also used : PotentialDuplicateConflictException(org.hisp.dhis.deduplication.PotentialDuplicateConflictException) MergeObject(org.hisp.dhis.deduplication.MergeObject) PotentialDuplicate(org.hisp.dhis.deduplication.PotentialDuplicate) Test(org.junit.jupiter.api.Test)

Aggregations

MergeObject (org.hisp.dhis.deduplication.MergeObject)6 PotentialDuplicate (org.hisp.dhis.deduplication.PotentialDuplicate)5 Test (org.junit.jupiter.api.Test)4 PotentialDuplicateConflictException (org.hisp.dhis.deduplication.PotentialDuplicateConflictException)2 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)2 AuditableEntity (org.hisp.dhis.artemis.audit.AuditableEntity)1 DeduplicationMergeParams (org.hisp.dhis.deduplication.DeduplicationMergeParams)1 PotentialDuplicateForbiddenException (org.hisp.dhis.deduplication.PotentialDuplicateForbiddenException)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)1