Search in sources :

Example 21 with PotentialDuplicate

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

the class DeduplicationControllerMvcTest method shouldUpdatePotentialDuplicate.

@Test
void shouldUpdatePotentialDuplicate() 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.INVALID.name()).content(objectMapper.writeValueAsString(potentialDuplicate)).contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk());
    ArgumentCaptor<PotentialDuplicate> potentialDuplicateArgumentCaptor = ArgumentCaptor.forClass(PotentialDuplicate.class);
    verify(deduplicationService).getPotentialDuplicateByUid(uid);
    verify(deduplicationService).updatePotentialDuplicate(potentialDuplicateArgumentCaptor.capture());
    assertEquals(DeduplicationStatus.INVALID, potentialDuplicateArgumentCaptor.getValue().getStatus());
}
Also used : PotentialDuplicate(org.hisp.dhis.deduplication.PotentialDuplicate) Test(org.junit.jupiter.api.Test)

Example 22 with PotentialDuplicate

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

the class DeduplicationControllerMvcTest method shouldThrowPostPotentialDuplicateMissingTei.

@Test
void shouldThrowPostPotentialDuplicateMissingTei() throws Exception {
    PotentialDuplicate potentialDuplicate = new PotentialDuplicate(teiA, null);
    mockMvc.perform(post(ENDPOINT).content(objectMapper.writeValueAsString(potentialDuplicate)).contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)).andExpect(result -> assertTrue(result.getResolvedException() instanceof BadRequestException));
}
Also used : PotentialDuplicate(org.hisp.dhis.deduplication.PotentialDuplicate) BadRequestException(org.hisp.dhis.webapi.controller.exception.BadRequestException) Test(org.junit.jupiter.api.Test)

Example 23 with PotentialDuplicate

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

the class DeduplicationControllerMvcTest method setUp.

@BeforeEach
void setUp() {
    deduplicationMergeParams = DeduplicationMergeParams.builder().potentialDuplicate(new PotentialDuplicate(teiA, teiB)).original(trackedEntityInstanceA).duplicate(trackedEntityInstanceB).mergeObject(MergeObject.builder().build()).build();
    mockMvc = MockMvcBuilders.standaloneSetup(deduplicationController).setControllerAdvice(new CrudControllerAdvice()).build();
    lenient().when(trackedEntityInstanceService.getTrackedEntityInstance(teiA)).thenReturn(trackedEntityInstanceA);
    lenient().when(trackedEntityInstanceService.getTrackedEntityInstance(teiB)).thenReturn(trackedEntityInstanceB);
    lenient().when(trackerAccessManager.canRead(any(), any(TrackedEntityInstance.class))).thenReturn(Lists.newArrayList());
}
Also used : PotentialDuplicate(org.hisp.dhis.deduplication.PotentialDuplicate) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) CrudControllerAdvice(org.hisp.dhis.webapi.controller.CrudControllerAdvice) BeforeEach(org.junit.jupiter.api.BeforeEach)

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