use of se.inera.intyg.common.support.modules.support.api.notification.NotificationMessage in project webcert by sklintyg.
the class NotificationMessageFactoryImpl method createNotificationMessage.
@Override
public NotificationMessage createNotificationMessage(Utkast utkast, HandelsekodEnum handelse, SchemaVersion version, String reference, Amneskod amne, LocalDate sistaSvarsDatum) {
String intygsId = utkast.getIntygsId();
String intygsTyp = utkast.getIntygsTyp();
LocalDateTime handelseTid = LocalDateTime.now();
String logiskAdress = utkast.getEnhetsId();
String utkastJson = utkast.getModel();
FragorOchSvar fragaSvar = null;
ArendeCount skickadeFragor = null;
ArendeCount mottagnaFragor = null;
if (SchemaVersion.VERSION_3 == version) {
Pair<ArendeCount, ArendeCount> arenden = Pair.of(ArendeCount.getEmpty(), ArendeCount.getEmpty());
// Add a count of questions to the message
if (USES_FRAGOR_OCH_SVAR.contains(handelse)) {
arenden = fragorOchSvarCreator.createArenden(intygsId, intygsTyp);
}
skickadeFragor = arenden.getLeft();
mottagnaFragor = arenden.getRight();
} else {
fragaSvar = FragorOchSvar.getEmpty();
// Add a count of questions to the message
if (USES_FRAGOR_OCH_SVAR.contains(handelse)) {
fragaSvar = fragorOchSvarCreator.createFragorOchSvar(intygsId);
}
}
return new NotificationMessage(intygsId, intygsTyp, handelseTid, handelse, logiskAdress, utkastJson, fragaSvar, skickadeFragor, mottagnaFragor, version, reference, amne, sistaSvarsDatum);
}
use of se.inera.intyg.common.support.modules.support.api.notification.NotificationMessage in project webcert by sklintyg.
the class NotificationMessageFactoryTest method testCreateNotificationMessageForUtkastSchemaVersion3.
@Test
public void testCreateNotificationMessageForUtkastSchemaVersion3() {
Utkast utkast = createUtkast(INTYGS_ID);
String reference = "ref";
NotificationMessage msg = notificationMessageFactory.createNotificationMessage(utkast, HandelsekodEnum.SIGNAT, SchemaVersion.VERSION_3, 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());
assertEquals(SchemaVersion.VERSION_3, msg.getVersion());
assertEquals(reference, msg.getReference());
assertNull(msg.getFragaSvar());
assertNotNull(msg.getSkickadeFragor());
assertNotNull(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 testCreateNotificationMessageForUsesFragorOchSvarSchemaVersion3.
@Test
public void testCreateNotificationMessageForUsesFragorOchSvarSchemaVersion3() {
when(mockFragorOchSvarCreator.createArenden(INTYGS_ID, INTYGS_TYP)).thenReturn(Pair.of(new ArendeCount(1, 1, 1, 1), new ArendeCount(2, 2, 2, 2)));
Utkast utkast = createUtkast(INTYGS_ID);
final String reference = "ref";
NotificationMessage msg = notificationMessageFactory.createNotificationMessage(utkast, HandelsekodEnum.NYFRFV, SchemaVersion.VERSION_3, reference, null, null);
assertNotNull(msg);
assertNotNull(msg.getHandelse());
assertEquals(HandelsekodEnum.NYFRFV, 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_3, msg.getVersion());
assertEquals(reference, msg.getReference());
assertNull(msg.getFragaSvar());
assertNotNull(msg.getSkickadeFragor());
assertEquals(1, msg.getSkickadeFragor().getTotalt());
assertEquals(1, msg.getSkickadeFragor().getBesvarade());
assertEquals(1, msg.getSkickadeFragor().getEjBesvarade());
assertEquals(1, msg.getSkickadeFragor().getHanterade());
assertNotNull(msg.getMottagnaFragor());
assertEquals(2, msg.getMottagnaFragor().getTotalt());
assertEquals(2, msg.getMottagnaFragor().getBesvarade());
assertEquals(2, msg.getMottagnaFragor().getEjBesvarade());
assertEquals(2, msg.getMottagnaFragor().getHanterade());
verify(mockFragorOchSvarCreator).createArenden(INTYGS_ID, INTYGS_TYP);
verifyNoMoreInteractions(mockFragorOchSvarCreator);
}
use of se.inera.intyg.common.support.modules.support.api.notification.NotificationMessage in project webcert by sklintyg.
the class NotificationServiceImplTest method testCreateAndSendNotificationWithReference.
@Test
public void testCreateAndSendNotificationWithReference() 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);
notMsg.setReference(USER_REFERENCE);
when(mockNotificationMessageFactory.createNotificationMessage(any(Utkast.class), eq(HandelsekodEnum.ANDRAT), eq(SchemaVersion.VERSION_1), eq(USER_REFERENCE), 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());
assertEquals(USER_REFERENCE, captNotMsg.getReference());
// verify call has been made
verify(mockNotificationMessageFactory).createNotificationMessage(any(Utkast.class), eq(HandelsekodEnum.ANDRAT), eq(SchemaVersion.VERSION_1), eq(USER_REFERENCE), or(isNull(), any(Amneskod.class)), or(isNull(), any(LocalDate.class)));
}
use of se.inera.intyg.common.support.modules.support.api.notification.NotificationMessage in project webcert by sklintyg.
the class NotificationServiceImplTest method testIntygsutkastCreated.
@Test
public void testIntygsutkastCreated() throws Exception {
when(mockSendNotificationStrategy.decideNotificationForIntyg(any(Utkast.class))).thenReturn(Optional.of(SchemaVersion.VERSION_3));
NotificationMessage notMsg = createNotificationMessage(HandelsekodEnum.SKAPAT, INTYG_JSON);
notMsg.setReference(USER_REFERENCE);
when(mockNotificationMessageFactory.createNotificationMessage(any(Utkast.class), eq(HandelsekodEnum.SKAPAT), eq(SchemaVersion.VERSION_3), eq(USER_REFERENCE), or(isNull(), any(Amneskod.class)), or(isNull(), any(LocalDate.class)))).thenReturn(notMsg);
notificationService.sendNotificationForDraftCreated(createUtkast());
// verify call has been made
verify(mockNotificationMessageFactory).createNotificationMessage(any(Utkast.class), eq(HandelsekodEnum.SKAPAT), eq(SchemaVersion.VERSION_3), eq(USER_REFERENCE), or(isNull(), any(Amneskod.class)), or(isNull(), any(LocalDate.class)));
}
Aggregations