Search in sources :

Example 21 with NotificationMessage

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);
}
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) ArendeCount(se.inera.intyg.common.support.modules.support.api.notification.ArendeCount)

Example 22 with NotificationMessage

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);
}
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 23 with NotificationMessage

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

Example 24 with NotificationMessage

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)));
}
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) Session(javax.jms.Session) Test(org.junit.Test)

Example 25 with NotificationMessage

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)));
}
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)

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