Search in sources :

Example 11 with PotentialDuplicate

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

the class DeduplicationControllerTest method postPotentialDuplicateTeiNotFound.

@Test
void postPotentialDuplicateTeiNotFound() {
    when(trackedEntityInstanceService.getTrackedEntityInstance(teiA)).thenReturn(null);
    try {
        deduplicationController.postPotentialDuplicate(new PotentialDuplicate(teiA, teiB));
    } catch (OperationNotAllowedException | ConflictException | NotFoundException | BadRequestException | PotentialDuplicateConflictException e) {
        assertTrue(e instanceof NotFoundException);
    }
    verify(deduplicationService, times(0)).addPotentialDuplicate(any());
}
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)

Example 12 with PotentialDuplicate

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

the class DeduplicationControllerTest method postPotentialDuplicateNoAccessToTeiA.

@Test
void postPotentialDuplicateNoAccessToTeiA() {
    when(trackerAccessManager.canRead(Mockito.any(), eq(trackedEntityInstanceA))).thenReturn(Lists.newArrayList("Error"));
    try {
        deduplicationController.postPotentialDuplicate(new PotentialDuplicate(teiA, teiB));
    } catch (OperationNotAllowedException | ConflictException | NotFoundException | BadRequestException | PotentialDuplicateConflictException e) {
        assertTrue(e instanceof OperationNotAllowedException);
    }
    verify(deduplicationService, times(0)).addPotentialDuplicate(any());
    verify(trackerAccessManager).canRead(user, trackedEntityInstanceA);
}
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)

Example 13 with PotentialDuplicate

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

the class DeduplicationControllerTest method postPotentialDuplicateNoAccessToTeiB.

@Test
void postPotentialDuplicateNoAccessToTeiB() {
    when(trackerAccessManager.canRead(Mockito.any(), eq(trackedEntityInstanceA))).thenReturn(Lists.newArrayList());
    when(trackerAccessManager.canRead(Mockito.any(), eq(trackedEntityInstanceB))).thenReturn(Lists.newArrayList("Error"));
    try {
        deduplicationController.postPotentialDuplicate(new PotentialDuplicate(teiA, teiB));
    } catch (OperationNotAllowedException | ConflictException | NotFoundException | BadRequestException | PotentialDuplicateConflictException e) {
        assertTrue(e instanceof OperationNotAllowedException);
    }
    verify(deduplicationService, times(0)).addPotentialDuplicate(any());
    verify(trackerAccessManager).canRead(user, trackedEntityInstanceA);
    verify(trackerAccessManager).canRead(user, trackedEntityInstanceB);
}
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)

Example 14 with PotentialDuplicate

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

the class DeduplicationControllerTest method shouldThrowUpdatePotentialDuplicateMergeRequest.

@Test
void shouldThrowUpdatePotentialDuplicateMergeRequest() {
    PotentialDuplicate potentialDuplicate = new PotentialDuplicate(teiA, teiB);
    when(deduplicationService.getPotentialDuplicateByUid(uid)).thenReturn(potentialDuplicate);
    assertThrows(BadRequestException.class, () -> deduplicationController.updatePotentialDuplicate(uid, DeduplicationStatus.MERGED.name()));
}
Also used : PotentialDuplicate(org.hisp.dhis.deduplication.PotentialDuplicate) Test(org.junit.jupiter.api.Test)

Example 15 with PotentialDuplicate

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

the class DeduplicationControllerTest method getPotentialDuplicateByUid.

@Test
void getPotentialDuplicateByUid() throws NotFoundException {
    when(deduplicationService.getPotentialDuplicateByUid(uid)).thenReturn(new PotentialDuplicate(teiA, teiB));
    PotentialDuplicate pd = deduplicationController.getPotentialDuplicateById(uid);
    assertEquals(teiA, pd.getOriginal());
    verify(deduplicationService).getPotentialDuplicateByUid(uid);
}
Also used : PotentialDuplicate(org.hisp.dhis.deduplication.PotentialDuplicate) 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