use of se.inera.intyg.common.support.modules.support.api.notification.NotificationMessage 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.common.support.modules.support.api.notification.NotificationMessage 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.common.support.modules.support.api.notification.NotificationMessage 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));
}
use of se.inera.intyg.common.support.modules.support.api.notification.NotificationMessage in project webcert by sklintyg.
the class NotificationServiceImplTest method createNotificationMessage.
private NotificationMessage createNotificationMessage(HandelsekodEnum handelse, String utkastJson) {
FragorOchSvar fs = FragorOchSvar.getEmpty();
LocalDateTime time = LocalDateTime.of(2001, 12, 31, 12, 34, 56, 789);
NotificationMessage notMsg = new NotificationMessage(INTYG_ID, INTYG_TYP_FK, time, handelse, LOGISK_ADDR, utkastJson, fs, null, null, SchemaVersion.VERSION_1, null);
return notMsg;
}
use of se.inera.intyg.common.support.modules.support.api.notification.NotificationMessage in project webcert by sklintyg.
the class NotificationServiceImplTest method verifySuccessfulInvocations.
private void verifySuccessfulInvocations(HandelsekodEnum kod, SchemaVersion schemaVersion) throws Exception {
verify(mockNotificationMessageFactory).createNotificationMessage(any(Utkast.class), eq(kod), eq(schemaVersion), anyString(), or(isNull(), any(Amneskod.class)), or(isNull(), any(LocalDate.class)));
ArgumentCaptor<MessageCreator> messageCaptor = ArgumentCaptor.forClass(MessageCreator.class);
verify(template).send(messageCaptor.capture());
Message res = messageCaptor.getValue().createMessage(session);
assertEquals(INTYG_ID, res.getStringProperty(NotificationRouteHeaders.INTYGS_ID));
assertEquals(INTYG_TYP_FK, res.getStringProperty(NotificationRouteHeaders.INTYGS_TYP));
assertEquals(kod.value(), res.getStringProperty(NotificationRouteHeaders.HANDELSE));
assertNotNull(((TextMessage) res).getText());
NotificationMessage nm = objectMapper.readValue(((TextMessage) res).getText(), NotificationMessage.class);
assertEquals(INTYG_JSON, nm.getUtkast());
verify(mockMonitoringLogService).logNotificationSent(kod.value(), ENHET_ID);
verify(handelseRepository).save(any(Handelse.class));
}
Aggregations