use of se.inera.intyg.webcert.persistence.utkast.model.Utkast 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));
}
use of se.inera.intyg.webcert.persistence.utkast.model.Utkast in project webcert by sklintyg.
the class NotificationMessageFactoryTest method testCreateNotificationMessageForUtkast.
@Test
public void testCreateNotificationMessageForUtkast() {
Utkast utkast = createUtkast(INTYGS_ID);
String reference = "ref";
NotificationMessage msg = notificationMessageFactory.createNotificationMessage(utkast, HandelsekodEnum.SIGNAT, SchemaVersion.VERSION_1, reference, null, null);
assertNotNull(msg);
assertNotNull(msg.getHandelse());
assertEquals(HandelsekodEnum.SIGNAT, msg.getHandelse());
assertNotNull(msg.getHandelseTid());
assertEquals(INTYGS_ID, msg.getIntygsId());
assertEquals(INTYGS_TYP, msg.getIntygsTyp());
assertEquals("SE12345678-1000", msg.getLogiskAdress());
assertEquals("{model}", msg.getUtkast());
assertNotNull(msg.getFragaSvar());
assertEquals(SchemaVersion.VERSION_1, msg.getVersion());
assertEquals(reference, msg.getReference());
assertNotNull(msg.getFragaSvar());
assertNull(msg.getSkickadeFragor());
assertNull(msg.getMottagnaFragor());
assertNull(msg.getAmne());
assertNull(msg.getSistaSvarsDatum());
verifyZeroInteractions(mockFragorOchSvarCreator);
}
use of se.inera.intyg.webcert.persistence.utkast.model.Utkast in project webcert by sklintyg.
the class NotificationMessageFactoryTest method createUtkast.
private Utkast createUtkast(String intygId) {
VardpersonReferens vardperson = new VardpersonReferens();
vardperson.setHsaId("SE12345678-0000");
vardperson.setNamn("Dr Börje Dengroth");
Utkast utkast = new Utkast();
utkast.setIntygsId(intygId);
utkast.setIntygsTyp(INTYGS_TYP);
utkast.setEnhetsId("SE12345678-1000");
utkast.setEnhetsNamn("Vårdenhet 1");
utkast.setPatientPersonnummer(Personnummer.createPersonnummer("19121212-1212").get());
utkast.setPatientFornamn("Tolvan");
utkast.setPatientEfternamn("Tolvansson");
utkast.setStatus(UtkastStatus.DRAFT_INCOMPLETE);
utkast.setModel("{model}");
utkast.setSkapadAv(vardperson);
utkast.setSenastSparadAv(vardperson);
return utkast;
}
use of se.inera.intyg.webcert.persistence.utkast.model.Utkast in project webcert by sklintyg.
the class NotificationMessageFactoryTest method testCreateNotificationMessageForUsesFragorOchSvarSchemaVersion1.
@Test
public void testCreateNotificationMessageForUsesFragorOchSvarSchemaVersion1() {
when(mockFragorOchSvarCreator.createFragorOchSvar(INTYGS_ID)).thenReturn(new FragorOchSvar(1, 1, 1, 1));
Utkast utkast = createUtkast(INTYGS_ID);
final String reference = "ref";
NotificationMessage msg = notificationMessageFactory.createNotificationMessage(utkast, HandelsekodEnum.NYFRFM, SchemaVersion.VERSION_1, reference, null, null);
assertNotNull(msg);
assertNotNull(msg.getHandelse());
assertEquals(HandelsekodEnum.NYFRFM, msg.getHandelse());
assertNotNull(msg.getHandelseTid());
assertEquals(INTYGS_ID, msg.getIntygsId());
assertEquals(INTYGS_TYP, msg.getIntygsTyp());
assertEquals("SE12345678-1000", msg.getLogiskAdress());
assertEquals("{model}", msg.getUtkast());
assertEquals(SchemaVersion.VERSION_1, msg.getVersion());
assertEquals(reference, msg.getReference());
assertNotNull(msg.getFragaSvar());
assertEquals(1, msg.getFragaSvar().getAntalFragor());
assertEquals(1, msg.getFragaSvar().getAntalHanteradeFragor());
assertEquals(1, msg.getFragaSvar().getAntalHanteradeSvar());
assertEquals(1, msg.getFragaSvar().getAntalSvar());
assertNull(msg.getSkickadeFragor());
assertNull(msg.getMottagnaFragor());
assertNull(msg.getAmne());
assertNull(msg.getSistaSvarsDatum());
verify(mockFragorOchSvarCreator).createFragorOchSvar(INTYGS_ID);
verifyNoMoreInteractions(mockFragorOchSvarCreator);
}
use of se.inera.intyg.webcert.persistence.utkast.model.Utkast in project webcert by sklintyg.
the class NotificationServiceImplTest method testCreateAndSendNotification.
@Test
public void testCreateAndSendNotification() throws Exception {
ArgumentCaptor<MessageCreator> messageCreatorCaptor = ArgumentCaptor.forClass(MessageCreator.class);
when(mockSendNotificationStrategy.decideNotificationForIntyg(any(Utkast.class))).thenReturn(Optional.of(SchemaVersion.VERSION_1));
NotificationMessage notMsg = createNotificationMessage(HandelsekodEnum.ANDRAT, INTYG_JSON);
when(mockNotificationMessageFactory.createNotificationMessage(any(Utkast.class), eq(HandelsekodEnum.ANDRAT), eq(SchemaVersion.VERSION_1), anyString(), or(isNull(), any(Amneskod.class)), or(isNull(), any(LocalDate.class)))).thenReturn(notMsg);
Utkast utkast = createUtkast();
notificationService.createAndSendNotification(utkast, HandelsekodEnum.ANDRAT);
verify(template, only()).send(messageCreatorCaptor.capture());
TextMessage textMessage = mock(TextMessage.class);
Session session = mock(Session.class);
ArgumentCaptor<String> stringArgumentCaptor = ArgumentCaptor.forClass(String.class);
when(session.createTextMessage(stringArgumentCaptor.capture())).thenReturn(textMessage);
MessageCreator messageCreator = messageCreatorCaptor.getValue();
messageCreator.createMessage(session);
// get the notfication message as json and transform it back to object
NotificationMessage captNotMsg = objectMapper.readValue(stringArgumentCaptor.getValue(), NotificationMessage.class);
// assert that things are still there
assertNotNull(captNotMsg);
assertEquals(INTYG_ID, captNotMsg.getIntygsId());
assertEquals(HandelsekodEnum.ANDRAT, captNotMsg.getHandelse());
assertEquals(INTYG_JSON, captNotMsg.getUtkast());
assertEquals(SchemaVersion.VERSION_1, captNotMsg.getVersion());
assertNull(captNotMsg.getReference());
// verify call has been made
verify(mockNotificationMessageFactory).createNotificationMessage(any(Utkast.class), eq(HandelsekodEnum.ANDRAT), eq(SchemaVersion.VERSION_1), anyString(), or(isNull(), any(Amneskod.class)), or(isNull(), any(LocalDate.class)));
verify(handelseRepository).save(any(Handelse.class));
}
Aggregations