mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-09-22 07:19:59 +00:00
Fix #644 Move duplicated validateTags method in tests to a common util
This commit is contained in:
parent
08cefee56a
commit
5906e5a19c
@ -629,7 +629,7 @@ public class ChartResourceTest extends CatalogApplicationTest {
|
|||||||
assertEquals(expectedService.getId(), chart.getService().getId());
|
assertEquals(expectedService.getId(), chart.getService().getId());
|
||||||
assertEquals(expectedService.getType(), chart.getService().getType());
|
assertEquals(expectedService.getType(), chart.getService().getType());
|
||||||
}
|
}
|
||||||
validateTags(expectedTags, chart.getTags());
|
TestUtils.validateTags(expectedTags, chart.getTags());
|
||||||
return chart;
|
return chart;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -794,24 +794,4 @@ public class ChartResourceTest extends CatalogApplicationTest {
|
|||||||
checkUserFollowing(userId, chartId, false, authHeaders);
|
checkUserFollowing(userId, chartId, false, authHeaders);
|
||||||
return getChart;
|
return getChart;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void validateTags(List<TagLabel> expectedList, List<TagLabel> actualList)
|
|
||||||
throws HttpResponseException {
|
|
||||||
if (expectedList == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// When tags from the expected list is added to an entity, the derived tags for those tags are automatically added
|
|
||||||
// So add to the expectedList, the derived tags before validating the tags
|
|
||||||
List<TagLabel> updatedExpectedList = new ArrayList<>(expectedList);
|
|
||||||
for (TagLabel expected : expectedList) {
|
|
||||||
List<TagLabel> derived = EntityUtil.getDerivedTags(expected, TagResourceTest.getTag(expected.getTagFQN(),
|
|
||||||
adminAuthHeaders()));
|
|
||||||
updatedExpectedList.addAll(derived);
|
|
||||||
}
|
|
||||||
updatedExpectedList = updatedExpectedList.stream().distinct().collect(Collectors.toList());
|
|
||||||
|
|
||||||
assertTrue(actualList.containsAll(updatedExpectedList));
|
|
||||||
assertTrue(updatedExpectedList.containsAll(actualList));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -673,7 +673,7 @@ public class DashboardResourceTest extends CatalogApplicationTest {
|
|||||||
assertEquals(expectedService.getType(), dashboard.getService().getType());
|
assertEquals(expectedService.getType(), dashboard.getService().getType());
|
||||||
}
|
}
|
||||||
validateDashboardCharts(dashboard, charts);
|
validateDashboardCharts(dashboard, charts);
|
||||||
validateTags(expectedTags, dashboard.getTags());
|
TestUtils.validateTags(expectedTags, dashboard.getTags());
|
||||||
return dashboard;
|
return dashboard;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -692,25 +692,6 @@ public class DashboardResourceTest extends CatalogApplicationTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void validateTags(List<TagLabel> expectedList, List<TagLabel> actualList)
|
|
||||||
throws HttpResponseException {
|
|
||||||
if (expectedList == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// When tags from the expected list is added to an entity, the derived tags for those tags are automatically added
|
|
||||||
// So add to the expectedList, the derived tags before validating the tags
|
|
||||||
List<TagLabel> updatedExpectedList = new ArrayList<>(expectedList);
|
|
||||||
for (TagLabel expected : expectedList) {
|
|
||||||
List<TagLabel> derived = EntityUtil.getDerivedTags(expected, TagResourceTest.getTag(expected.getTagFQN(),
|
|
||||||
adminAuthHeaders()));
|
|
||||||
updatedExpectedList.addAll(derived);
|
|
||||||
}
|
|
||||||
updatedExpectedList = updatedExpectedList.stream().distinct().collect(Collectors.toList());
|
|
||||||
|
|
||||||
assertTrue(actualList.containsAll(updatedExpectedList));
|
|
||||||
assertTrue(updatedExpectedList.containsAll(actualList));
|
|
||||||
}
|
|
||||||
|
|
||||||
private Dashboard patchDashboardAttributesAndCheck(Dashboard dashboard, String newDescription,
|
private Dashboard patchDashboardAttributesAndCheck(Dashboard dashboard, String newDescription,
|
||||||
EntityReference newOwner, List<TagLabel> tags,
|
EntityReference newOwner, List<TagLabel> tags,
|
||||||
Map<String, String> authHeaders)
|
Map<String, String> authHeaders)
|
||||||
|
@ -54,7 +54,6 @@ import org.openmetadata.catalog.type.TableJoins;
|
|||||||
import org.openmetadata.catalog.type.TableProfile;
|
import org.openmetadata.catalog.type.TableProfile;
|
||||||
import org.openmetadata.catalog.type.TableType;
|
import org.openmetadata.catalog.type.TableType;
|
||||||
import org.openmetadata.catalog.type.TagLabel;
|
import org.openmetadata.catalog.type.TagLabel;
|
||||||
import org.openmetadata.catalog.util.EntityUtil;
|
|
||||||
import org.openmetadata.catalog.util.EntityUtil.Fields;
|
import org.openmetadata.catalog.util.EntityUtil.Fields;
|
||||||
import org.openmetadata.catalog.util.JsonUtils;
|
import org.openmetadata.catalog.util.JsonUtils;
|
||||||
import org.openmetadata.catalog.util.RestUtil;
|
import org.openmetadata.catalog.util.RestUtil;
|
||||||
@ -75,7 +74,6 @@ import java.util.List;
|
|||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import static java.util.Collections.singletonList;
|
import static java.util.Collections.singletonList;
|
||||||
import static javax.ws.rs.core.Response.Status.BAD_REQUEST;
|
import static javax.ws.rs.core.Response.Status.BAD_REQUEST;
|
||||||
@ -476,8 +474,8 @@ public class TableResourceTest extends CatalogApplicationTest {
|
|||||||
.withDataLength(10).withFullyQualifiedName(table.getFullyQualifiedName() + ".c2").withTags(tags));
|
.withDataLength(10).withFullyQualifiedName(table.getFullyQualifiedName() + ".c2").withTags(tags));
|
||||||
table = updateAndCheckTable(request.withColumns(updatedColumns), OK, adminAuthHeaders());
|
table = updateAndCheckTable(request.withColumns(updatedColumns), OK, adminAuthHeaders());
|
||||||
assertEquals(2, table.getColumns().size());
|
assertEquals(2, table.getColumns().size());
|
||||||
validateTags(updatedColumns.get(0).getTags(), table.getColumns().get(0).getTags());
|
TestUtils.validateTags(updatedColumns.get(0).getTags(), table.getColumns().get(0).getTags());
|
||||||
validateTags(updatedColumns.get(1).getTags(), table.getColumns().get(1).getTags());
|
TestUtils.validateTags(updatedColumns.get(1).getTags(), table.getColumns().get(1).getTags());
|
||||||
|
|
||||||
// Ensure tag usage counts are updated - column c2 added both address and bank tags
|
// Ensure tag usage counts are updated - column c2 added both address and bank tags
|
||||||
assertEquals(tagCategoryUsageCount + 4, getTagCategoryUsageCount("user", userAuthHeaders()));
|
assertEquals(tagCategoryUsageCount + 4, getTagCategoryUsageCount("user", userAuthHeaders()));
|
||||||
@ -490,7 +488,7 @@ public class TableResourceTest extends CatalogApplicationTest {
|
|||||||
updatedColumns.remove(1);
|
updatedColumns.remove(1);
|
||||||
table = updateAndCheckTable(request.withColumns(updatedColumns), OK, adminAuthHeaders());
|
table = updateAndCheckTable(request.withColumns(updatedColumns), OK, adminAuthHeaders());
|
||||||
assertEquals(1, table.getColumns().size());
|
assertEquals(1, table.getColumns().size());
|
||||||
validateTags(columns.get(0).getTags(), table.getColumns().get(0).getTags());
|
TestUtils.validateTags(columns.get(0).getTags(), table.getColumns().get(0).getTags());
|
||||||
|
|
||||||
// Ensure tag usage counts are updated to reflect removal of column c2
|
// Ensure tag usage counts are updated to reflect removal of column c2
|
||||||
assertEquals(tagCategoryUsageCount + 2, getTagCategoryUsageCount("user", userAuthHeaders()));
|
assertEquals(tagCategoryUsageCount + 2, getTagCategoryUsageCount("user", userAuthHeaders()));
|
||||||
@ -1203,29 +1201,6 @@ public class TableResourceTest extends CatalogApplicationTest {
|
|||||||
assertEquals(table.getDatabase().getName(), DATABASE.getName());
|
assertEquals(table.getDatabase().getName(), DATABASE.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void validateTags(List<TagLabel> expectedList, List<TagLabel> actualList)
|
|
||||||
throws HttpResponseException {
|
|
||||||
if (expectedList == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// When tags from the expected list is added to an entity, the derived tags for those tags are automatically added
|
|
||||||
// So add to the expectedList, the derived tags before validating the tags
|
|
||||||
List<TagLabel> updatedExpectedList = new ArrayList<>(expectedList);
|
|
||||||
for (TagLabel expected : expectedList) {
|
|
||||||
List<TagLabel> derived = EntityUtil.getDerivedTags(expected, TagResourceTest.getTag(expected.getTagFQN(),
|
|
||||||
adminAuthHeaders()));
|
|
||||||
updatedExpectedList.addAll(derived);
|
|
||||||
}
|
|
||||||
updatedExpectedList = updatedExpectedList.stream().distinct().collect(Collectors.toList());
|
|
||||||
updatedExpectedList.sort(new TagLabelComparator());
|
|
||||||
actualList.sort(new TagLabelComparator());
|
|
||||||
|
|
||||||
assertEquals(updatedExpectedList.size(), actualList.size());
|
|
||||||
for (int i = 0; i < actualList.size(); i++) {
|
|
||||||
assertEquals(updatedExpectedList.get(i), actualList.get(i));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Table createTable(CreateTable create, Map<String, String> authHeaders) throws HttpResponseException {
|
public static Table createTable(CreateTable create, Map<String, String> authHeaders) throws HttpResponseException {
|
||||||
return TestUtils.post(CatalogApplicationTest.getResource("tables"), create, Table.class, authHeaders);
|
return TestUtils.post(CatalogApplicationTest.getResource("tables"), create, Table.class, authHeaders);
|
||||||
}
|
}
|
||||||
@ -1260,7 +1235,7 @@ public class TableResourceTest extends CatalogApplicationTest {
|
|||||||
|
|
||||||
// Validate table constraints
|
// Validate table constraints
|
||||||
assertEquals(expectedTableConstraints, table.getTableConstraints());
|
assertEquals(expectedTableConstraints, table.getTableConstraints());
|
||||||
validateTags(expectedTags, table.getTags());
|
TestUtils.validateTags(expectedTags, table.getTags());
|
||||||
TestUtils.validateEntityReference(table.getFollowers());
|
TestUtils.validateEntityReference(table.getFollowers());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1272,7 +1247,7 @@ public class TableResourceTest extends CatalogApplicationTest {
|
|||||||
if (expectedColumn.getDataTypeDisplay() != null) {
|
if (expectedColumn.getDataTypeDisplay() != null) {
|
||||||
assertEquals(expectedColumn.getDataTypeDisplay().toLowerCase(Locale.ROOT), actualColumn.getDataTypeDisplay());
|
assertEquals(expectedColumn.getDataTypeDisplay().toLowerCase(Locale.ROOT), actualColumn.getDataTypeDisplay());
|
||||||
}
|
}
|
||||||
validateTags(expectedColumn.getTags(), actualColumn.getTags());
|
TestUtils.validateTags(expectedColumn.getTags(), actualColumn.getTags());
|
||||||
|
|
||||||
// Check the nested columns
|
// Check the nested columns
|
||||||
validateColumns(expectedColumn.getChildren(), actualColumn.getChildren());
|
validateColumns(expectedColumn.getChildren(), actualColumn.getChildren());
|
||||||
|
@ -35,7 +35,6 @@ import org.openmetadata.catalog.exception.CatalogExceptionMessage;
|
|||||||
import org.openmetadata.catalog.resources.tasks.TaskResourceTest;
|
import org.openmetadata.catalog.resources.tasks.TaskResourceTest;
|
||||||
import org.openmetadata.catalog.resources.pipelines.PipelineResource.PipelineList;
|
import org.openmetadata.catalog.resources.pipelines.PipelineResource.PipelineList;
|
||||||
import org.openmetadata.catalog.resources.services.PipelineServiceResourceTest;
|
import org.openmetadata.catalog.resources.services.PipelineServiceResourceTest;
|
||||||
import org.openmetadata.catalog.resources.tags.TagResourceTest;
|
|
||||||
import org.openmetadata.catalog.resources.teams.TeamResourceTest;
|
import org.openmetadata.catalog.resources.teams.TeamResourceTest;
|
||||||
import org.openmetadata.catalog.resources.teams.UserResourceTest;
|
import org.openmetadata.catalog.resources.teams.UserResourceTest;
|
||||||
import org.openmetadata.catalog.type.EntityReference;
|
import org.openmetadata.catalog.type.EntityReference;
|
||||||
@ -55,7 +54,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import static java.util.Collections.singletonList;
|
import static java.util.Collections.singletonList;
|
||||||
import static javax.ws.rs.core.Response.Status.BAD_REQUEST;
|
import static javax.ws.rs.core.Response.Status.BAD_REQUEST;
|
||||||
@ -673,7 +671,7 @@ public class PipelineResourceTest extends CatalogApplicationTest {
|
|||||||
assertEquals(expectedService.getType(), pipeline.getService().getType());
|
assertEquals(expectedService.getType(), pipeline.getService().getType());
|
||||||
}
|
}
|
||||||
validatePipelineTASKs(pipeline, tasks);
|
validatePipelineTASKs(pipeline, tasks);
|
||||||
validateTags(expectedTags, pipeline.getTags());
|
TestUtils.validateTags(expectedTags, pipeline.getTags());
|
||||||
return pipeline;
|
return pipeline;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -692,25 +690,6 @@ public class PipelineResourceTest extends CatalogApplicationTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void validateTags(List<TagLabel> expectedList, List<TagLabel> actualList)
|
|
||||||
throws HttpResponseException {
|
|
||||||
if (expectedList == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// When tags from the expected list is added to an entity, the derived tags for those tags are automatically added
|
|
||||||
// So add to the expectedList, the derived tags before validating the tags
|
|
||||||
List<TagLabel> updatedExpectedList = new ArrayList<>(expectedList);
|
|
||||||
for (TagLabel expected : expectedList) {
|
|
||||||
List<TagLabel> derived = EntityUtil.getDerivedTags(expected, TagResourceTest.getTag(expected.getTagFQN(),
|
|
||||||
adminAuthHeaders()));
|
|
||||||
updatedExpectedList.addAll(derived);
|
|
||||||
}
|
|
||||||
updatedExpectedList = updatedExpectedList.stream().distinct().collect(Collectors.toList());
|
|
||||||
|
|
||||||
assertTrue(actualList.containsAll(updatedExpectedList));
|
|
||||||
assertTrue(updatedExpectedList.containsAll(actualList));
|
|
||||||
}
|
|
||||||
|
|
||||||
private Pipeline patchPipelineAttributesAndCheck(Pipeline pipeline, String newDescription,
|
private Pipeline patchPipelineAttributesAndCheck(Pipeline pipeline, String newDescription,
|
||||||
EntityReference newOwner, List<TagLabel> tags,
|
EntityReference newOwner, List<TagLabel> tags,
|
||||||
Map<String, String> authHeaders)
|
Map<String, String> authHeaders)
|
||||||
|
@ -32,7 +32,6 @@ import org.openmetadata.catalog.entity.teams.Team;
|
|||||||
import org.openmetadata.catalog.entity.teams.User;
|
import org.openmetadata.catalog.entity.teams.User;
|
||||||
import org.openmetadata.catalog.exception.CatalogExceptionMessage;
|
import org.openmetadata.catalog.exception.CatalogExceptionMessage;
|
||||||
import org.openmetadata.catalog.resources.tasks.TaskResource.TaskList;
|
import org.openmetadata.catalog.resources.tasks.TaskResource.TaskList;
|
||||||
import org.openmetadata.catalog.resources.tags.TagResourceTest;
|
|
||||||
import org.openmetadata.catalog.resources.teams.TeamResourceTest;
|
import org.openmetadata.catalog.resources.teams.TeamResourceTest;
|
||||||
import org.openmetadata.catalog.resources.teams.UserResourceTest;
|
import org.openmetadata.catalog.resources.teams.UserResourceTest;
|
||||||
import org.openmetadata.catalog.type.EntityReference;
|
import org.openmetadata.catalog.type.EntityReference;
|
||||||
@ -49,11 +48,9 @@ import javax.ws.rs.client.WebTarget;
|
|||||||
import javax.ws.rs.core.Response.Status;
|
import javax.ws.rs.core.Response.Status;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import static javax.ws.rs.core.Response.Status.BAD_REQUEST;
|
import static javax.ws.rs.core.Response.Status.BAD_REQUEST;
|
||||||
import static javax.ws.rs.core.Response.Status.CONFLICT;
|
import static javax.ws.rs.core.Response.Status.CONFLICT;
|
||||||
@ -65,7 +62,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
|||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
||||||
import static org.openmetadata.catalog.exception.CatalogExceptionMessage.entityNotFound;
|
import static org.openmetadata.catalog.exception.CatalogExceptionMessage.entityNotFound;
|
||||||
import static org.openmetadata.catalog.exception.CatalogExceptionMessage.readOnlyAttribute;
|
import static org.openmetadata.catalog.exception.CatalogExceptionMessage.readOnlyAttribute;
|
||||||
import static org.openmetadata.catalog.util.TestUtils.LONG_ENTITY_NAME;
|
import static org.openmetadata.catalog.util.TestUtils.LONG_ENTITY_NAME;
|
||||||
@ -588,7 +584,7 @@ public class TaskResourceTest extends CatalogApplicationTest {
|
|||||||
assertEquals(expectedService.getId(), task.getService().getId());
|
assertEquals(expectedService.getId(), task.getService().getId());
|
||||||
assertEquals(expectedService.getType(), task.getService().getType());
|
assertEquals(expectedService.getType(), task.getService().getType());
|
||||||
}
|
}
|
||||||
validateTags(expectedTags, task.getTags());
|
TestUtils.validateTags(expectedTags, task.getTags());
|
||||||
return task;
|
return task;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -690,29 +686,9 @@ public class TaskResourceTest extends CatalogApplicationTest {
|
|||||||
.withTaskUrl(new URI("http://localhost:0"));
|
.withTaskUrl(new URI("http://localhost:0"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void validateTags(List<TagLabel> expectedList, List<TagLabel> actualList)
|
|
||||||
throws HttpResponseException {
|
|
||||||
if (expectedList == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// When tags from the expected list is added to an entity, the derived tags for those tags are automatically added
|
|
||||||
// So add to the expectedList, the derived tags before validating the tags
|
|
||||||
List<TagLabel> updatedExpectedList = new ArrayList<>(expectedList);
|
|
||||||
for (TagLabel expected : expectedList) {
|
|
||||||
List<TagLabel> derived = EntityUtil.getDerivedTags(expected, TagResourceTest.getTag(expected.getTagFQN(),
|
|
||||||
adminAuthHeaders()));
|
|
||||||
updatedExpectedList.addAll(derived);
|
|
||||||
}
|
|
||||||
updatedExpectedList = updatedExpectedList.stream().distinct().collect(Collectors.toList());
|
|
||||||
|
|
||||||
assertTrue(actualList.containsAll(updatedExpectedList));
|
|
||||||
assertTrue(updatedExpectedList.containsAll(actualList));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static PipelineService createService(CreatePipelineService create,
|
public static PipelineService createService(CreatePipelineService create,
|
||||||
Map<String, String> authHeaders) throws HttpResponseException {
|
Map<String, String> authHeaders) throws HttpResponseException {
|
||||||
return TestUtils.post(CatalogApplicationTest.getResource("services/pipelineServices"),
|
return TestUtils.post(CatalogApplicationTest.getResource("services/pipelineServices"),
|
||||||
create, PipelineService.class, authHeaders);
|
create, PipelineService.class, authHeaders);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,6 @@ import org.openmetadata.catalog.entity.teams.Team;
|
|||||||
import org.openmetadata.catalog.entity.teams.User;
|
import org.openmetadata.catalog.entity.teams.User;
|
||||||
import org.openmetadata.catalog.exception.CatalogExceptionMessage;
|
import org.openmetadata.catalog.exception.CatalogExceptionMessage;
|
||||||
import org.openmetadata.catalog.resources.services.MessagingServiceResourceTest;
|
import org.openmetadata.catalog.resources.services.MessagingServiceResourceTest;
|
||||||
import org.openmetadata.catalog.resources.tags.TagResourceTest;
|
|
||||||
import org.openmetadata.catalog.resources.teams.TeamResourceTest;
|
import org.openmetadata.catalog.resources.teams.TeamResourceTest;
|
||||||
import org.openmetadata.catalog.resources.teams.UserResourceTest;
|
import org.openmetadata.catalog.resources.teams.UserResourceTest;
|
||||||
import org.openmetadata.catalog.resources.topics.TopicResource.TopicList;
|
import org.openmetadata.catalog.resources.topics.TopicResource.TopicList;
|
||||||
@ -48,13 +47,10 @@ import org.slf4j.LoggerFactory;
|
|||||||
import javax.json.JsonPatch;
|
import javax.json.JsonPatch;
|
||||||
import javax.ws.rs.client.WebTarget;
|
import javax.ws.rs.client.WebTarget;
|
||||||
import javax.ws.rs.core.Response.Status;
|
import javax.ws.rs.core.Response.Status;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import static java.util.Collections.singletonList;
|
|
||||||
import static javax.ws.rs.core.Response.Status.BAD_REQUEST;
|
import static javax.ws.rs.core.Response.Status.BAD_REQUEST;
|
||||||
import static javax.ws.rs.core.Response.Status.CONFLICT;
|
import static javax.ws.rs.core.Response.Status.CONFLICT;
|
||||||
import static javax.ws.rs.core.Response.Status.CREATED;
|
import static javax.ws.rs.core.Response.Status.CREATED;
|
||||||
@ -85,7 +81,6 @@ public class TopicResourceTest extends CatalogApplicationTest {
|
|||||||
public static EntityReference TEAM_OWNER1;
|
public static EntityReference TEAM_OWNER1;
|
||||||
public static EntityReference KAFKA_REFERENCE;
|
public static EntityReference KAFKA_REFERENCE;
|
||||||
public static EntityReference PULSAR_REFERENCE;
|
public static EntityReference PULSAR_REFERENCE;
|
||||||
public static final TagLabel USER_ADDRESS_TAG_LABEL = new TagLabel().withTagFQN("User.Address");
|
|
||||||
public static final TagLabel TIER1_TAG_LABEL = new TagLabel().withTagFQN("Tier.Tier1");
|
public static final TagLabel TIER1_TAG_LABEL = new TagLabel().withTagFQN("Tier.Tier1");
|
||||||
public static final TagLabel TIER2_TAG_LABEL = new TagLabel().withTagFQN("Tier.Tier2");
|
public static final TagLabel TIER2_TAG_LABEL = new TagLabel().withTagFQN("Tier.Tier2");
|
||||||
|
|
||||||
@ -624,7 +619,7 @@ public class TopicResourceTest extends CatalogApplicationTest {
|
|||||||
assertEquals(expectedService.getId(), topic.getService().getId());
|
assertEquals(expectedService.getId(), topic.getService().getId());
|
||||||
assertEquals(expectedService.getType(), topic.getService().getType());
|
assertEquals(expectedService.getType(), topic.getService().getType());
|
||||||
}
|
}
|
||||||
validateTags(expectedTags, topic.getTags());
|
TestUtils.validateTags(expectedTags, topic.getTags());
|
||||||
return topic;
|
return topic;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -789,24 +784,4 @@ public class TopicResourceTest extends CatalogApplicationTest {
|
|||||||
checkUserFollowing(userId, topicId, false, authHeaders);
|
checkUserFollowing(userId, topicId, false, authHeaders);
|
||||||
return getTopic;
|
return getTopic;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void validateTags(List<TagLabel> expectedList, List<TagLabel> actualList)
|
|
||||||
throws HttpResponseException {
|
|
||||||
if (expectedList == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// When tags from the expected list is added to an entity, the derived tags for those tags are automatically added
|
|
||||||
// So add to the expectedList, the derived tags before validating the tags
|
|
||||||
List<TagLabel> updatedExpectedList = new ArrayList<>(expectedList);
|
|
||||||
for (TagLabel expected : expectedList) {
|
|
||||||
List<TagLabel> derived = EntityUtil.getDerivedTags(expected, TagResourceTest.getTag(expected.getTagFQN(),
|
|
||||||
adminAuthHeaders()));
|
|
||||||
updatedExpectedList.addAll(derived);
|
|
||||||
}
|
|
||||||
updatedExpectedList = updatedExpectedList.stream().distinct().collect(Collectors.toList());
|
|
||||||
|
|
||||||
assertTrue(actualList.containsAll(updatedExpectedList));
|
|
||||||
assertTrue(updatedExpectedList.containsAll(actualList));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,11 +16,14 @@
|
|||||||
|
|
||||||
package org.openmetadata.catalog.util;
|
package org.openmetadata.catalog.util;
|
||||||
|
|
||||||
|
import org.openmetadata.catalog.resources.databases.TableResourceTest.TagLabelComparator;
|
||||||
|
import org.openmetadata.catalog.resources.tags.TagResourceTest;
|
||||||
import org.openmetadata.catalog.security.CatalogOpenIdAuthorizationRequestFilter;
|
import org.openmetadata.catalog.security.CatalogOpenIdAuthorizationRequestFilter;
|
||||||
import org.openmetadata.catalog.type.EntityReference;
|
import org.openmetadata.catalog.type.EntityReference;
|
||||||
import org.openmetadata.catalog.type.JdbcInfo;
|
import org.openmetadata.catalog.type.JdbcInfo;
|
||||||
import org.apache.http.client.HttpResponseException;
|
import org.apache.http.client.HttpResponseException;
|
||||||
import org.eclipse.jetty.http.HttpStatus;
|
import org.eclipse.jetty.http.HttpStatus;
|
||||||
|
import org.openmetadata.catalog.type.TagLabel;
|
||||||
|
|
||||||
import javax.json.JsonObject;
|
import javax.json.JsonObject;
|
||||||
import javax.json.JsonPatch;
|
import javax.json.JsonPatch;
|
||||||
@ -32,12 +35,14 @@ import javax.ws.rs.core.Response;
|
|||||||
import javax.ws.rs.core.Response.Status;
|
import javax.ws.rs.core.Response.Status;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
@ -210,6 +215,29 @@ public final class TestUtils {
|
|||||||
return headers;
|
return headers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void validateTags(List<TagLabel> expectedList, List<TagLabel> actualList)
|
||||||
|
throws HttpResponseException {
|
||||||
|
if (expectedList == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// When tags from the expected list is added to an entity, the derived tags for those tags are automatically added
|
||||||
|
// So add to the expectedList, the derived tags before validating the tags
|
||||||
|
List<TagLabel> updatedExpectedList = new ArrayList<>(expectedList);
|
||||||
|
for (TagLabel expected : expectedList) {
|
||||||
|
List<TagLabel> derived = EntityUtil.getDerivedTags(expected, TagResourceTest.getTag(expected.getTagFQN(),
|
||||||
|
adminAuthHeaders()));
|
||||||
|
updatedExpectedList.addAll(derived);
|
||||||
|
}
|
||||||
|
updatedExpectedList = updatedExpectedList.stream().distinct().collect(Collectors.toList());
|
||||||
|
updatedExpectedList.sort(new TagLabelComparator());
|
||||||
|
actualList.sort(new TagLabelComparator());
|
||||||
|
|
||||||
|
assertEquals(updatedExpectedList.size(), actualList.size());
|
||||||
|
for (int i = 0; i < actualList.size(); i++) {
|
||||||
|
assertEquals(updatedExpectedList.get(i), actualList.get(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static Map<String, String> adminAuthHeaders() {
|
public static Map<String, String> adminAuthHeaders() {
|
||||||
return authHeaders("admin@open-metadata.org");
|
return authHeaders("admin@open-metadata.org");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user