88import org .opendevstack .apiservice .externalservice .aap .exception .AutomationPlatformException ;
99import org .opendevstack .apiservice .externalservice .aap .model .AutomationExecutionResult ;
1010import org .opendevstack .apiservice .externalservice .aap .model .AutomationJobStatus ;
11+ import org .springframework .core .ParameterizedTypeReference ;
1112import org .springframework .test .util .ReflectionTestUtils ;
1213import org .springframework .web .client .RestClient ;
1314import org .springframework .web .client .RestClientException ;
@@ -81,7 +82,7 @@ void executeWorkflow_Success() throws AutomationPlatformException {
8182 responseBody .put ("status" , "pending" );
8283 responseBody .put ("url" , BASE_URL + "/workflow_jobs/12345/" );
8384
84- when (postResponseSpec .body (Map .class )). thenReturn ( responseBody );
85+ doReturn ( responseBody ). when (postResponseSpec ) .body (any ( ParameterizedTypeReference .class ));
8586
8687 AutomationExecutionResult result = service .executeWorkflow ("test-workflow" , Map .of ("env" , "dev" ));
8788
@@ -99,7 +100,7 @@ void executeWorkflow_WithNullParameters() throws AutomationPlatformException {
99100 responseBody .put ("id" , "12345" );
100101 responseBody .put ("status" , "pending" );
101102
102- when (postResponseSpec .body (Map .class )). thenReturn ( responseBody );
103+ doReturn ( responseBody ). when (postResponseSpec ) .body (any ( ParameterizedTypeReference .class ));
103104
104105 AutomationExecutionResult result = service .executeWorkflow ("test-workflow" , null );
105106
@@ -122,7 +123,7 @@ void executeWorkflow_RestClientException() {
122123
123124 @ Test
124125 void executeWorkflow_NullResponseBody () {
125- when (postResponseSpec .body (Map .class )). thenReturn ( null );
126+ doReturn ( null ). when (postResponseSpec ) .body (any ( ParameterizedTypeReference .class ));
126127
127128 AutomationPlatformException .WorkflowExecutionException ex = assertThrows (
128129 AutomationPlatformException .WorkflowExecutionException .class ,
@@ -134,7 +135,7 @@ void executeWorkflow_NullResponseBody() {
134135 @ Test
135136 void executeWorkflow_EmptyParameters () throws AutomationPlatformException {
136137 Map <String , Object > responseBody = Map .of ("id" , "12345" , "status" , "pending" );
137- when (postResponseSpec .body (Map .class )). thenReturn ( responseBody );
138+ doReturn ( responseBody ). when (postResponseSpec ) .body (any ( ParameterizedTypeReference .class ));
138139
139140 AutomationExecutionResult result = service .executeWorkflow ("test-workflow" , new HashMap <>());
140141 assertNotNull (result );
@@ -144,7 +145,7 @@ void executeWorkflow_EmptyParameters() throws AutomationPlatformException {
144145 @ Test
145146 void executeWorkflow_VerifyExtraVarsPassedCorrectly () throws AutomationPlatformException {
146147 Map <String , Object > responseBody = Map .of ("id" , "99999" , "status" , "pending" );
147- when (postResponseSpec .body (Map .class )). thenReturn ( responseBody );
148+ doReturn ( responseBody ). when (postResponseSpec ) .body (any ( ParameterizedTypeReference .class ));
148149
149150 Map <String , Object > params = new HashMap <>();
150151 params .put ("app_name" , "my-app" );
@@ -163,7 +164,7 @@ void executeWorkflow_VerifyExtraVarsPassedCorrectly() throws AutomationPlatformE
163164 @ Test
164165 void executeWorkflowAsync_Success () throws ExecutionException , InterruptedException {
165166 Map <String , Object > responseBody = Map .of ("id" , "67890" , "status" , "running" );
166- when (postResponseSpec .body (Map .class )). thenReturn ( responseBody );
167+ doReturn ( responseBody ). when (postResponseSpec ) .body (any ( ParameterizedTypeReference .class ));
167168
168169 CompletableFuture <AutomationExecutionResult > future =
169170 service .executeWorkflowAsync ("test-workflow" , Map .of ("env" , "prod" ));
@@ -199,7 +200,7 @@ void getJobStatus_Success() throws AutomationPlatformException {
199200 responseBody .put ("status" , "successful" );
200201 responseBody .put ("result_traceback" , "Job completed successfully" );
201202
202- when (getResponseSpec .body (Map .class )). thenReturn ( responseBody );
203+ doReturn ( responseBody ). when (getResponseSpec ) .body (any ( ParameterizedTypeReference .class ));
203204
204205 AutomationJobStatus status = service .getJobStatus ("12345" );
205206
@@ -212,45 +213,45 @@ void getJobStatus_Success() throws AutomationPlatformException {
212213
213214 @ Test
214215 void getJobStatus_PendingStatus () throws AutomationPlatformException {
215- when ( getResponseSpec . body ( Map .class )). thenReturn ( Map . of ("status" , "pending" ));
216+ doReturn ( Map .of ("status" , "pending" )). when ( getResponseSpec ). body ( any ( ParameterizedTypeReference . class ));
216217 assertEquals (AutomationJobStatus .Status .PENDING , service .getJobStatus ("1" ).getStatus ());
217218 }
218219
219220 @ Test
220221 void getJobStatus_RunningStatus () throws AutomationPlatformException {
221- when ( getResponseSpec . body ( Map .class )). thenReturn ( Map . of ("status" , "running" ));
222+ doReturn ( Map .of ("status" , "running" )). when ( getResponseSpec ). body ( any ( ParameterizedTypeReference . class ));
222223 assertEquals (AutomationJobStatus .Status .RUNNING , service .getJobStatus ("1" ).getStatus ());
223224 }
224225
225226 @ Test
226227 void getJobStatus_FailedStatus () throws AutomationPlatformException {
227- when ( getResponseSpec . body ( Map .class )). thenReturn ( Map . of ("status" , "failed" ));
228+ doReturn ( Map .of ("status" , "failed" )). when ( getResponseSpec ). body ( any ( ParameterizedTypeReference . class ));
228229 assertEquals (AutomationJobStatus .Status .FAILED , service .getJobStatus ("1" ).getStatus ());
229230 }
230231
231232 @ Test
232233 void getJobStatus_CancelledStatus () throws AutomationPlatformException {
233- when ( getResponseSpec . body ( Map .class )). thenReturn ( Map . of ("status" , "canceled" ));
234+ doReturn ( Map .of ("status" , "canceled" )). when ( getResponseSpec ). body ( any ( ParameterizedTypeReference . class ));
234235 assertEquals (AutomationJobStatus .Status .CANCELLED , service .getJobStatus ("1" ).getStatus ());
235236 }
236237
237238 @ Test
238239 void getJobStatus_CancelledAlternativeSpelling () throws AutomationPlatformException {
239- when ( getResponseSpec . body ( Map .class )). thenReturn ( Map . of ("status" , "cancelled" ));
240+ doReturn ( Map .of ("status" , "cancelled" )). when ( getResponseSpec ). body ( any ( ParameterizedTypeReference . class ));
240241 assertEquals (AutomationJobStatus .Status .CANCELLED , service .getJobStatus ("1" ).getStatus ());
241242 }
242243
243244 @ Test
244245 void getJobStatus_UnknownStatus () throws AutomationPlatformException {
245- when ( getResponseSpec . body ( Map .class )). thenReturn ( Map . of ("status" , "unknown_status" ));
246+ doReturn ( Map .of ("status" , "unknown_status" )). when ( getResponseSpec ). body ( any ( ParameterizedTypeReference . class ));
246247 assertEquals (AutomationJobStatus .Status .ERROR , service .getJobStatus ("1" ).getStatus ());
247248 }
248249
249250 @ Test
250251 void getJobStatus_NullStatus () throws AutomationPlatformException {
251252 Map <String , Object > body = new HashMap <>();
252253 body .put ("status" , null );
253- when (getResponseSpec .body (Map .class )). thenReturn ( body );
254+ doReturn ( body ). when (getResponseSpec ) .body (any ( ParameterizedTypeReference .class ));
254255 assertEquals (AutomationJobStatus .Status .ERROR , service .getJobStatus ("1" ).getStatus ());
255256 }
256257
@@ -268,7 +269,7 @@ void getJobStatus_JobNotFound() {
268269
269270 @ Test
270271 void getJobStatus_NullResponseBody () {
271- when (getResponseSpec .body (Map .class )). thenReturn ( null );
272+ doReturn ( null ). when (getResponseSpec ) .body (any ( ParameterizedTypeReference .class ));
272273
273274 assertThrows (
274275 AutomationPlatformException .JobNotFoundException .class ,
@@ -286,7 +287,7 @@ void getWorkflowJobStatus_Success() throws AutomationPlatformException {
286287 responseBody .put ("status" , "successful" );
287288 responseBody .put ("result_traceback" , "Workflow completed" );
288289
289- when (getResponseSpec .body (Map .class )). thenReturn ( responseBody );
290+ doReturn ( responseBody ). when (getResponseSpec ) .body (any ( ParameterizedTypeReference .class ));
290291
291292 AutomationJobStatus status = service .getWorkflowJobStatus ("67890" );
292293
@@ -295,7 +296,7 @@ void getWorkflowJobStatus_Success() throws AutomationPlatformException {
295296 assertEquals (AutomationJobStatus .Status .SUCCESSFUL , status .getStatus ());
296297 assertEquals ("Workflow completed" , status .getStatusMessage ());
297298
298- verify (getUriSpec ).uri (eq (BASE_URL + "/workflow_jobs/67890/" ));
299+ verify (getUriSpec , times ( 1 ) ).uri (eq (BASE_URL + "/workflow_jobs/67890/" ));
299300 }
300301
301302 @ Test
@@ -319,7 +320,7 @@ void validateConnection_Success() {
319320 when (getResponseSpec .toBodilessEntity ()).thenReturn (null ); // any non-throw = success
320321
321322 assertTrue (service .validateConnection ());
322- verify (getUriSpec ).uri (eq (BASE_URL + "/ping/" ));
323+ verify (getUriSpec , times ( 1 ) ).uri (eq (BASE_URL + "/ping/" ));
323324 }
324325
325326 @ Test
0 commit comments