Skip to content

Commit

Permalink
Fix #12854: Executable TestSuite should inherit the ownership from it…
Browse files Browse the repository at this point in the history
…s table (#14612)
  • Loading branch information
harshach authored Jan 8, 2024
1 parent e8eb2bd commit dcff230
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit dcff230

Please sign in to comment.