Search in sources :

Example 61 with FragaSvar

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

the class FragaSvarServiceImplTest method testSaveSvarForPaminnelse.

@Test(expected = WebCertServiceException.class)
public void testSaveSvarForPaminnelse() {
    FragaSvar fragaSvar = buildFragaSvar(1L, LocalDateTime.now(), LocalDateTime.now());
    fragaSvar.setAmne(Amne.PAMINNELSE);
    when(fragasvarRepositoryMock.findOne(1L)).thenReturn(fragaSvar);
    try {
        service.saveSvar(1L, "svarsText");
    } 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)

Example 62 with FragaSvar

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

the class FragaSvarServiceImplTest method testSaveSvarWsHTMLError.

@Test(expected = WebCertServiceException.class)
public void testSaveSvarWsHTMLError() throws Exception {
    FragaSvar fragaSvar = buildFragaSvar(1L, LocalDateTime.now(), LocalDateTime.now());
    when(webCertUserService.getUser()).thenReturn(createUser());
    when(fragasvarRepositoryMock.findOne(1L)).thenReturn(fragaSvar);
    when(webCertUserService.getUser()).thenReturn(createUser());
    when(webCertUserService.isAuthorizedForUnit(any(String.class), eq(false))).thenReturn(true);
    when(fragasvarRepositoryMock.save(fragaSvar)).thenReturn(fragaSvar);
    // mock error with content type html
    SOAPFault soapFault = SOAPFactory.newInstance().createFault();
    soapFault.setFaultString("Response was of unexpected text/html ContentType.");
    when(sendAnswerToFKClientMock.sendMedicalCertificateAnswer(any(AttributedURIType.class), any(SendMedicalCertificateAnswerType.class))).thenThrow(new SOAPFaultException(soapFault));
    try {
        service.saveSvar(1L, "svarsText");
    } finally {
        verifyZeroInteractions(notificationServiceMock);
    }
}
Also used : AttributedURIType(org.w3.wsaddressing10.AttributedURIType) FragaSvar(se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar) SOAPFault(javax.xml.soap.SOAPFault) SendMedicalCertificateAnswerType(se.inera.ifv.insuranceprocess.healthreporting.sendmedicalcertificateanswerresponder.v1.SendMedicalCertificateAnswerType) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 63 with FragaSvar

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

the class FragaSvarServiceImplTest method testCloseAllNonClosedQuestions.

@Test
public void testCloseAllNonClosedQuestions() {
    FragaSvar fragaSvarFromWc = buildFragaSvar(1L, LocalDateTime.now(), LocalDateTime.now());
    fragaSvarFromWc.setFrageStallare(FrageStallare.WEBCERT.getKod());
    fragaSvarFromWc.setStatus(Status.ANSWERED);
    FragaSvar fragaSvarFromFk = buildFragaSvar(2L, LocalDateTime.now(), LocalDateTime.now());
    fragaSvarFromFk.setFrageStallare(FrageStallare.FORSAKRINGSKASSAN.getKod());
    FragaSvar fragaSvarAlreadyClosed = buildFragaSvar(2L, LocalDateTime.now(), LocalDateTime.now());
    fragaSvarAlreadyClosed.setStatus(Status.CLOSED);
    final String intygId = "intygId";
    when(fragasvarRepositoryMock.findByIntygsReferensIntygsId(intygId)).thenReturn(Arrays.asList(fragaSvarFromWc, fragaSvarFromFk, fragaSvarAlreadyClosed));
    when(fragasvarRepositoryMock.save(any(FragaSvar.class))).thenAnswer(invocation -> invocation.getArguments()[0]);
    service.closeAllNonClosedQuestions(intygId);
    verify(fragasvarRepositoryMock).findByIntygsReferensIntygsId(intygId);
    verify(notificationServiceMock).sendNotificationForQAs(INTYG_ID, NotificationEvent.QUESTION_FROM_RECIPIENT_HANDLED);
    verify(notificationServiceMock).sendNotificationForQAs(INTYG_ID, NotificationEvent.QUESTION_FROM_CARE_WITH_ANSWER_HANDLED);
    ArgumentCaptor<FragaSvar> fragaSvarCaptor = ArgumentCaptor.forClass(FragaSvar.class);
    verify(fragasvarRepositoryMock, times(2)).save(fragaSvarCaptor.capture());
    assertEquals(Status.CLOSED, fragaSvarCaptor.getAllValues().get(0).getStatus());
    assertEquals(Status.CLOSED, fragaSvarCaptor.getAllValues().get(1).getStatus());
    verify(arendeDraftService).delete(INTYG_ID, Long.toString(2L));
    verifyNoMoreInteractions(arendeDraftService);
}
Also used : FragaSvar(se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 64 with FragaSvar

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

the class FragaSvarConverterTest method testConvertQuestion.

@Test
public void testConvertQuestion() throws Exception {
    FragaSvar fragaSvar = new FragaSvarConverter().convert(question("FragaSvarConverterTest/question.xml"));
    compareObjectWithReferenceFile(fragaSvar, "FragaSvarConverterTest/question.json");
}
Also used : FragaSvar(se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar) Test(org.junit.Test)

Example 65 with FragaSvar

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

the class FragaSvarConverterTest method testConvertQuestionLongMeddelandeRubrik.

@Test
public void testConvertQuestionLongMeddelandeRubrik() throws Exception {
    FragaSvar fragaSvar = new FragaSvarConverter().convert(question("FragaSvarConverterTest/question_long_meddelande_rubrik.xml"));
    compareObjectWithReferenceFile(fragaSvar, "FragaSvarConverterTest/question_long_meddelande_rubrik.json");
}
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