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);
}
}
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);
}
}
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");
}
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);
}
}
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());
}
Aggregations