Search in sources :

Example 56 with FragaSvar

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

the class FragaSvarServiceImplTest method testCloseQuestionToFKAsHandledOK.

@Test
public void testCloseQuestionToFKAsHandledOK() {
    FragaSvar fragaSvar = buildFragaSvar(1L, LocalDateTime.now(), LocalDateTime.now());
    fragaSvar.setFrageStallare(FrageStallare.WEBCERT.getKod());
    fragaSvar.setFrageText("Fråga till FK");
    fragaSvar.setStatus(Status.PENDING_EXTERNAL_ACTION);
    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_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 57 with FragaSvar

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

the class FragaSvarServiceImplTest method testSaveFragaNotAuthorizedForUnit.

@Test(expected = WebCertServiceException.class)
public void testSaveFragaNotAuthorizedForUnit() {
    FragaSvar fraga = buildFraga(1L, "frageText", Amne.OVRIGT, LocalDateTime.now());
    // create mocked Utlatande from intygstjansten
    when(intygServiceMock.fetchIntygData(fraga.getIntygsReferens().getIntygsId(), fraga.getIntygsReferens().getIntygsTyp(), false)).thenReturn(getIntygContentHolder());
    when(webCertUserService.getUser()).thenReturn(createUser());
    when(webCertUserService.isAuthorizedForUnit(any(String.class), eq(false))).thenReturn(false);
    // test call
    try {
        service.saveNewQuestion(fraga.getIntygsReferens().getIntygsId(), fraga.getIntygsReferens().getIntygsTyp(), fraga.getAmne(), fraga.getFrageText());
    } finally {
        verifyZeroInteractions(fragasvarRepositoryMock);
        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 58 with FragaSvar

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

the class FragaSvarServiceImplTest method testExceptionThrownWhenIntygIsUnsentToFK.

@Test(expected = WebCertServiceException.class)
public void testExceptionThrownWhenIntygIsUnsentToFK() {
    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(getUnsentIntygContentHolder());
    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);
        verifyZeroInteractions(fragasvarRepositoryMock);
    }
}
Also used : FragaSvar(se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 59 with FragaSvar

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

the class FragaSvarServiceImplTest method buildFragaSvar.

private FragaSvar buildFragaSvar(Long id, LocalDateTime fragaSkickadDatum, LocalDateTime svarSkickadDatum) {
    FragaSvar f = new FragaSvar();
    f.setStatus(Status.PENDING_INTERNAL_ACTION);
    f.setAmne(Amne.OVRIGT);
    f.setExternReferens("<fk-extern-referens>");
    f.setInternReferens(id);
    f.setFrageSkickadDatum(fragaSkickadDatum);
    f.setFrageText("frageText");
    f.setSvarSkickadDatum(svarSkickadDatum);
    IntygsReferens intygsReferens = new IntygsReferens();
    intygsReferens.setIntygsId(INTYG_ID);
    intygsReferens.setIntygsTyp("fk7263");
    intygsReferens.setPatientId(PNR);
    f.setIntygsReferens(intygsReferens);
    f.setKompletteringar(new HashSet<>());
    f.setVardperson(new Vardperson());
    f.getVardperson().setEnhetsId("enhet");
    return f;
}
Also used : Vardperson(se.inera.intyg.webcert.persistence.fragasvar.model.Vardperson) IntygsReferens(se.inera.intyg.webcert.persistence.fragasvar.model.IntygsReferens) FragaSvar(se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar)

Example 60 with FragaSvar

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

the class FragaSvarServiceImplTest method testOpenAsUnhandledInvalidState.

@Test(expected = WebCertServiceException.class)
public void testOpenAsUnhandledInvalidState() {
    FragaSvar fragaSvar = buildFragaSvar(1L, LocalDateTime.now(), LocalDateTime.now());
    fragaSvar.setFrageStallare(FrageStallare.FORSAKRINGSKASSAN.getKod());
    fragaSvar.setFrageText("Fråga från FK");
    fragaSvar.setSvarsText("Svar till FK från WC");
    fragaSvar.setStatus(Status.CLOSED);
    when(fragasvarRepositoryMock.findOne(1L)).thenReturn(fragaSvar);
    try {
        service.openQuestionAsUnhandled(1L);
    } finally {
        verify(fragasvarRepositoryMock, never()).save(any(FragaSvar.class));
        verifyZeroInteractions(notificationServiceMock);
    }
}
Also used : FragaSvar(se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar) 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