|
1 | 1 | package io.a2a.server.tasks; |
2 | 2 |
|
| 3 | +import static io.a2a.client.http.A2AHttpClient.APPLICATION_JSON; |
| 4 | +import static io.a2a.client.http.A2AHttpClient.CONTENT_TYPE; |
3 | 5 | import static org.junit.jupiter.api.Assertions.assertEquals; |
| 6 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
4 | 7 | import static org.junit.jupiter.api.Assertions.assertTrue; |
5 | 8 |
|
6 | 9 | import java.io.IOException; |
@@ -158,7 +161,12 @@ private void testSendNotificationWithInvalidToken(String token, String testName) |
158 | 161 | // Verify that no authentication header was sent (invalid token should not add header) |
159 | 162 | assertEquals(1, testHttpClient.headers.size()); |
160 | 163 | Map<String, String> sentHeaders = testHttpClient.headers.get(0); |
161 | | - assertTrue(sentHeaders.isEmpty(), "No headers should be sent when token is invalid"); |
| 164 | + assertEquals(1, sentHeaders.size()); |
| 165 | + assertFalse(sentHeaders.containsKey(A2AHeaders.X_A2A_NOTIFICATION_TOKEN), |
| 166 | + "X-A2A-Notification-Token header should not be sent when token is invalid"); |
| 167 | + // Content-Type header should always be present |
| 168 | + assertTrue(sentHeaders.containsKey(CONTENT_TYPE)); |
| 169 | + assertEquals(APPLICATION_JSON, sentHeaders.get(CONTENT_TYPE)); |
162 | 170 | } |
163 | 171 |
|
164 | 172 | private Task createSampleTask(String taskId, TaskState state) { |
@@ -227,8 +235,13 @@ public void testSendNotificationWithTokenSuccess() throws InterruptedException { |
227 | 235 | // Verify that the X-A2A-Notification-Token header is sent with the correct token |
228 | 236 | assertEquals(1, testHttpClient.headers.size()); |
229 | 237 | Map<String, String> sentHeaders = testHttpClient.headers.get(0); |
| 238 | + assertEquals(2, sentHeaders.size()); |
230 | 239 | assertTrue(sentHeaders.containsKey(A2AHeaders.X_A2A_NOTIFICATION_TOKEN)); |
231 | 240 | assertEquals(config.token(), sentHeaders.get(A2AHeaders.X_A2A_NOTIFICATION_TOKEN)); |
| 241 | + // Content-Type header should always be present |
| 242 | + assertTrue(sentHeaders.containsKey(CONTENT_TYPE)); |
| 243 | + assertEquals(APPLICATION_JSON, sentHeaders.get(CONTENT_TYPE)); |
| 244 | + |
232 | 245 | } |
233 | 246 |
|
234 | 247 | @Test |
@@ -290,10 +303,10 @@ public void testSendNotificationHttpError() { |
290 | 303 | String taskId = "task_send_http_err"; |
291 | 304 | Task taskData = createSampleTask(taskId, TaskState.COMPLETED); |
292 | 305 | PushNotificationConfig config = createSamplePushConfig("http://notify.me/http_error", "cfg1", null); |
293 | | - |
| 306 | + |
294 | 307 | // Set up the configuration in the store |
295 | 308 | configStore.setInfo(taskId, config); |
296 | | - |
| 309 | + |
297 | 310 | // Configure the test client to throw an exception |
298 | 311 | testHttpClient.shouldThrowException = true; |
299 | 312 |
|
|
0 commit comments