Skip to content

Commit cf984c0

Browse files
committed
adding more tests to confirm that objectMapper has unlimited readability
1 parent 999a53f commit cf984c0

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

service/src/intTest/java/uk/nhs/adaptors/gp2gp/ehr/SendDocumentComponentTest.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static org.assertj.core.api.Assertions.assertThat;
44
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
5+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
56
import static org.mockito.ArgumentMatchers.any;
67
import static org.mockito.Mockito.doThrow;
78

@@ -34,6 +35,9 @@
3435
@DirtiesContext
3536
public class SendDocumentComponentTest {
3637
private static final String DOCUMENT_NAME = "some-conversation-id/document-name.json";
38+
public static final String OUTBOUND_MESSAGE_JSON = "src/intTest/resources/outboundMessage.json";
39+
public static final String OUTBOUND_MESSAGE_WITH_OVER_20MB_PAYLOAD_JSON
40+
= "src/intTest/resources/outboundMessageWithOver20MbPayload.json";
3741

3842
@MockBean
3943
private MhsClient mhsClient;
@@ -47,9 +51,21 @@ public class SendDocumentComponentTest {
4751
@Autowired
4852
private LocalMockConnector localMockConnector;
4953

54+
@Test
55+
public void When_SendDocumentTaskRunsWithOver20MbPayloadMessage_Expect_NoException() throws IOException {
56+
var inputStream = readMessageAsInputStream(OUTBOUND_MESSAGE_WITH_OVER_20MB_PAYLOAD_JSON);
57+
localMockConnector.uploadToStorage(inputStream, inputStream.available(), DOCUMENT_NAME);
58+
var ehrExtractStatus = EhrExtractStatusTestUtils.prepareEhrExtractStatus();
59+
ehrExtractStatusRepository.save(ehrExtractStatus);
60+
61+
var sendDocumentTaskDefinition = prepareTaskDefinition(ehrExtractStatus);
62+
63+
assertDoesNotThrow(() -> sendDocumentTaskExecutor.execute(sendDocumentTaskDefinition));
64+
}
65+
5066
@Test
5167
public void When_SendDocumentTaskRunsTwice_Expect_DatabaseOverwritesEhrExtractStatus() throws IOException {
52-
var inputStream = readMessageAsInputStream();
68+
var inputStream = readMessageAsInputStream(OUTBOUND_MESSAGE_JSON);
5369
localMockConnector.uploadToStorage(inputStream, inputStream.available(), DOCUMENT_NAME);
5470
var ehrExtractStatus = EhrExtractStatusTestUtils.prepareEhrExtractStatus();
5571
ehrExtractStatusRepository.save(ehrExtractStatus);
@@ -67,7 +83,7 @@ public void When_SendDocumentTaskRunsTwice_Expect_DatabaseOverwritesEhrExtractSt
6783

6884
@Test
6985
public void When_SendDocumentTask_WithMhsConnectionException_Expect_ExceptionThrownAndDatabaseNotUpdated() throws IOException {
70-
var inputStream = readMessageAsInputStream();
86+
var inputStream = readMessageAsInputStream(OUTBOUND_MESSAGE_JSON);
7187
localMockConnector.uploadToStorage(inputStream, inputStream.available(), DOCUMENT_NAME);
7288
var ehrExtractStatus = EhrExtractStatusTestUtils.prepareEhrExtractStatus();
7389
ehrExtractStatusRepository.save(ehrExtractStatus);
@@ -87,7 +103,7 @@ public void When_SendDocumentTask_WithMhsConnectionException_Expect_ExceptionThr
87103

88104
@Test
89105
public void When_SendDocumentTask_WithMhsServerFailureException_Expect_ExceptionThrownAndDataBaseNotUpdated() throws IOException {
90-
var inputStream = readMessageAsInputStream();
106+
var inputStream = readMessageAsInputStream(OUTBOUND_MESSAGE_JSON);
91107
localMockConnector.uploadToStorage(inputStream, inputStream.available(), DOCUMENT_NAME);
92108
var ehrExtractStatus = EhrExtractStatusTestUtils.prepareEhrExtractStatus();
93109
ehrExtractStatusRepository.save(ehrExtractStatus);
@@ -105,8 +121,8 @@ public void When_SendDocumentTask_WithMhsServerFailureException_Expect_Exception
105121
assertThat(ehrExtractStatusHasSentDocuments(ehrExtractUpdated)).isFalse();
106122
}
107123

108-
private InputStream readMessageAsInputStream() throws IOException {
109-
File file = new File("src/intTest/resources/outboundMessage.json");
124+
private InputStream readMessageAsInputStream(String pathname) throws IOException {
125+
File file = new File(pathname);
110126
return new FileInputStream(file);
111127
}
112128

service/src/intTest/resources/outboundMessageWithOver20MbPayload.json

Lines changed: 6 additions & 0 deletions
Large diffs are not rendered by default.

service/src/test/java/uk/nhs/adaptors/gp2gp/common/configuration/ObjectMapperConfigTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
class ObjectMapperConfigTest {
1111

1212
@Test
13-
void objectMapperConfigTest() {
13+
void objectMapperConfigSetToWorkWithUnlimitedDataSizeTest() {
1414

1515
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ObjectMapperConfig.class);
1616

@@ -19,7 +19,7 @@ void objectMapperConfigTest() {
1919
StreamReadConstraints constraints = objectMapper.getFactory().streamReadConstraints();
2020

2121
assertEquals(Integer.MAX_VALUE, constraints.getMaxStringLength(),
22-
"Expected maxStringLength to be set to Integer.MAX_VALUE");
22+
"Expected objectMapper read constraint to be practically unlimited");
2323

2424
context.close();
2525
}

0 commit comments

Comments
 (0)