Search in sources :

Example 6 with PotentialDuplicate

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"));
}
Also used : PotentialDuplicate(org.hisp.dhis.deduplication.PotentialDuplicate) Test(org.junit.jupiter.api.Test)

Example 7 with PotentialDuplicate

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);
}
Also used : MergeObject(org.hisp.dhis.deduplication.MergeObject) PotentialDuplicate(org.hisp.dhis.deduplication.PotentialDuplicate) Test(org.junit.jupiter.api.Test)

Example 8 with PotentialDuplicate

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);
}
Also used : PotentialDuplicateForbiddenException(org.hisp.dhis.deduplication.PotentialDuplicateForbiddenException) MergeObject(org.hisp.dhis.deduplication.MergeObject) PotentialDuplicate(org.hisp.dhis.deduplication.PotentialDuplicate) Test(org.junit.jupiter.api.Test)

Example 9 with PotentialDuplicate

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);
}
Also used : PotentialDuplicate(org.hisp.dhis.deduplication.PotentialDuplicate) BadRequestException(org.hisp.dhis.webapi.controller.exception.BadRequestException) Test(org.junit.jupiter.api.Test)

Example 10 with PotentialDuplicate

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);
}
Also used : PotentialDuplicateConflictException(org.hisp.dhis.deduplication.PotentialDuplicateConflictException) PotentialDuplicateConflictException(org.hisp.dhis.deduplication.PotentialDuplicateConflictException) ConflictException(org.hisp.dhis.webapi.controller.exception.ConflictException) PotentialDuplicate(org.hisp.dhis.deduplication.PotentialDuplicate) NotFoundException(org.hisp.dhis.webapi.controller.exception.NotFoundException) BadRequestException(org.hisp.dhis.webapi.controller.exception.BadRequestException) OperationNotAllowedException(org.hisp.dhis.webapi.controller.exception.OperationNotAllowedException) Test(org.junit.jupiter.api.Test)

Aggregations

PotentialDuplicate (org.hisp.dhis.deduplication.PotentialDuplicate)23 Test (org.junit.jupiter.api.Test)19 BadRequestException (org.hisp.dhis.webapi.controller.exception.BadRequestException)7 PotentialDuplicateConflictException (org.hisp.dhis.deduplication.PotentialDuplicateConflictException)6 MergeObject (org.hisp.dhis.deduplication.MergeObject)5 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 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)3 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)2 DeduplicationMergeParams (org.hisp.dhis.deduplication.DeduplicationMergeParams)1 DeduplicationStatus (org.hisp.dhis.deduplication.DeduplicationStatus)1 PotentialDuplicateForbiddenException (org.hisp.dhis.deduplication.PotentialDuplicateForbiddenException)1 FieldFilterParams (org.hisp.dhis.fieldfilter.FieldFilterParams)1 RootNode (org.hisp.dhis.node.types.RootNode)1 CrudControllerAdvice (org.hisp.dhis.webapi.controller.CrudControllerAdvice)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1 PutMapping (org.springframework.web.bind.annotation.PutMapping)1