Skip to content

Commit 3ae1b5c

Browse files
NIAD-1136 remove lenient and refactor
--- updated-dependencies: - dependency-name: com.adobe.testing:s3mock-testcontainers dependency-version: 4.10.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Fix issue with docker / test containers (#1411) * Update testcontainers to version 2.0.2 and force version of `commons-io`. * Add developer notes to force docker api version to accept a minimum version of `1.44`. remove Bump com.adobe.testing:s3mock-testcontainers in /service (#1409) Bumps com.adobe.testing:s3mock-testcontainers from 4.7.0 to 4.10.0. --- updated-dependencies: - dependency-name: com.adobe.testing:s3mock-testcontainers dependency-version: 4.10.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Fix issue with docker / test containers (#1411) * Update testcontainers to version 2.0.2 and force version of `commons-io`. * Add developer notes to force docker api version to accept a minimum version of `1.44`. remove
1 parent 8800055 commit 3ae1b5c

34 files changed

+1430
-713
lines changed

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

Lines changed: 26 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import static org.assertj.core.api.Assertions.assertThat;
66
import static org.junit.jupiter.api.Assertions.assertFalse;
77
import static org.mockito.ArgumentMatchers.any;
8-
import static org.mockito.Mockito.lenient;
98
import static org.mockito.Mockito.never;
109
import static org.mockito.Mockito.verify;
1110
import static org.mockito.Mockito.when;
@@ -158,17 +157,16 @@ public void When_AcknowledgementReceivedOutOfOrderAcknowledgmentNotSent_Expect_E
158157
@Test
159158
public void When_DuplicateEhrRequestReceived_Expect_SkippedNoDatabaseUpdated() {
160159
var ehrExtractStatus = EhrExtractStatusTestUtils.prepareEhrExtractStatus();
161-
ehrExtractStatusRepository.save(ehrExtractStatus);
162-
163-
String requestPayload = asString(requestResponsePayload);
164-
String requestEbxml = asString(requestResponseEbxml);
165-
166-
mockEhrRequest(requestEbxml, requestPayload, EHR_EXTRACT_REQUEST, ehrExtractStatus.getConversationId());
167160

161+
ehrExtractStatusRepository.save(ehrExtractStatus);
168162
inboundMessageHandler.handle(message);
169-
var firstEhrStatus = ehrExtractStatusRepository.findByConversationId(ehrExtractStatus.getConversationId()).get();
163+
164+
var firstEhrStatus =
165+
ehrExtractStatusRepository.findByConversationId(ehrExtractStatus.getConversationId()).get();
170166
inboundMessageHandler.handle(message);
171-
var secondEhrStatus = ehrExtractStatusRepository.findByConversationId(ehrExtractStatus.getConversationId()).get();
167+
168+
var secondEhrStatus =
169+
ehrExtractStatusRepository.findByConversationId(ehrExtractStatus.getConversationId()).get();
172170

173171
assertThat(firstEhrStatus.getUpdatedAt()).isEqualTo(secondEhrStatus.getUpdatedAt());
174172
verify(taskDispatcher, never()).createTask(any());
@@ -220,9 +218,6 @@ public void When_DuplicateAcknowledgementSentTwice_Expect_SkippedNoDatabaseUpdat
220218
@Test
221219
@SneakyThrows
222220
public void When_UnsupportedMessageSent_Expect_ErrorThrown() {
223-
String incomingMessage = null;
224-
lenient().when(objectMapper.readValue(incomingMessage, InboundMessage.class)).thenReturn(inboundMessage);
225-
226221
assertFalse(inboundMessageHandler.handle(message));
227222

228223
verify(taskDispatcher, never()).createTask(any());
@@ -231,27 +226,27 @@ public void When_UnsupportedMessageSent_Expect_ErrorThrown() {
231226
@SneakyThrows
232227
private void mockEhrRequest(String ebxml, String payload, String interactionId, String conversationId) {
233228
String incomingMessage = null;
234-
lenient().when(objectMapper.readValue(incomingMessage, InboundMessage.class)).thenReturn(inboundMessage);
235-
lenient().when(inboundMessage.getEbXML()).thenReturn(ebxml);
236-
lenient().when(inboundMessage.getPayload()).thenReturn(payload);
229+
when(objectMapper.readValue(incomingMessage, InboundMessage.class)).thenReturn(inboundMessage);
230+
when(inboundMessage.getEbXML()).thenReturn(ebxml);
231+
when(inboundMessage.getPayload()).thenReturn(payload);
237232

238233
var ebxmlDocument = SERVICE.parseDocumentFromXml(ebxml);
239-
lenient().when(xPathService.parseDocumentFromXml(inboundMessage.getEbXML())).thenReturn(ebxmlDocument);
234+
when(xPathService.parseDocumentFromXml(inboundMessage.getEbXML())).thenReturn(ebxmlDocument);
240235
var payloadDocument = SERVICE.parseDocumentFromXml(payload);
241-
lenient().when(xPathService.parseDocumentFromXml(inboundMessage.getPayload())).thenReturn(payloadDocument);
242-
243-
lenient().when(xPathService.getNodeValue(ebxmlDocument, ACTION_PATH)).thenReturn(interactionId);
244-
lenient().when(xPathService.getNodeValue(ebxmlDocument, CONVERSATION_ID_PATH)).thenReturn(conversationId);
245-
246-
lenient().when(xPathService.getNodeValue(payloadDocument, REQUEST_ID_PATH)).thenReturn("123");
247-
lenient().when(xPathService.getNodeValue(payloadDocument, NHS_NUMBER_PATH)).thenReturn("123");
248-
lenient().when(xPathService.getNodeValue(ebxmlDocument, FROM_PARTY_ID_PATH)).thenReturn("123");
249-
lenient().when(xPathService.getNodeValue(ebxmlDocument, TO_PARTY_ID_PATH)).thenReturn("123");
250-
lenient().when(xPathService.getNodeValue(payloadDocument, FROM_ASID_PATH)).thenReturn("123");
251-
lenient().when(xPathService.getNodeValue(payloadDocument, TO_ASID_PATH)).thenReturn("123");
252-
lenient().when(xPathService.getNodeValue(payloadDocument, FROM_ODS_CODE_PATH)).thenReturn("123");
253-
lenient().when(xPathService.getNodeValue(payloadDocument, TO_ODS_CODE_PATH)).thenReturn("123");
254-
lenient().when(xPathService.getNodeValue(ebxmlDocument, MESSAGE_ID_PATH)).thenReturn("123");
236+
when(xPathService.parseDocumentFromXml(inboundMessage.getPayload())).thenReturn(payloadDocument);
237+
238+
when(xPathService.getNodeValue(ebxmlDocument, ACTION_PATH)).thenReturn(interactionId);
239+
when(xPathService.getNodeValue(ebxmlDocument, CONVERSATION_ID_PATH)).thenReturn(conversationId);
240+
241+
when(xPathService.getNodeValue(payloadDocument, REQUEST_ID_PATH)).thenReturn("123");
242+
when(xPathService.getNodeValue(payloadDocument, NHS_NUMBER_PATH)).thenReturn("123");
243+
when(xPathService.getNodeValue(ebxmlDocument, FROM_PARTY_ID_PATH)).thenReturn("123");
244+
when(xPathService.getNodeValue(ebxmlDocument, TO_PARTY_ID_PATH)).thenReturn("123");
245+
when(xPathService.getNodeValue(payloadDocument, FROM_ASID_PATH)).thenReturn("123");
246+
when(xPathService.getNodeValue(payloadDocument, TO_ASID_PATH)).thenReturn("123");
247+
when(xPathService.getNodeValue(payloadDocument, FROM_ODS_CODE_PATH)).thenReturn("123");
248+
when(xPathService.getNodeValue(payloadDocument, TO_ODS_CODE_PATH)).thenReturn("123");
249+
when(xPathService.getNodeValue(ebxmlDocument, MESSAGE_ID_PATH)).thenReturn("123");
255250
}
256251

257252
private static String asString(Resource resource) {
@@ -264,20 +259,11 @@ private static String asString(Resource resource) {
264259

265260
@SneakyThrows
266261
private void mockIncomingMessage(String ebxml, String payload, String interactionId, String conversationId) {
267-
String incomingMessage = null;
268-
lenient().when(objectMapper.readValue(incomingMessage, InboundMessage.class)).thenReturn(inboundMessage);
269-
lenient().when(inboundMessage.getEbXML()).thenReturn(ebxml);
270-
lenient().when(inboundMessage.getPayload()).thenReturn(payload);
271-
272-
var ebxmlDocument = SERVICE.parseDocumentFromXml(ebxml);
273-
lenient().when(xPathService.parseDocumentFromXml(inboundMessage.getEbXML())).thenReturn(ebxmlDocument);
274-
lenient().when(xPathService.getNodeValue(ebxmlDocument, ACTION_PATH)).thenReturn(interactionId);
275-
lenient().when(xPathService.getNodeValue(ebxmlDocument, CONVERSATION_ID_PATH)).thenReturn(conversationId);
262+
SERVICE.parseDocumentFromXml(ebxml);
276263
}
277264

278265
@SneakyThrows
279266
private void mockAcknowledgementMessage(String ebxml, String payload, String interactionId, String conversationId) {
280-
when(xPathService.getNodeValue(any(), any())).thenReturn(ACK_OK_CODE);
281267
mockIncomingMessage(ebxml, payload, interactionId, conversationId);
282268
}
283269
}

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

Lines changed: 54 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
55
import static org.mockito.ArgumentMatchers.any;
66
import static org.mockito.Mockito.doThrow;
7-
import static org.mockito.Mockito.lenient;
87
import static org.mockito.Mockito.verify;
98
import static org.mockito.Mockito.when;
109

@@ -40,7 +39,7 @@
4039
@ExtendWith({SpringExtension.class, MongoDBExtension.class, ActiveMQExtension.class, MockitoExtension.class})
4140
@DirtiesContext
4241
@SpringBootTest(properties = {
43-
"command.line.runner.enabled=false"})
42+
"command.line.runner.enabled=false"})
4443
public class SendAcknowledgementComponentTest {
4544
private static final String GENERATED_RANDOM_ID = "GENERATED-RANDOM-ID";
4645
private static final String FROM_ASID = "0000222-from-asid";
@@ -83,7 +82,7 @@ public class SendAcknowledgementComponentTest {
8382
@BeforeEach
8483
public void setUp() {
8584
when(randomIdGeneratorService.createNewId()).thenReturn(GENERATED_RANDOM_ID);
86-
lenient().when(timestampService.now()).thenReturn(Instant.parse(DATE));
85+
when(timestampService.now()).thenReturn(Instant.parse(DATE));
8786

8887
ehrExtractStatus = EhrExtractStatusTestUtils.prepareEhrExtractStatus();
8988
ehrExtractStatusRepository.save(ehrExtractStatus);
@@ -113,26 +112,26 @@ public void When_AcknowledgementTaskRunsTwice_Expect_DatabaseOverwritesEhrExtrac
113112
@Test
114113
public void When_NegativeAcknowledgementTaskExecuted_Expect_ValidRequestSentToMhs() {
115114
var taskDefinition =
116-
SendAcknowledgementTaskDefinition.builder()
117-
.fromAsid(FROM_ASID)
118-
.toAsid(TO_ASID)
119-
.fromOdsCode(FROM_ODS_CODE)
120-
.toOdsCode(TO_ODS_CODE)
121-
.ehrRequestMessageId(EHR_REQUEST_MESSAGE_ID)
122-
.reasonCode(REASON_CODE)
123-
.detail(REASON_MESSAGE)
124-
.conversationId(EhrStatusConstants.CONVERSATION_ID)
125-
.taskId(TASK_ID)
126-
.typeCode(NEGATIVE_ACK_TYPE_CODE)
127-
.build();
115+
SendAcknowledgementTaskDefinition.builder()
116+
.fromAsid(FROM_ASID)
117+
.toAsid(TO_ASID)
118+
.fromOdsCode(FROM_ODS_CODE)
119+
.toOdsCode(TO_ODS_CODE)
120+
.ehrRequestMessageId(EHR_REQUEST_MESSAGE_ID)
121+
.reasonCode(REASON_CODE)
122+
.detail(REASON_MESSAGE)
123+
.conversationId(EhrStatusConstants.CONVERSATION_ID)
124+
.taskId(TASK_ID)
125+
.typeCode(NEGATIVE_ACK_TYPE_CODE)
126+
.build();
128127

129128
sendAcknowledgementExecutor.execute(taskDefinition);
130129

131130
verify(mhsRequestBuilder).buildSendAcknowledgementRequest(
132-
asString(expectedNackMessage), FROM_ODS_CODE, EhrStatusConstants.CONVERSATION_ID, GENERATED_RANDOM_ID);
131+
asString(expectedNackMessage), FROM_ODS_CODE, EhrStatusConstants.CONVERSATION_ID, GENERATED_RANDOM_ID);
133132

134133
EhrExtractStatus updatedEhrExtractStatus =
135-
ehrExtractStatusRepository.findByConversationId(EhrStatusConstants.CONVERSATION_ID).get();
134+
ehrExtractStatusRepository.findByConversationId(EhrStatusConstants.CONVERSATION_ID).get();
136135
EhrExtractStatus.AckToRequester ackToRequester = updatedEhrExtractStatus.getAckToRequester();
137136
assertThat(ackToRequester.getTaskId()).isEqualTo(TASK_ID);
138137
assertThat(ackToRequester.getMessageId()).isEqualTo(GENERATED_RANDOM_ID);
@@ -144,24 +143,24 @@ public void When_NegativeAcknowledgementTaskExecuted_Expect_ValidRequestSentToMh
144143
@Test
145144
public void When_PositiveAcknowledgementTaskExecuted_Expect_ValidRequestSentToMhs() {
146145
var taskDefinition =
147-
SendAcknowledgementTaskDefinition.builder()
148-
.fromAsid(FROM_ASID)
149-
.toAsid(TO_ASID)
150-
.fromOdsCode(FROM_ODS_CODE)
151-
.toOdsCode(TO_ODS_CODE)
152-
.ehrRequestMessageId(EHR_REQUEST_MESSAGE_ID)
153-
.conversationId(EhrStatusConstants.CONVERSATION_ID)
154-
.taskId(TASK_ID)
155-
.typeCode(POSITIVE_ACK_TYPE_CODE)
156-
.build();
146+
SendAcknowledgementTaskDefinition.builder()
147+
.fromAsid(FROM_ASID)
148+
.toAsid(TO_ASID)
149+
.fromOdsCode(FROM_ODS_CODE)
150+
.toOdsCode(TO_ODS_CODE)
151+
.ehrRequestMessageId(EHR_REQUEST_MESSAGE_ID)
152+
.conversationId(EhrStatusConstants.CONVERSATION_ID)
153+
.taskId(TASK_ID)
154+
.typeCode(POSITIVE_ACK_TYPE_CODE)
155+
.build();
157156

158157
sendAcknowledgementExecutor.execute(taskDefinition);
159158

160159
verify(mhsRequestBuilder).buildSendAcknowledgementRequest(
161-
asString(expectedAckMessage), FROM_ODS_CODE, EhrStatusConstants.CONVERSATION_ID, GENERATED_RANDOM_ID);
160+
asString(expectedAckMessage), FROM_ODS_CODE, EhrStatusConstants.CONVERSATION_ID, GENERATED_RANDOM_ID);
162161

163162
EhrExtractStatus updatedEhrExtractStatus =
164-
ehrExtractStatusRepository.findByConversationId(EhrStatusConstants.CONVERSATION_ID).get();
163+
ehrExtractStatusRepository.findByConversationId(EhrStatusConstants.CONVERSATION_ID).get();
165164
EhrExtractStatus.AckToRequester ackToRequester = updatedEhrExtractStatus.getAckToRequester();
166165
assertThat(ackToRequester.getTaskId()).isEqualTo(TASK_ID);
167166
assertThat(ackToRequester.getMessageId()).isEqualTo(GENERATED_RANDOM_ID);
@@ -173,51 +172,51 @@ public void When_PositiveAcknowledgementTaskExecuted_Expect_ValidRequestSentToMh
173172
@Test
174173
public void When_SendAckTaskExecuted_WithMhsConnectionException_Expect_ExceptionThrownAndDbNotUpdated() {
175174
var taskDefinition =
176-
SendAcknowledgementTaskDefinition.builder()
177-
.fromAsid(FROM_ASID)
178-
.toAsid(TO_ASID)
179-
.fromOdsCode(FROM_ODS_CODE)
180-
.toOdsCode(TO_ODS_CODE)
181-
.ehrRequestMessageId(EHR_REQUEST_MESSAGE_ID)
182-
.conversationId(EhrStatusConstants.CONVERSATION_ID)
183-
.taskId(TASK_ID)
184-
.typeCode(POSITIVE_ACK_TYPE_CODE)
185-
.build();
175+
SendAcknowledgementTaskDefinition.builder()
176+
.fromAsid(FROM_ASID)
177+
.toAsid(TO_ASID)
178+
.fromOdsCode(FROM_ODS_CODE)
179+
.toOdsCode(TO_ODS_CODE)
180+
.ehrRequestMessageId(EHR_REQUEST_MESSAGE_ID)
181+
.conversationId(EhrStatusConstants.CONVERSATION_ID)
182+
.taskId(TASK_ID)
183+
.typeCode(POSITIVE_ACK_TYPE_CODE)
184+
.build();
186185

187186
doThrow(MhsConnectionException.class).when(mhsClient).sendMessageToMHS(any());
188187

189188
assertThatExceptionOfType(MhsConnectionException.class)
190-
.isThrownBy(() -> sendAcknowledgementExecutor.execute(taskDefinition));
189+
.isThrownBy(() -> sendAcknowledgementExecutor.execute(taskDefinition));
191190

192191
var updatedEhrExtractStatus = ehrExtractStatusRepository
193-
.findByConversationId(EhrStatusConstants.CONVERSATION_ID)
194-
.orElseThrow();
192+
.findByConversationId(EhrStatusConstants.CONVERSATION_ID)
193+
.orElseThrow();
195194

196195
assertThat(updatedEhrExtractStatus.getAckToRequester()).isNull();
197196
}
198197

199198
@Test
200199
public void When_SendAckTaskExecuted_WithMhsServerErrorException_Expect_ExceptionThrownAndDbNotUpdated() {
201200
var taskDefinition =
202-
SendAcknowledgementTaskDefinition.builder()
203-
.fromAsid(FROM_ASID)
204-
.toAsid(TO_ASID)
205-
.fromOdsCode(FROM_ODS_CODE)
206-
.toOdsCode(TO_ODS_CODE)
207-
.ehrRequestMessageId(EHR_REQUEST_MESSAGE_ID)
208-
.conversationId(EhrStatusConstants.CONVERSATION_ID)
209-
.taskId(TASK_ID)
210-
.typeCode(POSITIVE_ACK_TYPE_CODE)
211-
.build();
201+
SendAcknowledgementTaskDefinition.builder()
202+
.fromAsid(FROM_ASID)
203+
.toAsid(TO_ASID)
204+
.fromOdsCode(FROM_ODS_CODE)
205+
.toOdsCode(TO_ODS_CODE)
206+
.ehrRequestMessageId(EHR_REQUEST_MESSAGE_ID)
207+
.conversationId(EhrStatusConstants.CONVERSATION_ID)
208+
.taskId(TASK_ID)
209+
.typeCode(POSITIVE_ACK_TYPE_CODE)
210+
.build();
212211

213212
doThrow(MhsServerErrorException.class).when(mhsClient).sendMessageToMHS(any());
214213

215214
assertThatExceptionOfType(MhsServerErrorException.class)
216-
.isThrownBy(() -> sendAcknowledgementExecutor.execute(taskDefinition));
215+
.isThrownBy(() -> sendAcknowledgementExecutor.execute(taskDefinition));
217216

218217
var updatedEhrExtractStatus = ehrExtractStatusRepository
219-
.findByConversationId(EhrStatusConstants.CONVERSATION_ID)
220-
.orElseThrow();
218+
.findByConversationId(EhrStatusConstants.CONVERSATION_ID)
219+
.orElseThrow();
221220

222221
assertThat(updatedEhrExtractStatus.getAckToRequester()).isNull();
223222
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import static org.mockito.ArgumentMatchers.any;
55
import static org.mockito.Mockito.doReturn;
66
import static org.mockito.Mockito.doThrow;
7-
import static org.mockito.Mockito.lenient;
87
import static org.mockito.Mockito.never;
98
import static org.mockito.Mockito.verify;
109
import static org.mockito.Mockito.verifyNoInteractions;
@@ -73,7 +72,7 @@ public class TaskHandlingTest {
7372

7473
@BeforeEach
7574
public void setup() {
76-
lenient().doReturn(taskExecutor).when(taskExecutorFactory).getTaskExecutor(any());
75+
doReturn(taskExecutor).when(taskExecutorFactory).getTaskExecutor(any());
7776
}
7877

7978
@Test

0 commit comments

Comments
 (0)