|
5 | 5 | import static org.junit.jupiter.api.Assertions.assertEquals; |
6 | 6 | import static org.junit.jupiter.api.Assertions.assertInstanceOf; |
7 | 7 | import static org.junit.jupiter.api.Assertions.assertNotNull; |
| 8 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
8 | 9 | import static org.junit.jupiter.api.Assertions.assertTrue; |
9 | 10 | import static org.mockito.ArgumentMatchers.any; |
10 | 11 | import static org.mockito.Mockito.never; |
|
21 | 22 | import org.a2aproject.sdk.server.tasks.BasePushNotificationSender; |
22 | 23 | import org.a2aproject.sdk.server.tasks.PushNotificationConfigStore; |
23 | 24 | import org.a2aproject.sdk.server.tasks.PushNotificationUrlValidator; |
| 25 | +import org.a2aproject.sdk.spec.InvalidParamsError; |
24 | 26 | import org.a2aproject.sdk.spec.ListTaskPushNotificationConfigsParams; |
25 | 27 | import org.a2aproject.sdk.spec.ListTaskPushNotificationConfigsResult; |
26 | 28 | import org.a2aproject.sdk.spec.Task; |
@@ -149,18 +151,65 @@ public void testSetInfoWithoutConfigId() { |
149 | 151 | assertEquals(1, configResult.configs().size()); |
150 | 152 | assertEquals(taskId, configResult.configs().get(0).id()); |
151 | 153 |
|
152 | | - TaskPushNotificationConfig updatedConfig = TaskPushNotificationConfig.builder() |
| 154 | + TaskPushNotificationConfig duplicateConfig = TaskPushNotificationConfig.builder() |
153 | 155 | .id("") |
154 | 156 | .url("http://initial.url/callback_new") |
155 | 157 | .taskId(taskId) |
156 | 158 | .build(); |
157 | 159 |
|
158 | | - TaskPushNotificationConfig updatedResult = configStore.setInfo(updatedConfig); |
159 | | - assertEquals(taskId, updatedResult.id()); |
| 160 | + assertThrows(InvalidParamsError.class, () -> configStore.setInfo(duplicateConfig)); |
160 | 161 |
|
161 | 162 | configResult = configStore.getInfo(new ListTaskPushNotificationConfigsParams(taskId)); |
162 | | - assertEquals(1, configResult.configs().size(), "Should replace existing config with same ID rather than adding new one"); |
163 | | - assertEquals(updatedConfig.url(), configResult.configs().get(0).url()); |
| 163 | + assertEquals(1, configResult.configs().size()); |
| 164 | + assertEquals(initialConfig.url(), configResult.configs().get(0).url()); |
| 165 | + } |
| 166 | + |
| 167 | + @Test |
| 168 | + @Transactional |
| 169 | + public void testSetInfoWithNullConfigId() { |
| 170 | + String taskId = "task_null_config_id"; |
| 171 | + TaskPushNotificationConfig config = TaskPushNotificationConfig.builder() |
| 172 | + .url("http://null-id.url/callback") |
| 173 | + .taskId(taskId) |
| 174 | + .build(); |
| 175 | + |
| 176 | + TaskPushNotificationConfig result = configStore.setInfo(config); |
| 177 | + |
| 178 | + assertEquals(taskId, result.id(), "A missing config ID should default to the task ID"); |
| 179 | + ListTaskPushNotificationConfigsResult configResult = configStore.getInfo( |
| 180 | + new ListTaskPushNotificationConfigsParams(taskId)); |
| 181 | + assertEquals(1, configResult.configs().size()); |
| 182 | + assertEquals(taskId, configResult.configs().get(0).id()); |
| 183 | + |
| 184 | + TaskPushNotificationConfig duplicateConfig = TaskPushNotificationConfig.builder() |
| 185 | + .url("http://updated.url/callback") |
| 186 | + .taskId(taskId) |
| 187 | + .build(); |
| 188 | + |
| 189 | + assertThrows(InvalidParamsError.class, () -> configStore.setInfo(duplicateConfig)); |
| 190 | + } |
| 191 | + |
| 192 | + @Test |
| 193 | + @Transactional |
| 194 | + public void testSetInfoAllowsV03DefaultConfigUpdate() { |
| 195 | + String taskId = "task_v03_default_update"; |
| 196 | + TaskPushNotificationConfig initialConfig = TaskPushNotificationConfig.builder() |
| 197 | + .taskId(taskId) |
| 198 | + .url("http://initial.url/callback") |
| 199 | + .build(); |
| 200 | + TaskPushNotificationConfig updatedConfig = TaskPushNotificationConfig.builder() |
| 201 | + .taskId(taskId) |
| 202 | + .url("http://updated.url/callback") |
| 203 | + .build(); |
| 204 | + |
| 205 | + configStore.setInfo(initialConfig, "0.3"); |
| 206 | + TaskPushNotificationConfig result = configStore.setInfo(updatedConfig, "0.3"); |
| 207 | + |
| 208 | + assertEquals(taskId, result.id()); |
| 209 | + ListTaskPushNotificationConfigsResult stored = |
| 210 | + configStore.getInfo(new ListTaskPushNotificationConfigsParams(taskId)); |
| 211 | + assertEquals(1, stored.configs().size()); |
| 212 | + assertEquals(updatedConfig.url(), stored.configs().get(0).url()); |
164 | 213 | } |
165 | 214 |
|
166 | 215 | @Test |
|
0 commit comments