Search in sources :

Example 21 with InboundMessage

use of uk.nhs.adaptors.pss.translator.mhs.model.InboundMessage in project nia-patient-switching-standard-adaptor by NHSDigital.

the class AcknowledgmentMessageHandlerTest method handleMessageWithUnknownTypeCode.

@Test
public void handleMessageWithUnknownTypeCode() throws SAXException {
    inboundMessage = new InboundMessage();
    prepareXPathServiceMocks("unknown type");
    acknowledgmentMessageHandler.handleMessage(inboundMessage, CONVERSATION_ID);
    verifyNoInteractions(migrationStatusLogService);
}
Also used : InboundMessage(uk.nhs.adaptors.pss.translator.mhs.model.InboundMessage) Test(org.junit.jupiter.api.Test)

Example 22 with InboundMessage

use of uk.nhs.adaptors.pss.translator.mhs.model.InboundMessage in project nia-patient-switching-standard-adaptor by NHSDigital.

the class COPCMessageHandlerTest method prepareFragmentIndexWithCidMocks.

@SneakyThrows
private void prepareFragmentIndexWithCidMocks(InboundMessage message) {
    prepareMocks();
    message.setPayload(readXmlFile("inbound_message_payload_fragment_index.xml"));
    String ebxml = readXmlFile("inbound_message_ebxml_fragment_index.xml");
    message.setEbXML(ebxml);
    InboundMessage.Attachment attachment = new InboundMessage.Attachment("text/plain", "Yes", "Filename=\"CBBAE92D-C7E8-4A9C-8887-F5AEBA1F8CE1_0.messageattachment\" ContentType=application/x-gzip" + "Compressed=No LargeAttachment=No OriginalBase64=Yes", "ABC Not Required");
    InboundMessage.ExternalAttachment extAttachment = new InboundMessage.ExternalAttachment("CBBAE92D-C7E8-4A9C-8887-F5AEBA1F8CE1", "28B31-4245-4AFC-8DA2-8A40623A5101", "E39E79A2-FA96-48FF-9373-7BBCB9D036E7_0.messageattachment", "Filename=E39E79A2-FA96-48FF" + "-9373-7BBCB9D036E7_0.messageattachment ContentType=text/plain Compressed=No LargeAttachment=No OriginalBase64=Yes");
    message.setAttachments(Arrays.asList(attachment));
    message.setExternalAttachments(Arrays.asList(extAttachment));
    when(xPathService.parseDocumentFromXml(message.getEbXML())).thenReturn(ebXmlDocument);
    when(xPathService.getNodeValue(ebXmlDocument, "/Envelope/Header/MessageHeader/MessageData/MessageId")).thenReturn("CBBAE92D-C7E8-4A9C-8887-F5AEBA1F8CE1");
    when(xPathService.getNodeValue(ebXmlDocument, "/Envelope/Body/Manifest/Reference[position()=2]/Description")).thenReturn("Filename=blah");
    when(patientAttachmentLogService.findAttachmentLogs(CONVERSATION_ID)).thenReturn(Arrays.asList(buildPatientAttachmentLog("047C22B4-613F-47D3-9A72-44A1758464FB", "CBBAE92D-C7E8-4A9C-8887-F5AEBA1F8CE1", 0, true, true), buildPatientAttachmentLog("057C22B4-613F-47D3-9A72-44A1758464FB", "CBBAE92D-C7E8-4A9C-8887-F5AEBA1F8CE1", 1, false, true)));
}
Also used : InboundMessage(uk.nhs.adaptors.pss.translator.mhs.model.InboundMessage) FileUtil.readResourceAsString(uk.nhs.adaptors.common.util.FileUtil.readResourceAsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SneakyThrows(lombok.SneakyThrows)

Example 23 with InboundMessage

use of uk.nhs.adaptors.pss.translator.mhs.model.InboundMessage in project nia-patient-switching-standard-adaptor by NHSDigital.

the class COPCMessageHandlerTest method When_MIDFragmentRecordDoesNotHaveAnAttachmentLog_Expect_AttachmentLogToBeCreated.

@Test
public void When_MIDFragmentRecordDoesNotHaveAnAttachmentLog_Expect_AttachmentLogToBeCreated() throws JAXBException, InlineAttachmentProcessingException, SAXException, AttachmentLogException, AttachmentNotFoundException, BundleMappingException, JsonProcessingException {
    var childMid = "28B31-4245-4AFC-8DA2-8A40623A5101";
    InboundMessage message = new InboundMessage();
    prepareFragmentIndexMocks(message);
    when(patientAttachmentLogService.findAttachmentLog(MESSAGE_ID, CONVERSATION_ID)).thenReturn(buildPatientAttachmentLog("CBBAE92D-C7E8-4A9C-8887-F5AEBA1F8CE1", null, true));
    when(patientAttachmentLogService.findAttachmentLog(childMid, CONVERSATION_ID)).thenReturn(null);
    when(patientAttachmentLogService.findAttachmentLog("CBBAE92D-C7E8-4A9C-8887-F5AEBA1F8CE1", CONVERSATION_ID)).thenReturn(buildPatientAttachmentLog("047C22B4-613F-47D3-9A72-44A1758464FB", "CBBAE92D-C7E8-4A9C-8887-F5AEBA1F8CE1", true));
    EbxmlReference reference = new EbxmlReference("First instance is always a payload", "mid:xxxx-xxxx-xxxx-xxxx", "docId");
    EbxmlReference reference2 = new EbxmlReference("desc", "mid:28B31-4245-4AFC-8DA2-8A40623A5101", "docId");
    List<EbxmlReference> attachmentReferenceDescription = new ArrayList<>();
    attachmentReferenceDescription.add(reference);
    attachmentReferenceDescription.add(reference2);
    when(xmlParseUtilService.getEbxmlAttachmentsData(any())).thenReturn(attachmentReferenceDescription);
    copcMessageHandler.handleMessage(message, CONVERSATION_ID);
    verify(patientAttachmentLogService).addAttachmentLog(patientLogCaptor.capture());
    PatientAttachmentLog actual = patientLogCaptor.getValue();
    assertEquals(childMid, actual.getMid());
    assertEquals("E39E79A2-FA96-48FF-9373-7BBCB9D036E7_0.messageattachment", actual.getFilename());
    assertEquals("047C22B4-613F-47D3-9A72-44A1758464FB", actual.getParentMid());
    assertEquals(1, actual.getPatientMigrationReqId());
    assertEquals("text/plain", actual.getContentType());
    assertThat(actual.getCompressed()).isFalse();
    assertThat(actual.getLargeAttachment()).isTrue();
    assertThat(actual.getBase64()).isTrue();
    assertEquals(0, actual.getOrderNum());
}
Also used : PatientAttachmentLog(uk.nhs.adaptors.connector.model.PatientAttachmentLog) ArrayList(java.util.ArrayList) InboundMessage(uk.nhs.adaptors.pss.translator.mhs.model.InboundMessage) EbxmlReference(uk.nhs.adaptors.pss.translator.model.EbxmlReference) Test(org.junit.jupiter.api.Test)

Example 24 with InboundMessage

use of uk.nhs.adaptors.pss.translator.mhs.model.InboundMessage in project nia-patient-switching-standard-adaptor by NHSDigital.

the class COPCMessageHandlerTest method When_FragmentIndexIsRecievedWithCIDAndMIDParts_Expect_CIDMessageToBeProcessed.

@Test
public void When_FragmentIndexIsRecievedWithCIDAndMIDParts_Expect_CIDMessageToBeProcessed() throws JAXBException, InlineAttachmentProcessingException, SAXException, AttachmentLogException, AttachmentNotFoundException, BundleMappingException, JsonProcessingException {
    var childMid = "28B31-4245-4AFC-8DA2-8A40623A5101";
    var childCid = "435B1171-31F6-4EF2-AD7F-C7E64EEFF357";
    InboundMessage message = new InboundMessage();
    prepareFragmentIndexWithCidMocks(message);
    when(patientAttachmentLogService.findAttachmentLog(MESSAGE_ID, CONVERSATION_ID)).thenReturn(buildPatientAttachmentLog("CBBAE92D-C7E8-4A9C-8887-F5AEBA1F8CE1", null, true));
    when(patientAttachmentLogService.findAttachmentLog(childMid, CONVERSATION_ID)).thenReturn(null);
    when(patientAttachmentLogService.findAttachmentLog(childCid, CONVERSATION_ID)).thenReturn(null);
    when(patientAttachmentLogService.findAttachmentLog("CBBAE92D-C7E8-4A9C-8887-F5AEBA1F8CE1", CONVERSATION_ID)).thenReturn(buildPatientAttachmentLog("047C22B4-613F-47D3-9A72-44A1758464FB", "CBBAE92D-C7E8-4A9C-8887-F5AEBA1F8CE1", true));
    EbxmlReference reference = new EbxmlReference("First instance is always a payload", "mid:xxxx-xxxx-xxxx-xxxx", "docId");
    EbxmlReference reference1 = new EbxmlReference("desc", "cid:435B1171-31F6-4EF2-AD7F-C7E64EEFF357", "doc1Id");
    EbxmlReference reference2 = new EbxmlReference("desc", "mid:28B31-4245-4AFC-8DA2-8A40623A5101", "doc2Id");
    List<EbxmlReference> attachmentReferenceDescription = new ArrayList<>();
    attachmentReferenceDescription.add(reference);
    attachmentReferenceDescription.add(reference1);
    attachmentReferenceDescription.add(reference2);
    when(xmlParseUtilService.getEbxmlAttachmentsData(any())).thenReturn(attachmentReferenceDescription);
    copcMessageHandler.handleMessage(message, CONVERSATION_ID);
    verify(attachmentHandlerService).storeAttachments(message.getAttachments(), CONVERSATION_ID);
    verify(patientAttachmentLogService, times(2)).addAttachmentLog(patientLogCaptor.capture());
    PatientAttachmentLog actualCidAttachmentLog = patientLogCaptor.getAllValues().get(0);
    PatientAttachmentLog actualMidAttachmentLog = patientLogCaptor.getAllValues().get(1);
    assertEquals(childCid, actualCidAttachmentLog.getMid());
    assertEquals(childMid, actualMidAttachmentLog.getMid());
}
Also used : PatientAttachmentLog(uk.nhs.adaptors.connector.model.PatientAttachmentLog) ArrayList(java.util.ArrayList) InboundMessage(uk.nhs.adaptors.pss.translator.mhs.model.InboundMessage) EbxmlReference(uk.nhs.adaptors.pss.translator.model.EbxmlReference) Test(org.junit.jupiter.api.Test)

Example 25 with InboundMessage

use of uk.nhs.adaptors.pss.translator.mhs.model.InboundMessage in project nia-patient-switching-standard-adaptor by NHSDigital.

the class COPCMessageHandlerTest method prepareFragmentIndexMocks.

@SneakyThrows
private void prepareFragmentIndexMocks(InboundMessage message) {
    prepareMocks();
    message.setPayload(readXmlFile("inbound_message_payload_fragment_index.xml"));
    String ebxml = readXmlFile("inbound_message_ebxml_fragment_index.xml");
    message.setEbXML(ebxml);
    InboundMessage.ExternalAttachment extAttachment = new InboundMessage.ExternalAttachment("CBBAE92D-C7E8-4A9C-8887-F5AEBA1F8CE1", "28B31-4245-4AFC-8DA2-8A40623A5101", "E39E79A2-FA96-48FF-9373-7BBCB9D036E7_0.messageattachment", "Filename=E39E79A2-FA96-48FF" + "-9373-7BBCB9D036E7_0.messageattachment ContentType=text/plain Compressed=No LargeAttachment=No OriginalBase64=Yes");
    message.setExternalAttachments(Arrays.asList(extAttachment));
    when(xPathService.parseDocumentFromXml(message.getEbXML())).thenReturn(ebXmlDocument);
    when(xPathService.getNodeValue(ebXmlDocument, "/Envelope/Header/MessageHeader/MessageData/MessageId")).thenReturn("CBBAE92D-C7E8-4A9C-8887-F5AEBA1F8CE1");
    when(xPathService.getNodeValue(ebXmlDocument, "/Envelope/Body/Manifest/Reference[position()=2]/Description")).thenReturn("Filename=blah");
    when(patientAttachmentLogService.findAttachmentLogs(CONVERSATION_ID)).thenReturn(Arrays.asList(buildPatientAttachmentLog("047C22B4-613F-47D3-9A72-44A1758464FB", "CBBAE92D-C7E8-4A9C-8887-F5AEBA1F8CE1", 0, true, true), buildPatientAttachmentLog("057C22B4-613F-47D3-9A72-44A1758464FB", "CBBAE92D-C7E8-4A9C-8887-F5AEBA1F8CE1", 1, false, true)));
}
Also used : InboundMessage(uk.nhs.adaptors.pss.translator.mhs.model.InboundMessage) FileUtil.readResourceAsString(uk.nhs.adaptors.common.util.FileUtil.readResourceAsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SneakyThrows(lombok.SneakyThrows)

Aggregations

InboundMessage (uk.nhs.adaptors.pss.translator.mhs.model.InboundMessage)36 Test (org.junit.jupiter.api.Test)27 ArrayList (java.util.ArrayList)9 PatientAttachmentLog (uk.nhs.adaptors.connector.model.PatientAttachmentLog)8 Bundle (org.hl7.fhir.dstu3.model.Bundle)6 RCMRIN030000UK06Message (org.hl7.v3.RCMRIN030000UK06Message)6 SAXException (org.xml.sax.SAXException)6 PatientMigrationRequest (uk.nhs.adaptors.connector.model.PatientMigrationRequest)6 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)5 JAXBException (javax.xml.bind.JAXBException)5 BundleMappingException (uk.nhs.adaptors.pss.translator.exception.BundleMappingException)5 InlineAttachmentProcessingException (uk.nhs.adaptors.pss.translator.exception.InlineAttachmentProcessingException)5 EbxmlReference (uk.nhs.adaptors.pss.translator.model.EbxmlReference)5 ParseException (java.text.ParseException)4 Document (org.w3c.dom.Document)4 FileUtil.readResourceAsString (uk.nhs.adaptors.common.util.FileUtil.readResourceAsString)4 AttachmentNotFoundException (uk.nhs.adaptors.pss.translator.exception.AttachmentNotFoundException)4 XmlUnmarshallUtil.unmarshallString (uk.nhs.adaptors.pss.translator.util.XmlUnmarshallUtil.unmarshallString)4 DataFormatException (ca.uhn.fhir.parser.DataFormatException)3 AttachmentLogException (uk.nhs.adaptors.pss.translator.exception.AttachmentLogException)3