From 3d2e2e8214f68511cf0c98d426d6cec9878baad9 Mon Sep 17 00:00:00 2001 From: Onkar Ravgan Date: Fri, 3 May 2024 13:49:44 +0530 Subject: [PATCH] MINOR: Updated test case name field (#16048) * Removed entityName char limit * updated new field * fixed backend tests * fixed linting --- .../dqtests/TestCaseResourceTest.java | 24 +++++++++++++++++ .../dqtests/TestDefinitionResourceTest.java | 26 +++++++++++++++++++ .../json/schema/api/tests/createTestCase.json | 2 +- .../api/tests/createTestDefinition.json | 2 +- .../resources/json/schema/tests/testCase.json | 2 +- .../json/schema/tests/testDefinition.json | 2 +- .../resources/json/schema/type/basic.json | 6 +++++ 7 files changed, 60 insertions(+), 4 deletions(-) diff --git a/openmetadata-service/src/test/java/org/openmetadata/service/resources/dqtests/TestCaseResourceTest.java b/openmetadata-service/src/test/java/org/openmetadata/service/resources/dqtests/TestCaseResourceTest.java index f12c601c817..78582a1a706 100644 --- a/openmetadata-service/src/test/java/org/openmetadata/service/resources/dqtests/TestCaseResourceTest.java +++ b/openmetadata-service/src/test/java/org/openmetadata/service/resources/dqtests/TestCaseResourceTest.java @@ -48,6 +48,8 @@ import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInfo; import org.junit.jupiter.api.TestMethodOrder; +import org.junit.jupiter.api.parallel.Execution; +import org.junit.jupiter.api.parallel.ExecutionMode; import org.openmetadata.schema.api.data.CreateTable; import org.openmetadata.schema.api.feed.CloseTask; import org.openmetadata.schema.api.feed.ResolveTask; @@ -2376,6 +2378,28 @@ public class TestCaseResourceTest extends EntityResourceTest createEntity(request, ADMIN_AUTH_HEADERS), BAD_REQUEST, "[name must not be null]"); + + // Create an entity with mandatory name field empty + final CreateTestCase request1 = createRequest("", "description", "displayName", null); + assertResponseContains( + () -> createEntity(request1, ADMIN_AUTH_HEADERS), + BAD_REQUEST, + TestUtils.getEntityNameLengthError(entityClass)); + + // Any entity name that has EntityLink separator must fail + final CreateTestCase request3 = + createRequest("invalid::Name", "description", "displayName", null); + assertResponseContains( + () -> createEntity(request3, ADMIN_AUTH_HEADERS), BAD_REQUEST, "name must match"); + } + private void putInspectionQuery(TestCase testCase, String sql, Map authHeaders) throws IOException { TestCase putResponse = putInspectionQuery(testCase.getId(), sql, authHeaders); diff --git a/openmetadata-service/src/test/java/org/openmetadata/service/resources/dqtests/TestDefinitionResourceTest.java b/openmetadata-service/src/test/java/org/openmetadata/service/resources/dqtests/TestDefinitionResourceTest.java index 8d155d20bd2..11e85e7aaa1 100644 --- a/openmetadata-service/src/test/java/org/openmetadata/service/resources/dqtests/TestDefinitionResourceTest.java +++ b/openmetadata-service/src/test/java/org/openmetadata/service/resources/dqtests/TestDefinitionResourceTest.java @@ -6,6 +6,7 @@ import static org.openmetadata.service.util.TestUtils.ADMIN_AUTH_HEADERS; import static org.openmetadata.service.util.TestUtils.assertListNotNull; import static org.openmetadata.service.util.TestUtils.assertListNull; import static org.openmetadata.service.util.TestUtils.assertResponse; +import static org.openmetadata.service.util.TestUtils.assertResponseContains; import java.io.IOException; import java.util.List; @@ -14,6 +15,8 @@ import org.apache.http.client.HttpResponseException; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInfo; +import org.junit.jupiter.api.parallel.Execution; +import org.junit.jupiter.api.parallel.ExecutionMode; import org.openmetadata.schema.api.tests.CreateTestDefinition; import org.openmetadata.schema.tests.TestCaseParameter; import org.openmetadata.schema.tests.TestDefinition; @@ -22,6 +25,7 @@ import org.openmetadata.schema.type.TestDefinitionEntityType; import org.openmetadata.service.Entity; import org.openmetadata.service.resources.EntityResourceTest; import org.openmetadata.service.util.ResultList; +import org.openmetadata.service.util.TestUtils; public class TestDefinitionResourceTest extends EntityResourceTest { @@ -89,6 +93,28 @@ public class TestDefinitionResourceTest } } + @Test + @Execution(ExecutionMode.CONCURRENT) + protected void post_entityCreateWithInvalidName_400() { + // Create an entity with mandatory name field null + final CreateTestDefinition request = createRequest(null, "description", "displayName", null); + assertResponseContains( + () -> createEntity(request, ADMIN_AUTH_HEADERS), BAD_REQUEST, "[name must not be null]"); + + // Create an entity with mandatory name field empty + final CreateTestDefinition request1 = createRequest("", "description", "displayName", null); + assertResponseContains( + () -> createEntity(request1, ADMIN_AUTH_HEADERS), + BAD_REQUEST, + TestUtils.getEntityNameLengthError(entityClass)); + + // Any entity name that has EntityLink separator must fail + final CreateTestDefinition request3 = + createRequest("invalid::Name", "description", "displayName", null); + assertResponseContains( + () -> createEntity(request3, ADMIN_AUTH_HEADERS), BAD_REQUEST, "name must match"); + } + @Override public CreateTestDefinition createRequest(String name) { return new CreateTestDefinition() diff --git a/openmetadata-spec/src/main/resources/json/schema/api/tests/createTestCase.json b/openmetadata-spec/src/main/resources/json/schema/api/tests/createTestCase.json index b75886870ab..45d53f6748a 100644 --- a/openmetadata-spec/src/main/resources/json/schema/api/tests/createTestCase.json +++ b/openmetadata-spec/src/main/resources/json/schema/api/tests/createTestCase.json @@ -9,7 +9,7 @@ "properties": { "name": { "description": "Name that identifies this test case.", - "$ref": "../../type/basic.json#/definitions/entityName" + "$ref": "../../type/basic.json#/definitions/testCaseEntityName" }, "description": { "description": "Description of the testcase.", diff --git a/openmetadata-spec/src/main/resources/json/schema/api/tests/createTestDefinition.json b/openmetadata-spec/src/main/resources/json/schema/api/tests/createTestDefinition.json index 47b7617401b..9d24213fc22 100644 --- a/openmetadata-spec/src/main/resources/json/schema/api/tests/createTestDefinition.json +++ b/openmetadata-spec/src/main/resources/json/schema/api/tests/createTestDefinition.json @@ -9,7 +9,7 @@ "properties": { "name": { "description": "Name that identifies this test case.", - "$ref": "../../type/basic.json#/definitions/entityName" + "$ref": "../../type/basic.json#/definitions/testCaseEntityName" }, "displayName": { "description": "Display Name that identifies this test case.", diff --git a/openmetadata-spec/src/main/resources/json/schema/tests/testCase.json b/openmetadata-spec/src/main/resources/json/schema/tests/testCase.json index f0b1b27da18..b27e4d3628f 100644 --- a/openmetadata-spec/src/main/resources/json/schema/tests/testCase.json +++ b/openmetadata-spec/src/main/resources/json/schema/tests/testCase.json @@ -30,7 +30,7 @@ }, "name": { "description": "Name that identifies this test case.", - "$ref": "../type/basic.json#/definitions/entityName" + "$ref": "../type/basic.json#/definitions/testCaseEntityName" }, "displayName": { "description": "Display Name that identifies this test.", diff --git a/openmetadata-spec/src/main/resources/json/schema/tests/testDefinition.json b/openmetadata-spec/src/main/resources/json/schema/tests/testDefinition.json index 85d2af87a4f..d673b324a79 100644 --- a/openmetadata-spec/src/main/resources/json/schema/tests/testDefinition.json +++ b/openmetadata-spec/src/main/resources/json/schema/tests/testDefinition.json @@ -113,7 +113,7 @@ }, "name": { "description": "Name that identifies this test case.", - "$ref": "../type/basic.json#/definitions/entityName" + "$ref": "../type/basic.json#/definitions/testCaseEntityName" }, "displayName": { "description": "Display Name that identifies this test case.", diff --git a/openmetadata-spec/src/main/resources/json/schema/type/basic.json b/openmetadata-spec/src/main/resources/json/schema/type/basic.json index 45a4ee7a894..1477df6e3f5 100644 --- a/openmetadata-spec/src/main/resources/json/schema/type/basic.json +++ b/openmetadata-spec/src/main/resources/json/schema/type/basic.json @@ -110,6 +110,12 @@ "maxLength": 256, "pattern": "^((?!::).)*$" }, + "testCaseEntityName": { + "description": "Name that identifies a test definition and test case.", + "type": "string", + "minLength": 1, + "pattern": "^((?!::).)*$" + }, "fullyQualifiedEntityName": { "description": "A unique name that identifies an entity. Example for table 'DatabaseService.Database.Schema.Table'.", "type": "string",