Skip to content

Commit b5d3964

Browse files
committed
chore: reordering parameters.
Signed-off-by: Emmanuel Hugonnet <ehugonne@redhat.com>
1 parent f1bd581 commit b5d3964

6 files changed

Lines changed: 140 additions & 148 deletions

File tree

‎reference/rest/src/main/java/io/a2a/server/rest/quarkus/A2AServerRoutes.java‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public void sendMessage(@Body String body, RoutingContext rc) {
8787
ServerCallContext context = createCallContext(rc, SEND_MESSAGE_METHOD);
8888
HTTPRestResponse response = null;
8989
try {
90-
response = jsonRestHandler.sendMessage(body, extractTenant(rc), context);
90+
response = jsonRestHandler.sendMessage(context, extractTenant(rc), body);
9191
} catch (Throwable t) {
9292
response = jsonRestHandler.createErrorResponse(new InternalError(t.getMessage()));
9393
} finally {
@@ -101,7 +101,7 @@ public void sendMessageStreaming(@Body String body, RoutingContext rc) {
101101
HTTPRestStreamingResponse streamingResponse = null;
102102
HTTPRestResponse error = null;
103103
try {
104-
HTTPRestResponse response = jsonRestHandler.sendStreamingMessage(body, extractTenant(rc), context);
104+
HTTPRestResponse response = jsonRestHandler.sendStreamingMessage(context, extractTenant(rc), body);
105105
if (response instanceof HTTPRestStreamingResponse hTTPRestStreamingResponse) {
106106
streamingResponse = hTTPRestStreamingResponse;
107107
} else {
@@ -153,8 +153,8 @@ public void listTasks(RoutingContext rc) {
153153
includeArtifacts = Boolean.valueOf(includeArtifactsStr);
154154
}
155155

156-
response = jsonRestHandler.listTasks(contextId, statusStr, pageSize, pageToken,
157-
historyLength, lastUpdatedAfter, includeArtifacts, extractTenant(rc), context);
156+
response = jsonRestHandler.listTasks(context, extractTenant(rc), contextId, statusStr, pageSize, pageToken,
157+
historyLength, lastUpdatedAfter, includeArtifacts);
158158
} catch (NumberFormatException e) {
159159
response = jsonRestHandler.createErrorResponse(new InvalidParamsError("Invalid number format in parameters"));
160160
} catch (IllegalArgumentException e) {
@@ -179,7 +179,7 @@ public void getTask(RoutingContext rc) {
179179
if (rc.request().params().contains(HISTORY_LENGTH_PARAM)) {
180180
historyLength = Integer.valueOf(rc.request().params().get(HISTORY_LENGTH_PARAM));
181181
}
182-
response = jsonRestHandler.getTask(taskId, historyLength, extractTenant(rc), context);
182+
response = jsonRestHandler.getTask(context, extractTenant(rc), taskId, historyLength);
183183
}
184184
} catch (NumberFormatException e) {
185185
response = jsonRestHandler.createErrorResponse(new InvalidParamsError("bad historyLength"));
@@ -199,7 +199,7 @@ public void cancelTask(RoutingContext rc) {
199199
if (taskId == null || taskId.isEmpty()) {
200200
response = jsonRestHandler.createErrorResponse(new InvalidParamsError("bad task id"));
201201
} else {
202-
response = jsonRestHandler.cancelTask(taskId, extractTenant(rc), context);
202+
response = jsonRestHandler.cancelTask(context, extractTenant(rc), taskId);
203203
}
204204
} catch (Throwable t) {
205205
if (t instanceof A2AError error) {
@@ -233,7 +233,7 @@ public void subscribeToTask(RoutingContext rc) {
233233
if (taskId == null || taskId.isEmpty()) {
234234
error = jsonRestHandler.createErrorResponse(new InvalidParamsError("bad task id"));
235235
} else {
236-
HTTPRestResponse response = jsonRestHandler.subscribeToTask(taskId, extractTenant(rc), context);
236+
HTTPRestResponse response = jsonRestHandler.subscribeToTask(context, extractTenant(rc), taskId);
237237
if (response instanceof HTTPRestStreamingResponse hTTPRestStreamingResponse) {
238238
streamingResponse = hTTPRestStreamingResponse;
239239
} else {
@@ -262,7 +262,7 @@ public void setTaskPushNotificationConfiguration(@Body String body, RoutingConte
262262
if (taskId == null || taskId.isEmpty()) {
263263
response = jsonRestHandler.createErrorResponse(new InvalidParamsError("bad task id"));
264264
} else {
265-
response = jsonRestHandler.setTaskPushNotificationConfiguration(taskId, body, extractTenant(rc), context);
265+
response = jsonRestHandler.setTaskPushNotificationConfiguration(context, extractTenant(rc), body, taskId);
266266
}
267267
} catch (Throwable t) {
268268
response = jsonRestHandler.createErrorResponse(new InternalError(t.getMessage()));
@@ -281,7 +281,7 @@ public void getTaskPushNotificationConfiguration(RoutingContext rc) {
281281
if (taskId == null || taskId.isEmpty()) {
282282
response = jsonRestHandler.createErrorResponse(new InvalidParamsError("bad task id"));
283283
} else {
284-
response = jsonRestHandler.getTaskPushNotificationConfiguration(taskId, configId, extractTenant(rc), context);
284+
response = jsonRestHandler.getTaskPushNotificationConfiguration(context, extractTenant(rc), taskId, configId);
285285
}
286286
} catch (Throwable t) {
287287
response = jsonRestHandler.createErrorResponse(new InternalError(t.getMessage()));
@@ -300,7 +300,7 @@ public void getTaskPushNotificationConfigurationWithoutId(RoutingContext rc) {
300300
response = jsonRestHandler.createErrorResponse(new InvalidParamsError("bad task id"));
301301
} else {
302302
// Call get with null configId - trailing slash distinguishes this from list
303-
response = jsonRestHandler.getTaskPushNotificationConfiguration(taskId, null, extractTenant(rc), context);
303+
response = jsonRestHandler.getTaskPushNotificationConfiguration(context, extractTenant(rc), taskId, null);
304304
}
305305
} catch (Throwable t) {
306306
response = jsonRestHandler.createErrorResponse(new InternalError(t.getMessage()));
@@ -326,7 +326,7 @@ public void listTaskPushNotificationConfigurations(RoutingContext rc) {
326326
if (rc.request().params().contains(PAGE_TOKEN_PARAM)) {
327327
pageToken = Utils.defaultIfNull(rc.request().params().get(PAGE_TOKEN_PARAM), "");
328328
}
329-
response = jsonRestHandler.listTaskPushNotificationConfigurations(taskId, pageSize, pageToken, extractTenant(rc), context);
329+
response = jsonRestHandler.listTaskPushNotificationConfigurations(context, extractTenant(rc), taskId, pageSize, pageToken);
330330
}
331331
} catch (NumberFormatException e) {
332332
response = jsonRestHandler.createErrorResponse(new InvalidParamsError("bad " + PAGE_SIZE_PARAM));
@@ -349,7 +349,7 @@ public void deleteTaskPushNotificationConfiguration(RoutingContext rc) {
349349
} else if (configId == null || configId.isEmpty()) {
350350
response = jsonRestHandler.createErrorResponse(new InvalidParamsError("bad config id"));
351351
} else {
352-
response = jsonRestHandler.deleteTaskPushNotificationConfiguration(taskId, configId, extractTenant(rc), context);
352+
response = jsonRestHandler.deleteTaskPushNotificationConfiguration(context, extractTenant(rc), taskId, configId);
353353
}
354354
} catch (Throwable t) {
355355
response = jsonRestHandler.createErrorResponse(new InternalError(t.getMessage()));
@@ -388,7 +388,7 @@ public void getAgentCard(RoutingContext rc) {
388388

389389
@Route(regex = "^\\/(?<tenant>[^\\/]*\\/?)extendedAgentCard$", order = 1, methods = Route.HttpMethod.GET, produces = APPLICATION_JSON)
390390
public void getExtendedAgentCard(RoutingContext rc) {
391-
HTTPRestResponse response = jsonRestHandler.getExtendedAgentCard(extractTenant(rc), createCallContext(rc, GET_EXTENDED_AGENT_CARD_METHOD));
391+
HTTPRestResponse response = jsonRestHandler.getExtendedAgentCard(createCallContext(rc, GET_EXTENDED_AGENT_CARD_METHOD), extractTenant(rc));
392392
sendResponse(rc, response);
393393
}
394394

‎reference/rest/src/test/java/io/a2a/server/rest/quarkus/A2AServerRoutesTest.java‎

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,15 @@ public void testSendMessage_MethodNameSetInContext() {
9494
when(mockHttpResponse.getStatusCode()).thenReturn(200);
9595
when(mockHttpResponse.getContentType()).thenReturn("application/json");
9696
when(mockHttpResponse.getBody()).thenReturn("{}");
97-
when(mockRestHandler.sendMessage(anyString(), anyString(), any(ServerCallContext.class))).thenReturn(mockHttpResponse);
97+
when(mockRestHandler.sendMessage(any(ServerCallContext.class), anyString(), anyString())).thenReturn(mockHttpResponse);
9898

9999
ArgumentCaptor<ServerCallContext> contextCaptor = ArgumentCaptor.forClass(ServerCallContext.class);
100100

101101
// Act
102102
routes.sendMessage("{}", mockRoutingContext);
103103

104104
// Assert
105-
verify(mockRestHandler).sendMessage(eq("{}"), anyString(), contextCaptor.capture());
105+
verify(mockRestHandler).sendMessage(contextCaptor.capture(), anyString(), eq("{}"));
106106
ServerCallContext capturedContext = contextCaptor.getValue();
107107
assertNotNull(capturedContext);
108108
assertEquals(SEND_MESSAGE_METHOD, capturedContext.getState().get(METHOD_NAME_KEY));
@@ -115,7 +115,7 @@ public void testSendMessageStreaming_MethodNameSetInContext() {
115115
when(mockHttpResponse.getStatusCode()).thenReturn(200);
116116
when(mockHttpResponse.getContentType()).thenReturn("application/json");
117117
when(mockHttpResponse.getBody()).thenReturn("{}");
118-
when(mockRestHandler.sendStreamingMessage(anyString(), anyString(), any(ServerCallContext.class)))
118+
when(mockRestHandler.sendStreamingMessage(any(ServerCallContext.class), anyString(), anyString()))
119119
.thenReturn(mockHttpResponse);
120120

121121
ArgumentCaptor<ServerCallContext> contextCaptor = ArgumentCaptor.forClass(ServerCallContext.class);
@@ -124,7 +124,7 @@ public void testSendMessageStreaming_MethodNameSetInContext() {
124124
routes.sendMessageStreaming("{}", mockRoutingContext);
125125

126126
// Assert
127-
verify(mockRestHandler).sendStreamingMessage(eq("{}"), anyString(), contextCaptor.capture());
127+
verify(mockRestHandler).sendStreamingMessage(contextCaptor.capture(), anyString(), eq("{}"));
128128
ServerCallContext capturedContext = contextCaptor.getValue();
129129
assertNotNull(capturedContext);
130130
assertEquals(SEND_STREAMING_MESSAGE_METHOD, capturedContext.getState().get(METHOD_NAME_KEY));
@@ -138,15 +138,15 @@ public void testGetTask_MethodNameSetInContext() {
138138
when(mockHttpResponse.getStatusCode()).thenReturn(200);
139139
when(mockHttpResponse.getContentType()).thenReturn("application/json");
140140
when(mockHttpResponse.getBody()).thenReturn("{test:value}");
141-
when(mockRestHandler.getTask(anyString(), any(), anyString(), any(ServerCallContext.class))).thenReturn(mockHttpResponse);
141+
when(mockRestHandler.getTask(any(ServerCallContext.class), anyString(), anyString(), any())).thenReturn(mockHttpResponse);
142142

143143
ArgumentCaptor<ServerCallContext> contextCaptor = ArgumentCaptor.forClass(ServerCallContext.class);
144144

145145
// Act
146146
routes.getTask(mockRoutingContext);
147147

148148
// Assert
149-
verify(mockRestHandler).getTask(eq("task123"), any(), anyString(), contextCaptor.capture());
149+
verify(mockRestHandler).getTask(contextCaptor.capture(), anyString(), eq("task123"), any());
150150
ServerCallContext capturedContext = contextCaptor.getValue();
151151
assertNotNull(capturedContext);
152152
assertEquals(GET_TASK_METHOD, capturedContext.getState().get(METHOD_NAME_KEY));
@@ -160,15 +160,15 @@ public void testCancelTask_MethodNameSetInContext() {
160160
when(mockHttpResponse.getStatusCode()).thenReturn(200);
161161
when(mockHttpResponse.getContentType()).thenReturn("application/json");
162162
when(mockHttpResponse.getBody()).thenReturn("{}");
163-
when(mockRestHandler.cancelTask(anyString(), anyString(), any(ServerCallContext.class))).thenReturn(mockHttpResponse);
163+
when(mockRestHandler.cancelTask(any(ServerCallContext.class), anyString(), anyString())).thenReturn(mockHttpResponse);
164164

165165
ArgumentCaptor<ServerCallContext> contextCaptor = ArgumentCaptor.forClass(ServerCallContext.class);
166166

167167
// Act
168168
routes.cancelTask(mockRoutingContext);
169169

170170
// Assert
171-
verify(mockRestHandler).cancelTask(eq("task123"), anyString(), contextCaptor.capture());
171+
verify(mockRestHandler).cancelTask(contextCaptor.capture(), anyString(), eq("task123"));
172172
ServerCallContext capturedContext = contextCaptor.getValue();
173173
assertNotNull(capturedContext);
174174
assertEquals(CANCEL_TASK_METHOD, capturedContext.getState().get(METHOD_NAME_KEY));
@@ -182,7 +182,7 @@ public void testResubscribeTask_MethodNameSetInContext() {
182182
when(mockHttpResponse.getStatusCode()).thenReturn(200);
183183
when(mockHttpResponse.getContentType()).thenReturn("application/json");
184184
when(mockHttpResponse.getBody()).thenReturn("{}");
185-
when(mockRestHandler.subscribeToTask(anyString(), anyString(), any(ServerCallContext.class)))
185+
when(mockRestHandler.subscribeToTask(any(ServerCallContext.class), anyString(), anyString()))
186186
.thenReturn(mockHttpResponse);
187187

188188
ArgumentCaptor<ServerCallContext> contextCaptor = ArgumentCaptor.forClass(ServerCallContext.class);
@@ -191,7 +191,7 @@ public void testResubscribeTask_MethodNameSetInContext() {
191191
routes.subscribeToTask(mockRoutingContext);
192192

193193
// Assert
194-
verify(mockRestHandler).subscribeToTask(eq("task123"), anyString(), contextCaptor.capture());
194+
verify(mockRestHandler).subscribeToTask(contextCaptor.capture(), anyString(), eq("task123"));
195195
ServerCallContext capturedContext = contextCaptor.getValue();
196196
assertNotNull(capturedContext);
197197
assertEquals(SUBSCRIBE_TO_TASK_METHOD, capturedContext.getState().get(METHOD_NAME_KEY));
@@ -205,16 +205,15 @@ public void testSetTaskPushNotificationConfiguration_MethodNameSetInContext() {
205205
when(mockHttpResponse.getStatusCode()).thenReturn(200);
206206
when(mockHttpResponse.getContentType()).thenReturn("application/json");
207207
when(mockHttpResponse.getBody()).thenReturn("{}");
208-
when(mockRestHandler.setTaskPushNotificationConfiguration(anyString(), anyString(), anyString(),
209-
any(ServerCallContext.class))).thenReturn(mockHttpResponse);
208+
when(mockRestHandler.setTaskPushNotificationConfiguration(any(ServerCallContext.class), anyString(), anyString(), anyString())).thenReturn(mockHttpResponse);
210209

211210
ArgumentCaptor<ServerCallContext> contextCaptor = ArgumentCaptor.forClass(ServerCallContext.class);
212211

213212
// Act
214213
routes.setTaskPushNotificationConfiguration("{}", mockRoutingContext);
215214

216215
// Assert
217-
verify(mockRestHandler).setTaskPushNotificationConfiguration(eq("task123"), eq("{}"), anyString(), contextCaptor.capture());
216+
verify(mockRestHandler).setTaskPushNotificationConfiguration(contextCaptor.capture(), anyString(), eq("{}"), eq("task123"));
218217
ServerCallContext capturedContext = contextCaptor.getValue();
219218
assertNotNull(capturedContext);
220219
assertEquals(SET_TASK_PUSH_NOTIFICATION_CONFIG_METHOD, capturedContext.getState().get(METHOD_NAME_KEY));
@@ -229,17 +228,16 @@ public void testGetTaskPushNotificationConfiguration_MethodNameSetInContext() {
229228
when(mockHttpResponse.getStatusCode()).thenReturn(200);
230229
when(mockHttpResponse.getContentType()).thenReturn("application/json");
231230
when(mockHttpResponse.getBody()).thenReturn("{}");
232-
when(mockRestHandler.getTaskPushNotificationConfiguration(anyString(), anyString(), anyString(),
233-
any(ServerCallContext.class))).thenReturn(mockHttpResponse);
231+
when(mockRestHandler.getTaskPushNotificationConfiguration(any(ServerCallContext.class), anyString(), anyString(), anyString())).thenReturn(mockHttpResponse);
234232

235233
ArgumentCaptor<ServerCallContext> contextCaptor = ArgumentCaptor.forClass(ServerCallContext.class);
236234

237235
// Act
238236
routes.getTaskPushNotificationConfiguration(mockRoutingContext);
239237

240238
// Assert
241-
verify(mockRestHandler).getTaskPushNotificationConfiguration(eq("task123"), eq("config456"), anyString(),
242-
contextCaptor.capture());
239+
verify(mockRestHandler).getTaskPushNotificationConfiguration(contextCaptor.capture(), anyString(), eq("task123"),
240+
eq("config456"));
243241
ServerCallContext capturedContext = contextCaptor.getValue();
244242
assertNotNull(capturedContext);
245243
assertEquals(GET_TASK_PUSH_NOTIFICATION_CONFIG_METHOD, capturedContext.getState().get(METHOD_NAME_KEY));
@@ -253,7 +251,7 @@ public void testListTaskPushNotificationConfigurations_MethodNameSetInContext()
253251
when(mockHttpResponse.getStatusCode()).thenReturn(200);
254252
when(mockHttpResponse.getContentType()).thenReturn("application/json");
255253
when(mockHttpResponse.getBody()).thenReturn("{}");
256-
when(mockRestHandler.listTaskPushNotificationConfigurations(anyString(), anyInt(), anyString(), anyString(), any(ServerCallContext.class)))
254+
when(mockRestHandler.listTaskPushNotificationConfigurations(any(ServerCallContext.class), anyString(), anyString(), anyInt(), anyString()))
257255
.thenReturn(mockHttpResponse);
258256

259257
ArgumentCaptor<ServerCallContext> contextCaptor = ArgumentCaptor.forClass(ServerCallContext.class);
@@ -262,7 +260,7 @@ public void testListTaskPushNotificationConfigurations_MethodNameSetInContext()
262260
routes.listTaskPushNotificationConfigurations(mockRoutingContext);
263261

264262
// Assert
265-
verify(mockRestHandler).listTaskPushNotificationConfigurations(eq("task123"), anyInt(), anyString(), anyString(), contextCaptor.capture());
263+
verify(mockRestHandler).listTaskPushNotificationConfigurations(contextCaptor.capture(), anyString(), eq("task123"), anyInt(), anyString());
266264
ServerCallContext capturedContext = contextCaptor.getValue();
267265
assertNotNull(capturedContext);
268266
assertEquals(LIST_TASK_PUSH_NOTIFICATION_CONFIG_METHOD, capturedContext.getState().get(METHOD_NAME_KEY));
@@ -277,17 +275,16 @@ public void testDeleteTaskPushNotificationConfiguration_MethodNameSetInContext()
277275
when(mockHttpResponse.getStatusCode()).thenReturn(200);
278276
when(mockHttpResponse.getContentType()).thenReturn("application/json");
279277
when(mockHttpResponse.getBody()).thenReturn("{}");
280-
when(mockRestHandler.deleteTaskPushNotificationConfiguration(anyString(), anyString(), anyString(),
281-
any(ServerCallContext.class))).thenReturn(mockHttpResponse);
278+
when(mockRestHandler.deleteTaskPushNotificationConfiguration(any(ServerCallContext.class), anyString(), anyString(), anyString())).thenReturn(mockHttpResponse);
282279

283280
ArgumentCaptor<ServerCallContext> contextCaptor = ArgumentCaptor.forClass(ServerCallContext.class);
284281

285282
// Act
286283
routes.deleteTaskPushNotificationConfiguration(mockRoutingContext);
287284

288285
// Assert
289-
verify(mockRestHandler).deleteTaskPushNotificationConfiguration(eq("task123"), eq("config456"), anyString(),
290-
contextCaptor.capture());
286+
verify(mockRestHandler).deleteTaskPushNotificationConfiguration(contextCaptor.capture(), anyString(), eq("task123"),
287+
eq("config456"));
291288
ServerCallContext capturedContext = contextCaptor.getValue();
292289
assertNotNull(capturedContext);
293290
assertEquals(DELETE_TASK_PUSH_NOTIFICATION_CONFIG_METHOD, capturedContext.getState().get(METHOD_NAME_KEY));

0 commit comments

Comments
 (0)