mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-08-07 08:38:23 +00:00
This commit is contained in:
parent
6e7cf40a33
commit
eeecde3524
@ -817,9 +817,17 @@ public abstract class EntityRepository<T> {
|
||||
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<T> {
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
|
@ -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<Role> {
|
||||
.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<Role> {
|
||||
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"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<Team> {
|
||||
|
||||
@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());
|
||||
}
|
||||
|
@ -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<User> {
|
||||
|
||||
@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);
|
||||
|
@ -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<Chart> response = dao.delete(securityContext.getUserPrincipal().getName(), id);
|
||||
return response.toResponse();
|
||||
}
|
||||
|
@ -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<Dashboard> response = dao.delete(securityContext.getUserPrincipal().getName(), id);
|
||||
return response.toResponse();
|
||||
}
|
||||
|
@ -408,6 +408,7 @@ public class DatabaseResource {
|
||||
boolean recursive,
|
||||
@PathParam("id") String id)
|
||||
throws IOException {
|
||||
SecurityUtil.checkAdminOrBotRole(authorizer, securityContext);
|
||||
DeleteResponse<Database> response = dao.delete(securityContext.getUserPrincipal().getName(), id, recursive);
|
||||
return response.toResponse();
|
||||
}
|
||||
|
@ -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<Webhook> response = dao.delete(securityContext.getUserPrincipal().getName(), id);
|
||||
dao.deleteWebhookPublisher(UUID.fromString(id));
|
||||
return response.toResponse();
|
||||
|
@ -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<AirflowPipeline> response = dao.delete(securityContext.getUserPrincipal().getName(), id);
|
||||
return response.toResponse();
|
||||
}
|
||||
|
@ -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<Pipeline> response = dao.delete(securityContext.getUserPrincipal().getName(), id);
|
||||
return response.toResponse();
|
||||
}
|
||||
|
@ -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<Policy> response = dao.delete(securityContext.getUserPrincipal().getName(), id);
|
||||
return response.toResponse();
|
||||
}
|
||||
|
@ -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<Topic> response = dao.delete(securityContext.getUserPrincipal().getName(), id);
|
||||
return response.toResponse();
|
||||
}
|
||||
|
@ -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<T> 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<T> entityInterface = getEntityInterface(entity);
|
||||
assertListNull(entityInterface.getDescription(), entityInterface.getOwner());
|
||||
@ -983,6 +984,23 @@ public abstract class EntityResourceTest<T> 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<T> 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<T> 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<T> 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
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -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<Chart> {
|
||||
}
|
||||
}
|
||||
|
||||
@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 {
|
||||
|
@ -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<Dashboard> {
|
||||
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<String, String> authHeaders)
|
||||
throws HttpResponseException {
|
||||
return TestUtils.post(getResource("dashboards"), create, Dashboard.class, authHeaders);
|
||||
|
@ -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<Database> {
|
||||
}
|
||||
}
|
||||
|
||||
@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
|
||||
|
@ -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<Table> {
|
||||
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
|
||||
|
@ -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<Location> {
|
||||
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 =
|
||||
|
@ -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<MlModel> {
|
||||
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 {
|
||||
|
@ -504,12 +504,6 @@ public class AirflowPipelineResourceTest extends EntityOperationsResourceTest<Ai
|
||||
request.withDescription("newDescription").withOwner(USER_OWNER1), OK, adminAuthHeaders(), MINOR_UPDATE, change);
|
||||
}
|
||||
|
||||
@Test
|
||||
void delete_AirflowPipeline_200_ok(TestInfo test) throws HttpResponseException {
|
||||
AirflowPipeline airflowPipeline = createEntity(create(test), adminAuthHeaders());
|
||||
deleteEntity(airflowPipeline.getId(), adminAuthHeaders());
|
||||
}
|
||||
|
||||
@Test
|
||||
void delete_nonEmptyPipeline_4xx() {
|
||||
// TODO
|
||||
|
@ -30,14 +30,12 @@ import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
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;
|
||||
@ -56,7 +54,6 @@ import org.openmetadata.catalog.type.EntityReference;
|
||||
import org.openmetadata.catalog.type.FieldChange;
|
||||
import org.openmetadata.catalog.type.Task;
|
||||
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;
|
||||
@ -300,37 +297,11 @@ public class PipelineResourceTest extends EntityResourceTest<Pipeline> {
|
||||
// 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<String, String> authHeaders)
|
||||
throws HttpResponseException {
|
||||
return TestUtils.put(getResource("pipelines"), create, Pipeline.class, status, authHeaders);
|
||||
|
@ -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<Policy> {
|
||||
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
|
||||
|
@ -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<DashboardSe
|
||||
TestUtils.assertResponse(exception, FORBIDDEN, "Principal: CatalogPrincipal{name='test'} " + "is not admin");
|
||||
}
|
||||
|
||||
@Test
|
||||
void delete_ExistentDashboardService_as_admin_200(TestInfo test) throws IOException, URISyntaxException {
|
||||
Map<String, String> 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<String, String> 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));
|
||||
}
|
||||
|
@ -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<DatabaseServ
|
||||
TestUtils.assertResponse(exception, FORBIDDEN, "Principal: CatalogPrincipal{name='test'} " + "is not admin");
|
||||
}
|
||||
|
||||
@Test
|
||||
void delete_ExistentDatabaseService_as_admin_200(TestInfo test) throws IOException {
|
||||
Map<String, String> 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<String, String> 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));
|
||||
}
|
||||
|
@ -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<MessagingSe
|
||||
TestUtils.assertResponse(exception, FORBIDDEN, "Principal: CatalogPrincipal{name='test'} " + "is not admin");
|
||||
}
|
||||
|
||||
@Test
|
||||
void delete_ExistentMessagingService_as_admin_200(TestInfo test) throws IOException {
|
||||
Map<String, String> 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<String, String> 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));
|
||||
}
|
||||
|
@ -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<PipelineServ
|
||||
TestUtils.assertResponse(exception, FORBIDDEN, "Principal: CatalogPrincipal{name='test'} " + "is not admin");
|
||||
}
|
||||
|
||||
@Test
|
||||
void delete_ExistentPipelineService_as_admin_200(TestInfo test) throws IOException {
|
||||
Map<String, String> 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<String, String> 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));
|
||||
}
|
||||
|
@ -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<StorageServic
|
||||
TestUtils.assertResponse(exception, FORBIDDEN, "Principal: CatalogPrincipal{name='test'} " + "is not admin");
|
||||
}
|
||||
|
||||
@Test
|
||||
void delete_ExistentService_as_admin_200(TestInfo test) throws IOException {
|
||||
Map<String, String> 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<String, String> 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));
|
||||
}
|
||||
|
@ -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<Role> {
|
||||
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<Role> {
|
||||
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<Role> {
|
||||
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<Role> {
|
||||
TestUtils.validateEntityReference(role.getUsers());
|
||||
}
|
||||
|
||||
private Role patchRole(UUID roleId, String originalJson, Role updated, Map<String, String> 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<String, String> authHeaders)
|
||||
throws JsonProcessingException, HttpResponseException {
|
||||
return patchRole(updated.getId(), originalJson, updated, authHeaders);
|
||||
}
|
||||
|
||||
public static Role createRole(CreateTeam create, Map<String, String> authHeaders) throws HttpResponseException {
|
||||
return TestUtils.post(CatalogApplicationTest.getResource("roles"), create, Role.class, authHeaders);
|
||||
}
|
||||
|
@ -156,30 +156,6 @@ public class TeamResourceTest extends EntityResourceTest<Team> {
|
||||
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<UUID> 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 {
|
||||
|
@ -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<User> {
|
||||
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<User> {
|
||||
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();
|
||||
|
@ -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<Topic> {
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user