3535
3636import static org .assertj .core .api .Assertions .assertThatExceptionOfType ;
3737import static org .mockito .ArgumentMatchers .any ;
38- import static org .mockito .Mockito .lenient ;
3938import static org .mockito .Mockito .mock ;
4039import static org .mockito .Mockito .times ;
4140import static org .mockito .Mockito .verify ;
@@ -142,12 +141,17 @@ private GetGpcStructuredTaskDefinition createTaskMatchingXmlFixture() {
142141
143142 private static List <String > pathsToBodyValues () {
144143 return List .of (
145- "/RCMR_IN010000UK05/ControlActEvent/subject/EhrRequest/id/@root" ,
146144 "/RCMR_IN010000UK05/ControlActEvent/subject/EhrRequest/recordTarget/patient/id/@extension" ,
145+ "/RCMR_IN010000UK05/ControlActEvent/subject/EhrRequest/destination/AgentOrgSDS/agentOrganizationSDS/id/@extension"
146+ );
147+ }
148+
149+ private static List <String > pathsToBodyValuesNoEhrExtract () {
150+ return List .of (
151+ "/RCMR_IN010000UK05/ControlActEvent/subject/EhrRequest/id/@root" ,
147152 "/RCMR_IN010000UK05/communicationFunctionSnd/device/id/@extension" ,
148153 "/RCMR_IN010000UK05/communicationFunctionRcv/device/id/@extension" ,
149- "/RCMR_IN010000UK05/ControlActEvent/subject/EhrRequest/author/AgentOrgSDS/agentOrganizationSDS/id/@extension" ,
150- "/RCMR_IN010000UK05/ControlActEvent/subject/EhrRequest/destination/AgentOrgSDS/agentOrganizationSDS/id/@extension"
154+ "/RCMR_IN010000UK05/ControlActEvent/subject/EhrRequest/author/AgentOrgSDS/agentOrganizationSDS/id/@extension"
151155 );
152156 }
153157
@@ -158,7 +162,7 @@ void When_RequiredElementMissingFromBody_Expect_HandlerThrowsException(String xp
158162 Document header = ResourceHelper .loadClasspathResourceAsXml ("/ehr/request/RCMR_IN010000UK05_header.xml" );
159163 Document body = ResourceHelper .loadClasspathResourceAsXml ("/ehr/request/RCMR_IN010000UK05_body.xml" );
160164
161- lenient (). when (ehrExtractStatusRepository .save (any ()))
165+ when (ehrExtractStatusRepository .save (any ()))
162166 .thenAnswer ((Answer <EhrExtractStatus >) invocation -> (EhrExtractStatus ) invocation .getArguments ()[0 ]);
163167
164168 removeAttributeElement (xpath , body );
@@ -176,7 +180,7 @@ void When_RequiredValueIsBlankInBody_Expect_HandlerThrowsException(String xpath)
176180 Document header = ResourceHelper .loadClasspathResourceAsXml ("/ehr/request/RCMR_IN010000UK05_header.xml" );
177181 Document body = ResourceHelper .loadClasspathResourceAsXml ("/ehr/request/RCMR_IN010000UK05_body.xml" );
178182
179- lenient (). when (ehrExtractStatusRepository .save (any ()))
183+ when (ehrExtractStatusRepository .save (any ()))
180184 .thenAnswer ((Answer <EhrExtractStatus >) invocation -> (EhrExtractStatus ) invocation .getArguments ()[0 ]);
181185
182186 clearAttribute (xpath , body );
@@ -187,6 +191,21 @@ void When_RequiredValueIsBlankInBody_Expect_HandlerThrowsException(String xpath)
187191 .withMessageContaining (SpineInteraction .EHR_EXTRACT_REQUEST .getInteractionId ());
188192 }
189193
194+ @ SneakyThrows
195+ @ ParameterizedTest
196+ @ MethodSource ("pathsToBodyValuesNoEhrExtract" )
197+ void When_RequiredValueIsBlankInBodyAndNoNeedForEhrExtract_Expect_HandlerThrowsException (String xpath ) {
198+ Document header = ResourceHelper .loadClasspathResourceAsXml ("/ehr/request/RCMR_IN010000UK05_header.xml" );
199+ Document body = ResourceHelper .loadClasspathResourceAsXml ("/ehr/request/RCMR_IN010000UK05_body.xml" );
200+
201+ clearAttribute (xpath , body );
202+
203+ assertThatExceptionOfType (MissingValueException .class )
204+ .isThrownBy (() -> ehrExtractRequestHandler .handleStart (header , body , MESSAGE_TIMESTAMP ))
205+ .withMessageContaining (xpath )
206+ .withMessageContaining (SpineInteraction .EHR_EXTRACT_REQUEST .getInteractionId ());
207+ }
208+
190209 private static List <String > pathsToHeaderValues () {
191210 return List .of (
192211 "/Envelope/Header/MessageHeader/From/PartyId" ,
0 commit comments