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