11package io .a2a .server .rest .quarkus ;
22
3+ import static io .a2a .common .MediaType .APPLICATION_JSON ;
34import static io .a2a .spec .A2AMethods .CANCEL_TASK_METHOD ;
45import static io .a2a .spec .A2AMethods .DELETE_TASK_PUSH_NOTIFICATION_CONFIG_METHOD ;
56import static io .a2a .spec .A2AMethods .GET_TASK_METHOD ;
@@ -82,7 +83,7 @@ public void setUp() {
8283 when (mockRoutingContext .user ()).thenReturn (null );
8384 when (mockRequest .headers ()).thenReturn (mockHeaders );
8485 when (mockRequest .params ()).thenReturn (mockParams );
85- when (mockRequest .getHeader (any (CharSequence .class ))).thenReturn ("application/json" );
86+ when (mockRequest .getHeader (any (CharSequence .class ))).thenReturn (APPLICATION_JSON );
8687 when (mockRoutingContext .body ()).thenReturn (mockRequestBody );
8788 when (mockRequestBody .asString ()).thenReturn ("{}" );
8889 when (mockResponse .setStatusCode (any (Integer .class ))).thenReturn (mockResponse );
@@ -96,7 +97,7 @@ public void testSendMessage_MethodNameSetInContext() {
9697 // Arrange
9798 HTTPRestResponse mockHttpResponse = mock (HTTPRestResponse .class );
9899 when (mockHttpResponse .getStatusCode ()).thenReturn (200 );
99- when (mockHttpResponse .getContentType ()).thenReturn ("application/json" );
100+ when (mockHttpResponse .getContentType ()).thenReturn (APPLICATION_JSON );
100101 when (mockHttpResponse .getBody ()).thenReturn ("{}" );
101102 when (mockRestHandler .sendMessage (any (ServerCallContext .class ), anyString (), anyString ())).thenReturn (mockHttpResponse );
102103
@@ -117,7 +118,7 @@ public void testSendMessageStreaming_MethodNameSetInContext() {
117118 // Arrange
118119 HTTPRestResponse mockHttpResponse = mock (HTTPRestResponse .class );
119120 when (mockHttpResponse .getStatusCode ()).thenReturn (200 );
120- when (mockHttpResponse .getContentType ()).thenReturn ("application/json" );
121+ when (mockHttpResponse .getContentType ()).thenReturn (APPLICATION_JSON );
121122 when (mockHttpResponse .getBody ()).thenReturn ("{}" );
122123 when (mockRestHandler .sendStreamingMessage (any (ServerCallContext .class ), anyString (), anyString ()))
123124 .thenReturn (mockHttpResponse );
@@ -140,7 +141,7 @@ public void testGetTask_MethodNameSetInContext() {
140141 when (mockRoutingContext .pathParam ("taskId" )).thenReturn ("task123" );
141142 HTTPRestResponse mockHttpResponse = mock (HTTPRestResponse .class );
142143 when (mockHttpResponse .getStatusCode ()).thenReturn (200 );
143- when (mockHttpResponse .getContentType ()).thenReturn ("application/json" );
144+ when (mockHttpResponse .getContentType ()).thenReturn (APPLICATION_JSON );
144145 when (mockHttpResponse .getBody ()).thenReturn ("{test:value}" );
145146 when (mockRestHandler .getTask (any (ServerCallContext .class ), anyString (), anyString (), any ())).thenReturn (mockHttpResponse );
146147
@@ -162,7 +163,7 @@ public void testCancelTask_MethodNameSetInContext() {
162163 when (mockRoutingContext .pathParam ("taskId" )).thenReturn ("task123" );
163164 HTTPRestResponse mockHttpResponse = mock (HTTPRestResponse .class );
164165 when (mockHttpResponse .getStatusCode ()).thenReturn (200 );
165- when (mockHttpResponse .getContentType ()).thenReturn ("application/json" );
166+ when (mockHttpResponse .getContentType ()).thenReturn (APPLICATION_JSON );
166167 when (mockHttpResponse .getBody ()).thenReturn ("{}" );
167168 when (mockRestHandler .cancelTask (any (ServerCallContext .class ), anyString (), anyString (), anyString ())).thenReturn (mockHttpResponse );
168169
@@ -184,7 +185,7 @@ public void testCancelTask_WithMetadata() {
184185 when (mockRoutingContext .pathParam ("taskId" )).thenReturn ("task456" );
185186 HTTPRestResponse mockHttpResponse = mock (HTTPRestResponse .class );
186187 when (mockHttpResponse .getStatusCode ()).thenReturn (200 );
187- when (mockHttpResponse .getContentType ()).thenReturn ("application/json" );
188+ when (mockHttpResponse .getContentType ()).thenReturn (APPLICATION_JSON );
188189 when (mockHttpResponse .getBody ()).thenReturn ("{\" id\" :\" task456\" ,\" status\" :\" cancelled\" }" );
189190
190191 String requestBody = """
@@ -217,7 +218,7 @@ public void testCancelTask_WithEmptyMetadata() {
217218 when (mockRoutingContext .pathParam ("taskId" )).thenReturn ("task789" );
218219 HTTPRestResponse mockHttpResponse = mock (HTTPRestResponse .class );
219220 when (mockHttpResponse .getStatusCode ()).thenReturn (200 );
220- when (mockHttpResponse .getContentType ()).thenReturn ("application/json" );
221+ when (mockHttpResponse .getContentType ()).thenReturn (APPLICATION_JSON );
221222 when (mockHttpResponse .getBody ()).thenReturn ("{\" id\" :\" task789\" }" );
222223
223224 String requestBody = """
@@ -246,7 +247,7 @@ public void testCancelTask_WithNoMetadataField() {
246247 when (mockRoutingContext .pathParam ("taskId" )).thenReturn ("task999" );
247248 HTTPRestResponse mockHttpResponse = mock (HTTPRestResponse .class );
248249 when (mockHttpResponse .getStatusCode ()).thenReturn (200 );
249- when (mockHttpResponse .getContentType ()).thenReturn ("application/json" );
250+ when (mockHttpResponse .getContentType ()).thenReturn (APPLICATION_JSON );
250251 when (mockHttpResponse .getBody ()).thenReturn ("{\" id\" :\" task999\" }" );
251252
252253 String requestBody = "{}" ;
@@ -271,7 +272,7 @@ public void testCancelTask_WithNullBody() {
271272 when (mockRoutingContext .pathParam ("taskId" )).thenReturn ("task111" );
272273 HTTPRestResponse mockHttpResponse = mock (HTTPRestResponse .class );
273274 when (mockHttpResponse .getStatusCode ()).thenReturn (200 );
274- when (mockHttpResponse .getContentType ()).thenReturn ("application/json" );
275+ when (mockHttpResponse .getContentType ()).thenReturn (APPLICATION_JSON );
275276 when (mockHttpResponse .getBody ()).thenReturn ("{\" id\" :\" task111\" }" );
276277
277278 ArgumentCaptor <String > bodyCaptor = ArgumentCaptor .forClass (String .class );
@@ -293,7 +294,7 @@ public void testCancelTask_WithComplexMetadata() {
293294 when (mockRoutingContext .pathParam ("taskId" )).thenReturn ("task222" );
294295 HTTPRestResponse mockHttpResponse = mock (HTTPRestResponse .class );
295296 when (mockHttpResponse .getStatusCode ()).thenReturn (200 );
296- when (mockHttpResponse .getContentType ()).thenReturn ("application/json" );
297+ when (mockHttpResponse .getContentType ()).thenReturn (APPLICATION_JSON );
297298 when (mockHttpResponse .getBody ()).thenReturn ("{\" id\" :\" task222\" }" );
298299
299300 String requestBody = """
@@ -331,7 +332,7 @@ public void testSubscribeTask_MethodNameSetInContext() {
331332 when (mockRoutingContext .pathParam ("taskId" )).thenReturn ("task123" );
332333 HTTPRestResponse mockHttpResponse = mock (HTTPRestResponse .class );
333334 when (mockHttpResponse .getStatusCode ()).thenReturn (200 );
334- when (mockHttpResponse .getContentType ()).thenReturn ("application/json" );
335+ when (mockHttpResponse .getContentType ()).thenReturn (APPLICATION_JSON );
335336 when (mockHttpResponse .getBody ()).thenReturn ("{}" );
336337 when (mockRestHandler .subscribeToTask (any (ServerCallContext .class ), anyString (), anyString ()))
337338 .thenReturn (mockHttpResponse );
@@ -354,7 +355,7 @@ public void testCreateTaskPushNotificationConfiguration_MethodNameSetInContext()
354355 when (mockRoutingContext .pathParam ("taskId" )).thenReturn ("task123" );
355356 HTTPRestResponse mockHttpResponse = mock (HTTPRestResponse .class );
356357 when (mockHttpResponse .getStatusCode ()).thenReturn (200 );
357- when (mockHttpResponse .getContentType ()).thenReturn ("application/json" );
358+ when (mockHttpResponse .getContentType ()).thenReturn (APPLICATION_JSON );
358359 when (mockHttpResponse .getBody ()).thenReturn ("{}" );
359360 when (mockRestHandler .createTaskPushNotificationConfiguration (any (ServerCallContext .class ), anyString (), anyString (), anyString ())).thenReturn (mockHttpResponse );
360361
@@ -377,7 +378,7 @@ public void testGetTaskPushNotificationConfiguration_MethodNameSetInContext() {
377378 when (mockRoutingContext .pathParam ("configId" )).thenReturn ("config456" );
378379 HTTPRestResponse mockHttpResponse = mock (HTTPRestResponse .class );
379380 when (mockHttpResponse .getStatusCode ()).thenReturn (200 );
380- when (mockHttpResponse .getContentType ()).thenReturn ("application/json" );
381+ when (mockHttpResponse .getContentType ()).thenReturn (APPLICATION_JSON );
381382 when (mockHttpResponse .getBody ()).thenReturn ("{}" );
382383 when (mockRestHandler .getTaskPushNotificationConfiguration (any (ServerCallContext .class ), anyString (), anyString (), anyString ())).thenReturn (mockHttpResponse );
383384
@@ -400,7 +401,7 @@ public void testListTaskPushNotificationConfigurations_MethodNameSetInContext()
400401 when (mockRoutingContext .pathParam ("taskId" )).thenReturn ("task123" );
401402 HTTPRestResponse mockHttpResponse = mock (HTTPRestResponse .class );
402403 when (mockHttpResponse .getStatusCode ()).thenReturn (200 );
403- when (mockHttpResponse .getContentType ()).thenReturn ("application/json" );
404+ when (mockHttpResponse .getContentType ()).thenReturn (APPLICATION_JSON );
404405 when (mockHttpResponse .getBody ()).thenReturn ("{}" );
405406 when (mockRestHandler .listTaskPushNotificationConfigurations (any (ServerCallContext .class ), anyString (), anyString (), anyInt (), anyString ()))
406407 .thenReturn (mockHttpResponse );
@@ -424,7 +425,7 @@ public void testDeleteTaskPushNotificationConfiguration_MethodNameSetInContext()
424425 when (mockRoutingContext .pathParam ("configId" )).thenReturn ("config456" );
425426 HTTPRestResponse mockHttpResponse = mock (HTTPRestResponse .class );
426427 when (mockHttpResponse .getStatusCode ()).thenReturn (200 );
427- when (mockHttpResponse .getContentType ()).thenReturn ("application/json" );
428+ when (mockHttpResponse .getContentType ()).thenReturn (APPLICATION_JSON );
428429 when (mockHttpResponse .getBody ()).thenReturn ("{}" );
429430 when (mockRestHandler .deleteTaskPushNotificationConfiguration (any (ServerCallContext .class ), anyString (), anyString (), anyString ())).thenReturn (mockHttpResponse );
430431
@@ -446,7 +447,7 @@ public void testSendMessage_UnsupportedContentType_ReturnsContentTypeNotSupporte
446447 // Arrange
447448 HTTPRestResponse mockErrorResponse = mock (HTTPRestResponse .class );
448449 when (mockErrorResponse .getStatusCode ()).thenReturn (415 );
449- when (mockErrorResponse .getContentType ()).thenReturn ("application/problem+json" );
450+ when (mockErrorResponse .getContentType ()).thenReturn (APPLICATION_JSON );
450451 when (mockErrorResponse .getBody ()).thenReturn ("{\" error\" :{\" code\" :415,\" status\" :\" INVALID_ARGUMENT\" ,\" message\" :\" Incompatible content types\" ,\" details\" :[{\" reason\" :\" CONTENT_TYPE_NOT_SUPPORTED\" ,\" domain\" :\" a2a-protocol.org\" }]}}" );
451452 when (mockRestHandler .createErrorResponse (any (ContentTypeNotSupportedError .class ))).thenReturn (mockErrorResponse );
452453 when (mockRequest .getHeader (any (CharSequence .class ))).thenReturn ("text/plain" );
@@ -464,7 +465,7 @@ public void testSendMessageStreaming_UnsupportedContentType_ReturnsContentTypeNo
464465 // Arrange
465466 HTTPRestResponse mockErrorResponse = mock (HTTPRestResponse .class );
466467 when (mockErrorResponse .getStatusCode ()).thenReturn (415 );
467- when (mockErrorResponse .getContentType ()).thenReturn ("application/problem+json" );
468+ when (mockErrorResponse .getContentType ()).thenReturn (APPLICATION_JSON );
468469 when (mockErrorResponse .getBody ()).thenReturn ("{\" error\" :{\" code\" :415,\" status\" :\" INVALID_ARGUMENT\" ,\" message\" :\" Incompatible content types\" ,\" details\" :[{\" reason\" :\" CONTENT_TYPE_NOT_SUPPORTED\" ,\" domain\" :\" a2a-protocol.org\" }]}}" );
469470 when (mockRestHandler .createErrorResponse (any (ContentTypeNotSupportedError .class ))).thenReturn (mockErrorResponse );
470471 when (mockRequest .getHeader (any (CharSequence .class ))).thenReturn ("text/plain" );
@@ -482,9 +483,9 @@ public void testSendMessage_UnsupportedProtocolVersion_ReturnsVersionNotSupporte
482483 // Arrange: content type is OK, but RestHandler returns a VersionNotSupportedError response
483484 HTTPRestResponse mockErrorResponse = mock (HTTPRestResponse .class );
484485 when (mockErrorResponse .getStatusCode ()).thenReturn (400 );
485- when (mockErrorResponse .getContentType ()).thenReturn ("application/problem+json" );
486+ when (mockErrorResponse .getContentType ()).thenReturn (APPLICATION_JSON );
486487 when (mockErrorResponse .getBody ()).thenReturn ("{\" error\" :{\" code\" :400,\" status\" :\" UNIMPLEMENTED\" ,\" message\" :\" Protocol version not supported\" ,\" details\" :[{\" reason\" :\" VERSION_NOT_SUPPORTED\" ,\" domain\" :\" a2a-protocol.org\" }]}}" );
487- when (mockRequest .getHeader (any (CharSequence .class ))).thenReturn ("application/json" );
488+ when (mockRequest .getHeader (any (CharSequence .class ))).thenReturn (APPLICATION_JSON );
488489 when (mockRestHandler .sendMessage (any (ServerCallContext .class ), anyString (), anyString ()))
489490 .thenReturn (mockErrorResponse );
490491
0 commit comments