55import static org .assertj .core .api .Assertions .assertThat ;
66import static org .junit .jupiter .api .Assertions .assertFalse ;
77import static org .mockito .ArgumentMatchers .any ;
8- import static org .mockito .Mockito .lenient ;
98import static org .mockito .Mockito .never ;
109import static org .mockito .Mockito .verify ;
1110import 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}
0 commit comments