[issue-1992] - Allow Delete + PUT (#1993)

* Select entity deleted or not

* Allow to PUT back a deleted Entity

* Update interface to get deleted flag

* Add delete + put test

* Rename to isDeleted

* Rename to DeletedOrExists

* Update delete_put test

* format

* Remove delete put test from interface

* Add mlmodel delete put test

* Add mlmodel delete put test

* Use minor version change for recover deleted

* Prepare delete put test

* Add recover soft delete relationships

* Fix recover for Entities with services

* Fix recover for Entities with services

* Add delete put tests

* Add delete put tests

* Format and sonar
This commit is contained in:
Pere Miquel Brull 2022-01-06 12:38:09 +01:00 committed by GitHub
parent a3ccb1183d
commit d91f6bcb11
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
40 changed files with 453 additions and 1 deletions

View File

@ -92,6 +92,11 @@ public class BotsRepository extends EntityRepository<Bots> {
return entity.getDisplayName(); return entity.getDisplayName();
} }
@Override
public Boolean isDeleted() {
return entity.getDeleted();
}
@Override @Override
public String getFullyQualifiedName() { public String getFullyQualifiedName() {
return entity.getName(); return entity.getName();

View File

@ -165,6 +165,11 @@ public class ChartRepository extends EntityRepository<Chart> {
return entity.getDisplayName(); return entity.getDisplayName();
} }
@Override
public Boolean isDeleted() {
return entity.getDeleted();
}
@Override @Override
public EntityReference getOwner() { public EntityReference getOwner() {
return entity.getOwner(); return entity.getOwner();

View File

@ -451,6 +451,9 @@ public interface CollectionDAO {
"UPDATE entity_relationship SET deleted = true WHERE (toId = :id AND toEntity = :entity) " "UPDATE entity_relationship SET deleted = true WHERE (toId = :id AND toEntity = :entity) "
+ "OR (fromId = :id AND fromEntity = :entity)") + "OR (fromId = :id AND fromEntity = :entity)")
void softDeleteAll(@Bind("id") String id, @Bind("entity") String entity); void softDeleteAll(@Bind("id") String id, @Bind("entity") String entity);
@SqlUpdate("UPDATE entity_relationship SET deleted = false WHERE toId = :id OR fromId = :id")
void recoverSoftDeleteAll(@Bind("id") String id);
} }
interface FeedDAO { interface FeedDAO {

View File

@ -257,6 +257,11 @@ public class DashboardRepository extends EntityRepository<Dashboard> {
return entity.getDisplayName(); return entity.getDisplayName();
} }
@Override
public Boolean isDeleted() {
return entity.getDeleted();
}
@Override @Override
public EntityReference getOwner() { public EntityReference getOwner() {
return entity.getOwner(); return entity.getOwner();

View File

@ -124,6 +124,11 @@ public class DashboardServiceRepository extends EntityRepository<DashboardServic
return entity.getDisplayName(); return entity.getDisplayName();
} }
@Override
public Boolean isDeleted() {
return entity.getDeleted();
}
@Override @Override
public String getFullyQualifiedName() { public String getFullyQualifiedName() {
return entity.getName(); return entity.getName();

View File

@ -226,6 +226,11 @@ public class DatabaseRepository extends EntityRepository<Database> {
return entity.getDisplayName(); return entity.getDisplayName();
} }
@Override
public Boolean isDeleted() {
return entity.getDeleted();
}
@Override @Override
public EntityReference getOwner() { public EntityReference getOwner() {
return entity.getOwner(); return entity.getOwner();

View File

@ -103,6 +103,11 @@ public class DatabaseServiceRepository extends EntityRepository<DatabaseService>
return entity.getDisplayName(); return entity.getDisplayName();
} }
@Override
public Boolean isDeleted() {
return entity.getDeleted();
}
@Override @Override
public String getFullyQualifiedName() { public String getFullyQualifiedName() {
return entity.getName(); return entity.getName();

View File

@ -52,6 +52,10 @@ public interface EntityDAO<T> {
@SqlQuery("SELECT json FROM <table> WHERE <nameColumn> = :name AND deleted IS NOT TRUE") @SqlQuery("SELECT json FROM <table> WHERE <nameColumn> = :name AND deleted IS NOT TRUE")
String findByName(@Define("table") String table, @Define("nameColumn") String nameColumn, @Bind("name") String name); String findByName(@Define("table") String table, @Define("nameColumn") String nameColumn, @Bind("name") String name);
@SqlQuery("SELECT json FROM <table> WHERE <nameColumn> = :name")
String findByNameDeletedOrExists(
@Define("table") String table, @Define("nameColumn") String nameColumn, @Bind("name") String name);
@SqlQuery( @SqlQuery(
"SELECT count(*) FROM <table> WHERE " "SELECT count(*) FROM <table> WHERE "
+ "(<nameColumn> LIKE CONCAT(:fqnPrefix, '.%') OR :fqnPrefix IS NULL) AND deleted IS NOT TRUE") + "(<nameColumn> LIKE CONCAT(:fqnPrefix, '.%') OR :fqnPrefix IS NULL) AND deleted IS NOT TRUE")
@ -150,6 +154,10 @@ public interface EntityDAO<T> {
return findByName(getTableName(), getNameColumn(), fqn); return findByName(getTableName(), getNameColumn(), fqn);
} }
default String findDeletedOrExists(String fqn) {
return findByNameDeletedOrExists(getTableName(), getNameColumn(), fqn);
}
default int listCount(String databaseFQN) { default int listCount(String databaseFQN) {
return listCount(getTableName(), getNameColumn(), databaseFQN); return listCount(getTableName(), getNameColumn(), databaseFQN);
} }

View File

@ -300,10 +300,14 @@ public abstract class EntityRepository<T> {
@Transaction @Transaction
public final PutResponse<T> createOrUpdate(UriInfo uriInfo, T updated) throws IOException, ParseException { public final PutResponse<T> createOrUpdate(UriInfo uriInfo, T updated) throws IOException, ParseException {
prepare(updated); prepare(updated);
T original = JsonUtils.readValue(dao.findJsonByFqn(getFullyQualifiedName(updated)), entityClass); // Check if there is any original, deleted or not
T original = JsonUtils.readValue(dao.findDeletedOrExists(getFullyQualifiedName(updated)), entityClass);
if (original == null) { if (original == null) {
return new PutResponse<>(Status.CREATED, withHref(uriInfo, createNewEntity(updated)), RestUtil.ENTITY_CREATED); return new PutResponse<>(Status.CREATED, withHref(uriInfo, createNewEntity(updated)), RestUtil.ENTITY_CREATED);
} }
// Recover relationships if original was deleted before setFields
recoverDeletedRelationships(original);
// Get all the fields in the original entity that can be updated during PUT operation // Get all the fields in the original entity that can be updated during PUT operation
setFields(original, putFields); setFields(original, putFields);
@ -511,6 +515,15 @@ public abstract class EntityRepository<T> {
return RestUtil.getHref(uriInfo, collectionPath, id); return RestUtil.getHref(uriInfo, collectionPath, id);
} }
private void recoverDeletedRelationships(T original) {
// If original is deleted, we need to recover the relationships before setting the fields
// or we won't find the related services
EntityInterface<T> originalRef = getEntityInterface(original);
if (Boolean.TRUE.equals(originalRef.isDeleted())) {
daoCollection.relationshipDAO().recoverSoftDeleteAll(originalRef.getId().toString());
}
}
/** /**
* Class that performs PUT and PATCH update operation. It takes an <i>updated</i> entity and <i>original</i> entity. * Class that performs PUT and PATCH update operation. It takes an <i>updated</i> entity and <i>original</i> entity.
* Performs comparison between then and updates the stored entity and also updates all the relationships. This class * Performs comparison between then and updates the stored entity and also updates all the relationships. This class
@ -537,6 +550,7 @@ public abstract class EntityRepository<T> {
/** Compare original and updated entities and perform updates. Update the entity version and track changes. */ /** Compare original and updated entities and perform updates. Update the entity version and track changes. */
public final void update() throws IOException { public final void update() throws IOException {
updated.setId(original.getId()); updated.setId(original.getId());
updateDeleted();
updateDescription(); updateDescription();
updateDisplayName(); updateDisplayName();
updateOwner(); updateOwner();
@ -560,6 +574,13 @@ public abstract class EntityRepository<T> {
recordChange("description", original.getDescription(), updated.getDescription()); recordChange("description", original.getDescription(), updated.getDescription());
} }
private void updateDeleted() throws JsonProcessingException {
if (Boolean.TRUE.equals(original.isDeleted())) {
updated.setDeleted(false);
recordChange("deleted", true, false);
}
}
private void updateDisplayName() throws JsonProcessingException { private void updateDisplayName() throws JsonProcessingException {
if (!patchOperation && original.getDisplayName() != null && !original.getDisplayName().isEmpty()) { if (!patchOperation && original.getDisplayName() != null && !original.getDisplayName().isEmpty()) {
// Update displayName only when stored is empty to retain user authored descriptions // Update displayName only when stored is empty to retain user authored descriptions

View File

@ -161,6 +161,11 @@ public class IngestionRepository extends EntityRepository<Ingestion> {
return entity.getDisplayName(); return entity.getDisplayName();
} }
@Override
public Boolean isDeleted() {
return entity.getDeleted();
}
@Override @Override
public EntityReference getOwner() { public EntityReference getOwner() {
return entity.getOwner(); return entity.getOwner();

View File

@ -270,6 +270,11 @@ public class LocationRepository extends EntityRepository<Location> {
return entity.getDisplayName(); return entity.getDisplayName();
} }
@Override
public Boolean isDeleted() {
return entity.getDeleted();
}
@Override @Override
public EntityReference getOwner() { public EntityReference getOwner() {
return entity.getOwner(); return entity.getOwner();

View File

@ -103,6 +103,11 @@ public class MessagingServiceRepository extends EntityRepository<MessagingServic
return entity.getDisplayName(); return entity.getDisplayName();
} }
@Override
public Boolean isDeleted() {
return entity.getDeleted();
}
@Override @Override
public String getFullyQualifiedName() { public String getFullyQualifiedName() {
return entity.getName(); return entity.getName();

View File

@ -144,6 +144,11 @@ public class MetricsRepository extends EntityRepository<Metrics> {
return entity.getDisplayName(); return entity.getDisplayName();
} }
@Override
public Boolean isDeleted() {
return entity.getDeleted();
}
@Override @Override
public EntityReference getOwner() { public EntityReference getOwner() {
return entity.getOwner(); return entity.getOwner();

View File

@ -258,6 +258,11 @@ public class MlModelRepository extends EntityRepository<MlModel> {
return entity.getDisplayName(); return entity.getDisplayName();
} }
@Override
public Boolean isDeleted() {
return entity.getDeleted();
}
@Override @Override
public EntityReference getOwner() { public EntityReference getOwner() {
return entity.getOwner(); return entity.getOwner();

View File

@ -190,6 +190,11 @@ public class PipelineRepository extends EntityRepository<Pipeline> {
return entity.getDisplayName(); return entity.getDisplayName();
} }
@Override
public Boolean isDeleted() {
return entity.getDeleted();
}
@Override @Override
public EntityReference getOwner() { public EntityReference getOwner() {
return entity.getOwner(); return entity.getOwner();

View File

@ -103,6 +103,11 @@ public class PipelineServiceRepository extends EntityRepository<PipelineService>
return entity.getDisplayName(); return entity.getDisplayName();
} }
@Override
public Boolean isDeleted() {
return entity.getDeleted();
}
@Override @Override
public String getFullyQualifiedName() { public String getFullyQualifiedName() {
return entity.getName(); return entity.getName();

View File

@ -220,6 +220,11 @@ public class PolicyRepository extends EntityRepository<Policy> {
return entity.getDisplayName(); return entity.getDisplayName();
} }
@Override
public Boolean isDeleted() {
return entity.getDeleted();
}
@Override @Override
public EntityReference getOwner() { public EntityReference getOwner() {
return entity.getOwner(); return entity.getOwner();

View File

@ -128,6 +128,11 @@ public class ReportRepository extends EntityRepository<Report> {
return entity.getDisplayName(); return entity.getDisplayName();
} }
@Override
public Boolean isDeleted() {
return entity.getDeleted();
}
@Override @Override
public EntityReference getOwner() { public EntityReference getOwner() {
return entity.getOwner(); return entity.getOwner();

View File

@ -105,6 +105,11 @@ public class RoleRepository extends EntityRepository<Role> {
return entity.getDisplayName(); return entity.getDisplayName();
} }
@Override
public Boolean isDeleted() {
return entity.getDeleted();
}
@Override @Override
public String getFullyQualifiedName() { public String getFullyQualifiedName() {
return entity.getName(); return entity.getName();

View File

@ -93,6 +93,11 @@ public class StorageServiceRepository extends EntityRepository<StorageService> {
return entity.getDisplayName(); return entity.getDisplayName();
} }
@Override
public Boolean isDeleted() {
return entity.getDeleted();
}
@Override @Override
public String getFullyQualifiedName() { public String getFullyQualifiedName() {
return entity.getName(); return entity.getName();

View File

@ -700,6 +700,11 @@ public class TableRepository extends EntityRepository<Table> {
return entity.getDisplayName(); return entity.getDisplayName();
} }
@Override
public Boolean isDeleted() {
return entity.getDeleted();
}
@Override @Override
public EntityReference getOwner() { public EntityReference getOwner() {
return entity.getOwner(); return entity.getOwner();

View File

@ -165,6 +165,11 @@ public class TeamRepository extends EntityRepository<Team> {
return entity.getDisplayName(); return entity.getDisplayName();
} }
@Override
public Boolean isDeleted() {
return entity.getDeleted();
}
@Override @Override
public String getFullyQualifiedName() { public String getFullyQualifiedName() {
return entity.getName(); return entity.getName();

View File

@ -171,6 +171,11 @@ public class TopicRepository extends EntityRepository<Topic> {
return entity.getDisplayName(); return entity.getDisplayName();
} }
@Override
public Boolean isDeleted() {
return entity.getDeleted();
}
@Override @Override
public EntityReference getOwner() { public EntityReference getOwner() {
return entity.getOwner(); return entity.getOwner();

View File

@ -216,6 +216,11 @@ public class UserRepository extends EntityRepository<User> {
return entity.getDisplayName(); return entity.getDisplayName();
} }
@Override
public Boolean isDeleted() {
return entity.getDeleted();
}
@Override @Override
public String getFullyQualifiedName() { public String getFullyQualifiedName() {
return entity.getName(); return entity.getName();

View File

@ -188,6 +188,11 @@ public class WebhookRepository extends EntityRepository<Webhook> {
return entity.getName(); return entity.getName();
} }
@Override
public Boolean isDeleted() {
return entity.getDeleted();
}
@Override @Override
public String getFullyQualifiedName() { public String getFullyQualifiedName() {
return entity.getName(); return entity.getName();

View File

@ -29,6 +29,8 @@ public interface EntityInterface<T> {
String getDisplayName(); String getDisplayName();
Boolean isDeleted();
default EntityReference getOwner() { default EntityReference getOwner() {
return null; return null;
} }

View File

@ -18,6 +18,7 @@ import static javax.ws.rs.core.Response.Status.FORBIDDEN;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.openmetadata.catalog.security.SecurityUtil.authHeaders; 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.adminAuthHeaders;
import static org.openmetadata.catalog.util.TestUtils.assertListNotNull; import static org.openmetadata.catalog.util.TestUtils.assertListNotNull;
import static org.openmetadata.catalog.util.TestUtils.assertResponse; import static org.openmetadata.catalog.util.TestUtils.assertResponse;
@ -25,8 +26,10 @@ import static org.openmetadata.catalog.util.TestUtils.assertResponse;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import javax.ws.rs.core.Response;
import org.apache.http.client.HttpResponseException; import org.apache.http.client.HttpResponseException;
import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -42,8 +45,10 @@ import org.openmetadata.catalog.jdbi3.DashboardServiceRepository.DashboardServic
import org.openmetadata.catalog.resources.EntityResourceTest; import org.openmetadata.catalog.resources.EntityResourceTest;
import org.openmetadata.catalog.resources.charts.ChartResource.ChartList; import org.openmetadata.catalog.resources.charts.ChartResource.ChartList;
import org.openmetadata.catalog.resources.services.DashboardServiceResourceTest; import org.openmetadata.catalog.resources.services.DashboardServiceResourceTest;
import org.openmetadata.catalog.type.ChangeDescription;
import org.openmetadata.catalog.type.ChartType; import org.openmetadata.catalog.type.ChartType;
import org.openmetadata.catalog.type.EntityReference; import org.openmetadata.catalog.type.EntityReference;
import org.openmetadata.catalog.type.FieldChange;
import org.openmetadata.catalog.util.EntityInterface; import org.openmetadata.catalog.util.EntityInterface;
import org.openmetadata.catalog.util.ResultList; import org.openmetadata.catalog.util.ResultList;
import org.openmetadata.catalog.util.TestUtils; import org.openmetadata.catalog.util.TestUtils;
@ -152,6 +157,25 @@ public class ChartResourceTest extends EntityResourceTest<Chart> {
// TODO // TODO
} }
@Test
void delete_put_Chart_200(TestInfo test) throws IOException {
CreateChart request = create(test).withDescription("");
Chart chart = createEntity(request, adminAuthHeaders());
// Delete
deleteEntity(chart.getId(), adminAuthHeaders());
ChangeDescription change = getChangeDescription(chart.getVersion());
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="..." */ /** Validate returned fields GET .../charts/{id}?fields="..." or GET .../charts/name/{fqn}?fields="..." */
@Override @Override
public void validateGetWithDifferentFields(Chart chart, boolean byName) throws HttpResponseException { public void validateGetWithDifferentFields(Chart chart, boolean byName) throws HttpResponseException {

View File

@ -32,11 +32,13 @@ import static org.openmetadata.catalog.util.TestUtils.assertResponse;
import java.io.IOException; import java.io.IOException;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.ws.rs.core.Response;
import org.apache.http.client.HttpResponseException; import org.apache.http.client.HttpResponseException;
import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -235,6 +237,25 @@ public class DashboardResourceTest extends EntityResourceTest<Dashboard> {
// TODO // TODO
} }
@Test
void delete_put_Dashboard_200(TestInfo test) throws IOException {
CreateDashboard request = create(test).withDescription("");
Dashboard dashboard = createEntity(request, adminAuthHeaders());
// Delete
deleteEntity(dashboard.getId(), adminAuthHeaders());
ChangeDescription change = getChangeDescription(dashboard.getVersion());
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) public Dashboard createDashboard(CreateDashboard create, Map<String, String> authHeaders)
throws HttpResponseException { throws HttpResponseException {
return TestUtils.post(getResource("dashboards"), create, Dashboard.class, authHeaders); return TestUtils.post(getResource("dashboards"), create, Dashboard.class, authHeaders);

View File

@ -19,6 +19,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.openmetadata.catalog.security.SecurityUtil.authHeaders; 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.adminAuthHeaders;
import static org.openmetadata.catalog.util.TestUtils.assertListNotNull; import static org.openmetadata.catalog.util.TestUtils.assertListNotNull;
import static org.openmetadata.catalog.util.TestUtils.assertListNull; import static org.openmetadata.catalog.util.TestUtils.assertListNull;
@ -26,8 +27,10 @@ import static org.openmetadata.catalog.util.TestUtils.assertResponse;
import java.io.IOException; import java.io.IOException;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import javax.ws.rs.core.Response;
import org.apache.http.client.HttpResponseException; import org.apache.http.client.HttpResponseException;
import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -39,7 +42,9 @@ import org.openmetadata.catalog.entity.data.Database;
import org.openmetadata.catalog.jdbi3.DatabaseRepository.DatabaseEntityInterface; import org.openmetadata.catalog.jdbi3.DatabaseRepository.DatabaseEntityInterface;
import org.openmetadata.catalog.resources.EntityResourceTest; import org.openmetadata.catalog.resources.EntityResourceTest;
import org.openmetadata.catalog.resources.databases.DatabaseResource.DatabaseList; 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.EntityReference;
import org.openmetadata.catalog.type.FieldChange;
import org.openmetadata.catalog.util.EntityInterface; import org.openmetadata.catalog.util.EntityInterface;
import org.openmetadata.catalog.util.ResultList; import org.openmetadata.catalog.util.ResultList;
import org.openmetadata.catalog.util.TestUtils; import org.openmetadata.catalog.util.TestUtils;
@ -132,6 +137,25 @@ public class DatabaseResourceTest extends EntityResourceTest<Database> {
deleteEntity(database.getId(), adminAuthHeaders()); deleteEntity(database.getId(), 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
deleteEntity(database.getId(), adminAuthHeaders());
ChangeDescription change = getChangeDescription(database.getVersion());
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 @Test
void delete_nonEmptyDatabase_4xx() { void delete_nonEmptyDatabase_4xx() {
// TODO // TODO

View File

@ -58,6 +58,7 @@ import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import javax.ws.rs.client.WebTarget; import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status; import javax.ws.rs.core.Response.Status;
import org.apache.http.client.HttpResponseException; import org.apache.http.client.HttpResponseException;
import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeAll;
@ -1023,6 +1024,25 @@ public class TableResourceTest extends EntityResourceTest<Table> {
deleteEntity(table.getId(), adminAuthHeaders()); deleteEntity(table.getId(), 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
deleteEntity(table.getId(), adminAuthHeaders());
ChangeDescription change = getChangeDescription(table.getVersion());
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 @Test
void delete_table_as_non_admin_401(TestInfo test) throws HttpResponseException { void delete_table_as_non_admin_401(TestInfo test) throws HttpResponseException {
Table table = createEntity(create(test), adminAuthHeaders()); Table table = createEntity(create(test), adminAuthHeaders());

View File

@ -19,6 +19,7 @@ import static javax.ws.rs.core.Response.Status.OK;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.openmetadata.catalog.security.SecurityUtil.authHeaders; 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.adminAuthHeaders;
import static org.openmetadata.catalog.util.TestUtils.assertListNotNull; import static org.openmetadata.catalog.util.TestUtils.assertListNotNull;
import static org.openmetadata.catalog.util.TestUtils.assertResponse; import static org.openmetadata.catalog.util.TestUtils.assertResponse;
@ -32,6 +33,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javax.ws.rs.client.WebTarget; import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status; import javax.ws.rs.core.Response.Status;
import org.apache.http.client.HttpResponseException; import org.apache.http.client.HttpResponseException;
import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeAll;
@ -43,7 +45,9 @@ import org.openmetadata.catalog.entity.data.Location;
import org.openmetadata.catalog.jdbi3.LocationRepository.LocationEntityInterface; import org.openmetadata.catalog.jdbi3.LocationRepository.LocationEntityInterface;
import org.openmetadata.catalog.resources.EntityResourceTest; import org.openmetadata.catalog.resources.EntityResourceTest;
import org.openmetadata.catalog.resources.locations.LocationResource.LocationList; 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.EntityReference;
import org.openmetadata.catalog.type.FieldChange;
import org.openmetadata.catalog.util.EntityInterface; import org.openmetadata.catalog.util.EntityInterface;
import org.openmetadata.catalog.util.ResultList; import org.openmetadata.catalog.util.ResultList;
import org.openmetadata.catalog.util.TestUtils; import org.openmetadata.catalog.util.TestUtils;
@ -188,6 +192,25 @@ public class LocationResourceTest extends EntityResourceTest<Location> {
deleteEntity(location.getId(), adminAuthHeaders()); deleteEntity(location.getId(), adminAuthHeaders());
} }
@Test
void delete_put_Location_200(TestInfo test) throws IOException {
CreateLocation request = create(test).withDescription("");
Location location = createEntity(request, adminAuthHeaders());
// Delete
deleteEntity(location.getId(), adminAuthHeaders());
ChangeDescription change = getChangeDescription(location.getVersion());
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 @Test
void delete_location_as_non_admin_401(TestInfo test) throws HttpResponseException { void delete_location_as_non_admin_401(TestInfo test) throws HttpResponseException {
Location location = createLocation(create(test), adminAuthHeaders()); Location location = createLocation(create(test), adminAuthHeaders());

View File

@ -381,6 +381,26 @@ public class MlModelResourceTest extends EntityResourceTest<MlModel> {
deleteEntity(model.getId(), adminAuthHeaders()); deleteEntity(model.getId(), 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
deleteEntity(model.getId(), adminAuthHeaders());
ChangeDescription change = getChangeDescription(model.getVersion());
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="..." */ /** Validate returned fields GET .../models/{id}?fields="..." or GET .../models/name/{fqn}?fields="..." */
@Override @Override
public void validateGetWithDifferentFields(MlModel model, boolean byName) throws HttpResponseException { public void validateGetWithDifferentFields(MlModel model, boolean byName) throws HttpResponseException {

View File

@ -30,12 +30,14 @@ import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import javax.ws.rs.client.WebTarget; import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status; import javax.ws.rs.core.Response.Status;
import org.apache.http.client.HttpResponseException; import org.apache.http.client.HttpResponseException;
import org.joda.time.DateTime; import org.joda.time.DateTime;
@ -297,6 +299,25 @@ public class PipelineResourceTest extends EntityResourceTest<Pipeline> {
// TODO // 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
deleteEntity(pipeline.getId(), adminAuthHeaders());
ChangeDescription change = getChangeDescription(pipeline.getVersion());
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) public static Pipeline updatePipeline(CreatePipeline create, Status status, Map<String, String> authHeaders)
throws HttpResponseException { throws HttpResponseException {
return TestUtils.put(getResource("pipelines"), create, Pipeline.class, status, authHeaders); return TestUtils.put(getResource("pipelines"), create, Pipeline.class, status, authHeaders);

View File

@ -31,12 +31,14 @@ import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.ws.rs.client.WebTarget; import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.Response;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.http.client.HttpResponseException; import org.apache.http.client.HttpResponseException;
import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeAll;
@ -313,6 +315,25 @@ public class PolicyResourceTest extends EntityResourceTest<Policy> {
deleteEntity(policy.getId(), adminAuthHeaders()); deleteEntity(policy.getId(), adminAuthHeaders());
} }
@Test
void delete_put_Policy_200(TestInfo test) throws IOException {
CreatePolicy request = create(test).withDescription("");
Policy policy = createEntity(request, adminAuthHeaders());
// Delete
deleteEntity(policy.getId(), adminAuthHeaders());
ChangeDescription change = getChangeDescription(policy.getVersion());
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 @Test
void delete_nonEmptyPolicy_4xx() { void delete_nonEmptyPolicy_4xx() {
// TODO // TODO

View File

@ -20,14 +20,17 @@ import static javax.ws.rs.core.Response.Status.OK;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.openmetadata.catalog.security.SecurityUtil.authHeaders; 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.adminAuthHeaders;
import static org.openmetadata.catalog.util.TestUtils.getPrincipal; import static org.openmetadata.catalog.util.TestUtils.getPrincipal;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.Map; import java.util.Map;
import javax.ws.rs.core.Response;
import org.apache.http.client.HttpResponseException; import org.apache.http.client.HttpResponseException;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo; import org.junit.jupiter.api.TestInfo;
@ -222,6 +225,25 @@ public class DashboardServiceResourceTest extends EntityResourceTest<DashboardSe
deleteEntity(dashboardService.getId(), authHeaders); deleteEntity(dashboardService.getId(), authHeaders);
} }
@Test
void delete_put_DashboardService_200(TestInfo test) throws IOException, URISyntaxException {
CreateDashboardService request = create(test).withDescription("");
DashboardService dashboardService = createEntity(request, adminAuthHeaders());
// Delete
deleteEntity(dashboardService.getId(), adminAuthHeaders());
ChangeDescription change = getChangeDescription(dashboardService.getVersion());
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 @Test
void delete_as_user_401(TestInfo test) throws HttpResponseException, URISyntaxException { void delete_as_user_401(TestInfo test) throws HttpResponseException, URISyntaxException {
Map<String, String> authHeaders = adminAuthHeaders(); Map<String, String> authHeaders = adminAuthHeaders();

View File

@ -19,13 +19,16 @@ import static javax.ws.rs.core.Response.Status.OK;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.openmetadata.catalog.security.SecurityUtil.authHeaders; 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.adminAuthHeaders;
import static org.openmetadata.catalog.util.TestUtils.getPrincipal; import static org.openmetadata.catalog.util.TestUtils.getPrincipal;
import java.io.IOException; import java.io.IOException;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.Map; import java.util.Map;
import javax.ws.rs.core.Response;
import org.apache.http.client.HttpResponseException; import org.apache.http.client.HttpResponseException;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo; import org.junit.jupiter.api.TestInfo;
@ -199,6 +202,25 @@ public class DatabaseServiceResourceTest extends EntityResourceTest<DatabaseServ
deleteEntity(databaseService.getId(), authHeaders); deleteEntity(databaseService.getId(), authHeaders);
} }
@Test
void delete_put_DatabaseService_200(TestInfo test) throws IOException {
CreateDatabaseService request = create(test).withDescription("");
DatabaseService databaseService = createEntity(request, adminAuthHeaders());
// Delete
deleteEntity(databaseService.getId(), adminAuthHeaders());
ChangeDescription change = getChangeDescription(databaseService.getVersion());
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 @Test
void delete_as_user_401(TestInfo test) throws HttpResponseException { void delete_as_user_401(TestInfo test) throws HttpResponseException {
Map<String, String> authHeaders = adminAuthHeaders(); Map<String, String> authHeaders = adminAuthHeaders();

View File

@ -21,14 +21,17 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.openmetadata.catalog.security.SecurityUtil.authHeaders; 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.adminAuthHeaders;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javax.ws.rs.core.Response;
import org.apache.http.client.HttpResponseException; import org.apache.http.client.HttpResponseException;
import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -249,6 +252,25 @@ public class MessagingServiceResourceTest extends EntityResourceTest<MessagingSe
deleteEntity(messagingService.getId(), authHeaders); deleteEntity(messagingService.getId(), authHeaders);
} }
@Test
void delete_put_MessagingService_200(TestInfo test) throws IOException {
CreateMessagingService request = create(test).withDescription("");
MessagingService messagingService = createEntity(request, adminAuthHeaders());
// Delete
deleteEntity(messagingService.getId(), adminAuthHeaders());
ChangeDescription change = getChangeDescription(messagingService.getVersion());
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 @Test
void delete_as_user_401(TestInfo test) throws HttpResponseException { void delete_as_user_401(TestInfo test) throws HttpResponseException {
Map<String, String> authHeaders = adminAuthHeaders(); Map<String, String> authHeaders = adminAuthHeaders();

View File

@ -20,14 +20,17 @@ import static javax.ws.rs.core.Response.Status.OK;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.openmetadata.catalog.security.SecurityUtil.authHeaders; 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.adminAuthHeaders;
import static org.openmetadata.catalog.util.TestUtils.getPrincipal; import static org.openmetadata.catalog.util.TestUtils.getPrincipal;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.Map; import java.util.Map;
import javax.ws.rs.core.Response;
import org.apache.http.client.HttpResponseException; import org.apache.http.client.HttpResponseException;
import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -229,6 +232,25 @@ public class PipelineServiceResourceTest extends EntityResourceTest<PipelineServ
deleteEntity(pipelineService.getId(), authHeaders); deleteEntity(pipelineService.getId(), authHeaders);
} }
@Test
void delete_put_PipelineService_200(TestInfo test) throws IOException {
CreatePipelineService request = create(test).withDescription("");
PipelineService pipelineService = createEntity(request, adminAuthHeaders());
// Delete
deleteEntity(pipelineService.getId(), adminAuthHeaders());
ChangeDescription change = getChangeDescription(pipelineService.getVersion());
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 @Test
void delete_as_user_401(TestInfo test) throws HttpResponseException { void delete_as_user_401(TestInfo test) throws HttpResponseException {
Map<String, String> authHeaders = adminAuthHeaders(); Map<String, String> authHeaders = adminAuthHeaders();

View File

@ -19,12 +19,15 @@ import static javax.ws.rs.core.Response.Status.OK;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.openmetadata.catalog.security.SecurityUtil.authHeaders; 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.adminAuthHeaders;
import static org.openmetadata.catalog.util.TestUtils.getPrincipal; import static org.openmetadata.catalog.util.TestUtils.getPrincipal;
import java.io.IOException; import java.io.IOException;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.Map; import java.util.Map;
import javax.ws.rs.core.Response;
import org.apache.http.client.HttpResponseException; import org.apache.http.client.HttpResponseException;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo; import org.junit.jupiter.api.TestInfo;
@ -35,7 +38,9 @@ import org.openmetadata.catalog.exception.CatalogExceptionMessage;
import org.openmetadata.catalog.jdbi3.StorageServiceRepository.StorageServiceEntityInterface; import org.openmetadata.catalog.jdbi3.StorageServiceRepository.StorageServiceEntityInterface;
import org.openmetadata.catalog.resources.EntityResourceTest; import org.openmetadata.catalog.resources.EntityResourceTest;
import org.openmetadata.catalog.resources.services.storage.StorageServiceResource.StorageServiceList; 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.EntityReference;
import org.openmetadata.catalog.type.FieldChange;
import org.openmetadata.catalog.type.StorageServiceType; import org.openmetadata.catalog.type.StorageServiceType;
import org.openmetadata.catalog.util.EntityInterface; import org.openmetadata.catalog.util.EntityInterface;
import org.openmetadata.catalog.util.TestUtils; import org.openmetadata.catalog.util.TestUtils;
@ -104,6 +109,25 @@ public class StorageServiceResourceTest extends EntityResourceTest<StorageServic
deleteEntity(storageService.getId(), authHeaders); deleteEntity(storageService.getId(), authHeaders);
} }
@Test
void delete_put_StorageService_200(TestInfo test) throws IOException {
CreateStorageService request = create(test).withDescription("");
StorageService storageService = createEntity(request, adminAuthHeaders());
// Delete
deleteEntity(storageService.getId(), adminAuthHeaders());
ChangeDescription change = getChangeDescription(storageService.getVersion());
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 @Test
void delete_as_user_401(TestInfo test) throws HttpResponseException { void delete_as_user_401(TestInfo test) throws HttpResponseException {
Map<String, String> authHeaders = adminAuthHeaders(); Map<String, String> authHeaders = adminAuthHeaders();

View File

@ -18,17 +18,20 @@ import static javax.ws.rs.core.Response.Status.FORBIDDEN;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.openmetadata.catalog.security.SecurityUtil.authHeaders; 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.adminAuthHeaders;
import static org.openmetadata.catalog.util.TestUtils.assertListNotNull; import static org.openmetadata.catalog.util.TestUtils.assertListNotNull;
import static org.openmetadata.catalog.util.TestUtils.assertResponse; import static org.openmetadata.catalog.util.TestUtils.assertResponse;
import java.io.IOException; import java.io.IOException;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import javax.ws.rs.client.WebTarget; import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status; import javax.ws.rs.core.Response.Status;
import org.apache.http.client.HttpResponseException; import org.apache.http.client.HttpResponseException;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -244,6 +247,25 @@ public class TopicResourceTest extends EntityResourceTest<Topic> {
deleteEntity(topic.getId(), adminAuthHeaders()); deleteEntity(topic.getId(), adminAuthHeaders());
} }
@Test
void delete_put_Topic_200(TestInfo test) throws IOException {
CreateTopic request = create(test).withDescription("");
Topic topic = createEntity(request, adminAuthHeaders());
// Delete
deleteEntity(topic.getId(), adminAuthHeaders());
ChangeDescription change = getChangeDescription(topic.getVersion());
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 @Test
void delete_nonEmptyTopic_4xx() { void delete_nonEmptyTopic_4xx() {
// TODO // TODO