|
7 | 7 | import static org.junit.jupiter.api.Assertions.assertTrue; |
8 | 8 |
|
9 | 9 | import java.util.HashMap; |
| 10 | +import java.util.List; |
10 | 11 | import java.util.Map; |
11 | 12 | import java.util.UUID; |
12 | 13 | import org.junit.jupiter.api.Test; |
|
21 | 22 | import org.openmetadata.schema.entity.context.ContextMemoryType; |
22 | 23 | import org.openmetadata.schema.entity.context.MemoryShareConfig; |
23 | 24 | import org.openmetadata.schema.entity.context.MemoryVisibility; |
| 25 | +import org.openmetadata.schema.entity.teams.User; |
24 | 26 | import org.openmetadata.schema.type.EntityHistory; |
| 27 | +import org.openmetadata.schema.type.EntityReference; |
| 28 | +import org.openmetadata.sdk.fluent.Users; |
25 | 29 | import org.openmetadata.sdk.models.ListParams; |
26 | 30 | import org.openmetadata.sdk.models.ListResponse; |
27 | 31 | import org.openmetadata.sdk.services.context.ContextMemoryService; |
@@ -457,6 +461,80 @@ void test_listContextMemories(TestNamespace ns) { |
457 | 461 | assertTrue(response.getData().size() >= 2); |
458 | 462 | } |
459 | 463 |
|
| 464 | + // =================================================================== |
| 465 | + // OWNERSHIP TEST OVERRIDES |
| 466 | + // =================================================================== |
| 467 | + |
| 468 | + /** |
| 469 | + * ContextMemory auto-assigns the creating user as owner when the create request omits owners |
| 470 | + * (see {@code ContextMemoryMapper#defaultOwners}), so it deliberately diverges from the generic |
| 471 | + * BaseEntityIT precondition that a freshly created entity has no owner. The PATCH contract is |
| 472 | + * unchanged: setting an explicit owner replaces the creator. |
| 473 | + */ |
| 474 | + @Test |
| 475 | + @Override |
| 476 | + void patch_entityUpdateOwner_200(TestNamespace ns) { |
| 477 | + ContextMemory created = createEntity(createMinimalRequest(ns)); |
| 478 | + |
| 479 | + ContextMemory fetched = getEntityWithFields(created.getId().toString(), "owners"); |
| 480 | + assertNotNull(fetched.getOwners(), "ContextMemory should be owned by its creator initially"); |
| 481 | + assertEquals( |
| 482 | + 1, fetched.getOwners().size(), "ContextMemory creator should be the sole initial owner"); |
| 483 | + |
| 484 | + User botUser = Users.getByName("ingestion-bot"); |
| 485 | + EntityReference ownerRef = |
| 486 | + new EntityReference() |
| 487 | + .withId(botUser.getId()) |
| 488 | + .withType("user") |
| 489 | + .withName(botUser.getName()) |
| 490 | + .withFullyQualifiedName(botUser.getFullyQualifiedName()); |
| 491 | + |
| 492 | + fetched.setOwners(List.of(ownerRef)); |
| 493 | + ContextMemory updated = patchEntity(fetched.getId().toString(), fetched); |
| 494 | + |
| 495 | + ContextMemory updatedFetched = getEntityWithFields(updated.getId().toString(), "owners"); |
| 496 | + assertNotNull(updatedFetched.getOwners(), "Entity should have owners"); |
| 497 | + assertEquals(1, updatedFetched.getOwners().size(), "Entity should have 1 owner"); |
| 498 | + assertEquals( |
| 499 | + botUser.getId(), |
| 500 | + updatedFetched.getOwners().get(0).getId(), |
| 501 | + "Owner should be ingestion-bot user"); |
| 502 | + } |
| 503 | + |
| 504 | + /** |
| 505 | + * ContextMemory already has the creating user as its sole owner before this PATCH (see {@code |
| 506 | + * ContextMemoryMapper#defaultOwners}); the original "from null" precondition does not hold. |
| 507 | + * Setting an explicit owners list still replaces it wholesale. |
| 508 | + */ |
| 509 | + @Test |
| 510 | + @Override |
| 511 | + void patch_entityUpdateOwnerFromNull_200(TestNamespace ns) { |
| 512 | + ContextMemory entity = createEntity(createMinimalRequest(ns)); |
| 513 | + |
| 514 | + ContextMemory fetched = getEntityWithFields(entity.getId().toString(), "owners"); |
| 515 | + assertNotNull(fetched.getOwners(), "ContextMemory should be owned by its creator initially"); |
| 516 | + assertEquals( |
| 517 | + 1, fetched.getOwners().size(), "ContextMemory creator should be the sole initial owner"); |
| 518 | + |
| 519 | + EntityReference owner1 = |
| 520 | + new EntityReference() |
| 521 | + .withId(testUser1().getId()) |
| 522 | + .withType("user") |
| 523 | + .withName(testUser1().getName()); |
| 524 | + EntityReference owner2 = |
| 525 | + new EntityReference() |
| 526 | + .withId(testUser2().getId()) |
| 527 | + .withType("user") |
| 528 | + .withName(testUser2().getName()); |
| 529 | + |
| 530 | + fetched.setOwners(List.of(owner1, owner2)); |
| 531 | + ContextMemory updated = patchEntity(fetched.getId().toString(), fetched); |
| 532 | + |
| 533 | + ContextMemory verify = getEntityWithFields(updated.getId().toString(), "owners"); |
| 534 | + assertNotNull(verify.getOwners(), "Entity should have owners"); |
| 535 | + assertEquals(2, verify.getOwners().size(), "Entity should have 2 owners"); |
| 536 | + } |
| 537 | + |
460 | 538 | // =================================================================== |
461 | 539 | // HELPER METHODS |
462 | 540 | // =================================================================== |
|
0 commit comments