Search in sources :

Example 6 with PotentialDuplicateConflictException

use of org.hisp.dhis.deduplication.PotentialDuplicateConflictException 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

PotentialDuplicate (org.hisp.dhis.deduplication.PotentialDuplicate)6 PotentialDuplicateConflictException (org.hisp.dhis.deduplication.PotentialDuplicateConflictException)6 Test (org.junit.jupiter.api.Test)5 BadRequestException (org.hisp.dhis.webapi.controller.exception.BadRequestException)4 ConflictException (org.hisp.dhis.webapi.controller.exception.ConflictException)4 NotFoundException (org.hisp.dhis.webapi.controller.exception.NotFoundException)4 OperationNotAllowedException (org.hisp.dhis.webapi.controller.exception.OperationNotAllowedException)4 MergeObject (org.hisp.dhis.deduplication.MergeObject)2 DeduplicationMergeParams (org.hisp.dhis.deduplication.DeduplicationMergeParams)1 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)1