|
2 | 2 |
|
3 | 3 | import static org.junit.jupiter.api.Assertions.assertEquals; |
4 | 4 | import static org.junit.jupiter.api.Assertions.assertNull; |
| 5 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
5 | 6 |
|
6 | 7 | import java.util.Collections; |
7 | 8 | import java.util.List; |
|
12 | 13 |
|
13 | 14 | import org.a2aproject.sdk.server.ExtendedAgentCard; |
14 | 15 | import org.a2aproject.sdk.server.PublicAgentCard; |
| 16 | +import org.a2aproject.sdk.server.multitenancy.Tenant; |
15 | 17 | import org.a2aproject.sdk.spec.AgentCapabilities; |
16 | 18 | import org.a2aproject.sdk.spec.AgentCard; |
17 | 19 | import org.a2aproject.sdk.spec.AgentInterface; |
@@ -113,6 +115,58 @@ void publicCardNoDefaultReturnsNull() { |
113 | 115 | assertNull(router.resolvePublicCard("unknown")); |
114 | 116 | } |
115 | 117 |
|
| 118 | + @Test |
| 119 | + void publicCardWithPublicQualifierResolvesToTenantSpecific() { |
| 120 | + startContainer(DefaultPublicAndExtendedCardProducer.class, PublicQualifiedTenantCardProducer.class); |
| 121 | + CdiAgentCardRouter router = container.select(CdiAgentCardRouter.class).get(); |
| 122 | + assertEquals("acme-public-qualified", router.resolvePublicCard("acme").name()); |
| 123 | + } |
| 124 | + |
| 125 | + @Test |
| 126 | + void publicCardWithBothPublicAndExtendedQualifierResolvesToTenantSpecific() { |
| 127 | + startContainer(DefaultPublicAndExtendedCardProducer.class, PublicAndExtendedTenantCardProducer.class); |
| 128 | + CdiAgentCardRouter router = container.select(CdiAgentCardRouter.class).get(); |
| 129 | + assertEquals("acme-both", router.resolvePublicCard("acme").name()); |
| 130 | + } |
| 131 | + |
| 132 | + @Test |
| 133 | + void explicitPublicCardTakesPrecedenceOverBareTenantCard() { |
| 134 | + startContainer(DefaultPublicAndExtendedCardProducer.class, BareAndPublicQualifiedTenantCardProducer.class); |
| 135 | + CdiAgentCardRouter router = container.select(CdiAgentCardRouter.class).get(); |
| 136 | + assertEquals("acme-public-qualified", router.resolvePublicCard("acme").name()); |
| 137 | + } |
| 138 | + |
| 139 | + @Test |
| 140 | + void duplicatePublicQualifiedCardsThrows() { |
| 141 | + startContainer(DefaultPublicAndExtendedCardProducer.class, DuplicatePublicQualifiedTenantCardProducer.class); |
| 142 | + CdiAgentCardRouter router = container.select(CdiAgentCardRouter.class).get(); |
| 143 | + assertThrows(IllegalStateException.class, () -> router.resolvePublicCard("acme")); |
| 144 | + } |
| 145 | + |
| 146 | + @Test |
| 147 | + void duplicateBareTenantCardsThrows() { |
| 148 | + startContainer(DefaultPublicAndExtendedCardProducer.class, DuplicateBareTenantCardProducer.class); |
| 149 | + CdiAgentCardRouter router = container.select(CdiAgentCardRouter.class).get(); |
| 150 | + assertThrows(IllegalStateException.class, () -> router.resolvePublicCard("acme")); |
| 151 | + } |
| 152 | + |
| 153 | + @Test |
| 154 | + void duplicateExtendedTenantCardsThrows() { |
| 155 | + startContainer(DefaultPublicAndExtendedCardProducer.class, DuplicateExtendedTenantCardProducer.class); |
| 156 | + CdiAgentCardRouter router = container.select(CdiAgentCardRouter.class).get(); |
| 157 | + assertThrows(IllegalStateException.class, () -> router.resolveExtendedCard("acme")); |
| 158 | + } |
| 159 | + |
| 160 | + @Test |
| 161 | + void dualQualifiedCardResolvedByBothPublicAndExtended() { |
| 162 | + startContainer(DefaultPublicAndExtendedCardProducer.class, PublicAndExtendedTenantCardProducer.class); |
| 163 | + CdiAgentCardRouter router = container.select(CdiAgentCardRouter.class).get(); |
| 164 | + AgentCard publicCard = router.resolvePublicCard("acme"); |
| 165 | + AgentCard extendedCard = router.resolveExtendedCard("acme"); |
| 166 | + assertEquals("acme-both", publicCard.name()); |
| 167 | + assertEquals("acme-both", extendedCard.name()); |
| 168 | + } |
| 169 | + |
116 | 170 | private static AgentCard buildCard(String name) { |
117 | 171 | return AgentCard.builder() |
118 | 172 | .name(name) |
@@ -179,4 +233,105 @@ AgentCard acmeExtendedCard() { |
179 | 233 | return buildCard("acme-extended"); |
180 | 234 | } |
181 | 235 | } |
| 236 | + |
| 237 | + static class DefaultPublicAndExtendedCardProducer { |
| 238 | + |
| 239 | + @Produces |
| 240 | + @PublicAgentCard |
| 241 | + AgentCard defaultPublicCard() { |
| 242 | + return buildCard("default-public"); |
| 243 | + } |
| 244 | + |
| 245 | + @Produces |
| 246 | + @ExtendedAgentCard |
| 247 | + AgentCard defaultExtendedCard() { |
| 248 | + return buildCard("default-extended"); |
| 249 | + } |
| 250 | + } |
| 251 | + |
| 252 | + static class PublicQualifiedTenantCardProducer { |
| 253 | + |
| 254 | + @Produces |
| 255 | + @Tenant("acme") |
| 256 | + @PublicAgentCard |
| 257 | + AgentCard acmePublicCard() { |
| 258 | + return buildCard("acme-public-qualified"); |
| 259 | + } |
| 260 | + } |
| 261 | + |
| 262 | + static class PublicAndExtendedTenantCardProducer { |
| 263 | + |
| 264 | + @Produces |
| 265 | + @Tenant("acme") |
| 266 | + @PublicAgentCard |
| 267 | + @ExtendedAgentCard |
| 268 | + AgentCard acmeBothCard() { |
| 269 | + return buildCard("acme-both"); |
| 270 | + } |
| 271 | + } |
| 272 | + |
| 273 | + static class BareAndPublicQualifiedTenantCardProducer { |
| 274 | + |
| 275 | + @Produces |
| 276 | + @Tenant("acme") |
| 277 | + AgentCard acmeBareCard() { |
| 278 | + return buildCard("acme-bare"); |
| 279 | + } |
| 280 | + |
| 281 | + @Produces |
| 282 | + @Tenant("acme") |
| 283 | + @PublicAgentCard |
| 284 | + AgentCard acmePublicCard() { |
| 285 | + return buildCard("acme-public-qualified"); |
| 286 | + } |
| 287 | + } |
| 288 | + |
| 289 | + static class DuplicatePublicQualifiedTenantCardProducer { |
| 290 | + |
| 291 | + @Produces |
| 292 | + @Tenant("acme") |
| 293 | + @PublicAgentCard |
| 294 | + AgentCard acmePublicCard1() { |
| 295 | + return buildCard("acme-public-1"); |
| 296 | + } |
| 297 | + |
| 298 | + @Produces |
| 299 | + @Tenant("acme") |
| 300 | + @PublicAgentCard |
| 301 | + AgentCard acmePublicCard2() { |
| 302 | + return buildCard("acme-public-2"); |
| 303 | + } |
| 304 | + } |
| 305 | + |
| 306 | + static class DuplicateBareTenantCardProducer { |
| 307 | + |
| 308 | + @Produces |
| 309 | + @Tenant("acme") |
| 310 | + AgentCard acmeBareCard1() { |
| 311 | + return buildCard("acme-bare-1"); |
| 312 | + } |
| 313 | + |
| 314 | + @Produces |
| 315 | + @Tenant("acme") |
| 316 | + AgentCard acmeBareCard2() { |
| 317 | + return buildCard("acme-bare-2"); |
| 318 | + } |
| 319 | + } |
| 320 | + |
| 321 | + static class DuplicateExtendedTenantCardProducer { |
| 322 | + |
| 323 | + @Produces |
| 324 | + @Tenant("acme") |
| 325 | + @ExtendedAgentCard |
| 326 | + AgentCard acmeExtendedCard1() { |
| 327 | + return buildCard("acme-extended-1"); |
| 328 | + } |
| 329 | + |
| 330 | + @Produces |
| 331 | + @Tenant("acme") |
| 332 | + @ExtendedAgentCard |
| 333 | + AgentCard acmeExtendedCard2() { |
| 334 | + return buildCard("acme-extended-2"); |
| 335 | + } |
| 336 | + } |
182 | 337 | } |
0 commit comments