From eeecde352415bc3e7f4fab402bd9e63d2b36e1ce Mon Sep 17 00:00:00 2001 From: Suresh Srinivas Date: Sun, 23 Jan 2022 11:48:53 -0800 Subject: [PATCH] Fixes #2361 - Move DELETE related and DELETE + PUT tests to common class (#2362) --- .../catalog/jdbi3/EntityRepository.java | 22 +++++-- .../catalog/jdbi3/RoleRepository.java | 11 +--- .../catalog/jdbi3/TeamRepository.java | 5 -- .../catalog/jdbi3/UserRepository.java | 5 -- .../resources/charts/ChartResource.java | 1 + .../dashboards/DashboardResource.java | 1 + .../resources/databases/DatabaseResource.java | 1 + .../resources/events/WebhookResource.java | 1 + .../operations/AirflowPipelineResource.java | 1 + .../resources/pipelines/PipelineResource.java | 1 + .../resources/policies/PolicyResource.java | 1 + .../resources/topics/TopicResource.java | 1 + .../catalog/resources/EntityResourceTest.java | 54 +++++++++++++++++- .../resources/charts/ChartResourceTest.java | 32 ----------- .../dashboards/DashboardResourceTest.java | 29 ---------- .../databases/DatabaseResourceTest.java | 32 ----------- .../databases/TableResourceTest.java | 37 ------------ .../locations/LocationResourceTest.java | 40 ------------- .../mlmodels/MlModelResourceTest.java | 28 --------- .../AirflowPipelineResourceTest.java | 6 -- .../pipelines/PipelineResourceTest.java | 29 ---------- .../policies/PolicyResourceTest.java | 29 ---------- .../DashboardServiceResourceTest.java | 55 ------------------ .../services/DatabaseServiceResourceTest.java | 42 -------------- .../MessagingServiceResourceTest.java | 55 ------------------ .../services/PipelineServiceResourceTest.java | 54 ------------------ .../services/StorageServiceResourceTest.java | 57 ------------------- .../resources/teams/RoleResourceTest.java | 50 +--------------- .../resources/teams/TeamResourceTest.java | 24 -------- .../resources/teams/UserResourceTest.java | 22 ------- .../resources/topics/TopicResourceTest.java | 30 ---------- 31 files changed, 81 insertions(+), 675 deletions(-) diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/EntityRepository.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/EntityRepository.java index 86625a8d120..f489478e301 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/EntityRepository.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/EntityRepository.java @@ -817,9 +817,17 @@ public abstract class EntityRepository { PATCH, SOFT_DELETE; - public boolean isPatch() { return this == PATCH; } - public boolean isPut() { return this == PUT; } - public boolean isDelete() { return this == SOFT_DELETE; } + public boolean isPatch() { + return this == PATCH; + } + + public boolean isPut() { + return this == PUT; + } + + public boolean isDelete() { + return this == SOFT_DELETE; + } } /** @@ -877,12 +885,16 @@ public abstract class EntityRepository { } private void updateDeleted() throws JsonProcessingException { - if (operation.isPut() || operation.isPut()) { + if (operation.isPut() || operation.isPatch()) { + // Update operation can't set delete attributed to true. This can only be done as part of delete operation + if (updated.isDeleted() != original.isDeleted() && Boolean.TRUE.equals(updated.isDeleted())) { + throw new IllegalArgumentException(CatalogExceptionMessage.readOnlyAttribute(entityName, "deleted")); + } + // PUT or PATCH is restoring the soft-deleted entity if (Boolean.TRUE.equals(original.isDeleted())) { updated.setDeleted(false); recordChange("deleted", true, false); } - // TODO check if deleted flag is being set and throw exception } else { recordChange("deleted", original.isDeleted(), updated.isDeleted()); } diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/RoleRepository.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/RoleRepository.java index 236fcac2ad0..306938adb5e 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/RoleRepository.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/RoleRepository.java @@ -28,7 +28,6 @@ import org.jdbi.v3.sqlobject.transaction.Transaction; import org.openmetadata.catalog.Entity; import org.openmetadata.catalog.entity.policies.Policy; import org.openmetadata.catalog.entity.teams.Role; -import org.openmetadata.catalog.exception.CatalogExceptionMessage; import org.openmetadata.catalog.exception.EntityNotFoundException; import org.openmetadata.catalog.resources.teams.RoleResource; import org.openmetadata.catalog.type.ChangeDescription; @@ -164,7 +163,7 @@ public class RoleRepository extends EntityRepository { .withDeleted(false) .withUpdatedAt(role.getUpdatedAt()) .withUpdatedBy(role.getUpdatedBy()); - Entity.getEntityRepository(Entity.POLICY).storeEntity(policy, false); + Entity.getEntityRepository(Entity.POLICY).storeEntity(policy, update); } } @@ -309,13 +308,5 @@ public class RoleRepository extends EntityRepository { public RoleUpdater(Role original, Role updated, Operation operation) { super(original, updated, operation); } - - @Override - public void entitySpecificUpdate() throws IOException { - // Update operation cannot undelete a role. - if (updated.getEntity().getDeleted() != original.getEntity().getDeleted()) { - throw new IllegalArgumentException(CatalogExceptionMessage.readOnlyAttribute("Role", "deleted")); - } - } } } diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/TeamRepository.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/TeamRepository.java index e908ba7fdbf..ef86deb498c 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/TeamRepository.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/TeamRepository.java @@ -27,7 +27,6 @@ import java.util.Optional; import java.util.UUID; import org.openmetadata.catalog.Entity; import org.openmetadata.catalog.entity.teams.Team; -import org.openmetadata.catalog.exception.CatalogExceptionMessage; import org.openmetadata.catalog.resources.teams.TeamResource; import org.openmetadata.catalog.type.ChangeDescription; import org.openmetadata.catalog.type.EntityReference; @@ -267,10 +266,6 @@ public class TeamRepository extends EntityRepository { @Override public void entitySpecificUpdate() throws IOException { - // Update operation can't undelete a user - if (updated.getEntity().getDeleted() != original.getEntity().getDeleted()) { - throw new IllegalArgumentException(CatalogExceptionMessage.readOnlyAttribute("Team", "deleted")); - } recordChange("profile", original.getEntity().getProfile(), updated.getEntity().getProfile()); updateUsers(original.getEntity(), updated.getEntity()); } diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/UserRepository.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/UserRepository.java index cb623f0d42d..cfb24731402 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/UserRepository.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/UserRepository.java @@ -32,7 +32,6 @@ import lombok.extern.slf4j.Slf4j; import org.jdbi.v3.sqlobject.transaction.Transaction; import org.openmetadata.catalog.Entity; import org.openmetadata.catalog.entity.teams.User; -import org.openmetadata.catalog.exception.CatalogExceptionMessage; import org.openmetadata.catalog.resources.teams.UserResource; import org.openmetadata.catalog.type.ChangeDescription; import org.openmetadata.catalog.type.EntityReference; @@ -324,10 +323,6 @@ public class UserRepository extends EntityRepository { @Override public void entitySpecificUpdate() throws IOException { - // Update operation can't undelete a user - if (updated.getEntity().getDeleted() != original.getEntity().getDeleted()) { - throw new IllegalArgumentException(CatalogExceptionMessage.readOnlyAttribute("User", "deactivated")); - } updateRoles(original.getEntity(), updated.getEntity()); updateTeams(original.getEntity(), updated.getEntity()); recordChange("profile", original.getEntity().getProfile(), updated.getEntity().getProfile(), true); diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/resources/charts/ChartResource.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/resources/charts/ChartResource.java index fa2d858a380..696c476bf27 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/resources/charts/ChartResource.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/resources/charts/ChartResource.java @@ -409,6 +409,7 @@ public class ChartResource { }) public Response delete(@Context UriInfo uriInfo, @Context SecurityContext securityContext, @PathParam("id") String id) throws IOException { + SecurityUtil.checkAdminOrBotRole(authorizer, securityContext); DeleteResponse response = dao.delete(securityContext.getUserPrincipal().getName(), id); return response.toResponse(); } diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/resources/dashboards/DashboardResource.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/resources/dashboards/DashboardResource.java index 8ad0b9279cb..542aef18ab9 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/resources/dashboards/DashboardResource.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/resources/dashboards/DashboardResource.java @@ -417,6 +417,7 @@ public class DashboardResource { }) public Response delete(@Context UriInfo uriInfo, @Context SecurityContext securityContext, @PathParam("id") String id) throws IOException { + SecurityUtil.checkAdminOrBotRole(authorizer, securityContext); DeleteResponse response = dao.delete(securityContext.getUserPrincipal().getName(), id); return response.toResponse(); } diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/resources/databases/DatabaseResource.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/resources/databases/DatabaseResource.java index fbf45c0b50b..c3921d5ce85 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/resources/databases/DatabaseResource.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/resources/databases/DatabaseResource.java @@ -408,6 +408,7 @@ public class DatabaseResource { boolean recursive, @PathParam("id") String id) throws IOException { + SecurityUtil.checkAdminOrBotRole(authorizer, securityContext); DeleteResponse response = dao.delete(securityContext.getUserPrincipal().getName(), id, recursive); return response.toResponse(); } diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/resources/events/WebhookResource.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/resources/events/WebhookResource.java index 283e1067d56..b3c4cba2e19 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/resources/events/WebhookResource.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/resources/events/WebhookResource.java @@ -302,6 +302,7 @@ public class WebhookResource { @Context SecurityContext securityContext, @Parameter(description = "webhook Id", schema = @Schema(type = "string")) @PathParam("id") String id) throws IOException, GeneralSecurityException, ParseException, InterruptedException { + SecurityUtil.checkAdminOrBotRole(authorizer, securityContext); DeleteResponse response = dao.delete(securityContext.getUserPrincipal().getName(), id); dao.deleteWebhookPublisher(UUID.fromString(id)); return response.toResponse(); diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/resources/operations/AirflowPipelineResource.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/resources/operations/AirflowPipelineResource.java index 2cf42687d84..4ebfa6bf624 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/resources/operations/AirflowPipelineResource.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/resources/operations/AirflowPipelineResource.java @@ -432,6 +432,7 @@ public class AirflowPipelineResource { }) public Response delete(@Context UriInfo uriInfo, @Context SecurityContext securityContext, @PathParam("id") String id) throws IOException { + SecurityUtil.checkAdminOrBotRole(authorizer, securityContext); DeleteResponse response = dao.delete(securityContext.getUserPrincipal().getName(), id); return response.toResponse(); } diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/resources/pipelines/PipelineResource.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/resources/pipelines/PipelineResource.java index 79ea7122b4c..d1f5328c8a3 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/resources/pipelines/PipelineResource.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/resources/pipelines/PipelineResource.java @@ -416,6 +416,7 @@ public class PipelineResource { }) public Response delete(@Context UriInfo uriInfo, @Context SecurityContext securityContext, @PathParam("id") String id) throws IOException { + SecurityUtil.checkAdminOrBotRole(authorizer, securityContext); DeleteResponse response = dao.delete(securityContext.getUserPrincipal().getName(), id); return response.toResponse(); } diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/resources/policies/PolicyResource.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/resources/policies/PolicyResource.java index f4361d2aa4c..1cc8d74c0e3 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/resources/policies/PolicyResource.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/resources/policies/PolicyResource.java @@ -377,6 +377,7 @@ public class PolicyResource { }) public Response delete(@Context UriInfo uriInfo, @Context SecurityContext securityContext, @PathParam("id") String id) throws IOException { + SecurityUtil.checkAdminOrBotRole(authorizer, securityContext); DeleteResponse response = dao.delete(securityContext.getUserPrincipal().getName(), id); return response.toResponse(); } diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/resources/topics/TopicResource.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/resources/topics/TopicResource.java index 91281ad59f4..f7cec1f7851 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/resources/topics/TopicResource.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/resources/topics/TopicResource.java @@ -413,6 +413,7 @@ public class TopicResource { }) public Response delete(@Context UriInfo uriInfo, @Context SecurityContext securityContext, @PathParam("id") String id) throws IOException { + SecurityUtil.checkAdminOrBotRole(authorizer, securityContext); DeleteResponse response = dao.delete(securityContext.getUserPrincipal().getName(), id); return response.toResponse(); } diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/EntityResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/EntityResourceTest.java index 9b786c1c8c0..f0d79fc40e3 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/EntityResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/EntityResourceTest.java @@ -61,6 +61,7 @@ import java.util.function.BiConsumer; import java.util.function.Predicate; import javax.json.JsonPatch; import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; import lombok.extern.slf4j.Slf4j; import org.apache.http.client.HttpResponseException; @@ -889,7 +890,7 @@ public abstract class EntityResourceTest extends CatalogApplicationTest { if (!supportsPatch) { return; } - // Create chart without description, owner + // Create entity without description, owner T entity = createEntity(createRequest(getEntityName(test), null, null, null), adminAuthHeaders()); EntityInterface entityInterface = getEntityInterface(entity); assertListNull(entityInterface.getDescription(), entityInterface.getOwner()); @@ -983,6 +984,23 @@ public abstract class EntityResourceTest extends CatalogApplicationTest { patchEntityAndCheck(entity, origJson, adminAuthHeaders(), MINOR_UPDATE, change); } + @Test + void patch_deleted_attribute_disallowed_400(TestInfo test) + throws HttpResponseException, JsonProcessingException, URISyntaxException { + if (!supportsPatch) { + return; + } + // `deleted` attribute can't be set to true in PATCH operation & can only be done using DELETE operation + T entity = createEntity(createRequest(getEntityName(test), "", "", null), adminAuthHeaders()); + EntityInterface entityInterface = getEntityInterface(entity); + String json = JsonUtils.pojoToJson(entity); + entityInterface.setDeleted(true); + HttpResponseException exception = + assertThrows( + HttpResponseException.class, () -> patchEntity(entityInterface.getId(), json, entity, adminAuthHeaders())); + assertResponse(exception, BAD_REQUEST, CatalogExceptionMessage.readOnlyAttribute(entityName, "deleted")); + } + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Common entity tests for DELETE operations /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -993,6 +1011,40 @@ public abstract class EntityResourceTest extends CatalogApplicationTest { assertResponse(exception, NOT_FOUND, entityNotFound(entityName, NON_EXISTENT_ENTITY)); } + @Test + void delete_entity_as_admin_200(TestInfo test) throws IOException, URISyntaxException { + Object request = createRequest(getEntityName(test), "", "", null); + T entity = createEntity(request, adminAuthHeaders()); + deleteAndCheckEntity(entity, adminAuthHeaders()); + } + + @Test + void delete_entity_as_non_admin_401(TestInfo test) throws HttpResponseException, URISyntaxException { + Object request = createRequest(getEntityName(test), "", "", null); + T entity = createEntity(request, adminAuthHeaders()); + HttpResponseException exception = + assertThrows( + HttpResponseException.class, () -> deleteAndCheckEntity(entity, authHeaders("test@open-metadata.org"))); + assertResponse(exception, FORBIDDEN, "Principal: CatalogPrincipal{name='test'} is not admin"); + } + + /** Soft delete an entity and then use PUT request to restore it back */ + @Test + void delete_put_entity_200(TestInfo test) throws IOException, URISyntaxException { + Object request = createRequest(getEntityName(test), "", "", null); + T entity = createEntity(request, adminAuthHeaders()); + EntityInterface entityInterface = getEntityInterface(entity); + + // Soft delete the entity + deleteAndCheckEntity(entity, adminAuthHeaders()); + Double version = EntityUtil.nextVersion(entityInterface.getVersion()); // Version changes during soft-delete + + // Send PUT request (with no changes) to restore the entity from soft deleted state + ChangeDescription change = getChangeDescription(version); + change.getFieldsUpdated().add(new FieldChange().withName("deleted").withNewValue(false).withOldValue(true)); + updateAndCheckEntity(request, Response.Status.OK, adminAuthHeaders(), MINOR_UPDATE, change); + } + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Other tests /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/charts/ChartResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/charts/ChartResourceTest.java index e2239590c93..45a94bddbaf 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/charts/ChartResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/charts/ChartResourceTest.java @@ -18,7 +18,6 @@ import static javax.ws.rs.core.Response.Status.FORBIDDEN; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.openmetadata.catalog.security.SecurityUtil.authHeaders; -import static org.openmetadata.catalog.util.TestUtils.UpdateType.MINOR_UPDATE; import static org.openmetadata.catalog.util.TestUtils.adminAuthHeaders; import static org.openmetadata.catalog.util.TestUtils.assertListNotNull; import static org.openmetadata.catalog.util.TestUtils.assertResponse; @@ -26,10 +25,8 @@ import static org.openmetadata.catalog.util.TestUtils.assertResponse; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; -import java.util.Arrays; import java.util.HashMap; import java.util.Map; -import javax.ws.rs.core.Response; import lombok.extern.slf4j.Slf4j; import org.apache.http.client.HttpResponseException; import org.junit.jupiter.api.BeforeAll; @@ -46,12 +43,9 @@ import org.openmetadata.catalog.jdbi3.DashboardServiceRepository.DashboardServic import org.openmetadata.catalog.resources.EntityResourceTest; import org.openmetadata.catalog.resources.charts.ChartResource.ChartList; import org.openmetadata.catalog.resources.services.DashboardServiceResourceTest; -import org.openmetadata.catalog.type.ChangeDescription; import org.openmetadata.catalog.type.ChartType; 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.ResultList; import org.openmetadata.catalog.util.TestUtils; @@ -149,37 +143,11 @@ public class ChartResourceTest extends EntityResourceTest { } } - @Test - void delete_emptyChart_200_ok(TestInfo test) throws IOException { - Chart chart = createEntity(create(test), adminAuthHeaders()); - deleteAndCheckEntity(chart, adminAuthHeaders()); - } - @Test void delete_nonEmptyChart_4xx() { // TODO } - @Test - void delete_put_Chart_200(TestInfo test) throws IOException { - CreateChart request = create(test).withDescription(""); - Chart chart = createEntity(request, adminAuthHeaders()); - - // Delete - deleteAndCheckEntity(chart, adminAuthHeaders()); - - Double version = EntityUtil.nextVersion(chart.getVersion()); // Account for the version change during delete - ChangeDescription change = getChangeDescription(version); - change.setFieldsUpdated( - Arrays.asList( - new FieldChange().withName("deleted").withNewValue(false).withOldValue(true), - new FieldChange().withName("description").withNewValue("updatedDescription").withOldValue(""))); - - // PUT with updated description - updateAndCheckEntity( - request.withDescription("updatedDescription"), Response.Status.OK, adminAuthHeaders(), MINOR_UPDATE, change); - } - /** Validate returned fields GET .../charts/{id}?fields="..." or GET .../charts/name/{fqn}?fields="..." */ @Override public void validateGetWithDifferentFields(Chart chart, boolean byName) throws HttpResponseException { diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/dashboards/DashboardResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/dashboards/DashboardResourceTest.java index 41afabec5d7..430607d205d 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/dashboards/DashboardResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/dashboards/DashboardResourceTest.java @@ -32,13 +32,11 @@ import static org.openmetadata.catalog.util.TestUtils.assertResponse; import java.io.IOException; import java.net.URISyntaxException; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; import java.util.stream.Collectors; -import javax.ws.rs.core.Response; import lombok.extern.slf4j.Slf4j; import org.apache.http.client.HttpResponseException; import org.junit.jupiter.api.BeforeAll; @@ -63,7 +61,6 @@ 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.JsonUtils; import org.openmetadata.catalog.util.ResultList; import org.openmetadata.catalog.util.TestUtils; @@ -230,37 +227,11 @@ public class DashboardResourceTest extends EntityResourceTest { updateAndCheckEntity(request.withCharts(CHART_REFERENCES), OK, adminAuthHeaders(), MINOR_UPDATE, change); } - @Test - void delete_emptyDashboard_200_ok(TestInfo test) throws IOException { - Dashboard dashboard = createDashboard(create(test), adminAuthHeaders()); - deleteAndCheckEntity(dashboard, adminAuthHeaders()); - } - @Test void delete_nonEmptyDashboard_4xx() { // TODO } - @Test - void delete_put_Dashboard_200(TestInfo test) throws IOException { - CreateDashboard request = create(test).withDescription(""); - Dashboard dashboard = createEntity(request, adminAuthHeaders()); - - // Delete - deleteAndCheckEntity(dashboard, adminAuthHeaders()); - - Double version = EntityUtil.nextVersion(dashboard.getVersion()); // Account for the version change during delete - ChangeDescription change = getChangeDescription(version); - change.setFieldsUpdated( - Arrays.asList( - new FieldChange().withName("deleted").withNewValue(false).withOldValue(true), - new FieldChange().withName("description").withNewValue("updatedDescription").withOldValue(""))); - - // PUT with updated description - updateAndCheckEntity( - request.withDescription("updatedDescription"), Response.Status.OK, adminAuthHeaders(), MINOR_UPDATE, change); - } - public Dashboard createDashboard(CreateDashboard create, Map authHeaders) throws HttpResponseException { return TestUtils.post(getResource("dashboards"), create, Dashboard.class, authHeaders); diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/databases/DatabaseResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/databases/DatabaseResourceTest.java index 3ae23f8d0ff..6fe43a82a4b 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/databases/DatabaseResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/databases/DatabaseResourceTest.java @@ -19,7 +19,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.openmetadata.catalog.security.SecurityUtil.authHeaders; -import static org.openmetadata.catalog.util.TestUtils.UpdateType.MINOR_UPDATE; import static org.openmetadata.catalog.util.TestUtils.adminAuthHeaders; import static org.openmetadata.catalog.util.TestUtils.assertListNotNull; import static org.openmetadata.catalog.util.TestUtils.assertListNull; @@ -27,10 +26,8 @@ import static org.openmetadata.catalog.util.TestUtils.assertResponse; import java.io.IOException; import java.net.URISyntaxException; -import java.util.Arrays; import java.util.HashMap; import java.util.Map; -import javax.ws.rs.core.Response; import lombok.extern.slf4j.Slf4j; import org.apache.http.client.HttpResponseException; import org.junit.jupiter.api.BeforeAll; @@ -43,11 +40,8 @@ import org.openmetadata.catalog.entity.data.Database; import org.openmetadata.catalog.jdbi3.DatabaseRepository.DatabaseEntityInterface; import org.openmetadata.catalog.resources.EntityResourceTest; import org.openmetadata.catalog.resources.databases.DatabaseResource.DatabaseList; -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.ResultList; import org.openmetadata.catalog.util.TestUtils; @@ -142,32 +136,6 @@ public class DatabaseResourceTest extends EntityResourceTest { } } - @Test - void delete_emptyDatabase_200_ok(TestInfo test) throws IOException { - Database database = createDatabase(create(test), adminAuthHeaders()); - deleteAndCheckEntity(database, adminAuthHeaders()); - } - - @Test - void delete_put_Database_200(TestInfo test) throws IOException { - CreateDatabase request = create(test).withService(MYSQL_REFERENCE).withDescription(""); - Database database = createEntity(request, adminAuthHeaders()); - - // Delete - deleteAndCheckEntity(database, adminAuthHeaders()); - - Double version = EntityUtil.nextVersion(database.getVersion()); // Account for the version change during delete - ChangeDescription change = getChangeDescription(version); - change.setFieldsUpdated( - Arrays.asList( - new FieldChange().withName("deleted").withNewValue(false).withOldValue(true), - new FieldChange().withName("description").withNewValue("updatedDescription").withOldValue(""))); - - // PUT with updated description - updateAndCheckEntity( - request.withDescription("updatedDescription"), Response.Status.OK, adminAuthHeaders(), MINOR_UPDATE, change); - } - @Test void delete_nonEmptyDatabase_4xx() { // TODO diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/databases/TableResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/databases/TableResourceTest.java index f656cb50337..0a9fa015140 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/databases/TableResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/databases/TableResourceTest.java @@ -59,7 +59,6 @@ import java.util.Locale; import java.util.Map; import java.util.UUID; import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; import lombok.extern.slf4j.Slf4j; import org.apache.http.client.HttpResponseException; @@ -105,7 +104,6 @@ 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.EntityUtil; import org.openmetadata.catalog.util.EntityUtil.Fields; import org.openmetadata.catalog.util.JsonUtils; import org.openmetadata.catalog.util.RestUtil; @@ -1052,41 +1050,6 @@ public class TableResourceTest extends EntityResourceTest { assertFields(tableList1.getData(), fields1); } - @Test - void delete_table_200_ok(TestInfo test) throws IOException { - Table table = createEntity(create(test), adminAuthHeaders()); - deleteAndCheckEntity(table, adminAuthHeaders()); - } - - @Test - void delete_put_Table_200(TestInfo test) throws IOException { - CreateTable request = create(test).withDatabase(DATABASE.getId()).withDescription(""); - Table table = createEntity(request, adminAuthHeaders()); - - // Delete - deleteAndCheckEntity(table, adminAuthHeaders()); - - Double version = EntityUtil.nextVersion(table.getVersion()); // Account for the version change during delete - ChangeDescription change = getChangeDescription(version); - change.setFieldsUpdated( - Arrays.asList( - new FieldChange().withName("deleted").withNewValue(false).withOldValue(true), - new FieldChange().withName("description").withNewValue("updatedDescription").withOldValue(""))); - - // PUT with updated description - updateAndCheckEntity( - request.withDescription("updatedDescription"), Response.Status.OK, adminAuthHeaders(), MINOR_UPDATE, change); - } - - @Test - void delete_table_as_non_admin_401(TestInfo test) throws HttpResponseException { - Table table = createEntity(create(test), adminAuthHeaders()); - HttpResponseException exception = - assertThrows( - HttpResponseException.class, () -> deleteAndCheckEntity(table, authHeaders("test@open-metadata.org"))); - assertResponse(exception, FORBIDDEN, "Principal: CatalogPrincipal{name='test'} is not admin"); - } - /** * See EntityResourceTest#patch_entityAttributes_200_ok(TestInfo) for other patch related tests for patching display, * description, owner, and tags diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/locations/LocationResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/locations/LocationResourceTest.java index a0e708742e1..d7a00d33b38 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/locations/LocationResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/locations/LocationResourceTest.java @@ -19,7 +19,6 @@ import static javax.ws.rs.core.Response.Status.OK; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.openmetadata.catalog.security.SecurityUtil.authHeaders; -import static org.openmetadata.catalog.util.TestUtils.UpdateType.MINOR_UPDATE; import static org.openmetadata.catalog.util.TestUtils.adminAuthHeaders; import static org.openmetadata.catalog.util.TestUtils.assertListNotNull; import static org.openmetadata.catalog.util.TestUtils.assertResponse; @@ -33,7 +32,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; import lombok.extern.slf4j.Slf4j; import org.apache.http.client.HttpResponseException; @@ -46,11 +44,8 @@ import org.openmetadata.catalog.entity.data.Location; import org.openmetadata.catalog.jdbi3.LocationRepository.LocationEntityInterface; import org.openmetadata.catalog.resources.EntityResourceTest; import org.openmetadata.catalog.resources.locations.LocationResource.LocationList; -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.ResultList; import org.openmetadata.catalog.util.TestUtils; @@ -198,41 +193,6 @@ public class LocationResourceTest extends EntityResourceTest { assertResponse(exception, FORBIDDEN, "Principal: CatalogPrincipal{name='test'} is not admin"); } - @Test - void delete_location_200_ok(TestInfo test) throws IOException { - Location location = createLocation(create(test), adminAuthHeaders()); - deleteAndCheckEntity(location, adminAuthHeaders()); - } - - @Test - void delete_put_Location_200(TestInfo test) throws IOException { - CreateLocation request = create(test).withDescription(""); - Location location = createEntity(request, adminAuthHeaders()); - - // Delete - deleteAndCheckEntity(location, adminAuthHeaders()); - - Double version = EntityUtil.nextVersion(location.getVersion()); // Account for the version change during delete - ChangeDescription change = getChangeDescription(version); - change.setFieldsUpdated( - Arrays.asList( - new FieldChange().withName("deleted").withNewValue(false).withOldValue(true), - new FieldChange().withName("description").withNewValue("updatedDescription").withOldValue(""))); - - // PUT with updated description - updateAndCheckEntity( - request.withDescription("updatedDescription"), Response.Status.OK, adminAuthHeaders(), MINOR_UPDATE, change); - } - - @Test - void delete_location_as_non_admin_401(TestInfo test) throws HttpResponseException { - Location location = createLocation(create(test), adminAuthHeaders()); - HttpResponseException exception = - assertThrows( - HttpResponseException.class, () -> deleteEntity(location.getId(), authHeaders("test@open-metadata.org"))); - assertResponse(exception, FORBIDDEN, "Principal: CatalogPrincipal{name='test'} is not admin"); - } - @Test void post_locationWithoutRequiredFields_4xx(TestInfo test) { HttpResponseException exception = diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/mlmodels/MlModelResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/mlmodels/MlModelResourceTest.java index 37227df092f..2a1272b6505 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/mlmodels/MlModelResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/mlmodels/MlModelResourceTest.java @@ -74,7 +74,6 @@ import org.openmetadata.catalog.type.MlFeatureSource; import org.openmetadata.catalog.type.MlHyperParameter; import org.openmetadata.catalog.type.MlStore; import org.openmetadata.catalog.util.EntityInterface; -import org.openmetadata.catalog.util.EntityUtil; import org.openmetadata.catalog.util.JsonUtils; import org.openmetadata.catalog.util.TestUtils; @@ -402,33 +401,6 @@ public class MlModelResourceTest extends EntityResourceTest { updateAndCheckEntity(request.withTarget("newTarget"), Status.OK, adminAuthHeaders(), MAJOR_UPDATE, change); } - @Test - void delete_MlModel_200_ok(TestInfo test) throws IOException { - MlModel model = createMlModel(create(test), adminAuthHeaders()); - deleteAndCheckEntity(model, adminAuthHeaders()); - } - - @Test - void delete_put_MlModel_200(TestInfo test) throws IOException { - // Create with empty description - CreateMlModel request = create(test).withDescription(""); - MlModel model = createAndCheckEntity(request, adminAuthHeaders()); - - // Delete - deleteAndCheckEntity(model, adminAuthHeaders()); - - Double version = EntityUtil.nextVersion(model.getVersion()); // Account for the version change during delete - ChangeDescription change = getChangeDescription(version); - change.setFieldsUpdated( - Arrays.asList( - new FieldChange().withName("deleted").withNewValue(false).withOldValue(true), - new FieldChange().withName("description").withNewValue("updatedDescription").withOldValue(""))); - - // PUT with updated description and expect a MAJOR_UPDATE with updated description - updateAndCheckEntity( - request.withDescription("updatedDescription"), Status.OK, adminAuthHeaders(), MINOR_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 { diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/operations/AirflowPipelineResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/operations/AirflowPipelineResourceTest.java index 41a768883d6..68e596d6bcd 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/operations/AirflowPipelineResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/operations/AirflowPipelineResourceTest.java @@ -504,12 +504,6 @@ public class AirflowPipelineResourceTest extends EntityOperationsResourceTest { // updateAndCheckEntity(request.withTasks(TASKS), OK, adminAuthHeaders(), MINOR_UPDATE, change); } - @Test - void delete_emptyPipeline_200_ok(TestInfo test) throws IOException { - Pipeline pipeline = createPipeline(create(test), adminAuthHeaders()); - deleteAndCheckEntity(pipeline, adminAuthHeaders()); - } - @Test void delete_nonEmptyPipeline_4xx() { // TODO } - @Test - void delete_put_Pipeline_200(TestInfo test) throws IOException { - CreatePipeline request = create(test).withService(AIRFLOW_REFERENCE).withDescription(""); - Pipeline pipeline = createEntity(request, adminAuthHeaders()); - - // Delete - deleteAndCheckEntity(pipeline, adminAuthHeaders()); - - Double version = EntityUtil.nextVersion(pipeline.getVersion()); // Account for the version change during delete - ChangeDescription change = getChangeDescription(version); - change.setFieldsUpdated( - Arrays.asList( - new FieldChange().withName("deleted").withNewValue(false).withOldValue(true), - new FieldChange().withName("description").withNewValue("updatedDescription").withOldValue(""))); - - // PUT with updated description - updateAndCheckEntity( - request.withDescription("updatedDescription"), Response.Status.OK, adminAuthHeaders(), MINOR_UPDATE, change); - } - public static Pipeline updatePipeline(CreatePipeline create, Status status, Map authHeaders) throws HttpResponseException { return TestUtils.put(getResource("pipelines"), create, Pipeline.class, status, authHeaders); diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/policies/PolicyResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/policies/PolicyResourceTest.java index aa57bd2fb6c..413bf45ca5c 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/policies/PolicyResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/policies/PolicyResourceTest.java @@ -31,14 +31,12 @@ import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.util.ArrayList; -import java.util.Arrays; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.UUID; import java.util.stream.Collectors; import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.Response; import lombok.extern.slf4j.Slf4j; import org.apache.http.client.HttpResponseException; import org.junit.jupiter.api.BeforeAll; @@ -61,7 +59,6 @@ import org.openmetadata.catalog.type.FieldChange; import org.openmetadata.catalog.type.MetadataOperation; import org.openmetadata.catalog.type.PolicyType; import org.openmetadata.catalog.util.EntityInterface; -import org.openmetadata.catalog.util.EntityUtil; import org.openmetadata.catalog.util.JsonUtils; import org.openmetadata.catalog.util.PolicyUtils; import org.openmetadata.catalog.util.TestUtils; @@ -342,32 +339,6 @@ public class PolicyResourceTest extends EntityResourceTest { patchEntityAndCheck(policy, origJson, adminAuthHeaders(), MINOR_UPDATE, change); } - @Test - void delete_emptyPolicy_200_ok(TestInfo test) throws IOException { - Policy policy = createPolicy(create(test), adminAuthHeaders()); - deleteAndCheckEntity(policy, adminAuthHeaders()); - } - - @Test - void delete_put_Policy_200(TestInfo test) throws IOException { - CreatePolicy request = create(test).withDescription(""); - Policy policy = createEntity(request, adminAuthHeaders()); - - // Delete - deleteAndCheckEntity(policy, adminAuthHeaders()); - - Double version = EntityUtil.nextVersion(policy.getVersion()); // Account for the version change during delete - ChangeDescription change = getChangeDescription(version); - change.setFieldsUpdated( - Arrays.asList( - new FieldChange().withName("deleted").withNewValue(false).withOldValue(true), - new FieldChange().withName("description").withNewValue("updatedDescription").withOldValue(""))); - - // PUT with updated description - updateAndCheckEntity( - request.withDescription("updatedDescription"), Response.Status.OK, adminAuthHeaders(), MINOR_UPDATE, change); - } - @Test void delete_nonEmptyPolicy_4xx() { // TODO diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/services/DashboardServiceResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/services/DashboardServiceResourceTest.java index bda8f4df2c1..20a20557c85 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/services/DashboardServiceResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/services/DashboardServiceResourceTest.java @@ -15,22 +15,18 @@ package org.openmetadata.catalog.resources.services; import static javax.ws.rs.core.Response.Status.BAD_REQUEST; import static javax.ws.rs.core.Response.Status.FORBIDDEN; -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; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.openmetadata.catalog.security.SecurityUtil.authHeaders; -import static org.openmetadata.catalog.util.TestUtils.UpdateType.MINOR_UPDATE; import static org.openmetadata.catalog.util.TestUtils.adminAuthHeaders; import static org.openmetadata.catalog.util.TestUtils.getPrincipal; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; -import java.util.Arrays; import java.util.Date; import java.util.Map; -import javax.ws.rs.core.Response; import lombok.extern.slf4j.Slf4j; import org.apache.http.client.HttpResponseException; import org.junit.jupiter.api.Test; @@ -38,7 +34,6 @@ import org.junit.jupiter.api.TestInfo; import org.openmetadata.catalog.Entity; import org.openmetadata.catalog.api.services.CreateDashboardService; import org.openmetadata.catalog.entity.services.DashboardService; -import org.openmetadata.catalog.exception.CatalogExceptionMessage; import org.openmetadata.catalog.jdbi3.DashboardServiceRepository.DashboardServiceEntityInterface; import org.openmetadata.catalog.resources.EntityResourceTest; import org.openmetadata.catalog.resources.services.dashboard.DashboardServiceResource.DashboardServiceList; @@ -47,7 +42,6 @@ import org.openmetadata.catalog.type.EntityReference; import org.openmetadata.catalog.type.FieldChange; import org.openmetadata.catalog.type.Schedule; import org.openmetadata.catalog.util.EntityInterface; -import org.openmetadata.catalog.util.EntityUtil; import org.openmetadata.catalog.util.JsonUtils; import org.openmetadata.catalog.util.TestUtils; import org.openmetadata.catalog.util.TestUtils.UpdateType; @@ -222,55 +216,6 @@ public class DashboardServiceResourceTest extends EntityResourceTest authHeaders = adminAuthHeaders(); - DashboardService dashboardService = createEntity(create(test), authHeaders); - deleteAndCheckEntity(dashboardService, authHeaders); - } - - @Test - void delete_put_DashboardService_200(TestInfo test) throws IOException, URISyntaxException { - CreateDashboardService request = create(test).withDescription(""); - DashboardService dashboardService = createEntity(request, adminAuthHeaders()); - - // Delete - deleteAndCheckEntity(dashboardService, adminAuthHeaders()); - - Double version = - EntityUtil.nextVersion(dashboardService.getVersion()); // Account for the version change during delete - ChangeDescription change = getChangeDescription(version); - change.setFieldsUpdated( - Arrays.asList( - new FieldChange().withName("deleted").withNewValue(false).withOldValue(true), - new FieldChange().withName("description").withNewValue("updatedDescription").withOldValue(""))); - - // PUT with updated description - updateAndCheckEntity( - request.withDescription("updatedDescription"), Response.Status.OK, adminAuthHeaders(), MINOR_UPDATE, change); - } - - @Test - void delete_as_user_401(TestInfo test) throws HttpResponseException, URISyntaxException { - Map authHeaders = adminAuthHeaders(); - DashboardService dashboardService = createEntity(create(test), authHeaders); - HttpResponseException exception = - assertThrows( - HttpResponseException.class, - () -> deleteAndCheckEntity(dashboardService, authHeaders("test@open-metadata.org"))); - TestUtils.assertResponse(exception, FORBIDDEN, "Principal: CatalogPrincipal{name='test'} is not admin"); - } - - @Test - void delete_notExistentDashboardService() { - HttpResponseException exception = - assertThrows(HttpResponseException.class, () -> getEntity(TestUtils.NON_EXISTENT_ENTITY, adminAuthHeaders())); - TestUtils.assertResponse( - exception, - NOT_FOUND, - CatalogExceptionMessage.entityNotFound(Entity.DASHBOARD_SERVICE, TestUtils.NON_EXISTENT_ENTITY)); - } - private CreateDashboardService create(TestInfo test) throws URISyntaxException { return create(getEntityName(test)); } diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/services/DatabaseServiceResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/services/DatabaseServiceResourceTest.java index 6eb23a8d2a8..d93cdf5eac2 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/services/DatabaseServiceResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/services/DatabaseServiceResourceTest.java @@ -20,7 +20,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.openmetadata.catalog.Entity.helper; import static org.openmetadata.catalog.security.SecurityUtil.authHeaders; -import static org.openmetadata.catalog.util.TestUtils.UpdateType.MINOR_UPDATE; import static org.openmetadata.catalog.util.TestUtils.adminAuthHeaders; import static org.openmetadata.catalog.util.TestUtils.getPrincipal; @@ -29,7 +28,6 @@ import java.net.URISyntaxException; import java.text.ParseException; import java.util.Arrays; import java.util.Map; -import javax.ws.rs.core.Response; import lombok.extern.slf4j.Slf4j; import org.apache.http.client.HttpResponseException; import org.junit.jupiter.api.Test; @@ -55,7 +53,6 @@ import org.openmetadata.catalog.type.EntityReference; import org.openmetadata.catalog.type.FieldChange; import org.openmetadata.catalog.type.Schedule; import org.openmetadata.catalog.util.EntityInterface; -import org.openmetadata.catalog.util.EntityUtil; import org.openmetadata.catalog.util.JsonUtils; import org.openmetadata.catalog.util.TestUtils; import org.openmetadata.catalog.util.TestUtils.UpdateType; @@ -205,45 +202,6 @@ public class DatabaseServiceResourceTest extends EntityResourceTest authHeaders = adminAuthHeaders(); - DatabaseService databaseService = createEntity(create(test), authHeaders); - deleteAndCheckEntity(databaseService, authHeaders); - } - - @Test - void delete_put_DatabaseService_200(TestInfo test) throws IOException { - CreateDatabaseService request = create(test).withDescription(""); - DatabaseService databaseService = createEntity(request, adminAuthHeaders()); - - // Delete - deleteAndCheckEntity(databaseService, adminAuthHeaders()); - - Double version = - EntityUtil.nextVersion(databaseService.getVersion()); // Account for the version change during delete - ChangeDescription change = getChangeDescription(version); - change.setFieldsUpdated( - Arrays.asList( - new FieldChange().withName("deleted").withNewValue(false).withOldValue(true), - new FieldChange().withName("description").withNewValue("updatedDescription").withOldValue(""))); - - // PUT with updated description - updateAndCheckEntity( - request.withDescription("updatedDescription"), Response.Status.OK, adminAuthHeaders(), MINOR_UPDATE, change); - } - - @Test - void delete_as_user_401(TestInfo test) throws HttpResponseException { - Map authHeaders = adminAuthHeaders(); - DatabaseService databaseService = createEntity(create(test), authHeaders); - HttpResponseException exception = - assertThrows( - HttpResponseException.class, - () -> deleteAndCheckEntity(databaseService, authHeaders("test@open-metadata.org"))); - TestUtils.assertResponse(exception, FORBIDDEN, "Principal: CatalogPrincipal{name='test'} is not admin"); - } - public CreateDatabaseService create(TestInfo test) { return create(getEntityName(test)); } diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/services/MessagingServiceResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/services/MessagingServiceResourceTest.java index bedfd17c53f..f875fd204ff 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/services/MessagingServiceResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/services/MessagingServiceResourceTest.java @@ -15,23 +15,19 @@ package org.openmetadata.catalog.resources.services; import static javax.ws.rs.core.Response.Status.BAD_REQUEST; import static javax.ws.rs.core.Response.Status.FORBIDDEN; -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; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.openmetadata.catalog.security.SecurityUtil.authHeaders; -import static org.openmetadata.catalog.util.TestUtils.UpdateType.MINOR_UPDATE; import static org.openmetadata.catalog.util.TestUtils.adminAuthHeaders; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; -import java.util.Arrays; import java.util.Date; import java.util.List; import java.util.Map; -import javax.ws.rs.core.Response; import lombok.extern.slf4j.Slf4j; import org.apache.http.client.HttpResponseException; import org.junit.jupiter.api.BeforeAll; @@ -41,7 +37,6 @@ import org.openmetadata.catalog.Entity; import org.openmetadata.catalog.api.services.CreateMessagingService; import org.openmetadata.catalog.api.services.CreateMessagingService.MessagingServiceType; import org.openmetadata.catalog.entity.services.MessagingService; -import org.openmetadata.catalog.exception.CatalogExceptionMessage; import org.openmetadata.catalog.jdbi3.MessagingServiceRepository.MessagingServiceEntityInterface; import org.openmetadata.catalog.resources.EntityResourceTest; import org.openmetadata.catalog.resources.services.messaging.MessagingServiceResource.MessagingServiceList; @@ -50,7 +45,6 @@ import org.openmetadata.catalog.type.EntityReference; import org.openmetadata.catalog.type.FieldChange; import org.openmetadata.catalog.type.Schedule; import org.openmetadata.catalog.util.EntityInterface; -import org.openmetadata.catalog.util.EntityUtil; import org.openmetadata.catalog.util.JsonUtils; import org.openmetadata.catalog.util.TestUtils; import org.openmetadata.catalog.util.TestUtils.UpdateType; @@ -249,55 +243,6 @@ public class MessagingServiceResourceTest extends EntityResourceTest authHeaders = adminAuthHeaders(); - MessagingService messagingService = createEntity(create(test), authHeaders); - deleteAndCheckEntity(messagingService, authHeaders); - } - - @Test - void delete_put_MessagingService_200(TestInfo test) throws IOException { - CreateMessagingService request = create(test).withDescription(""); - MessagingService messagingService = createEntity(request, adminAuthHeaders()); - - // Delete - deleteAndCheckEntity(messagingService, adminAuthHeaders()); - - Double version = - EntityUtil.nextVersion(messagingService.getVersion()); // Account for the version change during delete - ChangeDescription change = getChangeDescription(version); - change.setFieldsUpdated( - Arrays.asList( - new FieldChange().withName("deleted").withNewValue(false).withOldValue(true), - new FieldChange().withName("description").withNewValue("updatedDescription").withOldValue(""))); - - // PUT with updated description - updateAndCheckEntity( - request.withDescription("updatedDescription"), Response.Status.OK, adminAuthHeaders(), MINOR_UPDATE, change); - } - - @Test - void delete_as_user_401(TestInfo test) throws HttpResponseException { - Map authHeaders = adminAuthHeaders(); - MessagingService messagingService = createEntity(create(test), authHeaders); - HttpResponseException exception = - assertThrows( - HttpResponseException.class, - () -> deleteAndCheckEntity(messagingService, authHeaders("test@open-metadata.org"))); - TestUtils.assertResponse(exception, FORBIDDEN, "Principal: CatalogPrincipal{name='test'} is not admin"); - } - - @Test - void delete_notExistentMessagingService() { - HttpResponseException exception = - assertThrows(HttpResponseException.class, () -> getEntity(TestUtils.NON_EXISTENT_ENTITY, adminAuthHeaders())); - TestUtils.assertResponse( - exception, - NOT_FOUND, - CatalogExceptionMessage.entityNotFound(Entity.MESSAGING_SERVICE, TestUtils.NON_EXISTENT_ENTITY)); - } - private CreateMessagingService create(TestInfo test) { return create(getEntityName(test)); } diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/services/PipelineServiceResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/services/PipelineServiceResourceTest.java index 9bb59a5171a..a6c9c96677b 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/services/PipelineServiceResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/services/PipelineServiceResourceTest.java @@ -15,22 +15,18 @@ package org.openmetadata.catalog.resources.services; import static javax.ws.rs.core.Response.Status.BAD_REQUEST; import static javax.ws.rs.core.Response.Status.FORBIDDEN; -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; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.openmetadata.catalog.security.SecurityUtil.authHeaders; -import static org.openmetadata.catalog.util.TestUtils.UpdateType.MINOR_UPDATE; import static org.openmetadata.catalog.util.TestUtils.adminAuthHeaders; import static org.openmetadata.catalog.util.TestUtils.getPrincipal; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; -import java.util.Arrays; import java.util.Date; import java.util.Map; -import javax.ws.rs.core.Response; import lombok.extern.slf4j.Slf4j; import org.apache.http.client.HttpResponseException; import org.junit.jupiter.api.BeforeAll; @@ -39,7 +35,6 @@ import org.junit.jupiter.api.TestInfo; import org.openmetadata.catalog.Entity; import org.openmetadata.catalog.api.services.CreatePipelineService; import org.openmetadata.catalog.entity.services.PipelineService; -import org.openmetadata.catalog.exception.CatalogExceptionMessage; import org.openmetadata.catalog.jdbi3.PipelineServiceRepository.PipelineServiceEntityInterface; import org.openmetadata.catalog.resources.EntityResourceTest; import org.openmetadata.catalog.resources.services.pipeline.PipelineServiceResource.PipelineServiceList; @@ -48,7 +43,6 @@ import org.openmetadata.catalog.type.EntityReference; import org.openmetadata.catalog.type.FieldChange; import org.openmetadata.catalog.type.Schedule; import org.openmetadata.catalog.util.EntityInterface; -import org.openmetadata.catalog.util.EntityUtil; import org.openmetadata.catalog.util.JsonUtils; import org.openmetadata.catalog.util.TestUtils; import org.openmetadata.catalog.util.TestUtils.UpdateType; @@ -229,54 +223,6 @@ public class PipelineServiceResourceTest extends EntityResourceTest authHeaders = adminAuthHeaders(); - PipelineService pipelineService = createEntity(create(test), authHeaders); - deleteAndCheckEntity(pipelineService, authHeaders); - } - - @Test - void delete_put_PipelineService_200(TestInfo test) throws IOException { - CreatePipelineService request = create(test).withDescription(""); - PipelineService pipelineService = createEntity(request, adminAuthHeaders()); - - // Delete - deleteAndCheckEntity(pipelineService, adminAuthHeaders()); - - Double version = EntityUtil.nextVersion(pipelineService.getVersion()); - ChangeDescription change = getChangeDescription(version); - change.setFieldsUpdated( - Arrays.asList( - new FieldChange().withName("deleted").withNewValue(false).withOldValue(true), - new FieldChange().withName("description").withNewValue("updatedDescription").withOldValue(""))); - - // PUT with updated description - updateAndCheckEntity( - request.withDescription("updatedDescription"), Response.Status.OK, adminAuthHeaders(), MINOR_UPDATE, change); - } - - @Test - void delete_as_user_401(TestInfo test) throws HttpResponseException { - Map authHeaders = adminAuthHeaders(); - PipelineService pipelineService = createEntity(create(test), authHeaders); - HttpResponseException exception = - assertThrows( - HttpResponseException.class, - () -> deleteAndCheckEntity(pipelineService, authHeaders("test@open-metadata.org"))); - TestUtils.assertResponse(exception, FORBIDDEN, "Principal: CatalogPrincipal{name='test'} is not admin"); - } - - @Test - void delete_notExistentPipelineService() { - HttpResponseException exception = - assertThrows(HttpResponseException.class, () -> getEntity(TestUtils.NON_EXISTENT_ENTITY, adminAuthHeaders())); - TestUtils.assertResponse( - exception, - NOT_FOUND, - CatalogExceptionMessage.entityNotFound(Entity.PIPELINE_SERVICE, TestUtils.NON_EXISTENT_ENTITY)); - } - private CreatePipelineService create(TestInfo test) { return create(getEntityName(test)); } diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/services/StorageServiceResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/services/StorageServiceResourceTest.java index c33710cd537..d96e3521c6d 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/services/StorageServiceResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/services/StorageServiceResourceTest.java @@ -14,20 +14,16 @@ package org.openmetadata.catalog.resources.services; import static javax.ws.rs.core.Response.Status.FORBIDDEN; -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; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.openmetadata.catalog.security.SecurityUtil.authHeaders; -import static org.openmetadata.catalog.util.TestUtils.UpdateType.MINOR_UPDATE; import static org.openmetadata.catalog.util.TestUtils.adminAuthHeaders; import static org.openmetadata.catalog.util.TestUtils.getPrincipal; import java.io.IOException; import java.net.URISyntaxException; -import java.util.Arrays; import java.util.Map; -import javax.ws.rs.core.Response; import lombok.extern.slf4j.Slf4j; import org.apache.http.client.HttpResponseException; import org.junit.jupiter.api.Test; @@ -35,16 +31,12 @@ import org.junit.jupiter.api.TestInfo; import org.openmetadata.catalog.Entity; import org.openmetadata.catalog.api.services.CreateStorageService; import org.openmetadata.catalog.entity.services.StorageService; -import org.openmetadata.catalog.exception.CatalogExceptionMessage; import org.openmetadata.catalog.jdbi3.StorageServiceRepository.StorageServiceEntityInterface; import org.openmetadata.catalog.resources.EntityResourceTest; import org.openmetadata.catalog.resources.services.storage.StorageServiceResource.StorageServiceList; -import org.openmetadata.catalog.type.ChangeDescription; import org.openmetadata.catalog.type.EntityReference; -import org.openmetadata.catalog.type.FieldChange; import org.openmetadata.catalog.type.StorageServiceType; import org.openmetadata.catalog.util.EntityInterface; -import org.openmetadata.catalog.util.EntityUtil; import org.openmetadata.catalog.util.TestUtils; import org.openmetadata.catalog.util.TestUtils.UpdateType; @@ -106,55 +98,6 @@ public class StorageServiceResourceTest extends EntityResourceTest authHeaders = adminAuthHeaders(); - StorageService storageService = createEntity(create(test), authHeaders); - deleteAndCheckEntity(storageService, authHeaders); - } - - @Test - void delete_put_StorageService_200(TestInfo test) throws IOException { - CreateStorageService request = create(test).withDescription(""); - StorageService storageService = createEntity(request, adminAuthHeaders()); - - // Delete - deleteAndCheckEntity(storageService, adminAuthHeaders()); - - Double version = - EntityUtil.nextVersion(storageService.getVersion()); // Account for the version change during delete - ChangeDescription change = getChangeDescription(version); - change.setFieldsUpdated( - Arrays.asList( - new FieldChange().withName("deleted").withNewValue(false).withOldValue(true), - new FieldChange().withName("description").withNewValue("updatedDescription").withOldValue(""))); - - // PUT with updated description - updateAndCheckEntity( - request.withDescription("updatedDescription"), Response.Status.OK, adminAuthHeaders(), MINOR_UPDATE, change); - } - - @Test - void delete_as_user_401(TestInfo test) throws HttpResponseException { - Map authHeaders = adminAuthHeaders(); - StorageService storageService = createEntity(create(test), authHeaders); - HttpResponseException exception = - assertThrows( - HttpResponseException.class, - () -> deleteAndCheckEntity(storageService, authHeaders("test@open-metadata.org"))); - TestUtils.assertResponse(exception, FORBIDDEN, "Principal: CatalogPrincipal{name='test'} is not admin"); - } - - @Test - void delete_notExistentStorageService() { - HttpResponseException exception = - assertThrows(HttpResponseException.class, () -> getEntity(TestUtils.NON_EXISTENT_ENTITY, adminAuthHeaders())); - TestUtils.assertResponse( - exception, - NOT_FOUND, - CatalogExceptionMessage.entityNotFound(Entity.STORAGE_SERVICE, TestUtils.NON_EXISTENT_ENTITY)); - } - private CreateStorageService create(TestInfo test) { return create(getEntityName(test)); } diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/teams/RoleResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/teams/RoleResourceTest.java index 489c5a3bf04..39fe8748d91 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/teams/RoleResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/teams/RoleResourceTest.java @@ -13,7 +13,6 @@ package org.openmetadata.catalog.resources.teams; -import static javax.ws.rs.core.Response.Status.BAD_REQUEST; import static javax.ws.rs.core.Response.Status.FORBIDDEN; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -28,7 +27,6 @@ import java.net.URISyntaxException; import java.util.List; import java.util.Map; import java.util.UUID; -import javax.json.JsonPatch; import javax.ws.rs.client.WebTarget; import lombok.extern.slf4j.Slf4j; import org.apache.http.client.HttpResponseException; @@ -40,7 +38,6 @@ import org.openmetadata.catalog.api.teams.CreateRole; import org.openmetadata.catalog.api.teams.CreateTeam; import org.openmetadata.catalog.entity.policies.Policy; import org.openmetadata.catalog.entity.teams.Role; -import org.openmetadata.catalog.exception.CatalogExceptionMessage; import org.openmetadata.catalog.jdbi3.RoleRepository.RoleEntityInterface; import org.openmetadata.catalog.resources.EntityResourceTest; import org.openmetadata.catalog.resources.policies.PolicyResource; @@ -95,37 +92,6 @@ public class RoleResourceTest extends EntityResourceTest { assertResponse(exception, FORBIDDEN, "Principal: CatalogPrincipal{name='test'} is not admin"); } - /** - * @see EntityResourceTest#put_addDeleteFollower_200 for tests related getting role with entities owned by the role - */ - @Test - void delete_validRole_200_OK(TestInfo test) throws IOException { - CreateRole create = create(test); - Role role = createAndCheckRole(create, adminAuthHeaders()); - deleteAndCheckEntity(role, adminAuthHeaders()); - } - - @Test - void delete_validRole_as_non_admin_401(TestInfo test) throws IOException { - CreateRole create = create(test); - Role role = createAndCheckRole(create, adminAuthHeaders()); - HttpResponseException exception = - assertThrows( - HttpResponseException.class, () -> deleteAndCheckEntity(role, authHeaders("test@open-metadata.org"))); - assertResponse(exception, FORBIDDEN, "Principal: CatalogPrincipal{name='test'} is not admin"); - } - - @Test - void patch_roleDeletedDisallowed_400(TestInfo test) throws HttpResponseException, JsonProcessingException { - // Ensure role deleted attribute can't be changed using patch - Role role = createRole(create(test), adminAuthHeaders()); - String roleJson = JsonUtils.pojoToJson(role); - role.setDeleted(true); - HttpResponseException exception = - assertThrows(HttpResponseException.class, () -> patchRole(roleJson, role, adminAuthHeaders())); - assertResponse(exception, BAD_REQUEST, CatalogExceptionMessage.readOnlyAttribute("Role", "deleted")); - } - @Test void patch_roleAttributes_as_non_admin_403(TestInfo test) throws HttpResponseException, JsonProcessingException { // Create table without any attributes @@ -136,7 +102,7 @@ public class RoleResourceTest extends EntityResourceTest { HttpResponseException exception = assertThrows( HttpResponseException.class, - () -> patchRole(role.getId(), originalJson, role, authHeaders("test@open-metadata.org"))); + () -> patchEntity(role.getId(), originalJson, role, authHeaders("test@open-metadata.org"))); assertResponse(exception, FORBIDDEN, "Principal: CatalogPrincipal{name='test'} is not admin"); } @@ -172,7 +138,7 @@ public class RoleResourceTest extends EntityResourceTest { UserResourceTest.create(role.getName() + "user1").withRoles(List.of(role.getId())), adminAuthHeaders()); UserResourceTest.createUser( UserResourceTest.create(role.getName() + "user2").withRoles(List.of(role.getId())), adminAuthHeaders()); - }; + } /** Validate returned fields GET .../roles/{id}?fields="..." or GET .../roles/name/{name}?fields="..." */ @Override @@ -197,18 +163,6 @@ public class RoleResourceTest extends EntityResourceTest { TestUtils.validateEntityReference(role.getUsers()); } - private Role patchRole(UUID roleId, String originalJson, Role updated, Map authHeaders) - throws JsonProcessingException, HttpResponseException { - String updatedJson = JsonUtils.pojoToJson(updated); - JsonPatch patch = JsonUtils.getJsonPatch(originalJson, updatedJson); - return TestUtils.patch(CatalogApplicationTest.getResource("roles/" + roleId), patch, Role.class, authHeaders); - } - - private Role patchRole(String originalJson, Role updated, Map authHeaders) - throws JsonProcessingException, HttpResponseException { - return patchRole(updated.getId(), originalJson, updated, authHeaders); - } - public static Role createRole(CreateTeam create, Map authHeaders) throws HttpResponseException { return TestUtils.post(CatalogApplicationTest.getResource("roles"), create, Role.class, authHeaders); } diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/teams/TeamResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/teams/TeamResourceTest.java index c40f62a9e20..c2af8e8cae0 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/teams/TeamResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/teams/TeamResourceTest.java @@ -156,30 +156,6 @@ public class TeamResourceTest extends EntityResourceTest { assertTrue(user.getTeams().isEmpty()); } - @Test - void delete_validTeam_as_non_admin_401(TestInfo test) throws IOException { - UserResourceTest userResourceTest = new UserResourceTest(); - User user1 = createUser(userResourceTest.create(test, 1), authHeaders("test@open-metadata.org")); - List users = Collections.singletonList(user1.getId()); - CreateTeam create = create(test).withUsers(users); - Team team = createAndCheckEntity(create, adminAuthHeaders()); - HttpResponseException exception = - assertThrows( - HttpResponseException.class, () -> deleteAndCheckEntity(team, authHeaders("test@open-metadata.org"))); - assertResponse(exception, FORBIDDEN, "Principal: CatalogPrincipal{name='test'} is not admin"); - } - - @Test - void patch_teamDeletedDisallowed_400(TestInfo test) throws HttpResponseException, JsonProcessingException { - // Ensure team deleted attribute can't be changed using patch - Team team = createTeam(create(test), adminAuthHeaders()); - String teamJson = JsonUtils.pojoToJson(team); - team.setDeleted(true); - HttpResponseException exception = - assertThrows(HttpResponseException.class, () -> patchTeam(teamJson, team, adminAuthHeaders())); - assertResponse(exception, BAD_REQUEST, CatalogExceptionMessage.readOnlyAttribute("Team", "deleted")); - } - // @Test // public void patch_teamAttributes_as_admin_200_ok(TestInfo test) // throws HttpResponseException, JsonProcessingException { diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/teams/UserResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/teams/UserResourceTest.java index 87b494491ed..6664275b127 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/teams/UserResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/teams/UserResourceTest.java @@ -25,7 +25,6 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.openmetadata.catalog.exception.CatalogExceptionMessage.readOnlyAttribute; import static org.openmetadata.catalog.resources.teams.RoleResourceTest.createRole; import static org.openmetadata.catalog.resources.teams.TeamResourceTest.createTeam; import static org.openmetadata.catalog.security.SecurityUtil.authHeaders; @@ -320,17 +319,6 @@ public class UserResourceTest extends EntityResourceTest { assertEquals(newDisplayName, user.getDisplayName()); } - @Test - void patch_userDeletedDisallowed_400(TestInfo test) throws HttpResponseException, JsonProcessingException { - // Ensure user deleted attributed can't be changed using patch - User user = createUser(create(test), adminAuthHeaders()); - String userJson = JsonUtils.pojoToJson(user); - user.setDeleted(true); - HttpResponseException exception = - assertThrows(HttpResponseException.class, () -> patchUser(userJson, user, adminAuthHeaders())); - assertResponse(exception, BAD_REQUEST, readOnlyAttribute("User", "deactivated")); - } - @Test void patch_userAttributes_as_admin_200_ok(TestInfo test) throws IOException { // Create user without any attributes - ***Note*** isAdmin by default is false. @@ -444,16 +432,6 @@ public class UserResourceTest extends EntityResourceTest { patchEntityAndCheck(user, origJson, adminAuthHeaders(), MINOR_UPDATE, change); } - @Test - void delete_validUser_as_non_admin_401(TestInfo test) throws HttpResponseException { - CreateUser create = create(test).withName("test3").withEmail("test3@email.com"); - User user = createUser(create, authHeaders("test3")); - - HttpResponseException exception = - assertThrows(HttpResponseException.class, () -> deleteAndCheckEntity(user, authHeaders("test3@email.com"))); - assertResponse(exception, FORBIDDEN, "Principal: CatalogPrincipal{name='test3'} is not admin"); - } - @Test void delete_validUser_as_admin_200(TestInfo test) throws IOException { TeamResourceTest teamResourceTest = new TeamResourceTest(); diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/topics/TopicResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/topics/TopicResourceTest.java index 691a94ffa47..ae4f8aa523c 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/topics/TopicResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/topics/TopicResourceTest.java @@ -18,20 +18,17 @@ import static javax.ws.rs.core.Response.Status.FORBIDDEN; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.openmetadata.catalog.security.SecurityUtil.authHeaders; -import static org.openmetadata.catalog.util.TestUtils.UpdateType.MINOR_UPDATE; import static org.openmetadata.catalog.util.TestUtils.adminAuthHeaders; import static org.openmetadata.catalog.util.TestUtils.assertListNotNull; import static org.openmetadata.catalog.util.TestUtils.assertResponse; import java.io.IOException; import java.net.URISyntaxException; -import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; import lombok.extern.slf4j.Slf4j; import org.apache.http.client.HttpResponseException; @@ -49,7 +46,6 @@ import org.openmetadata.catalog.type.FieldChange; import org.openmetadata.catalog.type.topic.CleanupPolicy; import org.openmetadata.catalog.type.topic.SchemaType; import org.openmetadata.catalog.util.EntityInterface; -import org.openmetadata.catalog.util.EntityUtil; import org.openmetadata.catalog.util.JsonUtils; import org.openmetadata.catalog.util.ResultList; import org.openmetadata.catalog.util.TestUtils; @@ -244,32 +240,6 @@ public class TopicResourceTest extends EntityResourceTest { patchEntityAndCheck(topic, origJson, adminAuthHeaders(), UpdateType.MINOR_UPDATE, change); } - @Test - void delete_emptyTopic_200_ok(TestInfo test) throws IOException { - Topic topic = createTopic(create(test), adminAuthHeaders()); - deleteAndCheckEntity(topic, adminAuthHeaders()); - } - - @Test - void delete_put_Topic_200(TestInfo test) throws IOException { - CreateTopic request = create(test).withDescription(""); - Topic topic = createEntity(request, adminAuthHeaders()); - - // Delete - deleteAndCheckEntity(topic, adminAuthHeaders()); - - Double version = EntityUtil.nextVersion(topic.getVersion()); // Account for the version change during delete - ChangeDescription change = getChangeDescription(version); - change.setFieldsUpdated( - Arrays.asList( - new FieldChange().withName("deleted").withNewValue(false).withOldValue(true), - new FieldChange().withName("description").withNewValue("updatedDescription").withOldValue(""))); - - // PUT with updated description - updateAndCheckEntity( - request.withDescription("updatedDescription"), Response.Status.OK, adminAuthHeaders(), MINOR_UPDATE, change); - } - @Test void delete_nonEmptyTopic_4xx() { // TODO