Skip to content

Commit

Permalink
Fix #2989: Add delete API for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
harshach committed Mar 1, 2022
1 parent 9272166 commit 4cb1123
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public Table addTableTest(UUID tableId, TableTest tableTest) throws IOException,
List<TableTest> storedTableTests = getTableTests(table);
// we will override any test case name passed by user/client with tableName + testType
// our assumption is there is only one instance of a test type as of now.
tableTest.setName(table.getName() + "." + tableTest.getTableTestCase().getTestType().toString());
tableTest.setName(table.getName() + "." + tableTest.getTestCase().getTableTestType().toString());
Map<String, TableTest> storedMapTableTests = new HashMap<>();
if (storedTableTests != null) {
for (TableTest t : storedTableTests) {
Expand Down Expand Up @@ -325,7 +325,7 @@ public Table addColumnTest(UUID tableId, ColumnTest columnTest) throws IOExcepti
validateColumn(table, columnName);
// we will override any test case name passed by user/client with columnName + testType
// our assumption is there is only one instance of a test type as of now.
columnTest.setName(columnName + "." + columnTest.getTestCase().getTestType().toString());
columnTest.setName(columnName + "." + columnTest.getTestCase().getColumnTestType().toString());
List<ColumnTest> storedColumnTests = getColumnTests(table, columnName);
Map<String, ColumnTest> storedMapColumnTests = new HashMap<>();
if (storedColumnTests != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -642,8 +642,7 @@ private TableTest getTableTest(SecurityContext securityContext, CreateTableTest
return new TableTest()
.withId(UUID.randomUUID())
.withDescription(create.getDescription())
.withTableName(create.getTableName())
.withTableTestCase(create.getTableTestCase())
.withTestCase(create.getTestCase())
.withOwner(create.getOwner())
.withExecutionFrequency(create.getExecutionFrequency())
.withResults(create.getResult() != null ? List.of(create.getResult()) : new ArrayList<>())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"description": "Table Name for which this test applies.",
"type": "string"
},
"tableTestCase": {
"testCase": {
"$ref": "../../tests/tableTest.json#/definitions/tableTestCase"
},
"executionFrequency": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"description": "Data one which profile is taken.",
"$ref": "../type/basic.json#/definitions/timestamp"
},
"status": {
"testCaseStatus": {
"description": "Status of Test Case run.",
"javaType": "org.openmetadata.catalog.tests.type.TestCaseStatus",
"type": "string",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
}
]
},
"testType": {
"columnTestType": {
"enum": [
"columnValuesToBeUnique",
"columnValuesToBeNotNull",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$id": "https://open-metadata.org/schema/tests/tableColumnCountToEqual.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "TableRowCountToEqual",
"title": "TableColumnCountToEqual",
"description": "This scheam defines the test TableColumnCountToEqual. Test the number of columns equal to a value.",
"type": "object",
"javaType": "org.openmetadata.catalog.tests.table.TableColumnCountToEqual",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$id": "https://open-metadata.org/schema/tests/tableRowCountToBeBetween.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "TableRowCountToEqual",
"title": "TableRowCountToBeBetween",
"description": "This scheam defines the test TableRowCountToBeBetween. Test the number of rows to between to two values.",
"type": "object",
"javaType": "org.openmetadata.catalog.tests.table.TableRowCountToBeBetween",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
}
]
},
"testType": {
"tableTestType": {
"enum": [
"tableRowCountToEqual",
"tableRowCountToBeBetween",
Expand All @@ -50,11 +50,7 @@
"description": "Description of the testcase.",
"type": "string"
},
"tableName": {
"description": "Table Name for which this test applies.",
"type": "string"
},
"tableTestCase": {
"testCase": {
"$ref": "#/definitions/tableTestCase"
},
"executionFrequency": {
Expand All @@ -81,6 +77,6 @@
"type": "string"
}
},
"required": ["name", "testCase", "tableName"],
"required": ["name", "testCase"],
"additionalProperties": false
}
Original file line number Diff line number Diff line change
Expand Up @@ -1041,12 +1041,12 @@ void createUpdateDelete_tableColumnTests_200(TestInfo test) throws IOException {
TableRowCountToEqual tableRowCountToEqual = new TableRowCountToEqual().withValue(100);
TableTestCase tableTestCase =
new TableTestCase()
.withTestType(TableTestCase.TestType.TABLE_ROW_COUNT_TO_EQUAL)
.withTableTestType(TableTestCase.TableTestType.TABLE_ROW_COUNT_TO_EQUAL)
.withConfig(tableRowCountToEqual);
CreateTableTest createTableTest =
new CreateTableTest()
.withTableName(table.getName())
.withTableTestCase(tableTestCase)
.withTestCase(tableTestCase)
.withExecutionFrequency(TestCaseExecutionFrequency.Hourly);
Table putResponse = putTableTest(table.getId(), createTableTest, ADMIN_AUTH_HEADERS);
verifyTableTest(putResponse.getName(), putResponse.getTableTests(), List.of(createTableTest));
Expand All @@ -1058,7 +1058,7 @@ void createUpdateDelete_tableColumnTests_200(TestInfo test) throws IOException {
TestCaseResult testCaseResult1 =
new TestCaseResult()
.withResult("Rows equal to 100")
.withStatus(TestCaseStatus.Success)
.withTestCaseStatus(TestCaseStatus.Success)
.withSampleData("Rows == 100")
.withExecutionTime(100L);
createTableTest.setResult(testCaseResult1);
Expand All @@ -1068,7 +1068,7 @@ void createUpdateDelete_tableColumnTests_200(TestInfo test) throws IOException {
TestCaseResult testCaseResult2 =
new TestCaseResult()
.withResult("Rows equal to 100")
.withStatus(TestCaseStatus.Success)
.withTestCaseStatus(TestCaseStatus.Success)
.withSampleData("Rows == 100")
.withExecutionTime(100L);
createTableTest.setResult(testCaseResult2);
Expand All @@ -1078,10 +1078,10 @@ void createUpdateDelete_tableColumnTests_200(TestInfo test) throws IOException {
new TableRowCountToBeBetween().withMinValue(100).withMaxValue(1000);
TableTestCase tableTestCase1 =
new TableTestCase()
.withTestType(TableTestCase.TestType.TABLE_ROW_COUNT_TO_BE_BETWEEN)
.withTableTestType(TableTestCase.TableTestType.TABLE_ROW_COUNT_TO_BE_BETWEEN)
.withConfig(tableRowCountToBeBetween);
CreateTableTest createTableTest1 =
new CreateTableTest().withTableTestCase(tableTestCase1).withTableName(table.getName());
new CreateTableTest().withTestCase(tableTestCase1).withTableName(table.getName());
putResponse = putTableTest(table.getId(), createTableTest1, ADMIN_AUTH_HEADERS);
// returns the current test thats updated or created
verifyTableTest(putResponse.getName(), putResponse.getTableTests(), List.of(createTableTest1));
Expand All @@ -1100,7 +1100,7 @@ void createUpdateDelete_tableColumnTests_200(TestInfo test) throws IOException {
new ColumnValueLengthsToBeBetween().withMaxValue(100).withMinValue(10);
ColumnTestCase columnTestCase =
new ColumnTestCase()
.withTestType(ColumnTestCase.TestType.COLUMN_VALUE_LENGTHS_TO_BE_BETWEEN)
.withColumnTestType(ColumnTestCase.ColumnTestType.COLUMN_VALUE_LENGTHS_TO_BE_BETWEEN)
.withConfig(columnValueLengthsToBeBetween);
CreateColumnTest createColumnTest =
new CreateColumnTest()
Expand All @@ -1118,7 +1118,7 @@ void createUpdateDelete_tableColumnTests_200(TestInfo test) throws IOException {
TestCaseResult colTestCaseResult =
new TestCaseResult()
.withResult("min is > 100 and max < 1000")
.withStatus(TestCaseStatus.Success)
.withTestCaseStatus(TestCaseStatus.Success)
.withSampleData("minValue is 100 and maxValue is 1000")
.withExecutionTime(100L);
createColumnTest.setResult(colTestCaseResult);
Expand All @@ -1129,7 +1129,7 @@ void createUpdateDelete_tableColumnTests_200(TestInfo test) throws IOException {
new ColumnValuesMissingCountToBeEqual().withMissingCountValue(10);
ColumnTestCase columnTestCase1 =
new ColumnTestCase()
.withTestType(ColumnTestCase.TestType.COLUMN_VALUES_MISSING_COUNT_TO_BE_EQUAL)
.withColumnTestType(ColumnTestCase.ColumnTestType.COLUMN_VALUES_MISSING_COUNT_TO_BE_EQUAL)
.withConfig(columnValuesMissingCountToBeEqual);
CreateColumnTest createColumnTest1 =
new CreateColumnTest()
Expand All @@ -1143,7 +1143,7 @@ void createUpdateDelete_tableColumnTests_200(TestInfo test) throws IOException {
columnValuesMissingCountToBeEqual = new ColumnValuesMissingCountToBeEqual().withMissingCountValue(100);
columnTestCase1 =
new ColumnTestCase()
.withTestType(ColumnTestCase.TestType.COLUMN_VALUES_MISSING_COUNT_TO_BE_EQUAL)
.withColumnTestType(ColumnTestCase.ColumnTestType.COLUMN_VALUES_MISSING_COUNT_TO_BE_EQUAL)
.withConfig(columnValuesMissingCountToBeEqual);
createColumnTest1 =
new CreateColumnTest()
Expand All @@ -1157,7 +1157,7 @@ void createUpdateDelete_tableColumnTests_200(TestInfo test) throws IOException {
TestCaseResult colTestCaseResult1 =
new TestCaseResult()
.withResult("min is > 100 and max < 1000")
.withStatus(TestCaseStatus.Success)
.withTestCaseStatus(TestCaseStatus.Success)
.withSampleData("minValue is 100 and maxValue is 1000")
.withExecutionTime(100L);
createColumnTest.setResult(colTestCaseResult1);
Expand All @@ -1171,12 +1171,12 @@ void createUpdateDelete_tableColumnTests_200(TestInfo test) throws IOException {
// delete the table test case
putResponse =
deleteTableTest(
table.getId(), createTableTest1.getTableTestCase().getTestType().toString(), ADMIN_AUTH_HEADERS);
table.getId(), createTableTest1.getTestCase().getTableTestType().toString(), ADMIN_AUTH_HEADERS);
table = getEntity(table.getId(), "tests", ADMIN_AUTH_HEADERS);
verifyTableTest(table.getName(), table.getTableTests(), List.of(createTableTest));

// delete column test case
deleteColumnTest(table.getId(), c1.getName(), columnTestCase1.getTestType().toString(), ADMIN_AUTH_HEADERS);
deleteColumnTest(table.getId(), c1.getName(), columnTestCase1.getColumnTestType().toString(), ADMIN_AUTH_HEADERS);
table = getEntity(table.getId(), "tests", ADMIN_AUTH_HEADERS);
verifyColumnTest(table, c1, List.of(createColumnTest));
}
Expand Down Expand Up @@ -1731,32 +1731,32 @@ private void verifyTableTest(String tableName, List<TableTest> actualTests, List
}
for (CreateTableTest test : expectedTests) {
// passed in test name will be overridden in backend
String expectedTestName = tableName + "." + test.getTableTestCase().getTestType().toString();
String expectedTestName = tableName + "." + test.getTestCase().getTableTestType().toString();
TableTest storedTest = tableTestMap.get(expectedTestName);
assertNotNull(storedTest);
assertEquals(expectedTestName, storedTest.getName());
assertEquals(test.getDescription(), storedTest.getDescription());
assertEquals(test.getExecutionFrequency(), storedTest.getExecutionFrequency());
assertEquals(test.getOwner(), storedTest.getOwner());
verifyTableTestCase(test.getTableTestCase(), storedTest.getTableTestCase());
verifyTableTestCase(test.getTestCase(), storedTest.getTestCase());
if (test.getResult() != null && storedTest.getResults().size() > 0) {
verifyTestCaseResults(test.getResult(), storedTest.getResults());
}
}
}

private void verifyTableTestCase(TableTestCase expected, TableTestCase actual) {
assertEquals(expected.getTestType(), actual.getTestType());
if (expected.getTestType() == TableTestCase.TestType.TABLE_COLUMN_COUNT_TO_EQUAL) {
assertEquals(expected.getTableTestType(), actual.getTableTestType());
if (expected.getTableTestType() == TableTestCase.TableTestType.TABLE_COLUMN_COUNT_TO_EQUAL) {
TableColumnCountToEqual expectedTest = (TableColumnCountToEqual) expected.getConfig();
TableColumnCountToEqual actualTest = JsonUtils.convertValue(actual.getConfig(), TableColumnCountToEqual.class);
assertEquals(expectedTest.getValue(), actualTest.getValue());
} else if (expected.getTestType() == TableTestCase.TestType.TABLE_ROW_COUNT_TO_BE_BETWEEN) {
} else if (expected.getTableTestType() == TableTestCase.TableTestType.TABLE_ROW_COUNT_TO_BE_BETWEEN) {
TableRowCountToBeBetween expectedTest = (TableRowCountToBeBetween) expected.getConfig();
TableRowCountToBeBetween actualTest = JsonUtils.convertValue(actual.getConfig(), TableRowCountToBeBetween.class);
assertEquals(expectedTest.getMaxValue(), actualTest.getMaxValue());
assertEquals(expectedTest.getMinValue(), actualTest.getMinValue());
} else if (expected.getTestType() == TableTestCase.TestType.TABLE_ROW_COUNT_TO_EQUAL) {
} else if (expected.getTableTestType() == TableTestCase.TableTestType.TABLE_ROW_COUNT_TO_EQUAL) {
TableRowCountToEqual expectedTest = (TableRowCountToEqual) expected.getConfig();
TableRowCountToEqual actualTest = JsonUtils.convertValue(actual.getConfig(), TableRowCountToEqual.class);
assertEquals(expectedTest.getValue(), actualTest.getValue());
Expand All @@ -1779,7 +1779,7 @@ private void verifyColumnTest(Table table, Column column, List<CreateColumnTest>

for (CreateColumnTest test : expectedTests) {
// passed in test name will be overridden in backend
String expectedTestName = column.getName() + "." + test.getTestCase().getTestType().toString();
String expectedTestName = column.getName() + "." + test.getTestCase().getColumnTestType().toString();
ColumnTest storedTest = columnTestMap.get(expectedTestName);
assertNotNull(storedTest);
assertEquals(expectedTestName, storedTest.getName());
Expand All @@ -1794,26 +1794,26 @@ private void verifyColumnTest(Table table, Column column, List<CreateColumnTest>
}

private void verifyColumnTestCase(ColumnTestCase expected, ColumnTestCase actual) {
assertEquals(expected.getTestType(), actual.getTestType());
if (expected.getTestType() == ColumnTestCase.TestType.COLUMN_VALUES_TO_BE_UNIQUE) {
assertEquals(expected.getColumnTestType(), actual.getColumnTestType());
if (expected.getColumnTestType() == ColumnTestCase.ColumnTestType.COLUMN_VALUES_TO_BE_UNIQUE) {
ColumnValuesToBeUnique expectedTest = (ColumnValuesToBeUnique) expected.getConfig();
ColumnValuesToBeUnique actualTest = JsonUtils.convertValue(actual.getConfig(), ColumnValuesToBeUnique.class);
assertEquals(expectedTest, actualTest);
} else if (expected.getTestType() == ColumnTestCase.TestType.COLUMN_VALUES_TO_BE_NOT_NULL) {
} else if (expected.getColumnTestType() == ColumnTestCase.ColumnTestType.COLUMN_VALUES_TO_BE_NOT_NULL) {
ColumnValuesToBeNotNull expectedTest = (ColumnValuesToBeNotNull) expected.getConfig();
ColumnValuesToBeNotNull actualTest = JsonUtils.convertValue(actual.getConfig(), ColumnValuesToBeNotNull.class);
assertEquals(expectedTest, actualTest);
} else if (expected.getTestType() == ColumnTestCase.TestType.COLUMN_VALUES_TO_MATCH_REGEX) {
} else if (expected.getColumnTestType() == ColumnTestCase.ColumnTestType.COLUMN_VALUES_TO_MATCH_REGEX) {
ColumnValuesToMatchRegex expectedTest = (ColumnValuesToMatchRegex) expected.getConfig();
ColumnValuesToMatchRegex actualTest = JsonUtils.convertValue(actual.getConfig(), ColumnValuesToMatchRegex.class);
assertEquals(expectedTest.getRegex(), actualTest.getRegex());
} else if (expected.getTestType() == ColumnTestCase.TestType.COLUMN_VALUE_LENGTHS_TO_BE_BETWEEN) {
} else if (expected.getColumnTestType() == ColumnTestCase.ColumnTestType.COLUMN_VALUE_LENGTHS_TO_BE_BETWEEN) {
ColumnValueLengthsToBeBetween expectedTest = (ColumnValueLengthsToBeBetween) expected.getConfig();
ColumnValueLengthsToBeBetween actualTest =
JsonUtils.convertValue(actual.getConfig(), ColumnValueLengthsToBeBetween.class);
assertEquals(expectedTest.getMaxValue(), actualTest.getMaxValue());
assertEquals(expectedTest.getMinValue(), actualTest.getMinValue());
} else if (expected.getTestType() == ColumnTestCase.TestType.COLUMN_VALUES_MISSING_COUNT_TO_BE_EQUAL) {
} else if (expected.getColumnTestType() == ColumnTestCase.ColumnTestType.COLUMN_VALUES_MISSING_COUNT_TO_BE_EQUAL) {
ColumnValuesMissingCountToBeEqual expectedTest = (ColumnValuesMissingCountToBeEqual) expected.getConfig();
ColumnValuesMissingCountToBeEqual actualTest =
JsonUtils.convertValue(actual.getConfig(), ColumnValuesMissingCountToBeEqual.class);
Expand Down

0 comments on commit 4cb1123

Please sign in to comment.