Skip to content

Commit

Permalink
Issue #17012: Multi User/Team Ownership - Fix Tests - Part 4
Browse files Browse the repository at this point in the history
  • Loading branch information
harshach committed Jul 18, 2024
1 parent c15046d commit c7bc364
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3242,9 +3242,16 @@ protected final void assertCommonFieldChange(String fieldName, Object expected,
}
if (fieldName.equals(FIELD_EXPERTS) || fieldName.equals(FIELD_REVIEWERS)) {
assertEntityReferencesFieldChange(expected, actual);
} else if (fieldName.endsWith(FIELD_OWNERS)
|| fieldName.equals(FIELD_DOMAIN)
|| fieldName.equals(FIELD_PARENT)) {
} else if (fieldName.endsWith(FIELD_OWNERS) && (expected != null && actual != null)) {
@SuppressWarnings("unchecked")
List<EntityReference> expectedOwners =
expected instanceof List
? (List<EntityReference>) expected
: JsonUtils.readObjects(expected.toString(), EntityReference.class);
List<EntityReference> actualOwners =
JsonUtils.readObjects(actual.toString(), EntityReference.class);
assertOwners(expectedOwners, actualOwners);
} else if (fieldName.equals(FIELD_DOMAIN) || fieldName.equals(FIELD_PARENT)) {
assertEntityReferenceFieldChange(expected, actual);
} else if (fieldName.endsWith(FIELD_TAGS)) {
@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public APICollection validateGetWithDifferentFields(APICollection apiCollection,
: getEntity(apiCollection.getId(), fields, ADMIN_AUTH_HEADERS);
assertListNotNull(apiCollection.getService(), apiCollection.getServiceType());

fields = "owner,tags";
fields = "owners,tags";
apiCollection =
byName
? getEntityByName(apiCollection.getFullyQualifiedName(), fields, ADMIN_AUTH_HEADERS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.openmetadata.service.Entity.FIELD_OWNERS;
import static org.openmetadata.service.resources.topics.TopicResourceTest.getField;
import static org.openmetadata.service.util.EntityUtil.fieldAdded;
import static org.openmetadata.service.util.EntityUtil.fieldDeleted;
import static org.openmetadata.service.util.EntityUtil.fieldUpdated;
import static org.openmetadata.service.util.TestUtils.ADMIN_AUTH_HEADERS;
import static org.openmetadata.service.util.TestUtils.UpdateType.MINOR_UPDATE;
Expand Down Expand Up @@ -145,7 +147,8 @@ void put_endPointAttributes_200_ok(TestInfo test) throws IOException {
.withRequestMethod(APIRequestMethod.POST);

ChangeDescription change = getChangeDescription(apiEndpoint, MINOR_UPDATE);
fieldUpdated(change, FIELD_OWNERS, USER1_REF, TEAM11_REF);
fieldAdded(change, FIELD_OWNERS, List.of(TEAM11_REF));
fieldDeleted(change, FIELD_OWNERS, List.of(USER1_REF));
fieldUpdated(change, "requestMethod", "GET", "POST");

updateAndCheckEntity(
Expand Down Expand Up @@ -212,7 +215,7 @@ public APIEndpoint validateGetWithDifferentFields(APIEndpoint endpoint, boolean
: getAPIEndpoint(endpoint.getId(), fields, ADMIN_AUTH_HEADERS);
assertListNull(endpoint.getOwners(), endpoint.getFollowers());

fields = "owner, followers, tags";
fields = "owners, followers, tags";
endpoint =
byName
? getAPIEndpointByName(endpoint.getFullyQualifiedName(), fields, ADMIN_AUTH_HEADERS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public AppMarketPlaceDefinition validateGetWithDifferentFields(
byName
? getEntityByName(entity.getFullyQualifiedName(), fields, ADMIN_AUTH_HEADERS)
: getEntity(entity.getId(), fields, ADMIN_AUTH_HEADERS);
TestUtils.assertListNull(entity.getOwner());
TestUtils.assertListNull(entity.getOwners());

fields = "owners,tags";
entity =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
import org.openmetadata.service.resources.EntityResourceTest;
import org.openmetadata.service.resources.databases.DatabaseSchemaResource.DatabaseSchemaList;
import org.openmetadata.service.util.FullyQualifiedName;
import org.openmetadata.service.util.JsonUtils;
import org.openmetadata.service.util.TestUtils;

@Slf4j
Expand Down Expand Up @@ -253,17 +252,6 @@ public void compareEntities(

@Override
public void assertFieldChange(String fieldName, Object expected, Object actual) {
if (fieldName.endsWith("owners") && (expected != null && actual != null)) {
@SuppressWarnings("unchecked")
List<EntityReference> expectedOwners =
expected instanceof List
? (List<EntityReference>) expected
: JsonUtils.readObjects(expected.toString(), EntityReference.class);
List<EntityReference> actualOwners =
JsonUtils.readObjects(actual.toString(), EntityReference.class);
assertOwners(expectedOwners, actualOwners);
} else {
assertCommonFieldChange(fieldName, expected, actual);
}
assertCommonFieldChange(fieldName, expected, actual);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ void put_topicAttributes_200_ok(TestInfo test) throws IOException {
.withCleanupPolicies(List.of(CleanupPolicy.DELETE));

ChangeDescription change = getChangeDescription(topic, MINOR_UPDATE);
fieldUpdated(change, FIELD_OWNERS, USER1_REF, TEAM11_REF);
fieldDeleted(change, FIELD_OWNERS, List.of(USER1_REF));
fieldAdded(change, FIELD_OWNERS, List.of(TEAM11_REF));
fieldUpdated(change, "maximumMessageSize", 1, 2);
fieldUpdated(change, "minimumInSyncReplicas", 1, 2);
fieldUpdated(change, "partitions", 1, 2);
Expand Down Expand Up @@ -240,7 +241,6 @@ void patch_topicAttributes_200_ok(TestInfo test) throws IOException {
.withCleanupPolicies(List.of(CleanupPolicy.DELETE));

ChangeDescription change = getChangeDescription(topic, MINOR_UPDATE);
fieldUpdated(change, FIELD_OWNERS, USER1_REF, TEAM11_REF);
fieldUpdated(change, "maximumMessageSize", 1, 2);
fieldUpdated(change, "minimumInSyncReplicas", 1, 2);
fieldUpdated(change, "partitions", 1, 2);
Expand All @@ -249,6 +249,8 @@ void patch_topicAttributes_200_ok(TestInfo test) throws IOException {
fieldUpdated(change, "retentionSize", 1.0, 2.0);
fieldDeleted(change, "cleanupPolicies", List.of(CleanupPolicy.COMPACT));
fieldAdded(change, "cleanupPolicies", List.of(CleanupPolicy.DELETE));
fieldDeleted(change, "owners", List.of(USER1_REF));
fieldAdded(change, "owners", List.of(TEAM11_REF));
patchEntityAndCheck(topic, origJson, ADMIN_AUTH_HEADERS, MINOR_UPDATE, change);
}

Expand Down Expand Up @@ -351,7 +353,8 @@ void patch_usingFqn_topicAttributes_200_ok(TestInfo test) throws IOException {
.withCleanupPolicies(List.of(CleanupPolicy.DELETE));

ChangeDescription change = getChangeDescription(topic, MINOR_UPDATE);
fieldUpdated(change, FIELD_OWNERS, USER1_REF, TEAM11_REF);
fieldDeleted(change, FIELD_OWNERS, List.of(USER1_REF));
fieldAdded(change, FIELD_OWNERS, List.of(TEAM11_REF));
fieldUpdated(change, "maximumMessageSize", 1, 2);
fieldUpdated(change, "minimumInSyncReplicas", 1, 2);
fieldUpdated(change, "partitions", 1, 2);
Expand Down Expand Up @@ -552,6 +555,15 @@ public void assertFieldChange(String fieldName, Object expected, Object actual)
SchemaType expectedSchemaType = (SchemaType) expected;
SchemaType actualSchemaType = SchemaType.fromValue(actual.toString());
assertEquals(expectedSchemaType, actualSchemaType);
} else if (fieldName.endsWith("owners") && (expected != null && actual != null)) {
@SuppressWarnings("unchecked")
List<EntityReference> expectedOwners =
expected instanceof List
? (List<EntityReference>) expected
: JsonUtils.readObjects(expected.toString(), EntityReference.class);
List<EntityReference> actualOwners =
JsonUtils.readObjects(actual.toString(), EntityReference.class);
assertOwners(expectedOwners, actualOwners);
} else {
assertCommonFieldChange(fieldName, expected, actual);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
"description": "FullyQualifiedName same as `name`.",
"$ref": "../../../type/basic.json#/definitions/fullyQualifiedEntityName"
},
"owner": {
"description": "Owner of this workflow.",
"owners": {
"description": "Owners of this workflow.",
"$ref": "../../../type/entityReferenceList.json",
"default": null
},
Expand Down

0 comments on commit c7bc364

Please sign in to comment.