use of se.inera.intyg.common.support.model.common.internal.HoSPersonal in project webcert by sklintyg.
the class UtkastServiceImplTest method testSaveDoesNotUpdateOnEmptyFornamn.
@Test
public void testSaveDoesNotUpdateOnEmptyFornamn() throws Exception {
final String utkastFornamn = "fornamn";
final String utkastEfternamn = "efternamn";
ValidateDraftResponse validationResponse = new ValidateDraftResponse(ValidationStatus.VALID, Collections.emptyList());
WebCertUser user = createUser();
Utlatande utlatande = mock(Utlatande.class);
GrundData grunddata = new GrundData();
grunddata.setSkapadAv(new HoSPersonal());
grunddata.setPatient(buildPatient(PERSON_ID, null, "Tolvansson"));
when(utlatande.getGrundData()).thenReturn(grunddata);
utkast.setPatientFornamn(utkastFornamn);
utkast.setPatientEfternamn(utkastEfternamn);
// Make a spy out of the utkast so we can verify invocations on the setters with proper names further down.
utkast = spy(utkast);
when(mockUtkastRepository.findOne(INTYG_ID)).thenReturn(utkast);
when(moduleRegistry.getModuleApi(INTYG_TYPE)).thenReturn(mockModuleApi);
when(mockModuleApi.validateDraft(anyString())).thenReturn(validationResponse);
when(mockModuleApi.getUtlatandeFromJson(anyString())).thenReturn(utlatande);
when(mockUtkastRepository.save(utkast)).thenReturn(utkast);
when(userService.getUser()).thenReturn(user);
when(mockModuleApi.updateBeforeSave(anyString(), any(HoSPersonal.class))).thenReturn("{}");
draftService.saveDraft(INTYG_ID, UTKAST_VERSION, INTYG_JSON, false);
verify(mockUtkastRepository).save(any(Utkast.class));
verify(utkast, times(0)).setPatientFornamn(null);
verify(utkast, times(0)).setPatientEfternamn("Tolvansson");
verify(utkast).setPatientPersonnummer(any(Personnummer.class));
}
use of se.inera.intyg.common.support.model.common.internal.HoSPersonal in project webcert by sklintyg.
the class UtkastServiceImplTest method testSaveDraftDraftFirstSave.
@Test
public void testSaveDraftDraftFirstSave() throws Exception {
ValidationMessage valMsg = new ValidationMessage("a.category", "a.field.somewhere", ValidationMessageType.OTHER, "This is soooo wrong!");
ValidateDraftResponse validationResponse = new ValidateDraftResponse(ValidationStatus.INVALID, Collections.singletonList(valMsg));
WebCertUser user = createUser();
Utlatande utlatande = mock(Utlatande.class);
GrundData grunddata = new GrundData();
grunddata.setSkapadAv(new HoSPersonal());
grunddata.setPatient(defaultPatient);
when(utlatande.getGrundData()).thenReturn(grunddata);
when(mockUtkastRepository.findOne(INTYG_ID)).thenReturn(utkast);
when(moduleRegistry.getModuleApi(INTYG_TYPE)).thenReturn(mockModuleApi);
when(mockModuleApi.validateDraft(anyString())).thenReturn(validationResponse);
when(mockModuleApi.getUtlatandeFromJson(anyString())).thenReturn(utlatande);
when(mockUtkastRepository.save(utkast)).thenReturn(utkast);
when(mockModuleApi.shouldNotify(any(String.class), any(String.class))).thenReturn(true);
when(userService.getUser()).thenReturn(user);
when(mockModuleApi.updateBeforeSave(anyString(), any(HoSPersonal.class))).thenReturn("{}");
SaveDraftResponse res = draftService.saveDraft(INTYG_ID, UTKAST_VERSION, INTYG_JSON, true);
verify(mockUtkastRepository).save(any(Utkast.class));
// Assert notification message
verify(notificationService).sendNotificationForDraftChanged(any(Utkast.class));
// Assert pdl log
verify(logService).logUpdateIntyg(any(LogRequest.class));
verify(mockMonitoringService).logUtkastEdited(INTYG_ID, INTYG_TYPE);
assertNotNull("An DraftValidation should be returned", res);
assertEquals("Validation should fail", UtkastStatus.DRAFT_INCOMPLETE, res.getStatus());
}
use of se.inera.intyg.common.support.model.common.internal.HoSPersonal in project webcert by sklintyg.
the class UtkastServiceImplTest method testUpdatePatientOnDraftNoMedarbetaruppdragThrowsException.
@Test(expected = WebCertServiceException.class)
public void testUpdatePatientOnDraftNoMedarbetaruppdragThrowsException() throws Exception {
utkast.setEnhetsId("<unknownenhet>");
Patient newPatient = getUpdatedPatient();
UpdatePatientOnDraftRequest request = new UpdatePatientOnDraftRequest(newPatient.getPersonId(), utkast.getIntygsId(), utkast.getVersion());
WebCertUser user = createUser();
Utlatande utlatande = mock(Utlatande.class);
GrundData grunddata = new GrundData();
grunddata.setPatient(defaultPatient);
grunddata.setSkapadAv(new HoSPersonal());
// Make a spy out of the utkast so we can verify invocations on the setters with proper names further down.
utkast = spy(utkast);
when(mockUtkastRepository.findOne(INTYG_ID)).thenReturn(utkast);
when(userService.getUser()).thenReturn(user);
draftService.updatePatientOnDraft(request);
verifyNoMoreInteractions(mockUtkastRepository, notificationService);
}
use of se.inera.intyg.common.support.model.common.internal.HoSPersonal in project webcert by sklintyg.
the class UtkastServiceImplTest method testSaveDraftWithExceptionInModule.
@SuppressWarnings("unchecked")
@Test(expected = WebCertServiceException.class)
public void testSaveDraftWithExceptionInModule() throws Exception {
WebCertUser user = createUser();
Utlatande utlatande = mock(Utlatande.class);
GrundData grunddata = new GrundData();
grunddata.setSkapadAv(new HoSPersonal());
grunddata.setPatient(defaultPatient);
when(utlatande.getGrundData()).thenReturn(grunddata);
when(userService.getUser()).thenReturn(user);
when(mockUtkastRepository.findOne(INTYG_ID)).thenReturn(utkast);
when(moduleRegistry.getModuleApi(INTYG_TYPE)).thenReturn(mockModuleApi);
when(mockModuleApi.updateBeforeSave(anyString(), any(HoSPersonal.class))).thenReturn("{}");
when(mockModuleApi.getUtlatandeFromJson(anyString())).thenReturn(utlatande);
when(mockModuleApi.validateDraft(anyString())).thenThrow(ModuleException.class);
draftService.saveDraft(INTYG_ID, UTKAST_VERSION, INTYG_JSON, false);
}
use of se.inera.intyg.common.support.model.common.internal.HoSPersonal in project webcert by sklintyg.
the class UtkastServiceImplTest method testSaveUpdatesChangedPatientName.
@Test
public void testSaveUpdatesChangedPatientName() throws Exception {
ValidateDraftResponse validationResponse = new ValidateDraftResponse(ValidationStatus.VALID, Collections.emptyList());
WebCertUser user = createUser();
Utlatande utlatande = mock(Utlatande.class);
GrundData grunddata = new GrundData();
grunddata.setSkapadAv(new HoSPersonal());
grunddata.setPatient(buildPatient(PERSON_ID, "Tolvan", "Tolvansson"));
when(utlatande.getGrundData()).thenReturn(grunddata);
utkast.setPatientFornamn("Inte Tolvan");
utkast.setPatientEfternamn("Inte Tolvansson");
// Make a spy out of the utkast so we can verify invocations on the setters with proper names further down.
utkast = spy(utkast);
when(mockUtkastRepository.findOne(INTYG_ID)).thenReturn(utkast);
when(moduleRegistry.getModuleApi(INTYG_TYPE)).thenReturn(mockModuleApi);
when(mockModuleApi.validateDraft(anyString())).thenReturn(validationResponse);
when(mockModuleApi.getUtlatandeFromJson(anyString())).thenReturn(utlatande);
when(mockUtkastRepository.save(utkast)).thenReturn(utkast);
when(userService.getUser()).thenReturn(user);
when(mockModuleApi.updateBeforeSave(anyString(), any(HoSPersonal.class))).thenReturn("{}");
draftService.saveDraft(INTYG_ID, UTKAST_VERSION, INTYG_JSON, false);
verify(mockUtkastRepository).save(any(Utkast.class));
verify(utkast).setPatientFornamn("Tolvan");
verify(utkast).setPatientEfternamn("Tolvansson");
verify(utkast).setPatientPersonnummer(any(Personnummer.class));
}
Aggregations