Search in sources :

Example 46 with FragaSvar

use of se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar in project webcert by sklintyg.

the class FragaSvarServiceImplTest method testSetVidareBefordradOK.

@Test
public void testSetVidareBefordradOK() {
    FragaSvar fraga = buildFraga(1L, "frageText", Amne.OVRIGT, LocalDateTime.now());
    when(webCertUserService.getUser()).thenReturn(createUser());
    when(fragasvarRepositoryMock.findByIntygsReferensIntygsId(any(String.class))).thenReturn(ImmutableList.of(fraga));
    assertFalse(fraga.getVidarebefordrad());
    List<FragaSvar> fragaSvarList = service.setVidareBefordrad(fraga.getIntygsReferens().getIntygsId());
    verify(fragasvarRepositoryMock).save(anyList());
    verifyZeroInteractions(notificationServiceMock);
    assertTrue(fragaSvarList.stream().allMatch(FragaSvar::getVidarebefordrad));
}
Also used : FragaSvar(se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 47 with FragaSvar

use of se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar in project webcert by sklintyg.

the class FragaSvarServiceImplTest method testCloseCompletionsAsHandled.

@Test
public void testCloseCompletionsAsHandled() {
    final String intygId = "intygId";
    FragaSvar fragaSvar1 = buildFragaSvar(1L, LocalDateTime.now(), LocalDateTime.now());
    fragaSvar1.setAmne(Amne.KOMPLETTERING_AV_LAKARINTYG);
    fragaSvar1.setFrageStallare(FrageStallare.FORSAKRINGSKASSAN.getKod());
    FragaSvar fragaSvar2 = buildFragaSvar(2L, LocalDateTime.now(), LocalDateTime.now());
    fragaSvar2.setAmne(Amne.KONTAKT);
    fragaSvar2.setFrageStallare(FrageStallare.FORSAKRINGSKASSAN.getKod());
    FragaSvar fragaSvar3 = buildFragaSvar(3L, LocalDateTime.now(), LocalDateTime.now());
    fragaSvar3.setAmne(Amne.KOMPLETTERING_AV_LAKARINTYG);
    fragaSvar3.setFrageStallare(FrageStallare.FORSAKRINGSKASSAN.getKod());
    FragaSvar fragaSvar4 = buildFragaSvar(4L, LocalDateTime.now(), LocalDateTime.now());
    fragaSvar4.setAmne(Amne.KOMPLETTERING_AV_LAKARINTYG);
    // already closed
    fragaSvar4.setStatus(Status.CLOSED);
    fragaSvar4.setFrageStallare(FrageStallare.FORSAKRINGSKASSAN.getKod());
    when(fragasvarRepositoryMock.findByIntygsReferensIntygsId(intygId)).thenReturn(Arrays.asList(fragaSvar1, fragaSvar2, fragaSvar3, fragaSvar4));
    ArgumentCaptor<FragaSvar> fsCapture = ArgumentCaptor.forClass(FragaSvar.class);
    when(fragasvarRepositoryMock.save(fsCapture.capture())).thenAnswer(invocation -> invocation.getArguments()[0]);
    service.closeCompletionsAsHandled(intygId);
    verify(fragasvarRepositoryMock).findByIntygsReferensIntygsId(intygId);
    verify(fragasvarRepositoryMock, times(2)).save(any(FragaSvar.class));
    assertEquals(fragaSvar1.getInternReferens(), fsCapture.getAllValues().get(0).getInternReferens());
    assertEquals(Status.CLOSED, fsCapture.getAllValues().get(0).getStatus());
    assertEquals(fragaSvar3.getInternReferens(), fsCapture.getAllValues().get(1).getInternReferens());
    assertEquals(Status.CLOSED, fsCapture.getAllValues().get(1).getStatus());
    verify(notificationServiceMock, times(2)).sendNotificationForQAs(INTYG_ID, NotificationEvent.QUESTION_FROM_RECIPIENT_HANDLED);
    verify(arendeDraftService, times(2)).delete(eq(INTYG_ID), anyString());
    verifyNoMoreInteractions(arendeDraftService);
}
Also used : FragaSvar(se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 48 with FragaSvar

use of se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar in project webcert by sklintyg.

the class FragaSvarServiceImplTest method testSaveSvarNotAuthorizedForunit.

@Test(expected = WebCertServiceException.class)
public void testSaveSvarNotAuthorizedForunit() {
    FragaSvar fragaSvar = buildFragaSvar(1L, LocalDateTime.now(), LocalDateTime.now());
    when(fragasvarRepositoryMock.findOne(1L)).thenReturn(fragaSvar);
    when(webCertUserService.isAuthorizedForUnit(any(String.class), eq(false))).thenReturn(false);
    try {
        service.saveSvar(1L, "svarsText");
    } finally {
        verify(fragasvarRepositoryMock, never()).save(any(FragaSvar.class));
        verifyZeroInteractions(notificationServiceMock);
        verifyZeroInteractions(arendeDraftService);
    }
}
Also used : FragaSvar(se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 49 with FragaSvar

use of se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar in project webcert by sklintyg.

the class FragaSvarServiceImplTest method testCloseAnsweredQuestionToFKAsHandledOK.

@Test
public void testCloseAnsweredQuestionToFKAsHandledOK() {
    // This is a question that we sent to FK that has been answered so we now have to close it
    FragaSvar fragaSvar = buildFragaSvar(1L, LocalDateTime.now(), LocalDateTime.now());
    fragaSvar.setFrageStallare(FrageStallare.WEBCERT.getKod());
    fragaSvar.setFrageText("Fråga från WC till FK");
    fragaSvar.setStatus(Status.ANSWERED);
    fragaSvar.setSvarsText("Med ett svar från FK");
    ArgumentCaptor<FragaSvar> fsCapture = ArgumentCaptor.forClass(FragaSvar.class);
    when(fragasvarRepositoryMock.findOne(1L)).thenReturn(fragaSvar);
    when(fragasvarRepositoryMock.save(fsCapture.capture())).thenReturn(fragaSvar);
    service.closeQuestionAsHandled(1L);
    verify(notificationServiceMock).sendNotificationForQAs(INTYG_ID, NotificationEvent.QUESTION_FROM_CARE_WITH_ANSWER_HANDLED);
    verify(fragasvarRepositoryMock).findOne(1L);
    verify(fragasvarRepositoryMock).save(any(FragaSvar.class));
    assertEquals(Status.CLOSED, fsCapture.getValue().getStatus());
    verifyZeroInteractions(arendeDraftService);
}
Also used : FragaSvar(se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar) Test(org.junit.Test)

Example 50 with FragaSvar

use of se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar in project webcert by sklintyg.

the class FragaSvarServiceImplTest method testExceptionThrownWhenIntygIsRevoked.

@Test(expected = WebCertServiceException.class)
public void testExceptionThrownWhenIntygIsRevoked() {
    FragaSvar fraga = buildFraga(1L, "frageText", Amne.OVRIGT, LocalDateTime.now());
    String intygsId = fraga.getIntygsReferens().getIntygsId();
    // Setup when - given -then
    when(intygServiceMock.fetchIntygData(intygsId, fraga.getIntygsReferens().getIntygsTyp(), false)).thenReturn(getRevokedIntygContentHolder());
    when(webCertUserService.getUser()).thenReturn(createUser());
    when(webCertUserService.isAuthorizedForUnit(any(String.class), eq(false))).thenReturn(true);
    // test call
    try {
        service.saveNewQuestion(fraga.getIntygsReferens().getIntygsId(), fraga.getIntygsReferens().getIntygsTyp(), fraga.getAmne(), fraga.getFrageText());
    } finally {
        verifyZeroInteractions(sendQuestionToFKClientMock);
        verifyZeroInteractions(notificationServiceMock);
        verify(fragasvarRepositoryMock, times(0)).save(any(FragaSvar.class));
    }
}
Also used : FragaSvar(se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Aggregations

FragaSvar (se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar)71 Test (org.junit.Test)42 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)14 IntygsReferens (se.inera.intyg.webcert.persistence.fragasvar.model.IntygsReferens)11 Vardperson (se.inera.intyg.webcert.persistence.fragasvar.model.Vardperson)11 Produces (javax.ws.rs.Produces)7 AttributedURIType (org.w3.wsaddressing10.AttributedURIType)7 Path (javax.ws.rs.Path)6 Filter (se.inera.intyg.webcert.persistence.model.Filter)6 LocalDateTime (java.time.LocalDateTime)5 Consumes (javax.ws.rs.Consumes)5 WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)5 ArendeListItem (se.inera.intyg.webcert.web.web.controller.api.dto.ArendeListItem)5 ArrayList (java.util.ArrayList)4 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)4 SendMedicalCertificateAnswerResponseType (se.inera.ifv.insuranceprocess.healthreporting.sendmedicalcertificateanswerresponder.v1.SendMedicalCertificateAnswerResponseType)4 SendMedicalCertificateAnswerType (se.inera.ifv.insuranceprocess.healthreporting.sendmedicalcertificateanswerresponder.v1.SendMedicalCertificateAnswerType)4 SendMedicalCertificateQuestionType (se.inera.ifv.insuranceprocess.healthreporting.sendmedicalcertificatequestionresponder.v1.SendMedicalCertificateQuestionType)4 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)4 Amne (se.inera.intyg.webcert.persistence.fragasvar.model.Amne)4