Fixes #3969 Database does not return database schemas under it (#3971)

* Fixes #3969 Database does not return database schemas under it

* Fixes #3969 Database does not return database schemas under it

* amend
This commit is contained in:
Suresh Srinivas 2022-04-08 16:18:57 -07:00 committed by GitHub
parent 92c7401b6d
commit 7ee375802a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 240 additions and 127 deletions

View File

@ -92,18 +92,18 @@ public class DatabaseRepository extends EntityRepository<Database> {
storeOwner(database, database.getOwner());
}
private List<EntityReference> getTables(Database database) throws IOException {
private List<EntityReference> getSchemas(Database database) throws IOException {
if (database == null) {
return null;
}
List<String> tableIds = findTo(database.getId(), Entity.DATABASE, Relationship.CONTAINS, Entity.TABLE);
return EntityUtil.populateEntityReferences(tableIds, Entity.TABLE);
List<String> schemaIds = findTo(database.getId(), Entity.DATABASE, Relationship.CONTAINS, Entity.DATABASE_SCHEMA);
return EntityUtil.populateEntityReferences(schemaIds, Entity.DATABASE_SCHEMA);
}
public Database setFields(Database database, Fields fields) throws IOException {
database.setService(getService(database));
database.setOwner(fields.contains(FIELD_OWNER) ? getOwner(database) : null);
database.setDatabaseSchemas(fields.contains("databaseSchemas") ? getTables(database) : null);
database.setDatabaseSchemas(fields.contains("databaseSchemas") ? getSchemas(database) : null);
database.setUsageSummary(
fields.contains("usageSummary") ? EntityUtil.getLatestUsage(daoCollection.usageDAO(), database.getId()) : null);
database.setLocation(fields.contains("location") ? getLocation(database) : null);

View File

@ -43,11 +43,14 @@ import static org.openmetadata.catalog.util.TestUtils.UpdateType;
import static org.openmetadata.catalog.util.TestUtils.UpdateType.MINOR_UPDATE;
import static org.openmetadata.catalog.util.TestUtils.UpdateType.NO_CHANGE;
import static org.openmetadata.catalog.util.TestUtils.assertEntityPagination;
import static org.openmetadata.catalog.util.TestUtils.assertListNotEmpty;
import static org.openmetadata.catalog.util.TestUtils.assertListNotNull;
import static org.openmetadata.catalog.util.TestUtils.assertListNull;
import static org.openmetadata.catalog.util.TestUtils.assertResponse;
import static org.openmetadata.catalog.util.TestUtils.assertResponseContains;
import static org.openmetadata.catalog.util.TestUtils.checkUserFollowing;
import static org.openmetadata.catalog.util.TestUtils.validateEntityReference;
import static org.openmetadata.catalog.util.TestUtils.validateEntityReferences;
import com.fasterxml.jackson.core.JsonProcessingException;
import java.io.IOException;
@ -535,11 +538,13 @@ public abstract class EntityResourceTest<T, K> extends CatalogApplicationTest {
// Get interface to access all common entity attributes
public abstract EntityInterface<T> getEntityInterface(T entity);
// Do some preparation work right before calling validateGetWithDifferentFields.
protected void prepareGetWithDifferentFields(T entity) throws HttpResponseException {}
// Get an entity by ID and name with different fields. See TableResourceTest for example.
public abstract void validateGetWithDifferentFields(T entity, boolean byName) throws HttpResponseException;
/**
* GET by id and GET by name with different `fields` parameter and ensure the requested fields are returned. Common
* fields for all entities - `owner`, `followers`, and `tags` need not be tested by implementations as it is done
* already in the base class.
*/
public abstract EntityInterface<T> validateGetWithDifferentFields(T entity, boolean byName)
throws HttpResponseException;
// Assert field change in an entity recorded during PUT or POST operations
public abstract void assertFieldChange(String fieldName, Object expected, Object actual) throws IOException;
@ -771,10 +776,38 @@ public abstract class EntityResourceTest<T, K> extends CatalogApplicationTest {
@Test
void get_entityWithDifferentFields_200_OK(TestInfo test) throws IOException {
K create = createRequest(getEntityName(test), "description", "displayName", USER_OWNER1);
T entity = createAndCheckEntity(create, ADMIN_AUTH_HEADERS);
prepareGetWithDifferentFields(entity);
validateGetWithDifferentFields(entity, false);
validateGetWithDifferentFields(entity, true);
EntityInterface<T> entityInterface = getEntityInterface(entity);
if (supportsTags) {
String origJson = JsonUtils.pojoToJson(entity);
entityInterface.setTags(new ArrayList<>());
entityInterface.getTags().add(USER_ADDRESS_TAG_LABEL);
entityInterface.getTags().add(GLOSSARY2_TERM1_LABEL);
entity = patchEntity(entityInterface.getId(), origJson, entity, ADMIN_AUTH_HEADERS);
}
if (supportsFollowers) {
UserResourceTest userResourceTest = new UserResourceTest();
User user1 = userResourceTest.createEntity(userResourceTest.createRequest(test, 1), TEST_AUTH_HEADERS);
addFollower(entityInterface.getId(), user1.getId(), CREATED, TEST_AUTH_HEADERS);
}
entityInterface = validateGetWithDifferentFields(entity, false);
validateGetCommonFields(entityInterface);
entityInterface = validateGetWithDifferentFields(entityInterface.getEntity(), true);
validateGetCommonFields(entityInterface);
}
private void validateGetCommonFields(EntityInterface<T> entityInterface) {
if (supportsOwner) {
validateEntityReference(entityInterface.getOwner());
}
if (supportsFollowers) {
validateEntityReferences(entityInterface.getFollowers(), true);
}
if (supportsTags) {
assertListNotEmpty(entityInterface.getTags());
}
}
@Test
@ -1936,8 +1969,7 @@ public abstract class EntityResourceTest<T, K> extends CatalogApplicationTest {
public void addAndCheckFollower(
UUID entityId, UUID userId, Status status, int totalFollowerCount, Map<String, String> authHeaders)
throws IOException {
WebTarget target = getFollowersCollection(entityId);
ChangeEvent event = TestUtils.put(target, userId.toString(), ChangeEvent.class, status, authHeaders);
ChangeEvent event = addFollower(entityId, userId, status, authHeaders);
// GET .../entity/{entityId} returns newly added follower
T getEntity = getEntity(entityId, authHeaders);
@ -1945,7 +1977,7 @@ public abstract class EntityResourceTest<T, K> extends CatalogApplicationTest {
List<EntityReference> followers = entityInterface.getFollowers();
assertEquals(totalFollowerCount, followers.size());
TestUtils.validateEntityReferences(followers);
validateEntityReferences(followers);
TestUtils.existsInEntityReferenceList(followers, userId, true);
// GET .../users/{userId} shows user as following the entity
@ -1956,6 +1988,12 @@ public abstract class EntityResourceTest<T, K> extends CatalogApplicationTest {
entityInterface, event.getTimestamp(), EventType.ENTITY_UPDATED, event.getChangeDescription(), authHeaders);
}
public ChangeEvent addFollower(UUID entityId, UUID userId, Status status, Map<String, String> authHeaders)
throws HttpResponseException {
WebTarget target = getFollowersCollection(entityId);
return TestUtils.put(target, userId.toString(), ChangeEvent.class, status, authHeaders);
}
protected void deleteAndCheckFollower(
UUID entityId, UUID userId, int totalFollowerCount, Map<String, String> authHeaders) throws IOException {
// Delete the follower
@ -1977,7 +2015,7 @@ public abstract class EntityResourceTest<T, K> extends CatalogApplicationTest {
// Get the entity and ensure the deleted follower is not in the followers list
T getEntity = getEntity(entityId, authHeaders);
List<EntityReference> followers = getEntityInterface(getEntity).getFollowers();
TestUtils.validateEntityReferences(followers);
validateEntityReferences(followers);
TestUtils.existsInEntityReferenceList(followers, userId, false);
return getEntity;
}

View File

@ -90,9 +90,9 @@ public class ChartResourceTest extends EntityResourceTest<Chart, CreateChart> {
// TODO
}
/** Validate returned fields GET .../charts/{id}?fields="..." or GET .../charts/name/{fqn}?fields="..." */
@Override
public void validateGetWithDifferentFields(Chart chart, boolean byName) throws HttpResponseException {
public EntityInterface<Chart> validateGetWithDifferentFields(Chart chart, boolean byName)
throws HttpResponseException {
String fields = "";
chart =
byName
@ -108,7 +108,8 @@ public class ChartResourceTest extends EntityResourceTest<Chart, CreateChart> {
? getEntityByName(chart.getFullyQualifiedName(), fields, ADMIN_AUTH_HEADERS)
: getEntity(chart.getId(), fields, ADMIN_AUTH_HEADERS);
assertListNotNull(chart.getService(), chart.getServiceType());
assertListNotNull(chart.getOwner(), chart.getFollowers(), chart.getTags());
// Checks for other owner, tags, and followers is done in the base class
return getEntityInterface(chart);
}
@Override

View File

@ -161,9 +161,9 @@ public class DashboardResourceTest extends EntityResourceTest<Dashboard, CreateD
// TODO
}
/** Validate returned fields GET .../dashboards/{id}?fields="..." or GET .../dashboards/name/{fqn}?fields="..." */
@Override
public void validateGetWithDifferentFields(Dashboard dashboard, boolean byName) throws HttpResponseException {
public EntityInterface<Dashboard> validateGetWithDifferentFields(Dashboard dashboard, boolean byName)
throws HttpResponseException {
String fields = "";
dashboard =
byName
@ -184,13 +184,10 @@ public class DashboardResourceTest extends EntityResourceTest<Dashboard, CreateD
? getEntityByName(dashboard.getFullyQualifiedName(), fields, ADMIN_AUTH_HEADERS)
: getEntity(dashboard.getId(), fields, ADMIN_AUTH_HEADERS);
assertListNotNull(dashboard.getService(), dashboard.getServiceType());
assertListNotNull(
dashboard.getOwner(),
dashboard.getCharts(),
dashboard.getFollowers(),
dashboard.getTags(),
dashboard.getUsageSummary());
TestUtils.validateEntityReferences(dashboard.getCharts());
assertListNotNull(dashboard.getUsageSummary());
TestUtils.validateEntityReferences(dashboard.getCharts(), true);
// Checks for other owner, tags, and followers is done in the base class
return getEntityInterface(dashboard);
}
private static void validateDashboardCharts(Dashboard dashboard, List<EntityReference> expectedCharts) {

View File

@ -17,6 +17,7 @@ import static javax.ws.rs.core.Response.Status.BAD_REQUEST;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.openmetadata.catalog.util.TestUtils.ADMIN_AUTH_HEADERS;
import static org.openmetadata.catalog.util.TestUtils.assertListNotEmpty;
import static org.openmetadata.catalog.util.TestUtils.assertListNotNull;
import static org.openmetadata.catalog.util.TestUtils.assertListNull;
import static org.openmetadata.catalog.util.TestUtils.assertResponse;
@ -34,6 +35,7 @@ import org.junit.jupiter.api.TestInfo;
import org.junit.jupiter.api.TestInstance;
import org.openmetadata.catalog.Entity;
import org.openmetadata.catalog.api.data.CreateDatabase;
import org.openmetadata.catalog.api.data.CreateDatabaseSchema;
import org.openmetadata.catalog.entity.data.Database;
import org.openmetadata.catalog.exception.CatalogExceptionMessage;
import org.openmetadata.catalog.jdbi3.DatabaseRepository.DatabaseEntityInterface;
@ -114,9 +116,20 @@ public class DatabaseResourceTest extends EntityResourceTest<Database, CreateDat
// TODO
}
/** Validate returned fields GET .../databases/{id}?fields="..." or GET .../databases/name/{fqn}?fields="..." */
@Override
public void validateGetWithDifferentFields(Database database, boolean byName) throws HttpResponseException {
public EntityInterface<Database> validateGetWithDifferentFields(Database database, boolean byName)
throws HttpResponseException {
// Add a schema if it already does not exist
if (database.getDatabaseSchemas() == null) {
EntityInterface<Database> entityInterface = getEntityInterface(database);
DatabaseSchemaResourceTest databaseSchemaResourceTest = new DatabaseSchemaResourceTest();
CreateDatabaseSchema create =
databaseSchemaResourceTest
.createRequest("schema", "", "", null)
.withDatabase(entityInterface.getEntityReference());
databaseSchemaResourceTest.createEntity(create, ADMIN_AUTH_HEADERS);
}
String fields = "";
database =
byName
@ -133,9 +146,10 @@ public class DatabaseResourceTest extends EntityResourceTest<Database, CreateDat
: getEntity(database.getId(), fields, ADMIN_AUTH_HEADERS);
assertListNotNull(database.getService(), database.getServiceType());
// Fields usageSummary and location are not set during creation - tested elsewhere
assertListNotNull(
database.getOwner(), database.getDatabaseSchemas() /*database.getUsageSummary(), database.getLocation()*/);
TestUtils.validateEntityReferences(database.getDatabaseSchemas());
TestUtils.validateEntityReferences(database.getDatabaseSchemas(), true);
assertListNotEmpty(database.getDatabaseSchemas());
// Checks for other owner, tags, and followers is done in the base class
return getEntityInterface(database);
}
@Override

View File

@ -32,7 +32,9 @@ import org.junit.jupiter.api.TestInfo;
import org.junit.jupiter.api.TestInstance;
import org.openmetadata.catalog.Entity;
import org.openmetadata.catalog.api.data.CreateDatabaseSchema;
import org.openmetadata.catalog.api.data.CreateTable;
import org.openmetadata.catalog.entity.data.DatabaseSchema;
import org.openmetadata.catalog.entity.data.Table;
import org.openmetadata.catalog.jdbi3.DatabaseSchemaRepository.DatabaseSchemaEntityInterface;
import org.openmetadata.catalog.resources.EntityResourceTest;
import org.openmetadata.catalog.resources.databases.DatabaseSchemaResource.DatabaseSchemaList;
@ -64,9 +66,23 @@ public class DatabaseSchemaResourceTest extends EntityResourceTest<DatabaseSchem
assertResponseContains(() -> createEntity(create, ADMIN_AUTH_HEADERS), BAD_REQUEST, "database must not be null");
}
/** Validate returned fields GET .../databases/{id}?fields="..." or GET .../databases/name/{fqn}?fields="..." */
@Override
public void validateGetWithDifferentFields(DatabaseSchema schema, boolean byName) throws HttpResponseException {
public EntityInterface<DatabaseSchema> validateGetWithDifferentFields(DatabaseSchema schema, boolean byName)
throws HttpResponseException {
// Add tables to the database schema
if (schema.getTables() == null) {
EntityInterface<DatabaseSchema> entityInterface = getEntityInterface(schema);
TableResourceTest tableResourceTest = new TableResourceTest();
CreateTable create =
tableResourceTest.createRequest("t1", "", "", null).withDatabaseSchema(entityInterface.getEntityReference());
Table t1 = tableResourceTest.createEntity(create, ADMIN_AUTH_HEADERS);
create.withName("t2");
Table t2 = tableResourceTest.createEntity(create, ADMIN_AUTH_HEADERS);
}
// Now query request different fields
String fields = "";
schema =
byName
@ -82,8 +98,10 @@ public class DatabaseSchemaResourceTest extends EntityResourceTest<DatabaseSchem
: getEntity(schema.getId(), fields, ADMIN_AUTH_HEADERS);
assertListNotNull(schema.getService(), schema.getServiceType());
// Fields usageSummary and location are not set during creation - tested elsewhere
assertListNotNull(schema.getOwner(), schema.getTables());
TestUtils.validateEntityReferences(schema.getTables());
assertListNotNull(schema.getTables());
TestUtils.validateEntityReferences(schema.getTables(), true);
// Checks for other owner, tags, and followers is done in the base class
return getEntityInterface(schema);
}
@Override

View File

@ -45,6 +45,7 @@ import static org.openmetadata.catalog.util.TestUtils.UpdateType;
import static org.openmetadata.catalog.util.TestUtils.UpdateType.MAJOR_UPDATE;
import static org.openmetadata.catalog.util.TestUtils.UpdateType.MINOR_UPDATE;
import static org.openmetadata.catalog.util.TestUtils.UpdateType.NO_CHANGE;
import static org.openmetadata.catalog.util.TestUtils.assertListNotEmpty;
import static org.openmetadata.catalog.util.TestUtils.assertListNotNull;
import static org.openmetadata.catalog.util.TestUtils.assertListNull;
import static org.openmetadata.catalog.util.TestUtils.assertResponse;
@ -130,6 +131,7 @@ import org.openmetadata.catalog.type.TableProfile;
import org.openmetadata.catalog.type.TableType;
import org.openmetadata.catalog.type.TagLabel;
import org.openmetadata.catalog.type.TagLabel.LabelType;
import org.openmetadata.catalog.util.EntityInterface;
import org.openmetadata.catalog.util.EntityUtil.Fields;
import org.openmetadata.catalog.util.FullyQualifiedName;
import org.openmetadata.catalog.util.JsonUtils;
@ -1635,9 +1637,9 @@ public class TableResourceTest extends EntityResourceTest<Table, CreateTable> {
assertListNotNull(table.getDatabase(), table.getService(), table.getServiceType());
}
/** Validate returned fields GET .../tables/{id}?fields="..." or GET .../tables/name/{fqn}?fields="..." */
@Override
public void validateGetWithDifferentFields(Table table, boolean byName) throws HttpResponseException {
public EntityInterface<Table> validateGetWithDifferentFields(Table table, boolean byName)
throws HttpResponseException {
table =
byName
? getEntityByName(table.getFullyQualifiedName(), null, ADMIN_AUTH_HEADERS)
@ -1670,11 +1672,11 @@ public class TableResourceTest extends EntityResourceTest<Table, CreateTable> {
assertListNotNull(
table.getTableConstraints(),
table.getUsageSummary(),
table.getOwner(),
table.getTags(),
table.getFollowers(),
table.getJoins() /*, table.getSampleData(), table.getViewDefinition(), table
.getTableProfile(), table.getLocation(), table.getTableQueries(), table.getDataModel()*/);
assertListNotEmpty(table.getTableConstraints());
// Checks for other owner, tags, and followers is done in the base class
return getEntityInterface(table);
}
private static void assertColumn(Column expectedColumn, Column actualColumn) throws HttpResponseException {
@ -2072,7 +2074,7 @@ public class TableResourceTest extends EntityResourceTest<Table, CreateTable> {
}
@Override
public TableEntityInterface getEntityInterface(Table entity) {
public EntityInterface<Table> getEntityInterface(Table entity) {
return new TableEntityInterface(entity);
}

View File

@ -256,8 +256,9 @@ public class WebhookResourceTest extends EntityResourceTest<Webhook, CreateWebho
}
@Override
public void validateGetWithDifferentFields(Webhook entity, boolean byName) throws HttpResponseException {
// Field query param is not supported in GET operations
public EntityInterface<Webhook> validateGetWithDifferentFields(Webhook entity, boolean byName)
throws HttpResponseException {
return getEntityInterface(entity); // Nothing to validate
}
@Override

View File

@ -17,7 +17,6 @@
package org.openmetadata.catalog.resources.glossary;
import static org.openmetadata.catalog.util.TestUtils.ADMIN_AUTH_HEADERS;
import static org.openmetadata.catalog.util.TestUtils.assertListNotNull;
import static org.openmetadata.catalog.util.TestUtils.assertListNull;
import java.io.IOException;
@ -38,6 +37,7 @@ import org.openmetadata.catalog.resources.EntityResourceTest;
import org.openmetadata.catalog.type.ChangeDescription;
import org.openmetadata.catalog.type.EntityReference;
import org.openmetadata.catalog.type.FieldChange;
import org.openmetadata.catalog.util.EntityInterface;
import org.openmetadata.catalog.util.JsonUtils;
import org.openmetadata.catalog.util.TestUtils;
import org.openmetadata.catalog.util.TestUtils.UpdateType;
@ -118,12 +118,13 @@ public class GlossaryResourceTest extends EntityResourceTest<Glossary, CreateGlo
}
@Override
public GlossaryEntityInterface getEntityInterface(Glossary entity) {
public EntityInterface<Glossary> getEntityInterface(Glossary entity) {
return new GlossaryEntityInterface(entity);
}
@Override
public void validateGetWithDifferentFields(Glossary entity, boolean byName) throws HttpResponseException {
public EntityInterface<Glossary> validateGetWithDifferentFields(Glossary entity, boolean byName)
throws HttpResponseException {
String fields = "";
entity =
byName
@ -136,7 +137,8 @@ public class GlossaryResourceTest extends EntityResourceTest<Glossary, CreateGlo
byName
? getEntityByName(entity.getName(), fields, ADMIN_AUTH_HEADERS)
: getEntity(entity.getId(), fields, ADMIN_AUTH_HEADERS);
assertListNotNull(entity.getOwner(), entity.getTags());
// Checks for other owner, tags, and followers is done in the base class
return getEntityInterface(entity);
}
@Override

View File

@ -24,6 +24,7 @@ import static org.openmetadata.catalog.exception.CatalogExceptionMessage.glossar
import static org.openmetadata.catalog.util.TestUtils.ADMIN_AUTH_HEADERS;
import static org.openmetadata.catalog.util.TestUtils.UpdateType.MINOR_UPDATE;
import static org.openmetadata.catalog.util.TestUtils.assertEntityReferenceList;
import static org.openmetadata.catalog.util.TestUtils.assertListNotEmpty;
import static org.openmetadata.catalog.util.TestUtils.assertListNotNull;
import static org.openmetadata.catalog.util.TestUtils.assertListNull;
import static org.openmetadata.catalog.util.TestUtils.assertResponse;
@ -55,6 +56,7 @@ import org.openmetadata.catalog.resources.EntityResourceTest;
import org.openmetadata.catalog.type.ChangeDescription;
import org.openmetadata.catalog.type.EntityReference;
import org.openmetadata.catalog.type.FieldChange;
import org.openmetadata.catalog.util.EntityInterface;
import org.openmetadata.catalog.util.EntityUtil;
import org.openmetadata.catalog.util.FullyQualifiedName;
import org.openmetadata.catalog.util.JsonUtils;
@ -304,12 +306,13 @@ public class GlossaryTermResourceTest extends EntityResourceTest<GlossaryTerm, C
}
@Override
public GlossaryTermEntityInterface getEntityInterface(GlossaryTerm entity) {
public EntityInterface<GlossaryTerm> getEntityInterface(GlossaryTerm entity) {
return new GlossaryTermEntityInterface(entity);
}
@Override
public void validateGetWithDifferentFields(GlossaryTerm term, boolean byName) throws HttpResponseException {
public EntityInterface<GlossaryTerm> validateGetWithDifferentFields(GlossaryTerm term, boolean byName)
throws HttpResponseException {
String fields = "";
term =
byName
@ -323,6 +326,9 @@ public class GlossaryTermResourceTest extends EntityResourceTest<GlossaryTerm, C
? getEntityByName(term.getFullyQualifiedName(), fields, ADMIN_AUTH_HEADERS)
: getEntity(term.getId(), fields, ADMIN_AUTH_HEADERS);
assertListNotNull(term.getRelatedTerms(), term.getReviewers(), term.getTags());
assertListNotEmpty(term.getRelatedTerms(), term.getReviewers());
// Checks for other owner, tags, and followers is done in the base class
return getEntityInterface(term);
}
@Override

View File

@ -203,9 +203,9 @@ public class LocationResourceTest extends EntityResourceTest<Location, CreateLoc
return TestUtils.put(getResource("locations"), create, Location.class, status, authHeaders);
}
/** Validate returned fields GET .../locations/{id}?fields="..." or GET .../locations/name/{fqn}?fields="..." */
@Override
public void validateGetWithDifferentFields(Location location, boolean byName) throws HttpResponseException {
public EntityInterface<Location> validateGetWithDifferentFields(Location location, boolean byName)
throws HttpResponseException {
String fields = "";
location =
byName
@ -220,7 +220,8 @@ public class LocationResourceTest extends EntityResourceTest<Location, CreateLoc
? getEntityByName(location.getFullyQualifiedName(), fields, ADMIN_AUTH_HEADERS)
: getEntity(location.getId(), fields, ADMIN_AUTH_HEADERS);
assertListNotNull(location.getService(), location.getServiceType());
assertListNotNull(location.getOwner(), location.getFollowers(), location.getTags());
// Checks for other owner, tags, and followers is done in the base class
return getEntityInterface(location);
}
public static LocationList listPrefixes(

View File

@ -348,9 +348,9 @@ public class MlModelResourceTest extends EntityResourceTest<MlModel, CreateMlMod
updateAndCheckEntity(request.withTarget("newTarget"), Status.OK, ADMIN_AUTH_HEADERS, MAJOR_UPDATE, change);
}
/** Validate returned fields GET .../models/{id}?fields="..." or GET .../models/name/{fqn}?fields="..." */
@Override
public void validateGetWithDifferentFields(MlModel model, boolean byName) throws HttpResponseException {
public EntityInterface<MlModel> validateGetWithDifferentFields(MlModel model, boolean byName)
throws HttpResponseException {
// .../models?fields=owner
String fields = "";
model =
@ -366,8 +366,9 @@ public class MlModelResourceTest extends EntityResourceTest<MlModel, CreateMlMod
byName
? getEntityByName(model.getFullyQualifiedName(), fields, ADMIN_AUTH_HEADERS)
: getEntity(model.getId(), fields, ADMIN_AUTH_HEADERS);
assertListNotNull(
model.getOwner(), model.getDashboard(), model.getFollowers(), model.getTags(), model.getUsageSummary());
assertListNotNull(model.getDashboard(), model.getUsageSummary());
// Checks for other owner, tags, and followers is done in the base class
return getEntityInterface(model);
}
@Override

View File

@ -493,9 +493,9 @@ public class PipelineResourceTest extends EntityResourceTest<Pipeline, CreatePip
// TODO
}
/** Validate returned fields GET .../pipelines/{id}?fields="..." or GET .../pipelines/name/{fqn}?fields="..." */
@Override
public void validateGetWithDifferentFields(Pipeline pipeline, boolean byName) throws HttpResponseException {
public EntityInterface<Pipeline> validateGetWithDifferentFields(Pipeline pipeline, boolean byName)
throws HttpResponseException {
String fields = "";
pipeline =
byName
@ -516,14 +516,8 @@ public class PipelineResourceTest extends EntityResourceTest<Pipeline, CreatePip
? getPipelineByName(pipeline.getFullyQualifiedName(), fields, ADMIN_AUTH_HEADERS)
: getPipeline(pipeline.getId(), fields, ADMIN_AUTH_HEADERS);
assertListNotNull(pipeline.getService(), pipeline.getServiceType());
// Some fields are not set and hence are null - tested elsewhere
assertListNotNull(
pipeline.getOwner(),
/*pipeline.getTasks(),
pipeline.getPipelineStatus(),*/
pipeline.getTags(),
pipeline.getFollowers(),
pipeline.getTags());
// Checks for other owner, tags, and followers is done in the base class
return getEntityInterface(pipeline);
}
public static Pipeline getPipeline(UUID id, String fields, Map<String, String> authHeaders)

View File

@ -311,9 +311,9 @@ public class PolicyResourceTest extends EntityResourceTest<Policy, CreatePolicy>
// TODO
}
/** Validate returned fields GET .../policies/{id}?fields="..." or GET .../policies/name/{fqn}?fields="..." */
@Override
public void validateGetWithDifferentFields(Policy policy, boolean byName) throws HttpResponseException {
public EntityInterface<Policy> validateGetWithDifferentFields(Policy policy, boolean byName)
throws HttpResponseException {
String fields = "";
policy =
byName
@ -329,6 +329,8 @@ public class PolicyResourceTest extends EntityResourceTest<Policy, CreatePolicy>
: getPolicy(policy.getId(), fields, ADMIN_AUTH_HEADERS);
// Field location is set during creation - tested elsewhere
assertListNotNull(policy.getOwner() /*, policy.getLocation()*/);
// Checks for other owner, tags, and followers is done in the base class
return getEntityInterface(policy);
}
public static Policy getPolicy(UUID id, String fields, Map<String, String> authHeaders) throws HttpResponseException {

View File

@ -171,7 +171,8 @@ public class DashboardServiceResourceTest extends EntityResourceTest<DashboardSe
}
@Override
public void validateGetWithDifferentFields(DashboardService service, boolean byName) throws HttpResponseException {
public EntityInterface<DashboardService> validateGetWithDifferentFields(DashboardService service, boolean byName)
throws HttpResponseException {
String fields = "";
service =
byName
@ -184,7 +185,8 @@ public class DashboardServiceResourceTest extends EntityResourceTest<DashboardSe
byName
? getEntityByName(service.getName(), fields, ADMIN_AUTH_HEADERS)
: getEntity(service.getId(), fields, ADMIN_AUTH_HEADERS);
TestUtils.assertListNotNull(service.getOwner());
// Checks for other owner, tags, and followers is done in the base class
return getEntityInterface(service);
}
@Override

View File

@ -207,12 +207,9 @@ public class DatabaseServiceResourceTest extends EntityResourceTest<DatabaseServ
return new DatabaseServiceEntityInterface(entity);
}
/**
* Validate returned fields GET .../databaseServices/{id}?fields="..." or GET
* .../databaseServices/name/{fqn}?fields="..."
*/
@Override
public void validateGetWithDifferentFields(DatabaseService service, boolean byName) throws HttpResponseException {
public EntityInterface<DatabaseService> validateGetWithDifferentFields(DatabaseService service, boolean byName)
throws HttpResponseException {
String fields = "";
service =
byName
@ -225,7 +222,8 @@ public class DatabaseServiceResourceTest extends EntityResourceTest<DatabaseServ
byName
? getEntityByName(service.getName(), fields, ADMIN_AUTH_HEADERS)
: getEntity(service.getId(), fields, ADMIN_AUTH_HEADERS);
TestUtils.assertListNotNull(service.getOwner());
// Checks for other owner, tags, and followers is done in the base class
return getEntityInterface(service);
}
@Override

View File

@ -203,7 +203,8 @@ public class MessagingServiceResourceTest extends EntityResourceTest<MessagingSe
}
@Override
public void validateGetWithDifferentFields(MessagingService service, boolean byName) throws HttpResponseException {
public EntityInterface<MessagingService> validateGetWithDifferentFields(MessagingService service, boolean byName)
throws HttpResponseException {
String fields = "";
service =
byName
@ -216,7 +217,8 @@ public class MessagingServiceResourceTest extends EntityResourceTest<MessagingSe
byName
? getEntityByName(service.getName(), fields, ADMIN_AUTH_HEADERS)
: getEntity(service.getId(), fields, ADMIN_AUTH_HEADERS);
TestUtils.assertListNotNull(service.getOwner());
// Checks for other owner, tags, and followers is done in the base class
return getEntityInterface(service);
}
@Override

View File

@ -235,7 +235,8 @@ public class PipelineServiceResourceTest extends EntityResourceTest<PipelineServ
}
@Override
public void validateGetWithDifferentFields(PipelineService service, boolean byName) throws HttpResponseException {
public EntityInterface<PipelineService> validateGetWithDifferentFields(PipelineService service, boolean byName)
throws HttpResponseException {
String fields = "";
service =
byName
@ -248,7 +249,8 @@ public class PipelineServiceResourceTest extends EntityResourceTest<PipelineServ
byName
? getEntityByName(service.getName(), fields, ADMIN_AUTH_HEADERS)
: getEntity(service.getId(), fields, ADMIN_AUTH_HEADERS);
TestUtils.assertListNotNull(service.getOwner());
// Checks for other owner, tags, and followers is done in the base class
return getEntityInterface(service);
}
@Override

View File

@ -89,7 +89,8 @@ public class StorageServiceResourceTest extends EntityResourceTest<StorageServic
}
@Override
public void validateGetWithDifferentFields(StorageService service, boolean byName) throws HttpResponseException {
public EntityInterface<StorageService> validateGetWithDifferentFields(StorageService service, boolean byName)
throws HttpResponseException {
String fields = "";
service =
byName
@ -102,7 +103,8 @@ public class StorageServiceResourceTest extends EntityResourceTest<StorageServic
byName
? getEntityByName(service.getName(), fields, ADMIN_AUTH_HEADERS)
: getEntity(service.getId(), fields, ADMIN_AUTH_HEADERS);
TestUtils.assertListNotNull(service.getOwner());
// Checks for other owner, tags, and followers is done in the base class
return getEntityInterface(service);
}
@Override

View File

@ -614,12 +614,9 @@ public class IngestionPipelineResourceTest extends EntityResourceTest<IngestionP
return TestUtils.put(getCollection(), create, IngestionPipeline.class, status, authHeaders);
}
/**
* Validate returned fields GET .../operations/IngestionPipelines/{id}?fields="..." or GET
* .../operations/IngestionPipelines/name/{fqn}?fields="..."
*/
@Override
public void validateGetWithDifferentFields(IngestionPipeline ingestion, boolean byName) throws HttpResponseException {
public EntityInterface<IngestionPipeline> validateGetWithDifferentFields(IngestionPipeline ingestion, boolean byName)
throws HttpResponseException {
String fields = "";
ingestion =
byName
@ -633,7 +630,8 @@ public class IngestionPipelineResourceTest extends EntityResourceTest<IngestionP
byName
? getEntityByName(ingestion.getFullyQualifiedName(), fields, ADMIN_AUTH_HEADERS)
: getEntity(ingestion.getId(), fields, ADMIN_AUTH_HEADERS);
assertListNotNull(ingestion.getOwner(), ingestion.getService());
// Checks for other owner, tags, and followers is done in the base class
return getEntityInterface(ingestion);
}
private void validateSourceConfig(SourceConfig orig, SourceConfig updated, IngestionPipeline ingestionPipeline) {

View File

@ -180,48 +180,53 @@ public class RoleResourceTest extends EntityResourceTest<Role, CreateRole> {
}
@Override
protected void prepareGetWithDifferentFields(Role role) throws HttpResponseException {
public EntityInterface<Role> validateGetWithDifferentFields(Role role, boolean byName) throws HttpResponseException {
// Assign two arbitrary users this role for testing.
UserResourceTest userResourceTest = new UserResourceTest();
userResourceTest.createEntity(
userResourceTest.createRequest(role.getName() + "user1", "", "", null).withRoles(List.of(role.getId())),
ADMIN_AUTH_HEADERS);
userResourceTest.createEntity(
userResourceTest.createRequest(role.getName() + "user2", "", "", null).withRoles(List.of(role.getId())),
ADMIN_AUTH_HEADERS);
if (role.getUsers() == null) {
UserResourceTest userResourceTest = new UserResourceTest();
userResourceTest.createEntity(
userResourceTest.createRequest(role.getName() + "user1", "", "", null).withRoles(List.of(role.getId())),
ADMIN_AUTH_HEADERS);
userResourceTest.createEntity(
userResourceTest.createRequest(role.getName() + "user2", "", "", null).withRoles(List.of(role.getId())),
ADMIN_AUTH_HEADERS);
}
// Assign two arbitrary teams this role for testing.
TeamResourceTest teamResourceTest = new TeamResourceTest();
teamResourceTest.createEntity(
teamResourceTest.createRequest(role.getName() + "team1", "", "", null).withDefaultRoles(List.of(role.getId())),
ADMIN_AUTH_HEADERS);
teamResourceTest.createEntity(
teamResourceTest.createRequest(role.getName() + "team2", "", "", null).withDefaultRoles(List.of(role.getId())),
ADMIN_AUTH_HEADERS);
}
if (role.getTeams() == null) {
TeamResourceTest teamResourceTest = new TeamResourceTest();
teamResourceTest.createEntity(
teamResourceTest
.createRequest(role.getName() + "team1", "", "", null)
.withDefaultRoles(List.of(role.getId())),
ADMIN_AUTH_HEADERS);
teamResourceTest.createEntity(
teamResourceTest
.createRequest(role.getName() + "team2", "", "", null)
.withDefaultRoles(List.of(role.getId())),
ADMIN_AUTH_HEADERS);
}
/** Validate returned fields GET .../roles/{id}?fields="..." or GET .../roles/name/{name}?fields="..." */
@Override
public void validateGetWithDifferentFields(Role expectedRole, boolean byName) throws HttpResponseException {
String updatedBy = TestUtils.getPrincipal(ADMIN_AUTH_HEADERS);
Role role =
role =
byName
? getEntityByName(expectedRole.getName(), null, ADMIN_AUTH_HEADERS)
: getEntity(expectedRole.getId(), null, ADMIN_AUTH_HEADERS);
validateRole(role, expectedRole.getDescription(), expectedRole.getDisplayName(), updatedBy);
? getEntityByName(role.getName(), null, ADMIN_AUTH_HEADERS)
: getEntity(role.getId(), null, ADMIN_AUTH_HEADERS);
validateRole(role, role.getDescription(), role.getDisplayName(), updatedBy);
assertListNull(role.getPolicy(), role.getUsers());
// .../roles?fields=policy,users
String fields = "policy,teams,users";
role =
byName
? getEntityByName(expectedRole.getName(), null, fields, ADMIN_AUTH_HEADERS)
: getEntity(expectedRole.getId(), fields, ADMIN_AUTH_HEADERS);
? getEntityByName(role.getName(), null, fields, ADMIN_AUTH_HEADERS)
: getEntity(role.getId(), fields, ADMIN_AUTH_HEADERS);
assertListNotNull(role.getPolicy(), role.getUsers());
validateRole(role, expectedRole.getDescription(), expectedRole.getDisplayName(), updatedBy);
validateRole(role, role.getDescription(), role.getDisplayName(), updatedBy);
TestUtils.validateEntityReference(role.getPolicy());
TestUtils.validateEntityReferences(role.getTeams());
TestUtils.validateEntityReferences(role.getUsers());
TestUtils.validateEntityReferences(role.getTeams(), true);
TestUtils.validateEntityReferences(role.getUsers(), true);
return getEntityInterface(role);
}
@Override

View File

@ -45,6 +45,7 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import org.openmetadata.catalog.Entity;
import org.openmetadata.catalog.api.teams.CreateTeam;
import org.openmetadata.catalog.api.teams.CreateUser;
import org.openmetadata.catalog.entity.policies.Policy;
import org.openmetadata.catalog.entity.policies.accessControl.Rule;
import org.openmetadata.catalog.entity.teams.Role;
@ -337,9 +338,15 @@ public class TeamResourceTest extends EntityResourceTest<Team, CreateTeam> {
validateEntityReferences(team.getOwns());
}
/** Validate returned fields GET .../teams/{id}?fields="..." or GET .../teams/name/{name}?fields="..." */
@Override
public void validateGetWithDifferentFields(Team expectedTeam, boolean byName) throws HttpResponseException {
public EntityInterface<Team> validateGetWithDifferentFields(Team expectedTeam, boolean byName)
throws HttpResponseException {
if (expectedTeam.getUsers() == null) {
UserResourceTest userResourceTest = new UserResourceTest();
CreateUser create = userResourceTest.createRequest("user", "", "", null).withTeams(List.of(expectedTeam.getId()));
userResourceTest.createEntity(create, ADMIN_AUTH_HEADERS);
}
String updatedBy = TestUtils.getPrincipal(ADMIN_AUTH_HEADERS);
String fields = "";
Team getTeam =
@ -349,15 +356,16 @@ public class TeamResourceTest extends EntityResourceTest<Team, CreateTeam> {
validateTeam(getTeam, expectedTeam.getDescription(), expectedTeam.getDisplayName(), null, null, null, updatedBy);
assertNull(getTeam.getOwns());
fields = "users,owns,profile,defaultRoles";
fields = "users,owns,profile,defaultRoles,owner";
getTeam =
byName
? getEntityByName(expectedTeam.getName(), fields, ADMIN_AUTH_HEADERS)
: getEntity(expectedTeam.getId(), fields, ADMIN_AUTH_HEADERS);
assertNotNull(getTeam.getProfile());
validateEntityReferences(getTeam.getOwns());
validateEntityReferences(getTeam.getUsers());
validateEntityReferences(getTeam.getUsers(), true);
validateEntityReferences(getTeam.getDefaultRoles());
return getEntityInterface(getTeam);
}
@Override

View File

@ -643,7 +643,7 @@ public class UserResourceTest extends EntityResourceTest<User, CreateUser> {
}
@Override
public void validateGetWithDifferentFields(User user, boolean byName) throws HttpResponseException {
public EntityInterface<User> validateGetWithDifferentFields(User user, boolean byName) throws HttpResponseException {
String fields = "";
user =
byName
@ -657,6 +657,7 @@ public class UserResourceTest extends EntityResourceTest<User, CreateUser> {
? getEntityByName(user.getName(), fields, ADMIN_AUTH_HEADERS)
: getEntity(user.getId(), fields, ADMIN_AUTH_HEADERS);
assertListNotNull(user.getProfile(), user.getRoles(), user.getTeams(), user.getFollows(), user.getOwns());
return getEntityInterface(user);
}
@Override

View File

@ -210,9 +210,9 @@ public class TopicResourceTest extends EntityResourceTest<Topic, CreateTopic> {
// TODO
}
/** Validate returned fields GET .../topics/{id}?fields="..." or GET .../topics/name/{fqn}?fields="..." */
@Override
public void validateGetWithDifferentFields(Topic topic, boolean byName) throws HttpResponseException {
public EntityInterface<Topic> validateGetWithDifferentFields(Topic topic, boolean byName)
throws HttpResponseException {
// .../topics?fields=owner
String fields = "";
topic =
@ -226,7 +226,9 @@ public class TopicResourceTest extends EntityResourceTest<Topic, CreateTopic> {
byName
? getTopicByName(topic.getFullyQualifiedName(), fields, ADMIN_AUTH_HEADERS)
: getTopic(topic.getId(), fields, ADMIN_AUTH_HEADERS);
assertListNotNull(topic.getOwner(), topic.getService(), topic.getServiceType());
assertListNotNull(topic.getService(), topic.getServiceType());
// Checks for other owner, tags, and followers is done in the base class
return getEntityInterface(topic);
}
public static Topic getTopic(UUID id, String fields, Map<String, String> authHeaders) throws HttpResponseException {

View File

@ -276,6 +276,14 @@ public final class TestUtils {
}
public static void validateEntityReferences(List<EntityReference> list) {
validateEntityReferences(list, false);
}
public static void validateEntityReferences(List<EntityReference> list, boolean expectedNotEmpty) {
if (expectedNotEmpty) {
assertNotNull(list);
assertListNotEmpty(list);
}
listOrEmpty(list).forEach(TestUtils::validateEntityReference);
}
@ -387,4 +395,12 @@ public final class TestUtils {
index++;
}
}
public static void assertListNotEmpty(List... values) {
int index = 0;
for (List value : values) {
Assertions.assertFalse(value.isEmpty(), "List at index " + index + "is empty");
index++;
}
}
}