@Test(expected = WebCertServiceException.class) public void testSaveSvarWsError() { FragaSvar fragaSvar = buildFragaSvar(1L, LocalDateTime.now(), LocalDateTime.now()); when(fragasvarRepositoryMock.findById(1L)).thenReturn(Optional.of(fragaSvar)); when(webCertUserService.getUser()).thenReturn(createUser()); when(webCertUserService.isAuthorizedForUnit(any(String.class), eq(false))).thenReturn(true); when(fragasvarRepositoryMock.save(fragaSvar)).thenReturn(fragaSvar); 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 { verifyNoInteractions(notificationServiceMock); verifyNoInteractions(certificateEventService); } }
@Override public FragaSvar saveSvar(Long fragaSvarsId, String svarsText) { if (Strings.isNullOrEmpty(svarsText)) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "SvarsText cannot be empty!"); } FragaSvar fragaSvar = lookupFragaSvar(fragaSvarsId); verifyEnhetsAuth(fragaSvar.getVardperson().getEnhetsId(), false); if (!fragaSvar.getStatus().equals(Status.PENDING_INTERNAL_ACTION)) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "FragaSvar with id " + fragaSvar.getInternReferens().toString() + " has invalid state for saving answer(" + fragaSvar.getStatus() + ")"); } if (Amne.PAMINNELSE.equals(fragaSvar.getAmne())) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "FragaSvar with id " + fragaSvar.getInternReferens().toString() + " has invalid Amne(" + fragaSvar.getAmne() + ") for saving answer"); } WebCertUser user = webCertUserService.getUser(); if (Amne.KOMPLETTERING_AV_LAKARINTYG.equals(fragaSvar.getAmne())) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "FragaSvar with id " + fragaSvar.getInternReferens().toString() + " has invalid Amne(" + fragaSvar.getAmne() + ") for saving answer"); } createSvar(user, svarsText, fragaSvar); FragaSvar saved = fragaSvarRepository.save(fragaSvar); sendFragaSvarToExternalParty(saved); arendeDraftService.delete(fragaSvar.getIntygsReferens().getIntygsId(), Long.toString(fragaSvar.getInternReferens())); return saved; }
FragaSvarServiceImpl implements FragaSvarService { @Override public FragaSvar saveSvar(Long fragaSvarsId, String svarsText) { if (Strings.isNullOrEmpty(svarsText)) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "SvarsText cannot be empty!"); } FragaSvar fragaSvar = lookupFragaSvar(fragaSvarsId); verifyEnhetsAuth(fragaSvar.getVardperson().getEnhetsId(), false); if (!fragaSvar.getStatus().equals(Status.PENDING_INTERNAL_ACTION)) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "FragaSvar with id " + fragaSvar.getInternReferens().toString() + " has invalid state for saving answer(" + fragaSvar.getStatus() + ")"); } if (Amne.PAMINNELSE.equals(fragaSvar.getAmne())) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "FragaSvar with id " + fragaSvar.getInternReferens().toString() + " has invalid Amne(" + fragaSvar.getAmne() + ") for saving answer"); } WebCertUser user = webCertUserService.getUser(); if (Amne.KOMPLETTERING_AV_LAKARINTYG.equals(fragaSvar.getAmne())) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "FragaSvar with id " + fragaSvar.getInternReferens().toString() + " has invalid Amne(" + fragaSvar.getAmne() + ") for saving answer"); } createSvar(user, svarsText, fragaSvar); FragaSvar saved = fragaSvarRepository.save(fragaSvar); sendFragaSvarToExternalParty(saved); arendeDraftService.delete(fragaSvar.getIntygsReferens().getIntygsId(), Long.toString(fragaSvar.getInternReferens())); return saved; } }
FragaSvarServiceImpl implements FragaSvarService { @Override public FragaSvar saveSvar(Long fragaSvarsId, String svarsText) { if (Strings.isNullOrEmpty(svarsText)) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "SvarsText cannot be empty!"); } FragaSvar fragaSvar = lookupFragaSvar(fragaSvarsId); verifyEnhetsAuth(fragaSvar.getVardperson().getEnhetsId(), false); if (!fragaSvar.getStatus().equals(Status.PENDING_INTERNAL_ACTION)) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "FragaSvar with id " + fragaSvar.getInternReferens().toString() + " has invalid state for saving answer(" + fragaSvar.getStatus() + ")"); } if (Amne.PAMINNELSE.equals(fragaSvar.getAmne())) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "FragaSvar with id " + fragaSvar.getInternReferens().toString() + " has invalid Amne(" + fragaSvar.getAmne() + ") for saving answer"); } WebCertUser user = webCertUserService.getUser(); if (Amne.KOMPLETTERING_AV_LAKARINTYG.equals(fragaSvar.getAmne())) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "FragaSvar with id " + fragaSvar.getInternReferens().toString() + " has invalid Amne(" + fragaSvar.getAmne() + ") for saving answer"); } createSvar(user, svarsText, fragaSvar); FragaSvar saved = fragaSvarRepository.save(fragaSvar); sendFragaSvarToExternalParty(saved); arendeDraftService.delete(fragaSvar.getIntygsReferens().getIntygsId(), Long.toString(fragaSvar.getInternReferens())); return saved; }  }
FragaSvarServiceImpl implements FragaSvarService { @Override public FragaSvar saveSvar(Long fragaSvarsId, String svarsText) { if (Strings.isNullOrEmpty(svarsText)) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "SvarsText cannot be empty!"); } FragaSvar fragaSvar = lookupFragaSvar(fragaSvarsId); verifyEnhetsAuth(fragaSvar.getVardperson().getEnhetsId(), false); if (!fragaSvar.getStatus().equals(Status.PENDING_INTERNAL_ACTION)) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "FragaSvar with id " + fragaSvar.getInternReferens().toString() + " has invalid state for saving answer(" + fragaSvar.getStatus() + ")"); } if (Amne.PAMINNELSE.equals(fragaSvar.getAmne())) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "FragaSvar with id " + fragaSvar.getInternReferens().toString() + " has invalid Amne(" + fragaSvar.getAmne() + ") for saving answer"); } WebCertUser user = webCertUserService.getUser(); if (Amne.KOMPLETTERING_AV_LAKARINTYG.equals(fragaSvar.getAmne())) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "FragaSvar with id " + fragaSvar.getInternReferens().toString() + " has invalid Amne(" + fragaSvar.getAmne() + ") for saving answer"); } createSvar(user, svarsText, fragaSvar); FragaSvar saved = fragaSvarRepository.save(fragaSvar); sendFragaSvarToExternalParty(saved); arendeDraftService.delete(fragaSvar.getIntygsReferens().getIntygsId(), Long.toString(fragaSvar.getInternReferens())); return saved; }  @Override FragaSvar processIncomingQuestion(FragaSvar fragaSvar); @Override FragaSvar processIncomingAnswer(Long internId, String svarsText, LocalDateTime svarSigneringsDatum); @Override @Transactional(readOnly = true) List<FragaSvarView> getFragaSvar(String intygId); @Override FragaSvar saveSvar(Long fragaSvarsId, String svarsText); @Override List<FragaSvarView> answerKomplettering(final String intygsId, final String svarsText); @Override FragaSvar saveNewQuestion(String intygId, String typ, Amne amne, String frageText); @Override List<FragaSvar> setVidareBefordrad(final String intygsId); @Override FragaSvar closeQuestionAsHandled(Long frageSvarId); @Override void closeCompletionsAsHandled(String intygId); @Override void closeAllNonClosedQuestions(String intygsId); @Override FragaSvar openQuestionAsUnhandled(Long frageSvarId); @Override @Transactional(readOnly = true) QueryFragaSvarResponse filterFragaSvar(Filter filter); @Override @Transactional(readOnly = true) List<Lakare> getFragaSvarHsaIdByEnhet(String enhetsId); @Override Map<String, Long> getNbrOfUnhandledFragaSvarForCareUnits(List<String> vardenheterIds, Set<String> intygsTyper); }
FragaSvarServiceImpl implements FragaSvarService { @Override public FragaSvar saveSvar(Long fragaSvarsId, String svarsText) { if (Strings.isNullOrEmpty(svarsText)) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "SvarsText cannot be empty!"); } FragaSvar fragaSvar = lookupFragaSvar(fragaSvarsId); verifyEnhetsAuth(fragaSvar.getVardperson().getEnhetsId(), false); if (!fragaSvar.getStatus().equals(Status.PENDING_INTERNAL_ACTION)) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "FragaSvar with id " + fragaSvar.getInternReferens().toString() + " has invalid state for saving answer(" + fragaSvar.getStatus() + ")"); } if (Amne.PAMINNELSE.equals(fragaSvar.getAmne())) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "FragaSvar with id " + fragaSvar.getInternReferens().toString() + " has invalid Amne(" + fragaSvar.getAmne() + ") for saving answer"); } WebCertUser user = webCertUserService.getUser(); if (Amne.KOMPLETTERING_AV_LAKARINTYG.equals(fragaSvar.getAmne())) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "FragaSvar with id " + fragaSvar.getInternReferens().toString() + " has invalid Amne(" + fragaSvar.getAmne() + ") for saving answer"); } createSvar(user, svarsText, fragaSvar); FragaSvar saved = fragaSvarRepository.save(fragaSvar); sendFragaSvarToExternalParty(saved); arendeDraftService.delete(fragaSvar.getIntygsReferens().getIntygsId(), Long.toString(fragaSvar.getInternReferens())); return saved; }  @Override FragaSvar processIncomingQuestion(FragaSvar fragaSvar); @Override FragaSvar processIncomingAnswer(Long internId, String svarsText, LocalDateTime svarSigneringsDatum); @Override @Transactional(readOnly = true) List<FragaSvarView> getFragaSvar(String intygId); @Override FragaSvar saveSvar(Long fragaSvarsId, String svarsText); @Override List<FragaSvarView> answerKomplettering(final String intygsId, final String svarsText); @Override FragaSvar saveNewQuestion(String intygId, String typ, Amne amne, String frageText); @Override List<FragaSvar> setVidareBefordrad(final String intygsId); @Override FragaSvar closeQuestionAsHandled(Long frageSvarId); @Override void closeCompletionsAsHandled(String intygId); @Override void closeAllNonClosedQuestions(String intygsId); @Override FragaSvar openQuestionAsUnhandled(Long frageSvarId); @Override @Transactional(readOnly = true) QueryFragaSvarResponse filterFragaSvar(Filter filter); @Override @Transactional(readOnly = true) List<Lakare> getFragaSvarHsaIdByEnhet(String enhetsId); @Override Map<String, Long> getNbrOfUnhandledFragaSvarForCareUnits(List<String> vardenheterIds, Set<String> intygsTyper);  }