From 7da9a936877dea743a002f2ee50d9374de525fc2 Mon Sep 17 00:00:00 2001 From: Vishnu Jain Date: Wed, 19 Aug 2026 11:48:12 +0530 Subject: [PATCH 1/3] fix(knowledge): carry the requested entityStatus onto the created page --- .../knowledge/KnowledgePageMapper.java | 5 +- .../knowledge/KnowledgePageMapperTest.java | 49 +++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 openmetadata-service/src/test/java/org/openmetadata/service/resources/knowledge/KnowledgePageMapperTest.java diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/resources/knowledge/KnowledgePageMapper.java b/openmetadata-service/src/main/java/org/openmetadata/service/resources/knowledge/KnowledgePageMapper.java index 1507c7d23c57..edf9402f2445 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/resources/knowledge/KnowledgePageMapper.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/resources/knowledge/KnowledgePageMapper.java @@ -31,6 +31,9 @@ public Page createToEntity(CreatePage create, String user) { .withPageType(create.getPageType()) .withPage(create.getPage()) .withParent(create.getParent()) - .withRelatedEntities(relatedEntities); + .withRelatedEntities(relatedEntities) + // Left null when the caller did not ask for a status; EntityRepository.setDefaultStatus + // then fills in Unprocessed. + .withEntityStatus(create.getEntityStatus()); } } diff --git a/openmetadata-service/src/test/java/org/openmetadata/service/resources/knowledge/KnowledgePageMapperTest.java b/openmetadata-service/src/test/java/org/openmetadata/service/resources/knowledge/KnowledgePageMapperTest.java new file mode 100644 index 000000000000..ffe8e023c4cc --- /dev/null +++ b/openmetadata-service/src/test/java/org/openmetadata/service/resources/knowledge/KnowledgePageMapperTest.java @@ -0,0 +1,49 @@ +package org.openmetadata.service.resources.knowledge; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + +import java.util.UUID; +import org.junit.jupiter.api.Test; +import org.openmetadata.schema.api.data.CreatePage; +import org.openmetadata.schema.entity.data.Article; +import org.openmetadata.schema.entity.data.Page; +import org.openmetadata.schema.entity.data.PageType; +import org.openmetadata.schema.type.EntityReference; +import org.openmetadata.schema.type.EntityStatus; + +class KnowledgePageMapperTest { + + @Test + void theRequestedEntityStatusReachesTheEntity() { + // CreatePage carries entityStatus, but the mapper never copied it, so every article was + // persisted as Unprocessed no matter what the caller asked for. + // EntityRepository.setDefaultStatus + // only fills in Unprocessed when the value is still null, so carrying it here is enough. + Page page = + new KnowledgePageMapper().createToEntity(createPage(EntityStatus.ARCHIVED), "admin"); + + assertEquals(EntityStatus.ARCHIVED, page.getEntityStatus()); + } + + @Test + void anAbsentEntityStatusIsLeftForTheRepositoryDefault() { + Page page = new KnowledgePageMapper().createToEntity(createPage(null), "admin"); + + assertNull(page.getEntityStatus()); + } + + /** + * relatedEntities is supplied so the mapper skips its Organization-team fallback, which needs a + * live entity registry and is not what these tests are about. + */ + private static CreatePage createPage(EntityStatus status) { + return new CreatePage() + .withName("runbook") + .withPageType(PageType.ARTICLE) + .withPage(new Article()) + .withRelatedEntities( + java.util.List.of(new EntityReference().withId(UUID.randomUUID()).withType("table"))) + .withEntityStatus(status); + } +} From c83f3d2fbce05a003fd54ca1ba92c6b3645aeab4 Mon Sep 17 00:00:00 2001 From: Vishnu Jain Date: Wed, 19 Aug 2026 12:23:46 +0530 Subject: [PATCH 2/3] test(knowledge): cover an omitted entityStatus, not just an explicit null --- .../knowledge/KnowledgePageMapperTest.java | 37 +++++++++++++------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/openmetadata-service/src/test/java/org/openmetadata/service/resources/knowledge/KnowledgePageMapperTest.java b/openmetadata-service/src/test/java/org/openmetadata/service/resources/knowledge/KnowledgePageMapperTest.java index ffe8e023c4cc..c7b346615ee9 100644 --- a/openmetadata-service/src/test/java/org/openmetadata/service/resources/knowledge/KnowledgePageMapperTest.java +++ b/openmetadata-service/src/test/java/org/openmetadata/service/resources/knowledge/KnowledgePageMapperTest.java @@ -27,23 +27,36 @@ void theRequestedEntityStatusReachesTheEntity() { } @Test - void anAbsentEntityStatusIsLeftForTheRepositoryDefault() { - Page page = new KnowledgePageMapper().createToEntity(createPage(null), "admin"); + void anOmittedEntityStatusIsLeftForTheRepositoryDefault() { + // Omits entityStatus entirely rather than setting it to null, so this still holds if the DTO + // ever starts carrying a value of its own. createPage.json declares "default": "Approved", but + // jsonschema2pojo does not materialize a default that sits alongside a $ref — the generated + // field is initialised to null (see the assertion below). Were that to change, the mapper would + // start persisting Approved instead of letting the repository default to Unprocessed. + CreatePage request = + new CreatePage().withName("runbook").withPageType(PageType.ARTICLE).withPage(new Article()); + assertNull(request.getEntityStatus(), "CreatePage must not supply an entityStatus of its own"); + + Page page = new KnowledgePageMapper().createToEntity(withRelatedEntity(request), "admin"); assertNull(page.getEntityStatus()); } - /** - * relatedEntities is supplied so the mapper skips its Organization-team fallback, which needs a - * live entity registry and is not what these tests are about. - */ private static CreatePage createPage(EntityStatus status) { - return new CreatePage() - .withName("runbook") - .withPageType(PageType.ARTICLE) - .withPage(new Article()) - .withRelatedEntities( - java.util.List.of(new EntityReference().withId(UUID.randomUUID()).withType("table"))) + return withRelatedEntity( + new CreatePage() + .withName("runbook") + .withPageType(PageType.ARTICLE) + .withPage(new Article())) .withEntityStatus(status); } + + /** + * Supplies relatedEntities so the mapper skips its Organization-team fallback, which needs a live + * entity registry and is not what these tests are about. + */ + private static CreatePage withRelatedEntity(CreatePage request) { + return request.withRelatedEntities( + java.util.List.of(new EntityReference().withId(UUID.randomUUID()).withType("table"))); + } } From e6bfc8b31b807db4397f3e3f23419f7b8c3e070e Mon Sep 17 00:00:00 2001 From: Vishnu Jain Date: Thu, 20 Aug 2026 14:09:38 +0530 Subject: [PATCH 3/3] test(knowledge): assert entityStatus propagation instead of the generated default --- .../knowledge/KnowledgePageMapper.java | 4 +-- .../knowledge/KnowledgePageMapperTest.java | 36 ++++++++++++------- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/resources/knowledge/KnowledgePageMapper.java b/openmetadata-service/src/main/java/org/openmetadata/service/resources/knowledge/KnowledgePageMapper.java index edf9402f2445..68fa4cdefeb6 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/resources/knowledge/KnowledgePageMapper.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/resources/knowledge/KnowledgePageMapper.java @@ -32,8 +32,8 @@ public Page createToEntity(CreatePage create, String user) { .withPage(create.getPage()) .withParent(create.getParent()) .withRelatedEntities(relatedEntities) - // Left null when the caller did not ask for a status; EntityRepository.setDefaultStatus - // then fills in Unprocessed. + // Handed through untouched: a null reaches EntityRepository.setDefaultStatus, which fills + // in Unprocessed. .withEntityStatus(create.getEntityStatus()); } } diff --git a/openmetadata-service/src/test/java/org/openmetadata/service/resources/knowledge/KnowledgePageMapperTest.java b/openmetadata-service/src/test/java/org/openmetadata/service/resources/knowledge/KnowledgePageMapperTest.java index c7b346615ee9..18b4a53f2f76 100644 --- a/openmetadata-service/src/test/java/org/openmetadata/service/resources/knowledge/KnowledgePageMapperTest.java +++ b/openmetadata-service/src/test/java/org/openmetadata/service/resources/knowledge/KnowledgePageMapperTest.java @@ -3,6 +3,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; +import java.util.List; import java.util.UUID; import org.junit.jupiter.api.Test; import org.openmetadata.schema.api.data.CreatePage; @@ -18,8 +19,6 @@ class KnowledgePageMapperTest { void theRequestedEntityStatusReachesTheEntity() { // CreatePage carries entityStatus, but the mapper never copied it, so every article was // persisted as Unprocessed no matter what the caller asked for. - // EntityRepository.setDefaultStatus - // only fills in Unprocessed when the value is still null, so carrying it here is enough. Page page = new KnowledgePageMapper().createToEntity(createPage(EntityStatus.ARCHIVED), "admin"); @@ -27,17 +26,30 @@ void theRequestedEntityStatusReachesTheEntity() { } @Test - void anOmittedEntityStatusIsLeftForTheRepositoryDefault() { - // Omits entityStatus entirely rather than setting it to null, so this still holds if the DTO - // ever starts carrying a value of its own. createPage.json declares "default": "Approved", but - // jsonschema2pojo does not materialize a default that sits alongside a $ref — the generated - // field is initialised to null (see the assertion below). Were that to change, the mapper would - // start persisting Approved instead of letting the repository default to Unprocessed. + void anOmittedEntityStatusIsCarriedThroughUnchanged() { + // Omits entityStatus entirely instead of setting it to null. Asserts propagation rather than a + // literal value on purpose: createPage.json declares "default": "Approved" next to a $ref, and + // whether jsonschema2pojo materializes that default at all depends on schema processing order, + // so the generated field is null on some builds and Unprocessed on others. Either way the + // mapper must hand the value through untouched - null then reaches + // EntityRepository.setDefaultStatus, which fills in Unprocessed. CreatePage request = - new CreatePage().withName("runbook").withPageType(PageType.ARTICLE).withPage(new Article()); - assertNull(request.getEntityStatus(), "CreatePage must not supply an entityStatus of its own"); + withRelatedEntity( + new CreatePage() + .withName("runbook") + .withPageType(PageType.ARTICLE) + .withPage(new Article())); + + Page page = new KnowledgePageMapper().createToEntity(request, "admin"); - Page page = new KnowledgePageMapper().createToEntity(withRelatedEntity(request), "admin"); + assertEquals(request.getEntityStatus(), page.getEntityStatus()); + } + + @Test + void anExplicitNullEntityStatusIsLeftForTheRepositoryDefault() { + // The mapper must not invent a status of its own: a null reaches the repository, which then + // fills in Unprocessed via setDefaultStatus. + Page page = new KnowledgePageMapper().createToEntity(createPage(null), "admin"); assertNull(page.getEntityStatus()); } @@ -57,6 +69,6 @@ private static CreatePage createPage(EntityStatus status) { */ private static CreatePage withRelatedEntity(CreatePage request) { return request.withRelatedEntities( - java.util.List.of(new EntityReference().withId(UUID.randomUUID()).withType("table"))); + List.of(new EntityReference().withId(UUID.randomUUID()).withType("table"))); } }