Search in sources :

Example 51 with FragaSvar

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

the class FragaSvarServiceImplTest method testSaveSvarWrongStateForAnswering.

@Test(expected = WebCertServiceException.class)
public void testSaveSvarWrongStateForAnswering() {
    FragaSvar fragaSvar = buildFragaSvar(1L, LocalDateTime.now(), LocalDateTime.now());
    fragaSvar.setStatus(Status.ANSWERED);
    when(fragasvarRepositoryMock.findOne(1L)).thenReturn(fragaSvar);
    when(webCertUserService.isAuthorizedForUnit(any(String.class), eq(false))).thenReturn(true);
    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) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 52 with FragaSvar

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

the class FragaSvarServiceImplTest method testSaveFragaWsHTMLError.

@Test(expected = WebCertServiceException.class)
public void testSaveFragaWsHTMLError() throws Exception {
    FragaSvar fraga = buildFraga(1L, "frageText", Amne.OVRIGT, LocalDateTime.now());
    when(intygServiceMock.fetchIntygData(fraga.getIntygsReferens().getIntygsId(), fraga.getIntygsReferens().getIntygsTyp(), false)).thenReturn(getIntygContentHolder());
    // mock error with content type html
    SOAPFault soapFault = SOAPFactory.newInstance().createFault();
    soapFault.setFaultString("Response was of unexpected text/html ContentType.");
    when(webCertUserService.getUser()).thenReturn(createUser());
    when(webCertUserService.isAuthorizedForUnit(any(String.class), eq(false))).thenReturn(true);
    when(fragasvarRepositoryMock.save(any(FragaSvar.class))).thenReturn(fraga);
    when(sendQuestionToFKClientMock.sendMedicalCertificateQuestion(any(AttributedURIType.class), any(SendMedicalCertificateQuestionType.class))).thenThrow(new SOAPFaultException(soapFault));
    try {
        service.saveNewQuestion(fraga.getIntygsReferens().getIntygsId(), fraga.getIntygsReferens().getIntygsTyp(), fraga.getAmne(), fraga.getFrageText());
    } finally {
        verifyZeroInteractions(notificationServiceMock);
        verifyZeroInteractions(arendeDraftService);
    }
}
Also used : AttributedURIType(org.w3.wsaddressing10.AttributedURIType) FragaSvar(se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar) SOAPFault(javax.xml.soap.SOAPFault) SendMedicalCertificateQuestionType(se.inera.ifv.insuranceprocess.healthreporting.sendmedicalcertificatequestionresponder.v1.SendMedicalCertificateQuestionType) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 53 with FragaSvar

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

the class FragaSvarServiceImplTest method intygWithoutFragaSvarDoesNotAcceptFraga.

@Test(expected = WebCertServiceException.class)
public void intygWithoutFragaSvarDoesNotAcceptFraga() {
    FragaSvar fragaSvar = buildFragaSvar(1L, LocalDateTime.now(), LocalDateTime.now());
    fragaSvar.getIntygsReferens().setIntygsTyp("ts-bas");
    when(authoritiesHelper.isFeatureActive(AuthoritiesConstants.FEATURE_HANTERA_FRAGOR, "ts-bas")).thenReturn(false);
    service.processIncomingQuestion(fragaSvar);
    fail("Processing should have thrown an exception");
}
Also used : FragaSvar(se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar) Test(org.junit.Test)

Example 54 with FragaSvar

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

the class FragaSvarServiceImplTest method testSaveSvarWsError.

@Test(expected = WebCertServiceException.class)
public void testSaveSvarWsError() {
    FragaSvar fragaSvar = buildFragaSvar(1L, LocalDateTime.now(), LocalDateTime.now());
    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 ws error response
    SendMedicalCertificateAnswerResponseType wsResponse = new SendMedicalCertificateAnswerResponseType();
    wsResponse.setResult(ResultOfCallUtil.failResult("some error"));
    when(sendAnswerToFKClientMock.sendMedicalCertificateAnswer(any(AttributedURIType.class), any(SendMedicalCertificateAnswerType.class))).thenReturn(wsResponse);
    try {
        service.saveSvar(1L, "svarsText");
    } finally {
        verifyZeroInteractions(notificationServiceMock);
    }
}
Also used : SendMedicalCertificateAnswerResponseType(se.inera.ifv.insuranceprocess.healthreporting.sendmedicalcertificateanswerresponder.v1.SendMedicalCertificateAnswerResponseType) AttributedURIType(org.w3.wsaddressing10.AttributedURIType) FragaSvar(se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar) SendMedicalCertificateAnswerType(se.inera.ifv.insuranceprocess.healthreporting.sendmedicalcertificateanswerresponder.v1.SendMedicalCertificateAnswerType) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 55 with FragaSvar

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

the class FragaSvarServiceImplTest method testFilterFragaSvarWithNoEnhetsIdAsParam.

@Test
public void testFilterFragaSvarWithNoEnhetsIdAsParam() {
    List<FragaSvar> queryResults = new ArrayList<>();
    queryResults.add(buildFragaSvar(1L, MAY, null));
    queryResults.add(buildFragaSvar(2L, MAY, null));
    when(fragasvarRepositoryMock.filterFragaSvar(any(Filter.class))).thenReturn(queryResults);
    when(fragasvarRepositoryMock.filterCountFragaSvar(any(Filter.class))).thenReturn(queryResults.size());
    QueryFragaSvarResponse response = service.filterFragaSvar(new Filter());
    verify(fragasvarRepositoryMock).filterFragaSvar(any(Filter.class));
    verify(fragasvarRepositoryMock).filterCountFragaSvar(any(Filter.class));
    assertNotNull(response);
    assertEquals(2, response.getResults().size());
}
Also used : Filter(se.inera.intyg.webcert.persistence.model.Filter) FragaSvar(se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar) QueryFragaSvarResponse(se.inera.intyg.webcert.web.service.fragasvar.dto.QueryFragaSvarResponse) 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