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);
}
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);
}
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);
}
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());
}
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);
}
Aggregations