|
37 | 37 | import java.util.List; |
38 | 38 | import java.util.Map; |
39 | 39 |
|
| 40 | +import com.google.gson.JsonObject; |
| 41 | +import com.google.gson.JsonParser; |
| 42 | + |
| 43 | +import org.a2aproject.sdk.jsonrpc.common.wrappers.ListTasksResult; |
40 | 44 | import org.a2aproject.sdk.spec.A2AClientException; |
41 | 45 | import org.a2aproject.sdk.spec.A2AClientHTTPError; |
42 | 46 | import org.a2aproject.sdk.spec.AgentCard; |
|
54 | 58 | import org.a2aproject.sdk.spec.FileWithUri; |
55 | 59 | import org.a2aproject.sdk.spec.GetExtendedAgentCardParams; |
56 | 60 | import org.a2aproject.sdk.spec.GetTaskPushNotificationConfigParams; |
| 61 | +import org.a2aproject.sdk.spec.ListTasksParams; |
57 | 62 | import org.a2aproject.sdk.spec.Message; |
58 | 63 | import org.a2aproject.sdk.spec.MessageSendConfiguration; |
59 | 64 | import org.a2aproject.sdk.spec.MessageSendParams; |
@@ -88,6 +93,50 @@ public void tearDown() { |
88 | 93 | server.stop(); |
89 | 94 | } |
90 | 95 |
|
| 96 | + @Test |
| 97 | + public void testListTasksWithDefaultBuilder() throws Exception { |
| 98 | + JsonObject params = listTasksAndGetRequestParams(ListTasksParams.builder().build()); |
| 99 | + |
| 100 | + assertEquals("", params.get("tenant").getAsString()); |
| 101 | + } |
| 102 | + |
| 103 | + @Test |
| 104 | + public void testListTasksWithDefaultConstructor() throws Exception { |
| 105 | + JsonObject params = listTasksAndGetRequestParams(new ListTasksParams()); |
| 106 | + |
| 107 | + assertEquals("", params.get("tenant").getAsString()); |
| 108 | + } |
| 109 | + |
| 110 | + @Test |
| 111 | + public void testListTasksWithTenant() throws Exception { |
| 112 | + JsonObject params = listTasksAndGetRequestParams(ListTasksParams.builder().tenant("tenant-123").build()); |
| 113 | + |
| 114 | + assertEquals("tenant-123", params.get("tenant").getAsString()); |
| 115 | + } |
| 116 | + |
| 117 | + private JsonObject listTasksAndGetRequestParams(ListTasksParams params) throws Exception { |
| 118 | + String body = """ |
| 119 | + { |
| 120 | + "jsonrpc": "2.0", |
| 121 | + "id": "list-tasks", |
| 122 | + "result": {"tasks": [], "totalSize": 0, "pageSize": 0} |
| 123 | + } |
| 124 | + """; |
| 125 | + server.when(request().withMethod("POST").withPath("/")) |
| 126 | + .respond(response().withStatusCode(200).withBody(body)); |
| 127 | + |
| 128 | + ListTasksResult result = new JSONRPCTransport("http://localhost:4001").listTasks(params, null); |
| 129 | + |
| 130 | + assertTrue(result.tasks().isEmpty()); |
| 131 | + assertEquals(0, result.totalSize()); |
| 132 | + assertEquals(0, result.pageSize()); |
| 133 | + var requests = server.retrieveRecordedRequests(request().withMethod("POST").withPath("/")); |
| 134 | + assertEquals(1, requests.length); |
| 135 | + JsonObject json = JsonParser.parseString(requests[0].getBodyAsString()).getAsJsonObject(); |
| 136 | + assertEquals("ListTasks", json.get("method").getAsString()); |
| 137 | + return json.getAsJsonObject("params"); |
| 138 | + } |
| 139 | + |
91 | 140 | @Test |
92 | 141 | public void testA2AClientSendMessage() throws Exception { |
93 | 142 | this.server.when( |
|
0 commit comments