Search in sources :

Example 1 with ConflictException

use of org.hisp.dhis.webapi.controller.exception.ConflictException 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)

Example 2 with ConflictException

use of org.hisp.dhis.webapi.controller.exception.ConflictException 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 3 with ConflictException

use of org.hisp.dhis.webapi.controller.exception.ConflictException 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 4 with ConflictException

use of org.hisp.dhis.webapi.controller.exception.ConflictException 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)

Aggregations

PotentialDuplicate (org.hisp.dhis.deduplication.PotentialDuplicate)4 PotentialDuplicateConflictException (org.hisp.dhis.deduplication.PotentialDuplicateConflictException)4 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 Test (org.junit.jupiter.api.Test)4