Skip to content

Commit

Permalink
Merge branch 'PRMT-4117'
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyFlintAnswerDigital committed Nov 30, 2023
2 parents c9b639c + 5b45fc1 commit 3d8cf0e
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import java.util.UUID;

import static org.junit.Assert.assertThrows;
import static org.junit.jupiter.api.Assertions.assertEquals;

class EhrCompleteParserTest {
Expand All @@ -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));
}

}
Original file line number Diff line number Diff line change
@@ -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());
}
}

0 comments on commit 3d8cf0e

Please sign in to comment.