Search in sources :

Example 16 with NotificationMessage

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);
}
Also used : NotificationMessage(se.inera.intyg.common.support.modules.support.api.notification.NotificationMessage) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) Test(org.junit.Test)

Example 17 with NotificationMessage

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);
}
Also used : FragorOchSvar(se.inera.intyg.common.support.modules.support.api.notification.FragorOchSvar) NotificationMessage(se.inera.intyg.common.support.modules.support.api.notification.NotificationMessage) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) Test(org.junit.Test)

Example 18 with NotificationMessage

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));
}
Also used : NotificationMessage(se.inera.intyg.common.support.modules.support.api.notification.NotificationMessage) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MessageCreator(org.springframework.jms.core.MessageCreator) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) TextMessage(javax.jms.TextMessage) Handelse(se.inera.intyg.webcert.persistence.handelse.model.Handelse) Session(javax.jms.Session) Test(org.junit.Test)

Example 19 with NotificationMessage

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;
}
Also used : LocalDateTime(java.time.LocalDateTime) FragorOchSvar(se.inera.intyg.common.support.modules.support.api.notification.FragorOchSvar) NotificationMessage(se.inera.intyg.common.support.modules.support.api.notification.NotificationMessage)

Example 20 with NotificationMessage

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));
}
Also used : NotificationMessage(se.inera.intyg.common.support.modules.support.api.notification.NotificationMessage) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) NotificationMessage(se.inera.intyg.common.support.modules.support.api.notification.NotificationMessage) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) MessageCreator(org.springframework.jms.core.MessageCreator) Handelse(se.inera.intyg.webcert.persistence.handelse.model.Handelse)

Aggregations

NotificationMessage (se.inera.intyg.common.support.modules.support.api.notification.NotificationMessage)32 Test (org.junit.Test)21 LocalDateTime (java.time.LocalDateTime)8 Message (org.apache.camel.Message)8 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)8 DefaultMessage (org.apache.camel.impl.DefaultMessage)5 ArendeCount (se.inera.intyg.common.support.modules.support.api.notification.ArendeCount)5 Intyg (se.riv.clinicalprocess.healthcond.certificate.v3.Intyg)5 TextMessage (javax.jms.TextMessage)3 ActiveMQTextMessage (org.apache.activemq.command.ActiveMQTextMessage)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 MessageCreator (org.springframework.jms.core.MessageCreator)3 HandelsekodEnum (se.inera.intyg.common.support.common.enumerations.HandelsekodEnum)3 FragorOchSvar (se.inera.intyg.common.support.modules.support.api.notification.FragorOchSvar)3 NotificationStubEntry (se.inera.intyg.webcert.notification_sender.mocks.NotificationStubEntry)3 CertificateStatusUpdateForCareType (se.riv.clinicalprocess.healthcond.certificate.certificatestatusupdateforcareresponder.v3.CertificateStatusUpdateForCareType)3 Session (javax.jms.Session)2 ModuleApi (se.inera.intyg.common.support.modules.support.api.ModuleApi)2 Handelse (se.inera.intyg.webcert.persistence.handelse.model.Handelse)2 CertificateStatusUpdateForCareType (se.riv.clinicalprocess.healthcond.certificate.certificatestatusupdateforcareresponder.v1.CertificateStatusUpdateForCareType)2