@@ -145,12 +145,44 @@ void When_HappyPathWithSkeletonAsRCMRMessage_Expect_ThrowNoErrors() throws Trans
145145 }
146146
147147 @ Test
148- void When_SkeletonAsWholeRCMRMessageHasXmlDeclarationAndWhitespace_Expect_InboundMessagePayloadIsNewRCMRMessage ()
148+ void When_SkeletonAsWholeRCMRMessageHasLeadingWhitespace_Expect_InboundMessagePayloadIsNewRCMRMessage ()
149149 throws TransformerException , SAXException {
150150 var inboundMessage = new InboundMessage ();
151151 var attachmentLog = createSkeletonPatientAttachmentLog ();
152- var skeletonMessage = "\n <?xml version=\" 1.0\" encoding=\" UTF-8\" ?>\n "
153- + readInboundMessagePayloadFromFile ();
152+ var skeletonMessage = "\n " + readInboundMessagePayloadFromFile ();
153+
154+ inboundMessage .setPayload (readInboundMessagePayloadFromFile ());
155+ inboundMessage .setEbXML (readInboundMessageEbXmlFromFile ());
156+
157+ when (attachmentHandlerService .getAttachment (any (), any ())).thenReturn (skeletonMessage .getBytes (StandardCharsets .UTF_8 ));
158+ when (xmlParseUtilService .getStringFromDocument (any ())).thenReturn (readInboundMessagePayloadFromFile ());
159+
160+ var newInboundMessage =
161+ skeletonProcessingService .updateInboundMessageWithSkeleton (attachmentLog , inboundMessage , CONVERSATION_ID );
162+
163+ assertTrue (newInboundMessage .getPayload ().contains ("<RCMR_IN030000UK06" ));
164+ }
165+
166+ @ Test
167+ void When_SkeletonAttachmentIsBlank_Expect_ThrowsRuntimeException () throws SAXException {
168+ var inboundMessage = new InboundMessage ();
169+ var attachmentLog = createSkeletonPatientAttachmentLog ();
170+
171+ inboundMessage .setPayload (readInboundMessagePayloadFromFile ());
172+ inboundMessage .setEbXML (readInboundMessageEbXmlFromFile ());
173+
174+ when (attachmentHandlerService .getAttachment (any (), any ())).thenReturn (" \n \t " .getBytes (StandardCharsets .UTF_8 ));
175+
176+ assertThrows (RuntimeException .class , () ->
177+ skeletonProcessingService .updateInboundMessageWithSkeleton (attachmentLog , inboundMessage , CONVERSATION_ID ));
178+ }
179+
180+ @ Test
181+ void When_SkeletonAsWholeRCMRMessageHasBomPrefix_Expect_InboundMessagePayloadIsNewRCMRMessage ()
182+ throws TransformerException , SAXException {
183+ var inboundMessage = new InboundMessage ();
184+ var attachmentLog = createSkeletonPatientAttachmentLog ();
185+ var skeletonMessage = "\uFEFF " + readInboundMessagePayloadFromFile ();
154186
155187 inboundMessage .setPayload (readInboundMessagePayloadFromFile ());
156188 inboundMessage .setEbXML (readInboundMessageEbXmlFromFile ());
0 commit comments