Skip to content

Commit ba8940b

Browse files
pmbrullclaude
andcommitted
test(context-memory): override owner ITs for creator-as-owner default
ContextMemoryMapper.defaultOwners() intentionally assigns the creating user as owner when the create request omits owners. BaseEntityIT's patch_entityUpdateOwner_200 and patch_entityUpdateOwnerFromNull_200 assert "no owner initially" for any supportsOwners entity, so both failed for ContextMemory. Override both in ContextMemoryIT: keep the PATCH-replace-owner contract, change only the precondition to expect the creator as the sole initial owner (asserted by count, not a hardcoded principal). Mapper unchanged. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent ed50f35 commit ba8940b

1 file changed

Lines changed: 78 additions & 0 deletions

File tree

openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/ContextMemoryIT.java

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import static org.junit.jupiter.api.Assertions.assertTrue;
88

99
import java.util.HashMap;
10+
import java.util.List;
1011
import java.util.Map;
1112
import java.util.UUID;
1213
import org.junit.jupiter.api.Test;
@@ -21,7 +22,10 @@
2122
import org.openmetadata.schema.entity.context.ContextMemoryType;
2223
import org.openmetadata.schema.entity.context.MemoryShareConfig;
2324
import org.openmetadata.schema.entity.context.MemoryVisibility;
25+
import org.openmetadata.schema.entity.teams.User;
2426
import org.openmetadata.schema.type.EntityHistory;
27+
import org.openmetadata.schema.type.EntityReference;
28+
import org.openmetadata.sdk.fluent.Users;
2529
import org.openmetadata.sdk.models.ListParams;
2630
import org.openmetadata.sdk.models.ListResponse;
2731
import org.openmetadata.sdk.services.context.ContextMemoryService;
@@ -457,6 +461,80 @@ void test_listContextMemories(TestNamespace ns) {
457461
assertTrue(response.getData().size() >= 2);
458462
}
459463

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+
460538
// ===================================================================
461539
// HELPER METHODS
462540
// ===================================================================

0 commit comments

Comments
 (0)