mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-11-02 19:48:17 +00:00
* Fix #6936: testPlatforms is required field in testSuite and createTestSuite schema * Fix #6936: testPlatforms is required field in testSuite and createTestSuite schema * Fix #6936: testPlatforms is required field in testSuite and createTestSuite schema * Fix #6936: testPlatforms is required field in testSuite and createTestSuite schema * Fix #6936: testPlatforms is required field in testSuite and createTestSuite schema * fixed glossary test * Fixed sample data ingestion * Add filters for testCaseResultSuccess testCaseResultFailed, testCaseResultAborted * Fix #6936: fix testcase listing * Fix #6936: fix java style Co-authored-by: Shailesh Parmar <shailesh.parmar.webdev@gmail.com> Co-authored-by: Teddy Crepineau <teddy.crepineau@gmail.com> Co-authored-by: mohitdeuex <mohit.y@deuexsolutions.com>
This commit is contained in:
parent
6c62433931
commit
f9a3f9988e
@ -92,4 +92,15 @@ WHERE serviceType = 'Oracle';
|
||||
|
||||
UPDATE dbservice_entity
|
||||
SET json = JSON_REMOVE(json, '$.connection.config.hostPort')
|
||||
WHERE serviceType = 'Athena';
|
||||
WHERE serviceType = 'Athena';
|
||||
UPDATE dbservice_entity
|
||||
SET json = JSON_REMOVE(json, '$.connection.config.username', '$.connection.config.password')
|
||||
WHERE serviceType in ('Databricks');
|
||||
|
||||
CREATE TABLE IF NOT EXISTS openmetadata_settings (
|
||||
id MEDIUMINT NOT NULL AUTO_INCREMENT,
|
||||
configType VARCHAR(36) NOT NULL,
|
||||
json JSON NOT NULL,
|
||||
PRIMARY KEY (id, configType),
|
||||
UNIQUE(configType)
|
||||
);
|
||||
|
||||
@ -1,11 +0,0 @@
|
||||
UPDATE dbservice_entity
|
||||
SET json = JSON_REMOVE(json, '$.connection.config.username', '$.connection.config.password')
|
||||
WHERE serviceType in ('Databricks');
|
||||
|
||||
CREATE TABLE IF NOT EXISTS openmetadata_settings (
|
||||
id MEDIUMINT NOT NULL AUTO_INCREMENT,
|
||||
configType VARCHAR(36) NOT NULL,
|
||||
json JSON NOT NULL,
|
||||
PRIMARY KEY (id, configType),
|
||||
UNIQUE(configType)
|
||||
);
|
||||
@ -87,4 +87,16 @@ WHERE serviceType = 'Oracle';
|
||||
|
||||
UPDATE dbservice_entity
|
||||
SET json = json::jsonb #- '{connection,config,hostPort}'
|
||||
WHERE serviceType = 'Athena';
|
||||
WHERE serviceType = 'Athena';
|
||||
UPDATE dbservice_entity
|
||||
SET json = json::jsonb #- '{connection,config,username}' #- '{connection,config,password}'
|
||||
WHERE serviceType in ('Databricks');
|
||||
|
||||
CREATE TABLE IF NOT EXISTS openmetadata_settings (
|
||||
id SERIAL NOT NULL ,
|
||||
configType VARCHAR(36) NOT NULL,
|
||||
json JSONB NOT NULL,
|
||||
PRIMARY KEY (id, configType),
|
||||
UNIQUE(configType)
|
||||
);
|
||||
|
||||
|
||||
@ -1,11 +0,0 @@
|
||||
UPDATE dbservice_entity
|
||||
SET json = json::jsonb #- '{connection,config,username}' #- '{connection,config,password}'
|
||||
WHERE serviceType in ('Databricks');
|
||||
|
||||
CREATE TABLE IF NOT EXISTS openmetadata_settings (
|
||||
id SERIAL NOT NULL ,
|
||||
configType VARCHAR(36) NOT NULL,
|
||||
json JSONB NOT NULL,
|
||||
PRIMARY KEY (id, configType),
|
||||
UNIQUE(configType)
|
||||
);
|
||||
@ -2560,7 +2560,7 @@ public interface CollectionDAO {
|
||||
condition =
|
||||
String.format(
|
||||
"%s AND id IN (SELECT toId FROM entity_relationship WHERE fromId='%s' AND toEntity='%s' AND relation=%d AND fromEntity='%s')",
|
||||
condition, testSuiteId, Entity.TEST_CASE, Relationship.HAS.ordinal(), Entity.TEST_SUITE);
|
||||
condition, testSuiteId, Entity.TEST_CASE, Relationship.CONTAINS.ordinal(), Entity.TEST_SUITE);
|
||||
}
|
||||
|
||||
return listBefore(getTableName(), getNameColumn(), condition, limit, before);
|
||||
@ -2587,7 +2587,7 @@ public interface CollectionDAO {
|
||||
condition =
|
||||
String.format(
|
||||
"%s AND id IN (SELECT toId FROM entity_relationship WHERE fromId='%s' AND toEntity='%s' AND relation=%d AND fromEntity='%s')",
|
||||
condition, testSuiteId, Entity.TEST_CASE, Relationship.HAS.ordinal(), Entity.TEST_SUITE);
|
||||
condition, testSuiteId, Entity.TEST_CASE, Relationship.CONTAINS.ordinal(), Entity.TEST_SUITE);
|
||||
}
|
||||
|
||||
return listAfter(getTableName(), getNameColumn(), condition, limit, after);
|
||||
@ -2614,7 +2614,7 @@ public interface CollectionDAO {
|
||||
condition =
|
||||
String.format(
|
||||
"%s AND id IN (SELECT toId FROM entity_relationship WHERE fromId='%s' AND toEntity='%s' AND relation=%d AND fromEntity='%s')",
|
||||
condition, testSuiteId, Entity.TEST_CASE, Relationship.HAS.ordinal(), Entity.TEST_SUITE);
|
||||
condition, testSuiteId, Entity.TEST_CASE, Relationship.CONTAINS.ordinal(), Entity.TEST_SUITE);
|
||||
}
|
||||
|
||||
return listCount(getTableName(), getNameColumn(), condition);
|
||||
|
||||
@ -9,8 +9,10 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.ws.rs.core.Response;
|
||||
import org.jdbi.v3.sqlobject.transaction.Transaction;
|
||||
import org.openmetadata.catalog.Entity;
|
||||
import org.openmetadata.catalog.EntityInterface;
|
||||
import org.openmetadata.catalog.exception.EntityNotFoundException;
|
||||
import org.openmetadata.catalog.resources.dqtests.TestSuiteResource;
|
||||
import org.openmetadata.catalog.resources.feeds.MessageParser;
|
||||
@ -19,7 +21,11 @@ import org.openmetadata.catalog.test.TestCaseParameterValue;
|
||||
import org.openmetadata.catalog.tests.TestCase;
|
||||
import org.openmetadata.catalog.tests.TestDefinition;
|
||||
import org.openmetadata.catalog.tests.type.TestCaseResult;
|
||||
import org.openmetadata.catalog.type.ChangeDescription;
|
||||
import org.openmetadata.catalog.type.ChangeEvent;
|
||||
import org.openmetadata.catalog.type.EntityReference;
|
||||
import org.openmetadata.catalog.type.EventType;
|
||||
import org.openmetadata.catalog.type.FieldChange;
|
||||
import org.openmetadata.catalog.type.Include;
|
||||
import org.openmetadata.catalog.type.Relationship;
|
||||
import org.openmetadata.catalog.util.EntityUtil;
|
||||
@ -68,7 +74,7 @@ public class TestCaseRepository extends EntityRepository<TestCase> {
|
||||
}
|
||||
|
||||
private EntityReference getTestSuite(TestCase test) throws IOException {
|
||||
return getFromEntityRef(test.getId(), Relationship.HAS, null, true);
|
||||
return getFromEntityRef(test.getId(), Relationship.CONTAINS, TEST_SUITE, true);
|
||||
}
|
||||
|
||||
private EntityReference getTestDefinition(TestCase test) throws IOException {
|
||||
@ -112,7 +118,7 @@ public class TestCaseRepository extends EntityRepository<TestCase> {
|
||||
MessageParser.EntityLink entityLink = MessageParser.EntityLink.parse(test.getEntityLink());
|
||||
EntityReference tableRef = EntityUtil.validateEntityLink(entityLink);
|
||||
// Add relationship from testSuite to test
|
||||
addRelationship(test.getTestSuite().getId(), test.getId(), TEST_SUITE, TEST_CASE, Relationship.HAS);
|
||||
addRelationship(test.getTestSuite().getId(), test.getId(), TEST_SUITE, TEST_CASE, Relationship.CONTAINS);
|
||||
// Add relationship from entity to test
|
||||
addRelationship(tableRef.getId(), test.getId(), tableRef.getType(), TEST_CASE, Relationship.CONTAINS);
|
||||
// Add relationship from test definition to test
|
||||
@ -123,7 +129,7 @@ public class TestCaseRepository extends EntityRepository<TestCase> {
|
||||
}
|
||||
|
||||
@Transaction
|
||||
public TestCase addTestCaseResult(String fqn, TestCaseResult testCaseResult) throws IOException {
|
||||
public RestUtil.PutResponse<?> addTestCaseResult(String fqn, TestCaseResult testCaseResult) throws IOException {
|
||||
// Validate the request content
|
||||
TestCase testCase = dao.findEntityByName(fqn);
|
||||
|
||||
@ -152,11 +158,16 @@ public class TestCaseRepository extends EntityRepository<TestCase> {
|
||||
JsonUtils.pojoToJson(testCaseResult));
|
||||
setFields(testCase, EntityUtil.Fields.EMPTY_FIELDS);
|
||||
}
|
||||
return testCase.withTestCaseResult(testCaseResult);
|
||||
|
||||
ChangeDescription change =
|
||||
addTestCaseChangeDescription(testCase.getVersion(), testCaseResult, storedTestCaseResult);
|
||||
ChangeEvent changeEvent = getChangeEvent(testCase, change, entityType, testCase.getVersion());
|
||||
|
||||
return new RestUtil.PutResponse<>(Response.Status.CREATED, changeEvent, RestUtil.ENTITY_FIELDS_CHANGED);
|
||||
}
|
||||
|
||||
@Transaction
|
||||
public TestCase deleteTestCaseResult(String fqn, Long timestamp) throws IOException {
|
||||
public RestUtil.PutResponse<?> deleteTestCaseResult(String fqn, Long timestamp) throws IOException {
|
||||
// Validate the request content
|
||||
TestCase testCase = dao.findEntityByName(fqn);
|
||||
TestCaseResult storedTestCaseResult =
|
||||
@ -168,12 +179,44 @@ public class TestCaseRepository extends EntityRepository<TestCase> {
|
||||
if (storedTestCaseResult != null) {
|
||||
daoCollection.entityExtensionTimeSeriesDao().deleteAtTimestamp(fqn, TESTCASE_RESULT_EXTENSION, timestamp);
|
||||
testCase.setTestCaseResult(storedTestCaseResult);
|
||||
return testCase;
|
||||
ChangeDescription change = deleteTestCaseChangeDescription(testCase.getVersion(), storedTestCaseResult);
|
||||
ChangeEvent changeEvent = getChangeEvent(testCase, change, entityType, testCase.getVersion());
|
||||
return new RestUtil.PutResponse<>(Response.Status.OK, changeEvent, RestUtil.ENTITY_FIELDS_CHANGED);
|
||||
}
|
||||
throw new EntityNotFoundException(
|
||||
String.format("Failed to find testCase result for %s at %s", testCase.getName(), timestamp));
|
||||
}
|
||||
|
||||
private ChangeDescription addTestCaseChangeDescription(Double version, Object newValue, Object oldValue) {
|
||||
FieldChange fieldChange =
|
||||
new FieldChange().withName("testCaseResult").withNewValue(newValue).withOldValue(oldValue);
|
||||
ChangeDescription change = new ChangeDescription().withPreviousVersion(version);
|
||||
change.getFieldsUpdated().add(fieldChange);
|
||||
return change;
|
||||
}
|
||||
|
||||
private ChangeDescription deleteTestCaseChangeDescription(Double version, Object oldValue) {
|
||||
FieldChange fieldChange = new FieldChange().withName("testCaseResult").withOldValue(oldValue);
|
||||
ChangeDescription change = new ChangeDescription().withPreviousVersion(version);
|
||||
change.getFieldsDeleted().add(fieldChange);
|
||||
return change;
|
||||
}
|
||||
|
||||
private ChangeEvent getChangeEvent(
|
||||
EntityInterface updated, ChangeDescription change, String entityType, Double prevVersion) {
|
||||
return new ChangeEvent()
|
||||
.withEntity(updated)
|
||||
.withChangeDescription(change)
|
||||
.withEventType(EventType.ENTITY_UPDATED)
|
||||
.withEntityType(entityType)
|
||||
.withEntityId(updated.getId())
|
||||
.withEntityFullyQualifiedName(updated.getFullyQualifiedName())
|
||||
.withUserName(updated.getUpdatedBy())
|
||||
.withTimestamp(System.currentTimeMillis())
|
||||
.withCurrentVersion(updated.getVersion())
|
||||
.withPreviousVersion(prevVersion);
|
||||
}
|
||||
|
||||
private TestCaseResult getTestCaseResult(TestCase testCase) throws IOException {
|
||||
return JsonUtils.readValue(
|
||||
daoCollection
|
||||
|
||||
@ -1,8 +1,10 @@
|
||||
package org.openmetadata.catalog.jdbi3;
|
||||
|
||||
import static org.openmetadata.catalog.Entity.TEST_CASE;
|
||||
import static org.openmetadata.catalog.Entity.TEST_SUITE;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import org.openmetadata.catalog.Entity;
|
||||
import org.openmetadata.catalog.resources.dqtests.TestSuiteResource;
|
||||
import org.openmetadata.catalog.tests.TestSuite;
|
||||
@ -29,6 +31,7 @@ public class TestSuiteRepository extends EntityRepository<TestSuite> {
|
||||
public TestSuite setFields(TestSuite entity, EntityUtil.Fields fields) throws IOException {
|
||||
entity.setOwner(fields.contains("owner") ? getOwner(entity) : null);
|
||||
entity.setPipeline(fields.contains("pipelines") ? getIngestionPipeline(entity) : null);
|
||||
entity.setTests(fields.contains("tests") ? getTestCases(entity) : null);
|
||||
return entity;
|
||||
}
|
||||
|
||||
@ -37,6 +40,12 @@ public class TestSuiteRepository extends EntityRepository<TestSuite> {
|
||||
setFullyQualifiedName(entity);
|
||||
}
|
||||
|
||||
private List<EntityReference> getTestCases(TestSuite entity) throws IOException {
|
||||
List<CollectionDAO.EntityRelationshipRecord> testCases =
|
||||
findTo(entity.getId(), TEST_SUITE, Relationship.CONTAINS, TEST_CASE);
|
||||
return EntityUtil.getEntityReferences(testCases);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void storeEntity(TestSuite entity, boolean update) throws IOException {
|
||||
EntityReference owner = entity.getOwner();
|
||||
|
||||
@ -381,15 +381,14 @@ public class TestCaseResource extends EntityResource<TestCase, TestCaseRepositor
|
||||
description = "Successfully updated the TestCase. ",
|
||||
content = @Content(mediaType = "application/json", schema = @Schema(implementation = TestCase.class)))
|
||||
})
|
||||
public TestCase addTestCaseResult(
|
||||
public Response addTestCaseResult(
|
||||
@Context UriInfo uriInfo,
|
||||
@Context SecurityContext securityContext,
|
||||
@Parameter(description = "fqn of the testCase", schema = @Schema(type = "string")) @PathParam("fqn") String fqn,
|
||||
@Valid TestCaseResult testCaseResult)
|
||||
throws IOException {
|
||||
authorizer.authorizeAdmin(securityContext, true);
|
||||
TestCase testCase = dao.addTestCaseResult(fqn, testCaseResult);
|
||||
return addHref(uriInfo, testCase);
|
||||
return dao.addTestCaseResult(fqn, testCaseResult).toResponse();
|
||||
}
|
||||
|
||||
@GET
|
||||
@ -466,7 +465,7 @@ public class TestCaseResource extends EntityResource<TestCase, TestCaseRepositor
|
||||
description = "Successfully deleted the TestCaseResult",
|
||||
content = @Content(mediaType = "application/json", schema = @Schema(implementation = TestCase.class)))
|
||||
})
|
||||
public TestCase deleteTestCaseResult(
|
||||
public Response deleteTestCaseResult(
|
||||
@Context UriInfo uriInfo,
|
||||
@Context SecurityContext securityContext,
|
||||
@Parameter(description = "fqn of the testCase", schema = @Schema(type = "string")) @PathParam("fqn") String fqn,
|
||||
@ -475,8 +474,7 @@ public class TestCaseResource extends EntityResource<TestCase, TestCaseRepositor
|
||||
Long timestamp)
|
||||
throws IOException {
|
||||
authorizer.authorizeAdmin(securityContext, true);
|
||||
TestCase testCase = dao.deleteTestCaseResult(fqn, timestamp);
|
||||
return addHref(uriInfo, testCase);
|
||||
return dao.deleteTestCaseResult(fqn, timestamp).toResponse();
|
||||
}
|
||||
|
||||
private TestCase getTestCase(CreateTestCase create, String user) throws IOException {
|
||||
|
||||
@ -25,6 +25,8 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.openmetadata.catalog.filter.EventFilter;
|
||||
import org.openmetadata.catalog.filter.Filters;
|
||||
import org.openmetadata.catalog.settings.Settings;
|
||||
import org.openmetadata.catalog.tests.type.TestCaseResult;
|
||||
import org.openmetadata.catalog.tests.type.TestCaseStatus;
|
||||
import org.openmetadata.catalog.type.ChangeDescription;
|
||||
import org.openmetadata.catalog.type.ChangeEvent;
|
||||
import org.openmetadata.catalog.type.EventType;
|
||||
@ -33,6 +35,8 @@ import org.openmetadata.catalog.type.FieldChange;
|
||||
@Slf4j
|
||||
public class FilterUtil {
|
||||
|
||||
private static final String TEST_CASE_RESULT = "testCaseResult";
|
||||
|
||||
public static boolean shouldProcessRequest(ChangeEvent changeEvent, Map<String, Map<EventType, Filters>> filtersMap) {
|
||||
if (filtersMap != null && !filtersMap.isEmpty()) {
|
||||
String entityType = changeEvent.getEntityType();
|
||||
@ -46,13 +50,35 @@ public class FilterUtil {
|
||||
if ((sf = filtersOfEntity.get(eventType)) == null) {
|
||||
return false;
|
||||
} else {
|
||||
return sf.getFields().contains("all") || checkIfFilterContainField(sf, getUpdateField(changeEvent));
|
||||
if (sf.getFields().contains("all")) {
|
||||
return true;
|
||||
} else {
|
||||
if (entityType.equals("testCase")) {
|
||||
return handleTestCaseFilter(changeEvent, sf);
|
||||
} else {
|
||||
return checkIfFilterContainField(sf, getUpdateField(changeEvent));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean handleTestCaseFilter(ChangeEvent changeEvent, Filters sf) {
|
||||
List<FieldChange> fieldChanges = getAllFieldChange(changeEvent);
|
||||
for (FieldChange fieldChange : fieldChanges) {
|
||||
if (fieldChange.getName().equals(TEST_CASE_RESULT)) {
|
||||
TestCaseResult testCaseResult = (TestCaseResult) fieldChange.getNewValue();
|
||||
TestCaseStatus status = testCaseResult.getTestCaseStatus();
|
||||
if (sf.getFields().contains(TEST_CASE_RESULT + status.toString())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return checkIfFilterContainField(sf, getUpdateField(changeEvent));
|
||||
}
|
||||
|
||||
public static boolean handleWithWildCardFilter(
|
||||
Map<EventType, Filters> wildCardFilter, EventType type, List<String> updatedField) {
|
||||
if (wildCardFilter != null && !wildCardFilter.isEmpty()) {
|
||||
@ -81,13 +107,17 @@ public class FilterUtil {
|
||||
|| changeEvent.getEventType() == EventType.ENTITY_SOFT_DELETED) {
|
||||
return List.of(changeEvent.getEntityType());
|
||||
}
|
||||
return getChangedFields(getAllFieldChange(changeEvent));
|
||||
}
|
||||
|
||||
public static List<FieldChange> getAllFieldChange(ChangeEvent changeEvent) {
|
||||
ChangeDescription description = changeEvent.getChangeDescription();
|
||||
List<FieldChange> allFieldChange = new ArrayList<>();
|
||||
allFieldChange.addAll(description.getFieldsAdded());
|
||||
allFieldChange.addAll(description.getFieldsUpdated());
|
||||
allFieldChange.addAll(description.getFieldsDeleted());
|
||||
|
||||
return getChangedFields(allFieldChange);
|
||||
return allFieldChange;
|
||||
}
|
||||
|
||||
public static List<String> getChangedFields(List<FieldChange> field) {
|
||||
|
||||
@ -19,15 +19,11 @@
|
||||
"description": "Description of the test suite.",
|
||||
"$ref": "../../type/basic.json#/definitions/markdown"
|
||||
},
|
||||
"scheduleInterval": {
|
||||
"description": "TestSuite schedule interval in cron format.",
|
||||
"type": "string"
|
||||
},
|
||||
"owner": {
|
||||
"description": "Owner of this test suite",
|
||||
"$ref": "../../type/entityReference.json"
|
||||
}
|
||||
},
|
||||
"required": ["name", "description", "testPlatforms"],
|
||||
"required": ["name", "description"],
|
||||
"additionalProperties": false
|
||||
}
|
||||
|
||||
@ -71,6 +71,6 @@
|
||||
"default": false
|
||||
}
|
||||
},
|
||||
"required": ["name", "description", "testPlatform"],
|
||||
"required": ["name", "description"],
|
||||
"additionalProperties": false
|
||||
}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package org.openmetadata.catalog.resources.dqtests;
|
||||
|
||||
import static javax.ws.rs.core.Response.Status.BAD_REQUEST;
|
||||
import static javax.ws.rs.core.Response.Status.CREATED;
|
||||
import static javax.ws.rs.core.Response.Status.NOT_FOUND;
|
||||
import static javax.ws.rs.core.Response.Status.OK;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
@ -35,6 +36,7 @@ import org.openmetadata.catalog.resources.EntityResourceTest;
|
||||
import org.openmetadata.catalog.resources.databases.TableResourceTest;
|
||||
import org.openmetadata.catalog.test.TestCaseParameterValue;
|
||||
import org.openmetadata.catalog.tests.TestCase;
|
||||
import org.openmetadata.catalog.tests.TestSuite;
|
||||
import org.openmetadata.catalog.tests.type.TestCaseResult;
|
||||
import org.openmetadata.catalog.tests.type.TestCaseStatus;
|
||||
import org.openmetadata.catalog.type.ChangeDescription;
|
||||
@ -202,8 +204,7 @@ public class TestCaseResourceTest extends EntityResourceTest<TestCase, CreateTes
|
||||
.withResult("tested")
|
||||
.withTestCaseStatus(TestCaseStatus.Success)
|
||||
.withTimestamp(TestUtils.dateToTimestamp("2021-09-09"));
|
||||
TestCase putResponse = putTestCaseResult(testCase.getFullyQualifiedName(), testCaseResult, ADMIN_AUTH_HEADERS);
|
||||
verifyTestCaseResult(putResponse.getTestCaseResult(), testCaseResult);
|
||||
putTestCaseResult(testCase.getFullyQualifiedName(), testCaseResult, ADMIN_AUTH_HEADERS);
|
||||
|
||||
ResultList<TestCaseResult> testCaseResults =
|
||||
getTestCaseResults(testCase.getFullyQualifiedName(), null, ADMIN_AUTH_HEADERS);
|
||||
@ -215,8 +216,7 @@ public class TestCaseResourceTest extends EntityResourceTest<TestCase, CreateTes
|
||||
.withResult("tested")
|
||||
.withTestCaseStatus(TestCaseStatus.Failed)
|
||||
.withTimestamp(TestUtils.dateToTimestamp("2021-09-10"));
|
||||
putResponse = putTestCaseResult(testCase.getFullyQualifiedName(), newTestCaseResult, ADMIN_AUTH_HEADERS);
|
||||
verifyTestCaseResult(putResponse.getTestCaseResult(), newTestCaseResult);
|
||||
putTestCaseResult(testCase.getFullyQualifiedName(), newTestCaseResult, ADMIN_AUTH_HEADERS);
|
||||
|
||||
testCaseResults = getTestCaseResults(testCase.getFullyQualifiedName(), null, ADMIN_AUTH_HEADERS);
|
||||
verifyTestCaseResults(testCaseResults, List.of(newTestCaseResult, testCaseResult), 2);
|
||||
@ -227,9 +227,7 @@ public class TestCaseResourceTest extends EntityResourceTest<TestCase, CreateTes
|
||||
.withResult("result")
|
||||
.withTestCaseStatus(TestCaseStatus.Success)
|
||||
.withTimestamp(TestUtils.dateToTimestamp("2021-09-10"));
|
||||
putResponse = putTestCaseResult(testCase.getFullyQualifiedName(), newTestCaseResult1, ADMIN_AUTH_HEADERS);
|
||||
assertEquals(newTestCaseResult1.getTimestamp(), putResponse.getTestCaseResult().getTimestamp());
|
||||
verifyTestCaseResult(putResponse.getTestCaseResult(), newTestCaseResult1);
|
||||
putTestCaseResult(testCase.getFullyQualifiedName(), newTestCaseResult1, ADMIN_AUTH_HEADERS);
|
||||
|
||||
testCase = getEntity(testCase.getId(), "testCaseResult", ADMIN_AUTH_HEADERS);
|
||||
// first result should be the latest date
|
||||
@ -337,18 +335,21 @@ public class TestCaseResourceTest extends EntityResourceTest<TestCase, CreateTes
|
||||
testCaseList = getTestCases(12, "*", TABLE_LINK_2, true, ADMIN_AUTH_HEADERS);
|
||||
expectedTestCaseList.addAll(expectedColTestCaseList);
|
||||
verifyTestCases(testCaseList, expectedTestCaseList, 12);
|
||||
|
||||
testCaseList = getTestCases(12, "*", TEST_SUITE1, false, ADMIN_AUTH_HEADERS);
|
||||
verifyTestCases(testCaseList, expectedTestCaseList, 12);
|
||||
}
|
||||
|
||||
public static TestCase putTestCaseResult(String fqn, TestCaseResult data, Map<String, String> authHeaders)
|
||||
public static void putTestCaseResult(String fqn, TestCaseResult data, Map<String, String> authHeaders)
|
||||
throws HttpResponseException {
|
||||
WebTarget target = CatalogApplicationTest.getResource("testCase/" + fqn + "/testCaseResult");
|
||||
return TestUtils.put(target, data, TestCase.class, OK, authHeaders);
|
||||
TestUtils.put(target, data, CREATED, authHeaders);
|
||||
}
|
||||
|
||||
public static TestCase deleteTestCaseResult(String fqn, Long timestamp, Map<String, String> authHeaders)
|
||||
public static void deleteTestCaseResult(String fqn, Long timestamp, Map<String, String> authHeaders)
|
||||
throws HttpResponseException {
|
||||
WebTarget target = CatalogApplicationTest.getResource("testCase/" + fqn + "/testCaseResult/" + timestamp);
|
||||
return TestUtils.delete(target, TestCase.class, authHeaders);
|
||||
TestUtils.delete(target, authHeaders);
|
||||
}
|
||||
|
||||
public static ResultList<TestCaseResult> getTestCaseResults(
|
||||
@ -373,6 +374,19 @@ public class TestCaseResourceTest extends EntityResourceTest<TestCase, CreateTes
|
||||
return TestUtils.get(target, TestCaseResource.TestCaseList.class, authHeaders);
|
||||
}
|
||||
|
||||
public static ResultList<TestCase> getTestCases(
|
||||
Integer limit, String fields, TestSuite testSuite, Boolean includeAll, Map<String, String> authHeaders)
|
||||
throws HttpResponseException {
|
||||
WebTarget target = CatalogApplicationTest.getResource("testCase");
|
||||
target = limit != null ? target.queryParam("limit", limit) : target;
|
||||
target = target.queryParam("fields", fields);
|
||||
target = target.queryParam("testSuiteId", testSuite.getId());
|
||||
if (includeAll) {
|
||||
target = target.queryParam("includeAllTests", true);
|
||||
}
|
||||
return TestUtils.get(target, TestCaseResource.TestCaseList.class, authHeaders);
|
||||
}
|
||||
|
||||
private void verifyTestCaseResults(
|
||||
ResultList<TestCaseResult> actualTestCaseResults,
|
||||
List<TestCaseResult> expectedTestCaseResults,
|
||||
|
||||
@ -6,14 +6,26 @@ import static org.openmetadata.catalog.util.TestUtils.ADMIN_AUTH_HEADERS;
|
||||
import static org.openmetadata.catalog.util.TestUtils.assertResponse;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import javax.ws.rs.client.WebTarget;
|
||||
import org.apache.http.client.HttpResponseException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInfo;
|
||||
import org.openmetadata.catalog.CatalogApplicationTest;
|
||||
import org.openmetadata.catalog.Entity;
|
||||
import org.openmetadata.catalog.api.tests.CreateTestCase;
|
||||
import org.openmetadata.catalog.api.tests.CreateTestSuite;
|
||||
import org.openmetadata.catalog.resources.EntityResourceTest;
|
||||
import org.openmetadata.catalog.tests.TestCase;
|
||||
import org.openmetadata.catalog.tests.TestSuite;
|
||||
import org.openmetadata.catalog.type.EntityReference;
|
||||
import org.openmetadata.catalog.util.ResultList;
|
||||
import org.openmetadata.catalog.util.TestUtils;
|
||||
|
||||
public class TestSuiteResourceTest extends EntityResourceTest<TestSuite, CreateTestSuite> {
|
||||
public TestSuiteResourceTest() {
|
||||
@ -48,9 +60,79 @@ public class TestSuiteResourceTest extends EntityResourceTest<TestSuite, CreateT
|
||||
"[name must not be null]");
|
||||
}
|
||||
|
||||
@Test
|
||||
void put_testCaseResults_200(TestInfo test) throws IOException, ParseException {
|
||||
TestCaseResourceTest testCaseResourceTest = new TestCaseResourceTest();
|
||||
List<EntityReference> testCases1 = new ArrayList<>();
|
||||
List<EntityReference> testCases2 = new ArrayList<>();
|
||||
CreateTestSuite createTestSuite1 = createRequest(test);
|
||||
TestSuite testSuite1 = createAndCheckEntity(createTestSuite1, ADMIN_AUTH_HEADERS);
|
||||
CreateTestSuite createTestSuite2 = createRequest(test.getDisplayName() + UUID.randomUUID());
|
||||
TestSuite testSuite2 = createAndCheckEntity(createTestSuite2, ADMIN_AUTH_HEADERS);
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
CreateTestCase createTestCase =
|
||||
testCaseResourceTest.createRequest("test_testSuite_1_" + i).withTestSuite(testSuite1.getEntityReference());
|
||||
TestCase testCase = testCaseResourceTest.createAndCheckEntity(createTestCase, ADMIN_AUTH_HEADERS);
|
||||
testCases1.add(testCase.getEntityReference());
|
||||
}
|
||||
|
||||
for (int i = 5; i < 10; i++) {
|
||||
CreateTestCase create =
|
||||
testCaseResourceTest.createRequest("test_testSuite_2_" + i).withTestSuite(testSuite2.getEntityReference());
|
||||
TestCase testCase = testCaseResourceTest.createAndCheckEntity(create, ADMIN_AUTH_HEADERS);
|
||||
testCases2.add(testCase.getEntityReference());
|
||||
}
|
||||
|
||||
ResultList<TestSuite> actualTestSuites = getTestSuites(10, "*", ADMIN_AUTH_HEADERS);
|
||||
verifyTestSuites(actualTestSuites, List.of(createTestSuite1, createTestSuite2));
|
||||
|
||||
for (TestSuite testSuite : actualTestSuites.getData()) {
|
||||
if (testSuite.getName().equals(createTestSuite1.getName())) {
|
||||
verifyTestCases(testSuite.getTests(), testCases1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static ResultList<TestSuite> getTestSuites(Integer limit, String fields, Map<String, String> authHeaders)
|
||||
throws HttpResponseException {
|
||||
WebTarget target = CatalogApplicationTest.getResource("testSuite");
|
||||
target = limit != null ? target.queryParam("limit", limit) : target;
|
||||
target = target.queryParam("fields", fields);
|
||||
return TestUtils.get(target, TestSuiteResource.TestSuiteList.class, authHeaders);
|
||||
}
|
||||
|
||||
private void verifyTestSuites(ResultList<TestSuite> actualTestSuites, List<CreateTestSuite> expectedTestSuites)
|
||||
throws HttpResponseException {
|
||||
Map<String, TestSuite> testSuiteMap = new HashMap<>();
|
||||
for (TestSuite result : actualTestSuites.getData()) {
|
||||
testSuiteMap.put(result.getName(), result);
|
||||
}
|
||||
for (CreateTestSuite result : expectedTestSuites) {
|
||||
TestSuite storedTestSuite = testSuiteMap.get(result.getName());
|
||||
if (storedTestSuite == null) continue;
|
||||
validateCreatedEntity(storedTestSuite, result, ADMIN_AUTH_HEADERS);
|
||||
}
|
||||
}
|
||||
|
||||
private void verifyTestCases(List<EntityReference> actualTestCases, List<EntityReference> expectedTestCases)
|
||||
throws HttpResponseException {
|
||||
assertEquals(expectedTestCases.size(), actualTestCases.size());
|
||||
Map<UUID, EntityReference> testCaseMap = new HashMap<>();
|
||||
for (EntityReference result : actualTestCases) {
|
||||
testCaseMap.put(result.getId(), result);
|
||||
}
|
||||
for (EntityReference result : expectedTestCases) {
|
||||
EntityReference storedTestCase = testCaseMap.get(result.getId());
|
||||
assertEquals(result.getId(), storedTestCase.getId());
|
||||
assertEquals(result.getName(), storedTestCase.getName());
|
||||
assertEquals(result.getDescription(), storedTestCase.getDescription());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CreateTestSuite createRequest(String name) {
|
||||
return new CreateTestSuite().withName(name).withDescription(name).withScheduleInterval("* * 1 * *");
|
||||
return new CreateTestSuite().withName(name).withDescription(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -867,7 +867,6 @@ class SampleDataSource(Source[Entity]):
|
||||
test_suite=CreateTestSuiteRequest(
|
||||
name=test_suite["testSuiteName"],
|
||||
description=test_suite["testSuiteDescription"],
|
||||
scheduleInterval=test_suite["scheduleInterval"],
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user