Search in sources :

Example 1 with BadRequestException

use of org.hisp.dhis.webapi.controller.exception.BadRequestException in project dhis2-core by dhis2.

the class DeduplicationControllerMvcTest method shouldThrowUpdatePotentialDuplicateAlreadyMerged.

@Test
void shouldThrowUpdatePotentialDuplicateAlreadyMerged() throws Exception {
    String uid = "uid";
    PotentialDuplicate potentialDuplicate = new PotentialDuplicate(teiA, teiB);
    potentialDuplicate.setStatus(DeduplicationStatus.MERGED);
    when(deduplicationService.getPotentialDuplicateByUid(uid)).thenReturn(potentialDuplicate);
    mockMvc.perform(put(ENDPOINT + "/" + uid).param("status", DeduplicationStatus.INVALID.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 2 with BadRequestException

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

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

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

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

Aggregations

BadRequestException (org.hisp.dhis.webapi.controller.exception.BadRequestException)13 PotentialDuplicate (org.hisp.dhis.deduplication.PotentialDuplicate)7 Test (org.junit.jupiter.api.Test)7 OperationNotAllowedException (org.hisp.dhis.webapi.controller.exception.OperationNotAllowedException)5 GetMapping (org.springframework.web.bind.annotation.GetMapping)5 PotentialDuplicateConflictException (org.hisp.dhis.deduplication.PotentialDuplicateConflictException)4 MetadataVersionServiceException (org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException)4 ConflictException (org.hisp.dhis.webapi.controller.exception.ConflictException)4 MetadataVersionException (org.hisp.dhis.webapi.controller.exception.MetadataVersionException)4 NotFoundException (org.hisp.dhis.webapi.controller.exception.NotFoundException)4 MetadataVersion (org.hisp.dhis.metadata.version.MetadataVersion)3 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 GZIPOutputStream (java.util.zip.GZIPOutputStream)1 MetadataSyncParams (org.hisp.dhis.dxf2.metadata.sync.MetadataSyncParams)1 MetadataSyncSummary (org.hisp.dhis.dxf2.metadata.sync.MetadataSyncSummary)1 DhisVersionMismatchException (org.hisp.dhis.dxf2.metadata.sync.exception.DhisVersionMismatchException)1 MetadataSyncImportException (org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncImportException)1