Search in sources :

Example 1 with InboundMessage

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

the class EhrExtractMessageHandlerTest method When_HandleMessageWithValidDataIsCalled_Expect_CallsBundleMapperServiceMapToBundle.

@Test
public void When_HandleMessageWithValidDataIsCalled_Expect_CallsBundleMapperServiceMapToBundle() throws JsonProcessingException, JAXBException, InlineAttachmentProcessingException, BundleMappingException, AttachmentNotFoundException, ParseException, SAXException {
    InboundMessage inboundMessage = new InboundMessage();
    prepareMocks(inboundMessage);
    ehrExtractMessageHandler.handleMessage(inboundMessage, CONVERSATION_ID);
    // mapped item is private to the class, so we cannot test an exact object
    verify(bundleMapperService).mapToBundle(any(RCMRIN030000UK06Message.class), any());
}
Also used : InboundMessage(uk.nhs.adaptors.pss.translator.mhs.model.InboundMessage) RCMRIN030000UK06Message(org.hl7.v3.RCMRIN030000UK06Message) Test(org.junit.jupiter.api.Test)

Example 2 with InboundMessage

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

the class EhrExtractMessageHandlerTest method When_HandleMessage_WithEncodeToJsonThrows_Expect_DataFormatException.

@Test
public void When_HandleMessage_WithEncodeToJsonThrows_Expect_DataFormatException() throws BundleMappingException, AttachmentNotFoundException, ValidationException, InlineAttachmentProcessingException {
    InboundMessage inboundMessage = new InboundMessage();
    inboundMessage.setPayload(readInboundMessagePayloadFromFile());
    Bundle bundle = new Bundle();
    bundle.setId("Test");
    inboundMessage.setPayload(readInboundMessagePayloadFromFile());
    inboundMessage.setExternalAttachments(new ArrayList<>());
    PatientMigrationRequest migrationRequest = PatientMigrationRequest.builder().losingPracticeOdsCode(LOSING_ODE_CODE).winningPracticeOdsCode(WINNING_ODE_CODE).build();
    when(bundleMapperService.mapToBundle(any(RCMRIN030000UK06Message.class), eq(LOSING_ODE_CODE))).thenReturn(bundle);
    when(migrationRequestDao.getMigrationRequest(CONVERSATION_ID)).thenReturn(migrationRequest);
    when(attachmentReferenceUpdaterService.updateReferenceToAttachment(inboundMessage.getAttachments(), CONVERSATION_ID, inboundMessage.getPayload())).thenReturn(inboundMessage.getPayload());
    doThrow(new DataFormatException()).when(fhirParser).encodeToJson(bundle);
    assertThrows(DataFormatException.class, () -> ehrExtractMessageHandler.handleMessage(inboundMessage, CONVERSATION_ID));
}
Also used : PatientMigrationRequest(uk.nhs.adaptors.connector.model.PatientMigrationRequest) DataFormatException(ca.uhn.fhir.parser.DataFormatException) Bundle(org.hl7.fhir.dstu3.model.Bundle) InboundMessage(uk.nhs.adaptors.pss.translator.mhs.model.InboundMessage) RCMRIN030000UK06Message(org.hl7.v3.RCMRIN030000UK06Message) Test(org.junit.jupiter.api.Test)

Example 3 with InboundMessage

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

the class EhrExtractMessageHandlerTest method When_HandleSingleMessageWithValidDataIsCalled_Expect_NotToCallSendContinueRequest.

@Test
public void When_HandleSingleMessageWithValidDataIsCalled_Expect_NotToCallSendContinueRequest() throws JsonProcessingException, JAXBException, InlineAttachmentProcessingException, BundleMappingException, AttachmentNotFoundException, ParseException, SAXException {
    Bundle bundle = new Bundle();
    bundle.setId("Test");
    InboundMessage inboundMessage = new InboundMessage();
    List<InboundMessage.ExternalAttachment> externalAttachmentsTestList = new ArrayList<>();
    inboundMessage.setPayload(readInboundSingleMessagePayloadFromFile());
    inboundMessage.setEbXML(readInboundSingleMessageEbXmlFromFile());
    inboundMessage.setExternalAttachments(externalAttachmentsTestList);
    prepareMigrationRequestAndMigrationStatusMocks();
    when(attachmentReferenceUpdaterService.updateReferenceToAttachment(inboundMessage.getAttachments(), CONVERSATION_ID, inboundMessage.getPayload())).thenReturn(inboundMessage.getPayload());
    EhrExtractMessageHandler ehrExtractMessageHandlerSpy = Mockito.spy(ehrExtractMessageHandler);
    ehrExtractMessageHandlerSpy.handleMessage(inboundMessage, CONVERSATION_ID);
    verify(ehrExtractMessageHandlerSpy, times(0)).sendContinueRequest(any(RCMRIN030000UK06Message.class), any(String.class), any(String.class), any(String.class), any(Instant.class));
}
Also used : Bundle(org.hl7.fhir.dstu3.model.Bundle) Instant(java.time.Instant) ArrayList(java.util.ArrayList) InboundMessage(uk.nhs.adaptors.pss.translator.mhs.model.InboundMessage) FileUtil.readResourceAsString(uk.nhs.adaptors.common.util.FileUtil.readResourceAsString) RCMRIN030000UK06Message(org.hl7.v3.RCMRIN030000UK06Message) Test(org.junit.jupiter.api.Test)

Example 4 with InboundMessage

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

the class EhrExtractMessageHandlerTest method When_HandleLargeMessageWithValidDataIsCalled_Expect_AddAttachmentExactNumerOfTimesAsExternalAttachmentsList.

// We are no longer storing the payload as an attachment in the case of a Skelton message.
// @Test
// public void When_HandleLargeMessageWithValidDataIsCalled_Expect_StoreMessagePayload()
// throws
// JsonProcessingException,
// JAXBException,
// InlineAttachmentProcessingException,
// BundleMappingException,
// AttachmentNotFoundException,
// ParseException,
// SAXException  {
// 
// Bundle bundle = new Bundle();
// bundle.setId("Test");
// 
// InboundMessage inboundMessage = new InboundMessage();
// List<InboundMessage.ExternalAttachment> externalAttachmentsTestList = new ArrayList<>();
// externalAttachmentsTestList.add(
// new InboundMessage.ExternalAttachment(
// "68E2A39F-7A24-449D-83CC-1B7CF1A9DAD7spine.nhs",
// "66B41202-C358-4B4C-93C6-7A10803F9584",
// "68E2A39F-7A24-449D-83CC-1B7CF1A9DAD7spine.nhs.ukExample1",
// "Filename=\"68E2A39F-7A24-449D-83CC-1B7CF1A9DAD7spine.nhs.ukExample1.gzip\" "
// + "ContentType=text/xml Compressed=Yes LargeAttachment=No OriginalBase64=Yes "
// + "DomainData=\"X-GP2GP-Skeleton: Yes\"")
// );
// 
// inboundMessage.setPayload(readLargeInboundMessagePayloadFromFile());
// inboundMessage.setEbXML(readLargeInboundMessageEbXmlFromFile());
// inboundMessage.setExternalAttachments(externalAttachmentsTestList);
// 
// prepareMigrationRequestAndMigrationStatusMocks();
// 
// ehrExtractMessageHandler.handleMessage(inboundMessage, CONVERSATION_ID);
// verify(attachmentHandlerService, times(1)).storeAttachementWithoutProcessing(any(), any(), any(), any());
// }
@Test
public void When_HandleLargeMessageWithValidDataIsCalled_Expect_AddAttachmentExactNumerOfTimesAsExternalAttachmentsList() throws JsonProcessingException, JAXBException, InlineAttachmentProcessingException, BundleMappingException, AttachmentNotFoundException, ParseException, SAXException {
    Bundle bundle = new Bundle();
    bundle.setId("Test");
    InboundMessage inboundMessage = new InboundMessage();
    List<InboundMessage.ExternalAttachment> externalAttachmentsTestList = new ArrayList<>();
    externalAttachmentsTestList.add(new InboundMessage.ExternalAttachment("68E2A39F-7A24-449D-83CC-1B7CF1A9DAD7spine.nhs", "66B41202-C358-4B4C-93C6-7A10803F9584", "68E2A39F-7A24-449D-83CC-1B7CF1A9DAD7spine.nhs.ukExample1", "Filename=\"68E2A39F-7A24-449D-83CC-1B7CF1A9DAD7spine.nhs.ukExample1.gzip\" " + "ContentType=text/xml Compressed=Yes LargeAttachment=No OriginalBase64=Yes " + "DomainData=\"X-GP2GP-Skeleton: Yes\""));
    externalAttachmentsTestList.add(new InboundMessage.ExternalAttachment("68E2A39F-7A24-449D-83CC-1B7CF1A9DAD7spine.nhs", "66B41202-C358-4B4C-93C6-7A10803F9584", "68E2A39F-7A24-449D-83CC-1B7CF1A9DAD7spine.nhs.ukExample1", "Filename=\"68E2A39F-7A24-449D-83CC-1B7CF1A9DAD7spine.nhs.ukExample1.gzip\" " + "ContentType=text/xml Compressed=Yes LargeAttachment=No OriginalBase64=Yes " + "DomainData=\"X-GP2GP-Skeleton: Yes\""));
    externalAttachmentsTestList.add(new InboundMessage.ExternalAttachment("68E2A39F-7A24-449D-83CC-1B7CF1A9DAD7spine.nhs", "66B41202-C358-4B4C-93C6-7A10803F9584", "68E2A39F-7A24-449D-83CC-1B7CF1A9DAD7spine.nhs.ukExample1", "Filename=\"68E2A39F-7A24-449D-83CC-1B7CF1A9DAD7spine.nhs.ukExample1.gzip\" " + "ContentType=text/xml Compressed=Yes LargeAttachment=No OriginalBase64=Yes"));
    externalAttachmentsTestList.add(new InboundMessage.ExternalAttachment("68E2A39F-7A24-449D-83CC-1B7CF1A9DAD7spine.nhs", "66B41202-C358-4B4C-93C6-7A10803F9584", "68E2A39F-7A24-449D-83CC-1B7CF1A9DAD7spine.nhs.ukExample1", "Filename=\"68E2A39F-7A24-449D-83CC-1B7CF1A9DAD7spine.nhs.ukExample1.gzip\" " + "ContentType=text/xml Compressed=Yes LargeAttachment=No OriginalBase64=Yes"));
    inboundMessage.setPayload(readLargeInboundMessagePayloadFromFile());
    inboundMessage.setEbXML(readLargeInboundMessageEbXmlFromFile());
    inboundMessage.setExternalAttachments(externalAttachmentsTestList);
    prepareMigrationRequestAndMigrationStatusMocks();
    ehrExtractMessageHandler.handleMessage(inboundMessage, CONVERSATION_ID);
    verify(patientAttachmentLogService, times(externalAttachmentsTestList.size())).addAttachmentLog(any());
}
Also used : Bundle(org.hl7.fhir.dstu3.model.Bundle) ArrayList(java.util.ArrayList) InboundMessage(uk.nhs.adaptors.pss.translator.mhs.model.InboundMessage) Test(org.junit.jupiter.api.Test)

Example 5 with InboundMessage

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

the class EhrExtractMessageHandlerTest method When_HandleLargeMessageWithValidDataIsCalled_Expect_CallSendContinueRequest.

@Test
public void When_HandleLargeMessageWithValidDataIsCalled_Expect_CallSendContinueRequest() throws JsonProcessingException, JAXBException, InlineAttachmentProcessingException, BundleMappingException, AttachmentNotFoundException, ParseException, SAXException {
    Bundle bundle = new Bundle();
    bundle.setId("Test");
    InboundMessage inboundMessage = new InboundMessage();
    List<InboundMessage.ExternalAttachment> externalAttachmentsTestList = new ArrayList<>();
    externalAttachmentsTestList.add(new InboundMessage.ExternalAttachment("68E2A39F-7A24-449D-83CC-1B7CF1A9DAD7spine.nhs", "66B41202-C358-4B4C-93C6-7A10803F9584", "68E2A39F-7A24-449D-83CC-1B7CF1A9DAD7spine.nhs.ukExample1", "Filename=\"68E2A39F-7A24-449D-83CC-1B7CF1A9DAD7spine.nhs.ukExample1.gzip\" " + "ContentType=text/xml Compressed=Yes LargeAttachment=No OriginalBase64=Yes " + "DomainData=\"X-GP2GP-Skeleton: Yes\""));
    inboundMessage.setPayload(readLargeInboundMessagePayloadFromFile());
    inboundMessage.setEbXML(readLargeInboundMessageEbXmlFromFile());
    inboundMessage.setExternalAttachments(externalAttachmentsTestList);
    prepareMigrationRequestAndMigrationStatusMocks();
    EhrExtractMessageHandler ehrExtractMessageHandlerSpy = Mockito.spy(ehrExtractMessageHandler);
    ehrExtractMessageHandlerSpy.handleMessage(inboundMessage, CONVERSATION_ID);
    verify(ehrExtractMessageHandlerSpy).sendContinueRequest(any(RCMRIN030000UK06Message.class), any(String.class), any(String.class), any(String.class), any(Instant.class));
}
Also used : Bundle(org.hl7.fhir.dstu3.model.Bundle) Instant(java.time.Instant) ArrayList(java.util.ArrayList) InboundMessage(uk.nhs.adaptors.pss.translator.mhs.model.InboundMessage) FileUtil.readResourceAsString(uk.nhs.adaptors.common.util.FileUtil.readResourceAsString) RCMRIN030000UK06Message(org.hl7.v3.RCMRIN030000UK06Message) Test(org.junit.jupiter.api.Test)

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