From dcff230bb656cdd504af341309207d4b2ab234e4 Mon Sep 17 00:00:00 2001 From: Sriharsha Chintalapani Date: Mon, 8 Jan 2024 08:24:37 -0800 Subject: [PATCH] Fix #12854: Executable TestSuite should inherit the ownership from its table (#14612) --- .../service/jdbi3/TestSuiteRepository.java | 11 +++++++ .../resources/dqtests/TestSuiteResource.java | 12 ------- .../dqtests/TestSuiteResourceTest.java | 31 +++++++++++++++++++ 3 files changed, 42 insertions(+), 12 deletions(-) diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TestSuiteRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TestSuiteRepository.java index c7d81c8faa99..07246afd8649 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TestSuiteRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TestSuiteRepository.java @@ -1,6 +1,8 @@ package org.openmetadata.service.jdbi3; import static org.openmetadata.common.utils.CommonUtil.listOrEmpty; +import static org.openmetadata.schema.type.Include.ALL; +import static org.openmetadata.service.Entity.TABLE; import static org.openmetadata.service.Entity.TEST_CASE; import static org.openmetadata.service.Entity.TEST_SUITE; import static org.openmetadata.service.util.FullyQualifiedName.quoteName; @@ -53,6 +55,15 @@ public void setFields(TestSuite entity, EntityUtil.Fields fields) { entity.withTests(fields.contains("tests") ? getTestCases(entity) : entity.getTests()); } + @Override + public void setInheritedFields(TestSuite testSuite, EntityUtil.Fields fields) { + if (Boolean.TRUE.equals(testSuite.getExecutable())) { + Table table = + Entity.getEntity(TABLE, testSuite.getExecutableEntityReference().getId(), "owner", ALL); + inheritOwner(testSuite, fields, table); + } + } + @Override public void clearFields(TestSuite entity, EntityUtil.Fields fields) { entity.setPipelines(fields.contains("pipelines") ? entity.getPipelines() : null); diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/resources/dqtests/TestSuiteResource.java b/openmetadata-service/src/main/java/org/openmetadata/service/resources/dqtests/TestSuiteResource.java index b40264e37bc7..7bf403ae1fe9 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/resources/dqtests/TestSuiteResource.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/resources/dqtests/TestSuiteResource.java @@ -378,7 +378,6 @@ public Response createExecutable( @Valid CreateTestSuite create) { TestSuite testSuite = getTestSuite(create, securityContext.getUserPrincipal().getName()); testSuite.setExecutable(true); - testSuite = setExecutableTestSuiteOwner(testSuite); return create(uriInfo, securityContext, testSuite); } @@ -653,15 +652,4 @@ private TestSuite getTestSuite(CreateTestSuite create, String user) { } return testSuite; } - - private TestSuite setExecutableTestSuiteOwner(TestSuite testSuite) { - Table tableEntity = - Entity.getEntity( - testSuite.getExecutableEntityReference().getType(), - testSuite.getExecutableEntityReference().getId(), - "owner", - ALL); - EntityReference ownerReference = tableEntity.getOwner(); - return testSuite.withOwner(ownerReference); - } } diff --git a/openmetadata-service/src/test/java/org/openmetadata/service/resources/dqtests/TestSuiteResourceTest.java b/openmetadata-service/src/test/java/org/openmetadata/service/resources/dqtests/TestSuiteResourceTest.java index 220f822046ed..e265e834afd5 100644 --- a/openmetadata-service/src/test/java/org/openmetadata/service/resources/dqtests/TestSuiteResourceTest.java +++ b/openmetadata-service/src/test/java/org/openmetadata/service/resources/dqtests/TestSuiteResourceTest.java @@ -42,6 +42,7 @@ import org.openmetadata.service.Entity; import org.openmetadata.service.resources.EntityResourceTest; import org.openmetadata.service.resources.databases.TableResourceTest; +import org.openmetadata.service.util.JsonUtils; import org.openmetadata.service.util.ResultList; import org.openmetadata.service.util.TestUtils; @@ -162,6 +163,36 @@ void put_testCaseResults_200() throws IOException, ParseException { assertEquals(true, deletedTestSuite.getDeleted()); } + @Test + void test_inheritOwnerFromTable(TestInfo test) throws IOException { + TableResourceTest tableResourceTest = new TableResourceTest(); + CreateTable tableReq = + tableResourceTest + .createRequest(test) + .withColumns( + List.of( + new Column() + .withName(C1) + .withDisplayName("c1") + .withDataType(ColumnDataType.VARCHAR) + .withDataLength(10))) + .withOwner(USER1_REF); + Table table = tableResourceTest.createEntity(tableReq, ADMIN_AUTH_HEADERS); + table = tableResourceTest.getEntity(table.getId(), "*", ADMIN_AUTH_HEADERS); + CreateTestSuite createExecutableTestSuite = createRequest(table.getFullyQualifiedName()); + TestSuite executableTestSuite = + createExecutableTestSuite(createExecutableTestSuite, ADMIN_AUTH_HEADERS); + TestSuite testSuite = getEntity(executableTestSuite.getId(), "*", ADMIN_AUTH_HEADERS); + assertEquals(testSuite.getOwner().getId(), table.getOwner().getId()); + Table updateTableOwner = table; + updateTableOwner.setOwner(TEAM11_REF); + tableResourceTest.patchEntity( + table.getId(), JsonUtils.pojoToJson(table), updateTableOwner, ADMIN_AUTH_HEADERS); + table = tableResourceTest.getEntity(table.getId(), "*", ADMIN_AUTH_HEADERS); + testSuite = getEntity(executableTestSuite.getId(), "*", ADMIN_AUTH_HEADERS); + assertEquals(table.getOwner().getId(), testSuite.getOwner().getId()); + } + @Test void post_createLogicalTestSuiteAndAddTests_200(TestInfo test) throws IOException { TestCaseResourceTest testCaseResourceTest = new TestCaseResourceTest();