|
3 | 3 | import static java.util.UUID.randomUUID; |
4 | 4 |
|
5 | 5 | import static org.junit.jupiter.api.Assertions.assertEquals; |
| 6 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
| 7 | +import static org.junit.jupiter.api.Assertions.assertNull; |
6 | 8 | import static org.junit.jupiter.api.Assertions.assertThrows; |
| 9 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
7 | 10 | import static org.mockito.ArgumentMatchers.any; |
8 | 11 |
|
9 | 12 | import static org.mockito.ArgumentMatchers.eq; |
@@ -143,6 +146,83 @@ void When_HappyPathWithSkeletonAsRCMRMessage_Expect_ThrowNoErrors() throws Trans |
143 | 146 | skeletonProcessingService.updateInboundMessageWithSkeleton(attachmentLog, inboundMessage, CONVERSATION_ID); |
144 | 147 | } |
145 | 148 |
|
| 149 | + @Test |
| 150 | + void When_SkeletonAsWholeRCMRMessageHasLeadingWhitespace_Expect_InboundMessagePayloadIsNewRCMRMessage() |
| 151 | + throws TransformerException, SAXException { |
| 152 | + var inboundMessage = new InboundMessage(); |
| 153 | + var attachmentLog = createSkeletonPatientAttachmentLog(); |
| 154 | + var skeletonMessage = "\n " + readInboundMessagePayloadFromFile(); |
| 155 | + |
| 156 | + inboundMessage.setPayload(readInboundMessagePayloadFromFile()); |
| 157 | + inboundMessage.setEbXML(readInboundMessageEbXmlFromFile()); |
| 158 | + |
| 159 | + when(attachmentHandlerService.getAttachment(any(), any())).thenReturn(skeletonMessage.getBytes(StandardCharsets.UTF_8)); |
| 160 | + when(xmlParseUtilService.getStringFromDocument(any())).thenReturn(readInboundMessagePayloadFromFile()); |
| 161 | + |
| 162 | + var newInboundMessage = |
| 163 | + skeletonProcessingService.updateInboundMessageWithSkeleton(attachmentLog, inboundMessage, CONVERSATION_ID); |
| 164 | + |
| 165 | + assertTrue(newInboundMessage.getPayload().contains("<RCMR_IN030000UK06")); |
| 166 | + } |
| 167 | + |
| 168 | + @Test |
| 169 | + void When_NormalizeSkeletonXmlCalledWithNull_Expect_ReturnsNull() throws Exception { |
| 170 | + var method = SkeletonProcessingService.class.getDeclaredMethod("normalizeSkeletonXml", String.class); |
| 171 | + method.setAccessible(true); |
| 172 | + |
| 173 | + assertNull(method.invoke(skeletonProcessingService, new Object[] {null})); |
| 174 | + } |
| 175 | + |
| 176 | + @Test |
| 177 | + void When_NormalizeSkeletonXmlCalledWithBlankString_Expect_ReturnsOriginalBlankString() throws Exception { |
| 178 | + var method = SkeletonProcessingService.class.getDeclaredMethod("normalizeSkeletonXml", String.class); |
| 179 | + method.setAccessible(true); |
| 180 | + |
| 181 | + var blankInput = " \n\t "; |
| 182 | + assertEquals(blankInput, method.invoke(skeletonProcessingService, blankInput)); |
| 183 | + } |
| 184 | + |
| 185 | + @Test |
| 186 | + void When_IsEntireRcmrSkeletonCalledWithNonRcmrPayload_Expect_ReturnsFalse() throws Exception { |
| 187 | + var method = SkeletonProcessingService.class.getDeclaredMethod("isEntireRcmrSkeleton", String.class); |
| 188 | + method.setAccessible(true); |
| 189 | + |
| 190 | + assertFalse((Boolean) method.invoke(skeletonProcessingService, "<MCCI_IN010000UK13>")); |
| 191 | + } |
| 192 | + |
| 193 | + @Test |
| 194 | + void When_NormalizeSkeletonXmlCalledWithXmlDeclaration_Expect_StripsDeclarationBeforeRcmrCheck() throws Exception { |
| 195 | + var normalizeMethod = SkeletonProcessingService.class.getDeclaredMethod("normalizeSkeletonXml", String.class); |
| 196 | + normalizeMethod.setAccessible(true); |
| 197 | + var isRcmrMethod = SkeletonProcessingService.class.getDeclaredMethod("isEntireRcmrSkeleton", String.class); |
| 198 | + isRcmrMethod.setAccessible(true); |
| 199 | + |
| 200 | + var xmlWithDeclaration = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<RCMR_IN030000UK06>"; |
| 201 | + var normalized = (String) normalizeMethod.invoke(skeletonProcessingService, xmlWithDeclaration); |
| 202 | + |
| 203 | + assertTrue(normalized.startsWith("<RCMR_IN030000UK06")); |
| 204 | + assertTrue((Boolean) isRcmrMethod.invoke(skeletonProcessingService, normalized)); |
| 205 | + } |
| 206 | + |
| 207 | + @Test |
| 208 | + void When_SkeletonAsWholeRCMRMessageHasBomPrefix_Expect_InboundMessagePayloadIsNewRCMRMessage() |
| 209 | + throws TransformerException, SAXException { |
| 210 | + var inboundMessage = new InboundMessage(); |
| 211 | + var attachmentLog = createSkeletonPatientAttachmentLog(); |
| 212 | + var skeletonMessage = "\uFEFF" + readInboundMessagePayloadFromFile(); |
| 213 | + |
| 214 | + inboundMessage.setPayload(readInboundMessagePayloadFromFile()); |
| 215 | + inboundMessage.setEbXML(readInboundMessageEbXmlFromFile()); |
| 216 | + |
| 217 | + when(attachmentHandlerService.getAttachment(any(), any())).thenReturn(skeletonMessage.getBytes(StandardCharsets.UTF_8)); |
| 218 | + when(xmlParseUtilService.getStringFromDocument(any())).thenReturn(readInboundMessagePayloadFromFile()); |
| 219 | + |
| 220 | + var newInboundMessage = |
| 221 | + skeletonProcessingService.updateInboundMessageWithSkeleton(attachmentLog, inboundMessage, CONVERSATION_ID); |
| 222 | + |
| 223 | + assertTrue(newInboundMessage.getPayload().contains("<RCMR_IN030000UK06")); |
| 224 | + } |
| 225 | + |
146 | 226 | @Test |
147 | 227 | void When_HappyPathWithSkeletonAsRCMRMessage_Expect_InboundMessagePayloadIsNewRCMRMessage() |
148 | 228 | throws TransformerException, SAXException { |
|
0 commit comments