diff --git a/src/main/java/uk/nhs/prm/repo/ehrtransferservice/gp2gp_message_models/ParsedMessage.java b/src/main/java/uk/nhs/prm/repo/ehrtransferservice/gp2gp_message_models/ParsedMessage.java index 3f4144e15..9f092734f 100644 --- a/src/main/java/uk/nhs/prm/repo/ehrtransferservice/gp2gp_message_models/ParsedMessage.java +++ b/src/main/java/uk/nhs/prm/repo/ehrtransferservice/gp2gp_message_models/ParsedMessage.java @@ -20,14 +20,6 @@ public ParsedMessage(SOAPEnvelope soapEnvelope, MessageContent messageContent, S this.messageBody = messageBody; } - public BytesMessage getBytesMessage() throws JMSException { - final byte[] bytesArray = this.messageBody.getBytes(StandardCharsets.UTF_8); - ActiveMQBytesMessage bytesMessage = new ActiveMQBytesMessage(); - bytesMessage.writeBytes(bytesArray); - bytesMessage.reset(); - return bytesMessage; - } - public String getMessageBody() { return messageBody; } diff --git a/src/main/java/uk/nhs/prm/repo/ehrtransferservice/models/sendEhrRequest/RegistrationRequestAttributes.java b/src/main/java/uk/nhs/prm/repo/ehrtransferservice/models/sendEhrRequest/RegistrationRequestAttributes.java deleted file mode 100644 index bbff3debc..000000000 --- a/src/main/java/uk/nhs/prm/repo/ehrtransferservice/models/sendEhrRequest/RegistrationRequestAttributes.java +++ /dev/null @@ -1,18 +0,0 @@ -package uk.nhs.prm.repo.ehrtransferservice.models.sendEhrRequest; - -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; - -public class RegistrationRequestAttributes { - @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") - public String ehrRequestId; - @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") - public String odsCode; - @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") - public String nhsNumber; - - public RegistrationRequestAttributes(String nhsNumber, String odsCode, String ehrRequestMessageId) { - this.odsCode = odsCode; - this.nhsNumber = nhsNumber; - this.ehrRequestId = ehrRequestMessageId; - } -} diff --git a/src/main/java/uk/nhs/prm/repo/ehrtransferservice/models/sendEhrRequest/RegistrationRequestBody.java b/src/main/java/uk/nhs/prm/repo/ehrtransferservice/models/sendEhrRequest/RegistrationRequestBody.java deleted file mode 100644 index aa121cc2d..000000000 --- a/src/main/java/uk/nhs/prm/repo/ehrtransferservice/models/sendEhrRequest/RegistrationRequestBody.java +++ /dev/null @@ -1,14 +0,0 @@ -package uk.nhs.prm.repo.ehrtransferservice.models.sendEhrRequest; - -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; - -import java.util.UUID; - -public class RegistrationRequestBody { - @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") - public RegistrationRequestData data; - - public RegistrationRequestBody(String ehrRequestMessageId, UUID conversationId, String nhsNumber, String odsCode) { - this.data = new RegistrationRequestData(ehrRequestMessageId, conversationId, nhsNumber, odsCode); - } -} diff --git a/src/main/java/uk/nhs/prm/repo/ehrtransferservice/models/sendEhrRequest/RegistrationRequestData.java b/src/main/java/uk/nhs/prm/repo/ehrtransferservice/models/sendEhrRequest/RegistrationRequestData.java deleted file mode 100644 index d941aa368..000000000 --- a/src/main/java/uk/nhs/prm/repo/ehrtransferservice/models/sendEhrRequest/RegistrationRequestData.java +++ /dev/null @@ -1,20 +0,0 @@ -package uk.nhs.prm.repo.ehrtransferservice.models.sendEhrRequest; - -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; - -import java.util.UUID; - -public class RegistrationRequestData { - @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") - public String type; - @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") - public UUID id; - @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") - public RegistrationRequestAttributes attributes; - - public RegistrationRequestData(String ehrRequestMessageId, UUID conversationId, String nhsNumber, String odsCode) { - this.type = "registration-requests"; - this.id = conversationId; - this.attributes = new RegistrationRequestAttributes(nhsNumber, odsCode, ehrRequestMessageId); - } -} diff --git a/src/test/java/uk/nhs/prm/repo/ehrtransferservice/gp2gp_message_models/ParsedMessageTest.java b/src/test/java/uk/nhs/prm/repo/ehrtransferservice/gp2gp_message_models/ParsedMessageTest.java index 4e9b8c8d7..66b56e8bb 100644 --- a/src/test/java/uk/nhs/prm/repo/ehrtransferservice/gp2gp_message_models/ParsedMessageTest.java +++ b/src/test/java/uk/nhs/prm/repo/ehrtransferservice/gp2gp_message_models/ParsedMessageTest.java @@ -87,6 +87,14 @@ void shouldReturnEhrRequestId() { assertThat(message.getEhrRequestId(), equalTo(ehrRequestId)); } + @Test + void getEhrRequestIdShouldReturnNullWhenMessageContentIsNotOfTypeEhrRequestMessageWrapper() { + EhrExtractMessageWrapper ehrExtractMessageWrapper = new EhrExtractMessageWrapper(); + + ParsedMessage message = new ParsedMessage(null, ehrExtractMessageWrapper, null); + assertThat(message.getEhrRequestId(), equalTo(null)); + } + @Test void shouldReturnNhsNumberForEhrRequest() { EhrRequestMessageWrapper ehrRequestMessageWrapper = new EhrRequestMessageWrapper(); @@ -102,6 +110,14 @@ void shouldReturnNhsNumberForEhrRequest() { assertThat(message.getNhsNumber(), equalTo("1234567890")); } + @Test + void getOdsCodeShouldReturnNullIfMessageContentIsNotOfTypeEhrRequestMessageWrapper() { + EhrExtractMessageWrapper ehrExtractMessageWrapper = new EhrExtractMessageWrapper(); + + ParsedMessage message = new ParsedMessage(null, ehrExtractMessageWrapper, null); + assertThat(message.getOdsCode(), equalTo(null)); + } + @Test void shouldReturnRequestingPracticeOdsCodeForEhrRequest() { EhrRequestMessageWrapper ehrRequestMessageWrapper = new EhrRequestMessageWrapper(); diff --git a/src/test/java/uk/nhs/prm/repo/ehrtransferservice/parsers/EhrCompleteParserTest.java b/src/test/java/uk/nhs/prm/repo/ehrtransferservice/parsers/EhrCompleteParserTest.java index 94efadae6..5e1453f1d 100644 --- a/src/test/java/uk/nhs/prm/repo/ehrtransferservice/parsers/EhrCompleteParserTest.java +++ b/src/test/java/uk/nhs/prm/repo/ehrtransferservice/parsers/EhrCompleteParserTest.java @@ -4,6 +4,7 @@ import java.util.UUID; +import static org.junit.Assert.assertThrows; import static org.junit.jupiter.api.Assertions.assertEquals; class EhrCompleteParserTest { @@ -20,4 +21,14 @@ void shouldParseRepoIncomingMessageCorrectlyWhenAMessageContainsExpectedValues() assertEquals(conversationId, parsedMessage.getConversationId()); assertEquals(messageId, parsedMessage.getMessageId()); } + + @Test + void shouldThrowExceptionWhenParsingIncorrectlyFormattedMessage() { + String invalidIncomingMessage = "invalid"; + + EhrCompleteParser ehrCompleteParser = new EhrCompleteParser(); + + assertThrows(RuntimeException.class, () -> ehrCompleteParser.parse(invalidIncomingMessage)); + } + } \ No newline at end of file diff --git a/src/test/java/uk/nhs/prm/repo/ehrtransferservice/parsers/LargeSqsMessageParserTest.java b/src/test/java/uk/nhs/prm/repo/ehrtransferservice/parsers/LargeSqsMessageParserTest.java new file mode 100644 index 000000000..228b8e540 --- /dev/null +++ b/src/test/java/uk/nhs/prm/repo/ehrtransferservice/parsers/LargeSqsMessageParserTest.java @@ -0,0 +1,58 @@ +package uk.nhs.prm.repo.ehrtransferservice.parsers; + +import com.fasterxml.jackson.core.JsonParseException; +import com.google.common.base.Charsets; +import com.google.common.io.ByteSource; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; +import uk.nhs.prm.repo.ehrtransferservice.models.LargeSqsMessage; +import uk.nhs.prm.repo.ehrtransferservice.utils.TestDataLoader; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.notNullValue; +import static org.junit.jupiter.api.Assertions.*; + +class LargeSqsMessageParserTest { + + private final LargeSqsMessageParser parser = new LargeSqsMessageParser(); + private final TestDataLoader loader = new TestDataLoader(); + + @SuppressFBWarnings + private InputStream readResourceFile(String resourceFileName) throws FileNotFoundException { + return new FileInputStream("src/test/resources/data/" + resourceFileName); + } + + @Test + void shouldParseLargeSQSMessage() throws IOException { + String messageAsString = loader.getDataAsString("RCMR_IN030000UK06"); + + var result = parser.parse(messageAsString); + + assertEquals(result.getClass(), LargeSqsMessage.class); + } + + + @ParameterizedTest + @ValueSource(strings = { + "simpleTextMessage.txt", + "RCMR_IN030000UK06WithoutInteractionId", + "RCMR_IN030000UK06WithoutMessageHeader", + "RCMR_IN030000UK06WithoutSoapHeader", + "RCMR_IN030000UK06WithIncorrectInteractionId" + }) + void shouldThrowJsonParseExceptionWhenCannotParseMessage(String fileName) throws IOException { + String messageAsString = loader.getDataAsString(fileName); + + Exception expected = assertThrows(JsonParseException.class, () -> + parser.parse(messageAsString) + ); + assertThat(expected, notNullValue()); + } +} \ No newline at end of file