diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/EntityResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/EntityResourceTest.java index 21faf77034a..7f5491766ce 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/EntityResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/EntityResourceTest.java @@ -24,10 +24,10 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotEquals; 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.ENTITY_ALREADY_EXISTS; import static org.openmetadata.catalog.exception.CatalogExceptionMessage.entityNotFound; +import static org.openmetadata.catalog.exception.CatalogExceptionMessage.readOnlyAttribute; import static org.openmetadata.catalog.resources.databases.TableResourceTest.getColumn; import static org.openmetadata.catalog.security.SecurityUtil.authHeaders; import static org.openmetadata.catalog.type.ColumnDataType.BIGINT; @@ -43,6 +43,7 @@ import static org.openmetadata.catalog.util.TestUtils.assertEntityPagination; import static org.openmetadata.catalog.util.TestUtils.assertListNotNull; import static org.openmetadata.catalog.util.TestUtils.assertListNull; import static org.openmetadata.catalog.util.TestUtils.assertResponse; +import static org.openmetadata.catalog.util.TestUtils.assertResponseContains; import static org.openmetadata.catalog.util.TestUtils.checkUserFollowing; import static org.openmetadata.catalog.util.TestUtils.userAuthHeaders; @@ -96,7 +97,6 @@ import org.openmetadata.catalog.entity.services.StorageService; import org.openmetadata.catalog.entity.teams.Role; import org.openmetadata.catalog.entity.teams.Team; import org.openmetadata.catalog.entity.teams.User; -import org.openmetadata.catalog.exception.CatalogExceptionMessage; import org.openmetadata.catalog.jdbi3.ChartRepository.ChartEntityInterface; import org.openmetadata.catalog.jdbi3.DashboardServiceRepository.DashboardServiceEntityInterface; import org.openmetadata.catalog.jdbi3.DatabaseRepository.DatabaseEntityInterface; @@ -562,10 +562,10 @@ public abstract class EntityResourceTest extends CatalogApplicationTest { ResultList listBeforeDeletion = listEntities(null, 1000, null, null, ADMIN_AUTH_HEADERS); // Delete non-empty container entity and ensure deletion is not allowed EntityResourceTest containerTest = ENTITY_RESOURCE_TEST_MAP.get(container.getType()); - HttpResponseException exception = - assertThrows( - HttpResponseException.class, () -> containerTest.deleteEntity(container.getId(), ADMIN_AUTH_HEADERS)); - assertResponse(exception, BAD_REQUEST, container.getType() + " is not empty"); + assertResponse( + () -> containerTest.deleteEntity(container.getId(), ADMIN_AUTH_HEADERS), + BAD_REQUEST, + container.getType() + " is not empty"); // Now delete the container with recursive flag on containerTest.deleteEntity(container.getId(), true, ADMIN_AUTH_HEADERS); @@ -582,24 +582,29 @@ public abstract class EntityResourceTest extends CatalogApplicationTest { @Test void get_entityListWithInvalidLimit_4xx() { // Limit must be >= 1 and <= 1000,000 - HttpResponseException exception = - assertThrows(HttpResponseException.class, () -> listEntities(null, -1, null, null, ADMIN_AUTH_HEADERS)); - assertResponse(exception, BAD_REQUEST, "[query param limit must be greater than or equal to 1]"); + assertResponse( + () -> listEntities(null, -1, null, null, ADMIN_AUTH_HEADERS), + BAD_REQUEST, + "[query param limit must be greater than or equal to 1]"); - exception = assertThrows(HttpResponseException.class, () -> listEntities(null, 0, null, null, ADMIN_AUTH_HEADERS)); - assertResponse(exception, BAD_REQUEST, "[query param limit must be greater than or equal to 1]"); + assertResponse( + () -> listEntities(null, 0, null, null, ADMIN_AUTH_HEADERS), + BAD_REQUEST, + "[query param limit must be greater than or equal to 1]"); - exception = - assertThrows(HttpResponseException.class, () -> listEntities(null, 1000001, null, null, ADMIN_AUTH_HEADERS)); - assertResponse(exception, BAD_REQUEST, "[query param limit must be less than or equal to 1000000]"); + assertResponse( + () -> listEntities(null, 1000001, null, null, ADMIN_AUTH_HEADERS), + BAD_REQUEST, + "[query param limit must be less than or equal to 1000000]"); } @Test void get_entityListWithInvalidPaginationCursors_4xx() { // Passing both before and after cursors is invalid - HttpResponseException exception = - assertThrows(HttpResponseException.class, () -> listEntities(null, 1, "", "", ADMIN_AUTH_HEADERS)); - assertResponse(exception, BAD_REQUEST, "Only one of before or after query parameter allowed"); + assertResponse( + () -> listEntities(null, 1, "", "", ADMIN_AUTH_HEADERS), + BAD_REQUEST, + "Only one of before or after query parameter allowed"); } @Test @@ -669,19 +674,15 @@ public abstract class EntityResourceTest extends CatalogApplicationTest { void post_entityCreateWithInvalidName_400() { // Create an entity with mandatory name field null final K request = createRequest(null, "description", "displayName", null); - HttpResponseException exception = - assertThrows(HttpResponseException.class, () -> createEntity(request, ADMIN_AUTH_HEADERS)); - assertResponse(exception, BAD_REQUEST, "[name must not be null]"); + assertResponse(() -> createEntity(request, ADMIN_AUTH_HEADERS), BAD_REQUEST, "[name must not be null]"); // Create an entity with mandatory name field empty final K request1 = createRequest("", "description", "displayName", null); - exception = assertThrows(HttpResponseException.class, () -> createEntity(request1, ADMIN_AUTH_HEADERS)); - assertResponse(exception, BAD_REQUEST, ENTITY_NAME_LENGTH_ERROR); + assertResponse(() -> createEntity(request1, ADMIN_AUTH_HEADERS), BAD_REQUEST, ENTITY_NAME_LENGTH_ERROR); // Create an entity with mandatory name field too long final K request2 = createRequest(LONG_ENTITY_NAME, "description", "displayName", null); - exception = assertThrows(HttpResponseException.class, () -> createEntity(request2, ADMIN_AUTH_HEADERS)); - assertResponse(exception, BAD_REQUEST, ENTITY_NAME_LENGTH_ERROR); + assertResponse(() -> createEntity(request2, ADMIN_AUTH_HEADERS), BAD_REQUEST, ENTITY_NAME_LENGTH_ERROR); } @Test @@ -691,9 +692,7 @@ public abstract class EntityResourceTest extends CatalogApplicationTest { } EntityReference owner = new EntityReference().withId(TEAM1.getId()); /* No owner type is set */ K create = createRequest(getEntityName(test), "", "", owner); - HttpResponseException exception = - assertThrows(HttpResponseException.class, () -> createEntity(create, ADMIN_AUTH_HEADERS)); - TestUtils.assertResponseContains(exception, BAD_REQUEST, "type must not be null"); + assertResponseContains(() -> createEntity(create, ADMIN_AUTH_HEADERS), BAD_REQUEST, "type must not be null"); } @Test @@ -703,9 +702,8 @@ public abstract class EntityResourceTest extends CatalogApplicationTest { } EntityReference owner = new EntityReference().withId(NON_EXISTENT_ENTITY).withType("user"); K create = createRequest(getEntityName(test), "", "", owner); - HttpResponseException exception = - assertThrows(HttpResponseException.class, () -> createEntity(create, ADMIN_AUTH_HEADERS)); - assertResponse(exception, NOT_FOUND, CatalogExceptionMessage.entityNotFound(Entity.USER, NON_EXISTENT_ENTITY)); + assertResponse( + () -> createEntity(create, ADMIN_AUTH_HEADERS), NOT_FOUND, entityNotFound(Entity.USER, NON_EXISTENT_ENTITY)); } @Test @@ -834,10 +832,10 @@ public abstract class EntityResourceTest extends CatalogApplicationTest { // Update description and remove owner as non-owner // Expect to throw an exception since only owner or admin can update resource K updateRequest = createRequest(getEntityName(test), "newDescription", "displayName", null); - HttpResponseException exception = - assertThrows(HttpResponseException.class, () -> updateEntity(updateRequest, OK, TEST_AUTH_HEADERS)); - TestUtils.assertResponse( - exception, FORBIDDEN, "Principal: CatalogPrincipal{name='test'} " + "does not have permissions"); + assertResponse( + () -> updateEntity(updateRequest, OK, TEST_AUTH_HEADERS), + FORBIDDEN, + "Principal: CatalogPrincipal{name='test'} " + "does not have permissions"); } @Test @@ -964,18 +962,16 @@ public abstract class EntityResourceTest extends CatalogApplicationTest { UUID entityId = getEntityInterface(entity).getId(); // Add non-existent user as follower to the entity - HttpResponseException exception = - assertThrows( - HttpResponseException.class, - () -> addAndCheckFollower(entityId, NON_EXISTENT_ENTITY, CREATED, 1, ADMIN_AUTH_HEADERS)); - assertResponse(exception, NOT_FOUND, CatalogExceptionMessage.entityNotFound(Entity.USER, NON_EXISTENT_ENTITY)); + assertResponse( + () -> addAndCheckFollower(entityId, NON_EXISTENT_ENTITY, CREATED, 1, ADMIN_AUTH_HEADERS), + NOT_FOUND, + entityNotFound(Entity.USER, NON_EXISTENT_ENTITY)); // Delete non-existent user as follower to the entity - exception = - assertThrows( - HttpResponseException.class, - () -> deleteAndCheckFollower(entityId, NON_EXISTENT_ENTITY, 1, ADMIN_AUTH_HEADERS)); - assertResponse(exception, NOT_FOUND, CatalogExceptionMessage.entityNotFound(Entity.USER, NON_EXISTENT_ENTITY)); + assertResponse( + () -> deleteAndCheckFollower(entityId, NON_EXISTENT_ENTITY, 1, ADMIN_AUTH_HEADERS), + NOT_FOUND, + entityNotFound(Entity.USER, NON_EXISTENT_ENTITY)); } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -1131,10 +1127,10 @@ public abstract class EntityResourceTest extends CatalogApplicationTest { EntityInterface entityInterface = getEntityInterface(entity); String json = JsonUtils.pojoToJson(entity); entityInterface.setDeleted(true); - HttpResponseException exception = - assertThrows( - HttpResponseException.class, () -> patchEntity(entityInterface.getId(), json, entity, ADMIN_AUTH_HEADERS)); - assertResponse(exception, BAD_REQUEST, CatalogExceptionMessage.readOnlyAttribute(entityType, "deleted")); + assertResponse( + () -> patchEntity(entityInterface.getId(), json, entity, ADMIN_AUTH_HEADERS), + BAD_REQUEST, + readOnlyAttribute(entityType, "deleted")); } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -1142,9 +1138,10 @@ public abstract class EntityResourceTest extends CatalogApplicationTest { /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @Test void delete_nonExistentEntity_404() { - HttpResponseException exception = - assertThrows(HttpResponseException.class, () -> deleteEntity(NON_EXISTENT_ENTITY, ADMIN_AUTH_HEADERS)); - assertResponse(exception, NOT_FOUND, entityNotFound(entityType, NON_EXISTENT_ENTITY)); + assertResponse( + () -> deleteEntity(NON_EXISTENT_ENTITY, ADMIN_AUTH_HEADERS), + NOT_FOUND, + entityNotFound(entityType, NON_EXISTENT_ENTITY)); } @Test @@ -1158,9 +1155,10 @@ public abstract class EntityResourceTest extends CatalogApplicationTest { void delete_entity_as_non_admin_401(TestInfo test) throws HttpResponseException { K request = createRequest(getEntityName(test), "", "", null); T entity = createEntity(request, ADMIN_AUTH_HEADERS); - HttpResponseException exception = - assertThrows(HttpResponseException.class, () -> deleteAndCheckEntity(entity, TEST_AUTH_HEADERS)); - assertResponse(exception, FORBIDDEN, "Principal: CatalogPrincipal{name='test'} is not admin"); + assertResponse( + () -> deleteAndCheckEntity(entity, TEST_AUTH_HEADERS), + FORBIDDEN, + "Principal: CatalogPrincipal{name='test'} is not admin"); } /** Soft delete an entity and then use PUT request to restore it back */ @@ -1186,25 +1184,22 @@ public abstract class EntityResourceTest extends CatalogApplicationTest { @Test void testInvalidEntityList() { // Invalid entityCreated list - HttpResponseException exception = - assertThrows( - HttpResponseException.class, - () -> getChangeEvents("invalidEntity", entityType, null, System.currentTimeMillis(), ADMIN_AUTH_HEADERS)); - assertResponse(exception, BAD_REQUEST, "Invalid entity invalidEntity in query param entityCreated"); + assertResponse( + () -> getChangeEvents("invalidEntity", entityType, null, System.currentTimeMillis(), ADMIN_AUTH_HEADERS), + BAD_REQUEST, + "Invalid entity invalidEntity in query param entityCreated"); // Invalid entityUpdated list - exception = - assertThrows( - HttpResponseException.class, - () -> getChangeEvents(null, "invalidEntity", entityType, System.currentTimeMillis(), ADMIN_AUTH_HEADERS)); - assertResponse(exception, BAD_REQUEST, "Invalid entity invalidEntity in query param entityUpdated"); + assertResponse( + () -> getChangeEvents(null, "invalidEntity", entityType, System.currentTimeMillis(), ADMIN_AUTH_HEADERS), + BAD_REQUEST, + "Invalid entity invalidEntity in query param entityUpdated"); // Invalid entityDeleted list - exception = - assertThrows( - HttpResponseException.class, - () -> getChangeEvents(entityType, null, "invalidEntity", System.currentTimeMillis(), ADMIN_AUTH_HEADERS)); - assertResponse(exception, BAD_REQUEST, "Invalid entity invalidEntity in query param entityDeleted"); + assertResponse( + () -> getChangeEvents(entityType, null, "invalidEntity", System.currentTimeMillis(), ADMIN_AUTH_HEADERS), + BAD_REQUEST, + "Invalid entity invalidEntity in query param entityDeleted"); } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -1469,14 +1464,9 @@ public abstract class EntityResourceTest extends CatalogApplicationTest { entityInterface.setDescription(newDescription); if (shouldThrowException) { - HttpResponseException exception = - assertThrows( - HttpResponseException.class, - () -> - patchEntity( - entityInterface.getId(), originalJson, entity, authHeaders(userName + "@open-metadata.org"))); assertResponse( - exception, + () -> + patchEntity(entityInterface.getId(), originalJson, entity, authHeaders(userName + "@open-metadata.org")), FORBIDDEN, String.format( "Principal: CatalogPrincipal{name='%s'} does not have permission to UpdateDescription", userName)); diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/dashboards/DashboardResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/dashboards/DashboardResourceTest.java index 8a3275108c1..59795b2ed4c 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/dashboards/DashboardResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/dashboards/DashboardResourceTest.java @@ -18,7 +18,6 @@ import static javax.ws.rs.core.Response.Status.BAD_REQUEST; import static javax.ws.rs.core.Response.Status.OK; 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.junit.jupiter.api.Assertions.assertTrue; import static org.openmetadata.catalog.exception.CatalogExceptionMessage.invalidServiceEntity; import static org.openmetadata.catalog.util.TestUtils.ADMIN_AUTH_HEADERS; @@ -107,10 +106,8 @@ public class DashboardResourceTest extends EntityResourceTest createEntity(create, ADMIN_AUTH_HEADERS)); assertResponse( - exception, + () -> createEntity(create, ADMIN_AUTH_HEADERS), BAD_REQUEST, invalidServiceEntity(SUPERSET_INVALID_SERVICE_REFERENCE.getType(), Entity.DASHBOARD, Entity.DASHBOARD_SERVICE)); } diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/databases/DatabaseResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/databases/DatabaseResourceTest.java index 53796f5dd52..b7dbe7b4033 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/databases/DatabaseResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/databases/DatabaseResourceTest.java @@ -16,10 +16,11 @@ package org.openmetadata.catalog.resources.databases; import static javax.ws.rs.core.Response.Status.BAD_REQUEST; 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.util.TestUtils.ADMIN_AUTH_HEADERS; import static org.openmetadata.catalog.util.TestUtils.assertListNotNull; import static org.openmetadata.catalog.util.TestUtils.assertListNull; +import static org.openmetadata.catalog.util.TestUtils.assertResponse; +import static org.openmetadata.catalog.util.TestUtils.assertResponseContains; import java.io.IOException; import java.net.URISyntaxException; @@ -70,7 +71,7 @@ public class DatabaseResourceTest extends EntityResourceTest createEntity(create, ADMIN_AUTH_HEADERS), BAD_REQUEST, CatalogExceptionMessage.invalidServiceEntity("invalid", Entity.DATABASE, Entity.DATABASE_SERVICE)); @@ -99,9 +100,7 @@ public class DatabaseResourceTest extends EntityResourceTest createEntity(create, ADMIN_AUTH_HEADERS)); - TestUtils.assertResponseContains(exception, BAD_REQUEST, "service must not be null"); + assertResponseContains(() -> createEntity(create, ADMIN_AUTH_HEADERS), BAD_REQUEST, "service must not be null"); } @Test diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/databases/TableResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/databases/TableResourceTest.java index 39120e2981a..275140d0a9d 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/databases/TableResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/databases/TableResourceTest.java @@ -21,7 +21,8 @@ import static javax.ws.rs.core.Response.Status.OK; import static org.junit.jupiter.api.Assertions.assertEquals; 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.openmetadata.catalog.exception.CatalogExceptionMessage.entityNotFound; +import static org.openmetadata.catalog.exception.CatalogExceptionMessage.invalidColumnFQN; import static org.openmetadata.catalog.type.ColumnDataType.ARRAY; import static org.openmetadata.catalog.type.ColumnDataType.BIGINT; import static org.openmetadata.catalog.type.ColumnDataType.BINARY; @@ -40,6 +41,8 @@ import static org.openmetadata.catalog.util.TestUtils.UpdateType.MINOR_UPDATE; import static org.openmetadata.catalog.util.TestUtils.UpdateType.NO_CHANGE; import static org.openmetadata.catalog.util.TestUtils.assertListNotNull; import static org.openmetadata.catalog.util.TestUtils.assertResponse; +import static org.openmetadata.catalog.util.TestUtils.assertResponseContains; +import static org.openmetadata.catalog.util.TestUtils.put; import static org.openmetadata.catalog.util.TestUtils.userAuthHeaders; import static org.openmetadata.common.utils.CommonUtil.getDateStringByOffset; @@ -73,7 +76,6 @@ import org.openmetadata.catalog.entity.data.Database; import org.openmetadata.catalog.entity.data.Location; import org.openmetadata.catalog.entity.data.Table; import org.openmetadata.catalog.entity.services.DatabaseService; -import org.openmetadata.catalog.exception.CatalogExceptionMessage; import org.openmetadata.catalog.jdbi3.TableRepository.TableEntityInterface; import org.openmetadata.catalog.resources.EntityResourceTest; import org.openmetadata.catalog.resources.databases.TableResource.TableList; @@ -129,10 +131,10 @@ public class TableResourceTest extends EntityResourceTest { for (ColumnDataType dataType : columnDataTypes) { create.getColumns().get(0).withDataType(dataType); - HttpResponseException exception = - assertThrows(HttpResponseException.class, () -> createEntity(create, ADMIN_AUTH_HEADERS)); assertResponse( - exception, BAD_REQUEST, "For column data types char, varchar, binary, varbinary dataLength must not be null"); + () -> createEntity(create, ADMIN_AUTH_HEADERS), + BAD_REQUEST, + "For column data types char, varchar, binary, varbinary dataLength must not be null"); } } @@ -141,15 +143,17 @@ public class TableResourceTest extends EntityResourceTest { // No arrayDataType passed for array List columns = singletonList(getColumn("c1", ARRAY, "array", null)); CreateTable create = createRequest(test).withColumns(columns); - HttpResponseException exception = - assertThrows(HttpResponseException.class, () -> createEntity(create, ADMIN_AUTH_HEADERS)); - assertResponse(exception, BAD_REQUEST, "For column data type array, arrayDataType must not be null"); + assertResponse( + () -> createEntity(create, ADMIN_AUTH_HEADERS), + BAD_REQUEST, + "For column data type array, arrayDataType must not be null"); // No dataTypeDisplay passed for array columns.get(0).withArrayDataType(INT).withDataTypeDisplay(null); - exception = assertThrows(HttpResponseException.class, () -> createEntity(create, ADMIN_AUTH_HEADERS)); assertResponse( - exception, BAD_REQUEST, "For column data type array, dataTypeDisplay must be of type array"); + () -> createEntity(create, ADMIN_AUTH_HEADERS), + BAD_REQUEST, + "For column data type array, dataTypeDisplay must be of type array"); } @Test @@ -160,9 +164,10 @@ public class TableResourceTest extends EntityResourceTest { Arrays.asList( getColumn(repeatedColumnName, ARRAY, "array", null), getColumn(repeatedColumnName, INT, null)); CreateTable create = createRequest(test).withColumns(columns); - HttpResponseException exception = - assertThrows(HttpResponseException.class, () -> createEntity(create, ADMIN_AUTH_HEADERS)); - assertResponse(exception, BAD_REQUEST, String.format("Column name %s is repeated", repeatedColumnName)); + assertResponse( + () -> createEntity(create, ADMIN_AUTH_HEADERS), + BAD_REQUEST, + String.format("Column name %s is repeated", repeatedColumnName)); } @Test @@ -303,9 +308,10 @@ public class TableResourceTest extends EntityResourceTest { void post_tableWithInvalidDatabase_404(TestInfo test) { EntityReference database = new EntityReference().withId(NON_EXISTENT_ENTITY).withType(Entity.DATABASE); CreateTable create = createRequest(test).withDatabase(database); - HttpResponseException exception = - assertThrows(HttpResponseException.class, () -> createEntity(create, ADMIN_AUTH_HEADERS)); - assertResponse(exception, NOT_FOUND, CatalogExceptionMessage.entityNotFound(Entity.DATABASE, NON_EXISTENT_ENTITY)); + assertResponse( + () -> createEntity(create, ADMIN_AUTH_HEADERS), + NOT_FOUND, + entityNotFound(Entity.DATABASE, NON_EXISTENT_ENTITY)); } @Test @@ -613,33 +619,31 @@ public class TableResourceTest extends EntityResourceTest { String columnFQN = "invalidDB"; JoinedWith joinedWith = new JoinedWith().withFullyQualifiedName(columnFQN); joins.get(0).withJoinedWith(singletonList(joinedWith)); - HttpResponseException exception = - assertThrows(HttpResponseException.class, () -> putJoins(table1.getId(), tableJoins, ADMIN_AUTH_HEADERS)); - assertResponse(exception, BAD_REQUEST, CatalogExceptionMessage.invalidColumnFQN(columnFQN)); + assertResponse( + () -> putJoins(table1.getId(), tableJoins, ADMIN_AUTH_HEADERS), BAD_REQUEST, invalidColumnFQN(columnFQN)); // Invalid table name columnFQN = table2.getDatabase().getName() + ".invalidTable"; joinedWith = new JoinedWith().withFullyQualifiedName(columnFQN); joins.get(0).withJoinedWith(singletonList(joinedWith)); - exception = - assertThrows(HttpResponseException.class, () -> putJoins(table1.getId(), tableJoins, ADMIN_AUTH_HEADERS)); - assertResponse(exception, BAD_REQUEST, CatalogExceptionMessage.invalidColumnFQN(columnFQN)); + assertResponse( + () -> putJoins(table1.getId(), tableJoins, ADMIN_AUTH_HEADERS), BAD_REQUEST, invalidColumnFQN(columnFQN)); // Invalid column name columnFQN = table2.getFullyQualifiedName() + ".invalidColumn"; joinedWith = new JoinedWith().withFullyQualifiedName(columnFQN); joins.get(0).withJoinedWith(singletonList(joinedWith)); - exception = - assertThrows(HttpResponseException.class, () -> putJoins(table1.getId(), tableJoins, ADMIN_AUTH_HEADERS)); - assertResponse(exception, BAD_REQUEST, CatalogExceptionMessage.invalidColumnFQN(columnFQN)); + assertResponse( + () -> putJoins(table1.getId(), tableJoins, ADMIN_AUTH_HEADERS), BAD_REQUEST, invalidColumnFQN(columnFQN)); // Invalid date older than 30 days joinedWith = new JoinedWith().withFullyQualifiedName(table2.getFullyQualifiedName() + ".c1"); joins.get(0).withJoinedWith(singletonList(joinedWith)); tableJoins.withStartDate(RestUtil.today(-30)); // 30 days older than today - exception = - assertThrows(HttpResponseException.class, () -> putJoins(table1.getId(), tableJoins, ADMIN_AUTH_HEADERS)); - assertResponse(exception, BAD_REQUEST, "Date range can only include past 30 days starting today"); + assertResponse( + () -> putJoins(table1.getId(), tableJoins, ADMIN_AUTH_HEADERS), + BAD_REQUEST, + "Date range can only include past 30 days starting today"); } public void assertColumnJoins(List expected, TableJoins actual) throws ParseException { @@ -686,25 +690,28 @@ public class TableResourceTest extends EntityResourceTest { List columns = Arrays.asList("c1", "c2", "invalidColumn"); // Invalid column name List> rows = singletonList(Arrays.asList("c1Value1", 1, true)); // Valid sample data tableData.withColumns(columns).withRows(rows); - HttpResponseException exception = - assertThrows(HttpResponseException.class, () -> putSampleData(table.getId(), tableData, ADMIN_AUTH_HEADERS)); - TestUtils.assertResponseContains(exception, BAD_REQUEST, "Invalid column name invalidColumn"); + assertResponseContains( + () -> putSampleData(table.getId(), tableData, ADMIN_AUTH_HEADERS), + BAD_REQUEST, + "Invalid column name invalidColumn"); // Send sample data that has more samples than the number of columns columns = Arrays.asList("c1", "c2", "c3"); // Invalid column name rows = singletonList(Arrays.asList("c1Value1", 1, true, "extra value")); // Extra value tableData.withColumns(columns).withRows(rows); - exception = - assertThrows(HttpResponseException.class, () -> putSampleData(table.getId(), tableData, ADMIN_AUTH_HEADERS)); - TestUtils.assertResponseContains(exception, BAD_REQUEST, "Number of columns is 3 but row " + "has 4 sample values"); + assertResponseContains( + () -> putSampleData(table.getId(), tableData, ADMIN_AUTH_HEADERS), + BAD_REQUEST, + "Number of columns is 3 but row " + "has 4 sample values"); // Send sample data that has fewer samples than the number of columns columns = Arrays.asList("c1", "c2", "c3"); // Invalid column name rows = singletonList(Arrays.asList("c1Value1", 1 /* Missing Value */)); tableData.withColumns(columns).withRows(rows); - exception = - assertThrows(HttpResponseException.class, () -> putSampleData(table.getId(), tableData, ADMIN_AUTH_HEADERS)); - TestUtils.assertResponseContains(exception, BAD_REQUEST, "Number of columns is 3 but row h" + "as 2 sample values"); + assertResponseContains( + () -> putSampleData(table.getId(), tableData, ADMIN_AUTH_HEADERS), + BAD_REQUEST, + "Number of columns is 3 but row h" + "as 2 sample values"); } @Test @@ -737,10 +744,8 @@ public class TableResourceTest extends EntityResourceTest { + "select * from spectrum.sales\n" + "with no schema binding;\n"; createTable.setViewDefinition(query); - HttpResponseException exception = - assertThrows(HttpResponseException.class, () -> createAndCheckEntity(createTable, ADMIN_AUTH_HEADERS)); - TestUtils.assertResponseContains( - exception, + assertResponseContains( + () -> createAndCheckEntity(createTable, ADMIN_AUTH_HEADERS), BAD_REQUEST, "ViewDefinition can only be set on " + "TableType View, SecureView or MaterializedView"); } @@ -810,10 +815,10 @@ public class TableResourceTest extends EntityResourceTest { .withColumnCount(3.0) .withColumnProfile(columnProfiles) .withProfileDate("2021-09-09"); - HttpResponseException exception = - assertThrows( - HttpResponseException.class, () -> putTableProfileData(table.getId(), tableProfile, ADMIN_AUTH_HEADERS)); - TestUtils.assertResponseContains(exception, BAD_REQUEST, "Invalid column name invalidColumn"); + assertResponseContains( + () -> putTableProfileData(table.getId(), tableProfile, ADMIN_AUTH_HEADERS), + BAD_REQUEST, + "Invalid column name invalidColumn"); } @Test diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/feeds/FeedResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/feeds/FeedResourceTest.java index d145ab30399..80f4c443250 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/feeds/FeedResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/feeds/FeedResourceTest.java @@ -17,10 +17,12 @@ import static javax.ws.rs.core.Response.Status.BAD_REQUEST; import static javax.ws.rs.core.Response.Status.NOT_FOUND; 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.exception.CatalogExceptionMessage.entityNotFound; import static org.openmetadata.catalog.security.SecurityUtil.authHeaders; import static org.openmetadata.catalog.util.TestUtils.ADMIN_AUTH_HEADERS; +import static org.openmetadata.catalog.util.TestUtils.NON_EXISTENT_ENTITY; +import static org.openmetadata.catalog.util.TestUtils.assertResponse; +import static org.openmetadata.catalog.util.TestUtils.assertResponseContains; import java.io.IOException; import java.net.URISyntaxException; @@ -86,9 +88,7 @@ public class FeedResourceTest extends CatalogApplicationTest { void post_feedWithoutAbout_4xx() { // Create thread without addressed to entity in the request CreateThread create = create().withFrom(USER.getId()).withAbout(null); - HttpResponseException exception = - assertThrows(HttpResponseException.class, () -> createThread(create, authHeaders(USER.getEmail()))); - TestUtils.assertResponse(exception, BAD_REQUEST, "[about must not be null]"); + assertResponse(() -> createThread(create, authHeaders(USER.getEmail())), BAD_REQUEST, "[about must not be null]"); } @Test @@ -96,57 +96,56 @@ public class FeedResourceTest extends CatalogApplicationTest { // Create thread without addressed to entity in the request CreateThread create = create().withFrom(USER.getId()).withAbout("<>"); // Invalid EntityLink Map authHeaders = authHeaders(USER.getEmail()); - HttpResponseException exception = - assertThrows(HttpResponseException.class, () -> createThread(create, authHeaders)); - TestUtils.assertResponseContains(exception, BAD_REQUEST, "[about must match \"^<#E/\\S+/\\S+>$\"]"); + assertResponseContains( + () -> createThread(create, authHeaders), BAD_REQUEST, "[about must match \"^<#E/\\S+/\\S+>$\"]"); create.withAbout("<#E/>"); // Invalid EntityLink - missing entityType and entityId - exception = assertThrows(HttpResponseException.class, () -> createThread(create, authHeaders)); - TestUtils.assertResponseContains(exception, BAD_REQUEST, "[about must match \"^<#E/\\S+/\\S+>$\"]"); + assertResponseContains( + () -> createThread(create, authHeaders), BAD_REQUEST, "[about must match \"^<#E/\\S+/\\S+>$\"]"); create.withAbout("<#E/table/>"); // Invalid EntityLink - missing entityId - exception = assertThrows(HttpResponseException.class, () -> createThread(create, authHeaders)); - TestUtils.assertResponseContains(exception, BAD_REQUEST, "[about must match \"^<#E/\\S+/\\S+>$\"]"); + assertResponseContains( + () -> createThread(create, authHeaders), BAD_REQUEST, "[about must match \"^<#E/\\S+/\\S+>$\"]"); create.withAbout("<#E/table/tableName"); // Invalid EntityLink - missing closing bracket ">" - exception = assertThrows(HttpResponseException.class, () -> createThread(create, authHeaders)); - TestUtils.assertResponseContains(exception, BAD_REQUEST, "[about must match \"^<#E/\\S+/\\S+>$\"]"); + assertResponseContains( + () -> createThread(create, authHeaders), BAD_REQUEST, "[about must match \"^<#E/\\S+/\\S+>$\"]"); } @Test void post_feedWithoutMessage_4xx() { // Create thread without message field in the request CreateThread create = create().withFrom(USER.getId()).withMessage(null); - HttpResponseException exception = - assertThrows(HttpResponseException.class, () -> createThread(create, authHeaders(USER.getEmail()))); - TestUtils.assertResponseContains(exception, BAD_REQUEST, "[message must not be null]"); + assertResponseContains( + () -> createThread(create, authHeaders(USER.getEmail())), BAD_REQUEST, "[message must not be null]"); } @Test void post_feedWithoutFrom_4xx() { // Create thread without from field in the request CreateThread create = create().withFrom(null); - HttpResponseException exception = - assertThrows(HttpResponseException.class, () -> createThread(create, authHeaders(USER.getEmail()))); - TestUtils.assertResponseContains(exception, BAD_REQUEST, "[from must not be null]"); + assertResponseContains( + () -> createThread(create, authHeaders(USER.getEmail())), BAD_REQUEST, "[from must not be null]"); } @Test void post_feedWithNonExistentFrom_404() { // Create thread with non-existent from - CreateThread create = create().withFrom(TestUtils.NON_EXISTENT_ENTITY); - HttpResponseException exception = - assertThrows(HttpResponseException.class, () -> createThread(create, authHeaders(USER.getEmail()))); - TestUtils.assertResponse(exception, NOT_FOUND, entityNotFound(Entity.USER, TestUtils.NON_EXISTENT_ENTITY)); + CreateThread create = create().withFrom(NON_EXISTENT_ENTITY); + assertResponse( + () -> createThread(create, authHeaders(USER.getEmail())), + NOT_FOUND, + entityNotFound(Entity.USER, NON_EXISTENT_ENTITY)); } @Test void post_feedWithNonExistentAbout_404() { // Create thread with non-existent addressed To entity CreateThread create = create().withAbout("<#E/table/invalidTableName>"); - HttpResponseException exception = - assertThrows(HttpResponseException.class, () -> createThread(create, authHeaders(USER.getEmail()))); - TestUtils.assertResponse(exception, NOT_FOUND, entityNotFound(Entity.TABLE, "invalidTableName")); + assertResponse( + () -> createThread(create, authHeaders(USER.getEmail())), + NOT_FOUND, + entityNotFound(Entity.TABLE, "invalidTableName")); } @Test @@ -178,27 +177,26 @@ public class FeedResourceTest extends CatalogApplicationTest { void post_addPostWithoutMessage_4xx() { // Add post to a thread without message field Post post = createPost().withMessage(null); - HttpResponseException exception = - assertThrows(HttpResponseException.class, () -> addPost(THREAD.getId(), post, authHeaders(USER.getEmail()))); - TestUtils.assertResponseContains(exception, BAD_REQUEST, "[message must not be null]"); + assertResponseContains( + () -> addPost(THREAD.getId(), post, authHeaders(USER.getEmail())), BAD_REQUEST, "[message must not be null]"); } @Test void post_addPostWithoutFrom_4xx() { // Add post to a thread without from field Post post = createPost().withFrom(null); - HttpResponseException exception = - assertThrows(HttpResponseException.class, () -> addPost(THREAD.getId(), post, authHeaders(USER.getEmail()))); - TestUtils.assertResponseContains(exception, BAD_REQUEST, "[from must not be null]"); + assertResponseContains( + () -> addPost(THREAD.getId(), post, authHeaders(USER.getEmail())), BAD_REQUEST, "[from must not be null]"); } @Test void post_addPostWithNonExistentFrom_404() { // Add post to a thread with non-existent from user - Post post = createPost().withFrom(TestUtils.NON_EXISTENT_ENTITY); - HttpResponseException exception = - assertThrows(HttpResponseException.class, () -> addPost(THREAD.getId(), post, authHeaders(USER.getEmail()))); - TestUtils.assertResponse(exception, NOT_FOUND, entityNotFound(Entity.USER, TestUtils.NON_EXISTENT_ENTITY)); + Post post = createPost().withFrom(NON_EXISTENT_ENTITY); + assertResponse( + () -> addPost(THREAD.getId(), post, authHeaders(USER.getEmail())), + NOT_FOUND, + entityNotFound(Entity.USER, NON_EXISTENT_ENTITY)); } @Test diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/lineage/LineageResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/lineage/LineageResourceTest.java index cfd9b7e1485..df8f8d7523f 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/lineage/LineageResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/lineage/LineageResourceTest.java @@ -16,7 +16,6 @@ package org.openmetadata.catalog.resources.lineage; import static javax.ws.rs.core.Response.Status.FORBIDDEN; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; -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.ADMIN_AUTH_HEADERS; @@ -107,16 +106,12 @@ public class LineageResourceTest extends CatalogApplicationTest { Map authHeaders = authHeaders(userName + "@open-metadata.org"); if (shouldThrowException) { - HttpResponseException exception = - assertThrows(HttpResponseException.class, () -> addEdge(TABLES.get(1), TABLES.get(2), authHeaders)); assertResponse( - exception, + () -> addEdge(TABLES.get(1), TABLES.get(2), authHeaders), FORBIDDEN, String.format("Principal: CatalogPrincipal{name='%s'} does not have permission to UpdateLineage", userName)); - exception = - assertThrows(HttpResponseException.class, () -> deleteEdge(TABLES.get(1), TABLES.get(2), authHeaders)); assertResponse( - exception, + () -> deleteEdge(TABLES.get(1), TABLES.get(2), authHeaders), FORBIDDEN, String.format("Principal: CatalogPrincipal{name='%s'} does not have permission to UpdateLineage", userName)); return; diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/locations/LocationResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/locations/LocationResourceTest.java index d083b4692f8..78571f39a30 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/locations/LocationResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/locations/LocationResourceTest.java @@ -16,7 +16,6 @@ package org.openmetadata.catalog.resources.locations; import static javax.ws.rs.core.Response.Status.BAD_REQUEST; 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.util.TestUtils.ADMIN_AUTH_HEADERS; import static org.openmetadata.catalog.util.TestUtils.assertListNotNull; import static org.openmetadata.catalog.util.TestUtils.assertResponse; @@ -177,16 +176,16 @@ public class LocationResourceTest extends EntityResourceTest createEntity(createRequest(test).withName(null), ADMIN_AUTH_HEADERS)); - assertResponse(exception, BAD_REQUEST, "[name must not be null]"); + assertResponse( + () -> createEntity(createRequest(test).withName(null), ADMIN_AUTH_HEADERS), + BAD_REQUEST, + "[name must not be null]"); // Service is required field - exception = - assertThrows( - HttpResponseException.class, () -> createEntity(createRequest(test).withService(null), ADMIN_AUTH_HEADERS)); - assertResponse(exception, BAD_REQUEST, "[service must not be null]"); + assertResponse( + () -> createEntity(createRequest(test).withService(null), ADMIN_AUTH_HEADERS), + BAD_REQUEST, + "[service must not be null]"); } @Test diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/operations/AirflowPipelineResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/operations/AirflowPipelineResourceTest.java index 5a61c41dea7..efa04b304b7 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/operations/AirflowPipelineResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/operations/AirflowPipelineResourceTest.java @@ -32,6 +32,7 @@ import static org.openmetadata.catalog.fernet.Fernet.decryptIfTokenized; import static org.openmetadata.catalog.util.TestUtils.ADMIN_AUTH_HEADERS; import static org.openmetadata.catalog.util.TestUtils.UpdateType.MINOR_UPDATE; import static org.openmetadata.catalog.util.TestUtils.assertListNotNull; +import static org.openmetadata.catalog.util.TestUtils.assertResponseContains; import java.io.IOException; import java.net.URISyntaxException; @@ -204,9 +205,7 @@ public class AirflowPipelineResourceTest extends EntityOperationsResourceTest createEntity(create, ADMIN_AUTH_HEADERS)); - TestUtils.assertResponseContains(exception, BAD_REQUEST, "service must not be null"); + assertResponseContains(() -> createEntity(create, ADMIN_AUTH_HEADERS), BAD_REQUEST, "service must not be null"); } @Test diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/pipelines/PipelineResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/pipelines/PipelineResourceTest.java index d3e13fc1c96..7dc6d9927c5 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/pipelines/PipelineResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/pipelines/PipelineResourceTest.java @@ -18,10 +18,10 @@ import static javax.ws.rs.core.Response.Status.OK; import static org.junit.jupiter.api.Assertions.assertEquals; 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.openmetadata.catalog.util.TestUtils.ADMIN_AUTH_HEADERS; import static org.openmetadata.catalog.util.TestUtils.UpdateType.MINOR_UPDATE; import static org.openmetadata.catalog.util.TestUtils.assertListNotNull; +import static org.openmetadata.catalog.util.TestUtils.assertResponseContains; import java.io.IOException; import java.net.URI; @@ -184,9 +184,7 @@ public class PipelineResourceTest extends EntityResourceTest createEntity(create, ADMIN_AUTH_HEADERS)); - TestUtils.assertResponseContains(exception, BAD_REQUEST, "service must not be null"); + assertResponseContains(() -> createEntity(create, ADMIN_AUTH_HEADERS), BAD_REQUEST, "service must not be null"); } @Test @@ -362,11 +360,10 @@ public class PipelineResourceTest extends EntityResourceTest putPipelineStatusData(pipeline.getId(), pipelineStatus, ADMIN_AUTH_HEADERS)); - TestUtils.assertResponseContains(exception, BAD_REQUEST, "Invalid task name invalidTask"); + assertResponseContains( + () -> putPipelineStatusData(pipeline.getId(), pipelineStatus, ADMIN_AUTH_HEADERS), + BAD_REQUEST, + "Invalid task name invalidTask"); } @Test diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/policies/PolicyResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/policies/PolicyResourceTest.java index 3bb28df3549..abaaf4fc164 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/policies/PolicyResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/policies/PolicyResourceTest.java @@ -17,7 +17,6 @@ import static javax.ws.rs.core.Response.Status.BAD_REQUEST; import static org.junit.jupiter.api.Assertions.assertEquals; 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.fail; import static org.openmetadata.catalog.util.TestUtils.ADMIN_AUTH_HEADERS; import static org.openmetadata.catalog.util.TestUtils.UpdateType.MINOR_UPDATE; @@ -130,9 +129,7 @@ public class PolicyResourceTest extends EntityResourceTest @Test void post_PolicyWithoutPolicyType_400_badRequest(TestInfo test) { CreatePolicy create = createRequest(test).withPolicyType(null); - HttpResponseException exception = - assertThrows(HttpResponseException.class, () -> createEntity(create, ADMIN_AUTH_HEADERS)); - assertResponse(exception, BAD_REQUEST, "[policyType must not be null]"); + assertResponse(() -> createEntity(create, ADMIN_AUTH_HEADERS), BAD_REQUEST, "[policyType must not be null]"); } @Test @@ -160,10 +157,8 @@ public class PolicyResourceTest extends EntityResourceTest rules.add( PolicyUtils.accessControlRule("rule21", null, null, null, MetadataOperation.UpdateDescription, true, 0, true)); CreatePolicy create = createAccessControlPolicyWithRules(getEntityName(test), rules); - HttpResponseException exception = - assertThrows(HttpResponseException.class, () -> createEntity(create, ADMIN_AUTH_HEADERS)); assertResponseContains( - exception, + () -> createEntity(create, ADMIN_AUTH_HEADERS), BAD_REQUEST, String.format( "Found invalid rule rule21 within policy %s. Please ensure that at least one among the user " @@ -184,37 +179,41 @@ public class PolicyResourceTest extends EntityResourceTest PolicyUtils.accessControlRule( "rule3", null, null, "DataConsumer", MetadataOperation.UpdateTags, true, 1, true)); CreatePolicy create = createAccessControlPolicyWithRules(getEntityName(test), rules); - HttpResponseException exception = - assertThrows(HttpResponseException.class, () -> createEntity(create, ADMIN_AUTH_HEADERS)); assertResponseContains( - exception, + () -> createEntity(create, ADMIN_AUTH_HEADERS), BAD_REQUEST, String.format( - "Found multiple rules with operation UpdateTags within policy %s. Please ensure that operation across all rules within the policy are distinct", + "Found multiple rules with operation UpdateTags within policy %s. " + + "Please ensure that operation across all rules within the policy are distinct", getEntityName(test))); } @Test void get_PolicyListWithInvalidLimitOffset_4xx() { // Limit must be >= 1 and <= 1000,000 - HttpResponseException exception = - assertThrows(HttpResponseException.class, () -> listPolicies(null, -1, null, null, ADMIN_AUTH_HEADERS)); - assertResponse(exception, BAD_REQUEST, "[query param limit must be greater than or equal to 1]"); + assertResponse( + () -> listPolicies(null, -1, null, null, ADMIN_AUTH_HEADERS), + BAD_REQUEST, + "[query param limit must be greater than or equal to 1]"); - exception = assertThrows(HttpResponseException.class, () -> listPolicies(null, 0, null, null, ADMIN_AUTH_HEADERS)); - assertResponse(exception, BAD_REQUEST, "[query param limit must be greater than or equal to 1]"); + assertResponse( + () -> listPolicies(null, 0, null, null, ADMIN_AUTH_HEADERS), + BAD_REQUEST, + "[query param limit must be greater than or equal to 1]"); - exception = - assertThrows(HttpResponseException.class, () -> listPolicies(null, 1000001, null, null, ADMIN_AUTH_HEADERS)); - assertResponse(exception, BAD_REQUEST, "[query param limit must be less than or equal to 1000000]"); + assertResponse( + () -> listPolicies(null, 1000001, null, null, ADMIN_AUTH_HEADERS), + BAD_REQUEST, + "[query param limit must be less than or equal to 1000000]"); } @Test void get_PolicyListWithInvalidPaginationCursors_4xx() { // Passing both before and after cursors is invalid - HttpResponseException exception = - assertThrows(HttpResponseException.class, () -> listPolicies(null, 1, "", "", ADMIN_AUTH_HEADERS)); - assertResponse(exception, BAD_REQUEST, "Only one of before or after query parameter allowed"); + assertResponse( + () -> listPolicies(null, 1, "", "", ADMIN_AUTH_HEADERS), + BAD_REQUEST, + "Only one of before or after query parameter allowed"); } @Test diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/services/DashboardServiceResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/services/DashboardServiceResourceTest.java index 7443946d3dc..14b65d5408f 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/services/DashboardServiceResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/services/DashboardServiceResourceTest.java @@ -16,8 +16,9 @@ package org.openmetadata.catalog.resources.services; import static javax.ws.rs.core.Response.Status.BAD_REQUEST; 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.util.TestUtils.ADMIN_AUTH_HEADERS; +import static org.openmetadata.catalog.util.TestUtils.assertResponse; +import static org.openmetadata.catalog.util.TestUtils.assertResponseContains; import static org.openmetadata.catalog.util.TestUtils.getPrincipal; import java.io.IOException; @@ -63,18 +64,16 @@ public class DashboardServiceResourceTest extends EntityResourceTest createEntity(createRequest(test).withServiceType(null), ADMIN_AUTH_HEADERS)); - TestUtils.assertResponse(exception, BAD_REQUEST, "[serviceType must not be null]"); + assertResponse( + () -> createEntity(createRequest(test).withServiceType(null), ADMIN_AUTH_HEADERS), + BAD_REQUEST, + "[serviceType must not be null]"); // Create dashboard with mandatory dashboardUrl field empty - exception = - assertThrows( - HttpResponseException.class, - () -> createEntity(createRequest(test).withDashboardUrl(null), ADMIN_AUTH_HEADERS)); - TestUtils.assertResponse(exception, BAD_REQUEST, "[dashboardUrl must not be null]"); + assertResponse( + () -> createEntity(createRequest(test).withDashboardUrl(null), ADMIN_AUTH_HEADERS), + BAD_REQUEST, + "[dashboardUrl must not be null]"); } @Test @@ -94,31 +93,27 @@ public class DashboardServiceResourceTest extends EntityResourceTest createEntity(create, ADMIN_AUTH_HEADERS)); - TestUtils.assertResponse(exception, BAD_REQUEST, "Invalid ingestion repeatFrequency INVALID"); + assertResponse( + () -> createEntity(create, ADMIN_AUTH_HEADERS), BAD_REQUEST, "Invalid ingestion repeatFrequency INVALID"); // Duration that contains years, months and seconds are not allowed create.withIngestionSchedule(schedule.withRepeatFrequency("P1Y")); - exception = assertThrows(HttpResponseException.class, () -> createEntity(create, ADMIN_AUTH_HEADERS)); - TestUtils.assertResponse( - exception, + assertResponse( + () -> createEntity(create, ADMIN_AUTH_HEADERS), BAD_REQUEST, - "Ingestion repeatFrequency can only contain Days, Hours, " + "and Minutes - example P{d}DT{h}H{m}M"); + "Ingestion repeatFrequency can only contain Days, Hours, and Minutes - example P{d}DT{h}H{m}M"); create.withIngestionSchedule(schedule.withRepeatFrequency("P1M")); - exception = assertThrows(HttpResponseException.class, () -> createEntity(create, ADMIN_AUTH_HEADERS)); - TestUtils.assertResponse( - exception, + assertResponse( + () -> createEntity(create, ADMIN_AUTH_HEADERS), BAD_REQUEST, - "Ingestion repeatFrequency can only contain Days, Hours, " + "and Minutes - example P{d}DT{h}H{m}M"); + "Ingestion repeatFrequency can only contain Days, Hours, and Minutes - example P{d}DT{h}H{m}M"); create.withIngestionSchedule(schedule.withRepeatFrequency("PT1S")); - exception = assertThrows(HttpResponseException.class, () -> createEntity(create, ADMIN_AUTH_HEADERS)); - TestUtils.assertResponse( - exception, + assertResponse( + () -> createEntity(create, ADMIN_AUTH_HEADERS), BAD_REQUEST, - "Ingestion repeatFrequency can only contain Days, Hours, " + "and Minutes - example P{d}DT{h}H{m}M"); + "Ingestion repeatFrequency can only contain Days, Hours, and Minutes - example P{d}DT{h}H{m}M"); } @Test @@ -140,15 +135,16 @@ public class DashboardServiceResourceTest extends EntityResourceTest createEntity(create, ADMIN_AUTH_HEADERS)); - TestUtils.assertResponseContains( - exception, BAD_REQUEST, "Ingestion repeatFrequency is too short and must be more than 60 minutes"); + assertResponseContains( + () -> createEntity(create, ADMIN_AUTH_HEADERS), + BAD_REQUEST, + "Ingestion repeatFrequency is too short and must be more than 60 minutes"); create.withIngestionSchedule(schedule.withRepeatFrequency("PT59M")); // Repeat every 50 minutes 59 seconds - exception = assertThrows(HttpResponseException.class, () -> createEntity(create, ADMIN_AUTH_HEADERS)); - TestUtils.assertResponse( - exception, BAD_REQUEST, "Ingestion repeatFrequency is too short and must " + "be more than 60 minutes"); + assertResponse( + () -> createEntity(create, ADMIN_AUTH_HEADERS), + BAD_REQUEST, + "Ingestion repeatFrequency is too short and must be more than 60 minutes"); } @Test diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/services/DatabaseServiceResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/services/DatabaseServiceResourceTest.java index fe181ca2c75..cfb15e6a9be 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/services/DatabaseServiceResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/services/DatabaseServiceResourceTest.java @@ -18,10 +18,10 @@ import static javax.ws.rs.core.Response.Status.BAD_REQUEST; import static javax.ws.rs.core.Response.Status.OK; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertThrows; import static org.openmetadata.catalog.Entity.helper; import static org.openmetadata.catalog.util.TestUtils.ADMIN_AUTH_HEADERS; import static org.openmetadata.catalog.util.TestUtils.TEST_AUTH_HEADERS; +import static org.openmetadata.catalog.util.TestUtils.assertResponseContains; import static org.openmetadata.catalog.util.TestUtils.getPrincipal; import io.dropwizard.db.DataSourceFactory; @@ -91,9 +91,8 @@ public class DatabaseServiceResourceTest extends EntityResourceTest createEntity(create, ADMIN_AUTH_HEADERS)); - TestUtils.assertResponseContains(exception, BAD_REQUEST, "databaseConnection must not be null"); + assertResponseContains( + () -> createEntity(create, ADMIN_AUTH_HEADERS), BAD_REQUEST, "databaseConnection must not be null"); } @Test diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/services/MessagingServiceResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/services/MessagingServiceResourceTest.java index f45b749d724..515b070bf93 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/services/MessagingServiceResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/services/MessagingServiceResourceTest.java @@ -16,9 +16,10 @@ package org.openmetadata.catalog.resources.services; import static javax.ws.rs.core.Response.Status.BAD_REQUEST; 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.util.TestUtils.ADMIN_AUTH_HEADERS; +import static org.openmetadata.catalog.util.TestUtils.assertResponse; +import static org.openmetadata.catalog.util.TestUtils.assertResponseContains; import java.io.IOException; import java.net.URI; @@ -76,17 +77,16 @@ public class MessagingServiceResourceTest extends EntityResourceTest createEntity(createRequest(test).withServiceType(null), ADMIN_AUTH_HEADERS)); - TestUtils.assertResponse(exception, BAD_REQUEST, "[serviceType must not be null]"); + assertResponse( + () -> createEntity(createRequest(test).withServiceType(null), ADMIN_AUTH_HEADERS), + BAD_REQUEST, + "[serviceType must not be null]"); // Create messaging with mandatory brokers field empty - exception = - assertThrows( - HttpResponseException.class, () -> createEntity(createRequest(test).withBrokers(null), ADMIN_AUTH_HEADERS)); - TestUtils.assertResponse(exception, BAD_REQUEST, "[brokers must not be null]"); + assertResponse( + () -> createEntity(createRequest(test).withBrokers(null), ADMIN_AUTH_HEADERS), + BAD_REQUEST, + "[brokers must not be null]"); } @Test @@ -106,31 +106,27 @@ public class MessagingServiceResourceTest extends EntityResourceTest createEntity(create, ADMIN_AUTH_HEADERS)); - TestUtils.assertResponse(exception, BAD_REQUEST, "Invalid ingestion repeatFrequency INVALID"); + assertResponse( + () -> createEntity(create, ADMIN_AUTH_HEADERS), BAD_REQUEST, "Invalid ingestion repeatFrequency INVALID"); // Duration that contains years, months and seconds are not allowed create.withIngestionSchedule(schedule.withRepeatFrequency("P1Y")); - exception = assertThrows(HttpResponseException.class, () -> createEntity(create, ADMIN_AUTH_HEADERS)); - TestUtils.assertResponse( - exception, + assertResponse( + () -> createEntity(create, ADMIN_AUTH_HEADERS), BAD_REQUEST, - "Ingestion repeatFrequency can only contain Days, Hours, " + "and Minutes - example P{d}DT{h}H{m}M"); + "Ingestion repeatFrequency can only contain Days, Hours, and Minutes - example P{d}DT{h}H{m}M"); create.withIngestionSchedule(schedule.withRepeatFrequency("P1M")); - exception = assertThrows(HttpResponseException.class, () -> createEntity(create, ADMIN_AUTH_HEADERS)); - TestUtils.assertResponse( - exception, + assertResponse( + () -> createEntity(create, ADMIN_AUTH_HEADERS), BAD_REQUEST, - "Ingestion repeatFrequency can only contain Days, Hours, " + "and Minutes - example P{d}DT{h}H{m}M"); + "Ingestion repeatFrequency can only contain Days, Hours, and Minutes - example P{d}DT{h}H{m}M"); create.withIngestionSchedule(schedule.withRepeatFrequency("PT1S")); - exception = assertThrows(HttpResponseException.class, () -> createEntity(create, ADMIN_AUTH_HEADERS)); - TestUtils.assertResponse( - exception, + assertResponse( + () -> createEntity(create, ADMIN_AUTH_HEADERS), BAD_REQUEST, - "Ingestion repeatFrequency can only contain Days, Hours, " + "and Minutes - example P{d}DT{h}H{m}M"); + "Ingestion repeatFrequency can only contain Days, Hours, and Minutes - example P{d}DT{h}H{m}M"); } @Test @@ -152,15 +148,16 @@ public class MessagingServiceResourceTest extends EntityResourceTest createEntity(create, ADMIN_AUTH_HEADERS)); - TestUtils.assertResponseContains( - exception, BAD_REQUEST, "Ingestion repeatFrequency is too short and must be more than 60 minutes"); + assertResponseContains( + () -> createEntity(create, ADMIN_AUTH_HEADERS), + BAD_REQUEST, + "Ingestion repeatFrequency is too short and must be more than 60 minutes"); create.withIngestionSchedule(schedule.withRepeatFrequency("PT59M")); // Repeat every 50 minutes 59 seconds - exception = assertThrows(HttpResponseException.class, () -> createEntity(create, ADMIN_AUTH_HEADERS)); - TestUtils.assertResponse( - exception, BAD_REQUEST, "Ingestion repeatFrequency is too short and must " + "be more than 60 minutes"); + assertResponse( + () -> createEntity(create, ADMIN_AUTH_HEADERS), + BAD_REQUEST, + "Ingestion repeatFrequency is too short and must be more than 60 minutes"); } @Test diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/services/PipelineServiceResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/services/PipelineServiceResourceTest.java index 0049bcb14eb..4fd4defaa6d 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/services/PipelineServiceResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/services/PipelineServiceResourceTest.java @@ -16,8 +16,9 @@ package org.openmetadata.catalog.resources.services; import static javax.ws.rs.core.Response.Status.BAD_REQUEST; 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.util.TestUtils.ADMIN_AUTH_HEADERS; +import static org.openmetadata.catalog.util.TestUtils.assertResponse; +import static org.openmetadata.catalog.util.TestUtils.assertResponseContains; import static org.openmetadata.catalog.util.TestUtils.getPrincipal; import java.io.IOException; @@ -74,18 +75,16 @@ public class PipelineServiceResourceTest extends EntityResourceTest createEntity(createRequest(test).withServiceType(null), ADMIN_AUTH_HEADERS)); - TestUtils.assertResponse(exception, BAD_REQUEST, "[serviceType must not be null]"); + assertResponse( + () -> createEntity(createRequest(test).withServiceType(null), ADMIN_AUTH_HEADERS), + BAD_REQUEST, + "[serviceType must not be null]"); // Create pipeline with mandatory `brokers` field empty - exception = - assertThrows( - HttpResponseException.class, - () -> createEntity(createRequest(test).withPipelineUrl(null), ADMIN_AUTH_HEADERS)); - TestUtils.assertResponse(exception, BAD_REQUEST, "[pipelineUrl must not be null]"); + assertResponse( + () -> createEntity(createRequest(test).withPipelineUrl(null), ADMIN_AUTH_HEADERS), + BAD_REQUEST, + "[pipelineUrl must not be null]"); } @Test @@ -105,31 +104,27 @@ public class PipelineServiceResourceTest extends EntityResourceTest createEntity(create, ADMIN_AUTH_HEADERS)); - TestUtils.assertResponse(exception, BAD_REQUEST, "Invalid ingestion repeatFrequency INVALID"); + assertResponse( + () -> createEntity(create, ADMIN_AUTH_HEADERS), BAD_REQUEST, "Invalid ingestion repeatFrequency INVALID"); // Duration that contains years, months and seconds are not allowed create.withIngestionSchedule(schedule.withRepeatFrequency("P1Y")); - exception = assertThrows(HttpResponseException.class, () -> createEntity(create, ADMIN_AUTH_HEADERS)); - TestUtils.assertResponse( - exception, + assertResponse( + () -> createEntity(create, ADMIN_AUTH_HEADERS), BAD_REQUEST, - "Ingestion repeatFrequency can only contain Days, Hours, " + "and Minutes - example P{d}DT{h}H{m}M"); + "Ingestion repeatFrequency can only contain Days, Hours, and Minutes - example P{d}DT{h}H{m}M"); create.withIngestionSchedule(schedule.withRepeatFrequency("P1M")); - exception = assertThrows(HttpResponseException.class, () -> createEntity(create, ADMIN_AUTH_HEADERS)); - TestUtils.assertResponse( - exception, + assertResponse( + () -> createEntity(create, ADMIN_AUTH_HEADERS), BAD_REQUEST, - "Ingestion repeatFrequency can only contain Days, Hours, " + "and Minutes - example P{d}DT{h}H{m}M"); + "Ingestion repeatFrequency can only contain Days, Hours, and Minutes - example P{d}DT{h}H{m}M"); create.withIngestionSchedule(schedule.withRepeatFrequency("PT1S")); - exception = assertThrows(HttpResponseException.class, () -> createEntity(create, ADMIN_AUTH_HEADERS)); - TestUtils.assertResponse( - exception, + assertResponse( + () -> createEntity(create, ADMIN_AUTH_HEADERS), BAD_REQUEST, - "Ingestion repeatFrequency can only contain Days, Hours, " + "and Minutes - example P{d}DT{h}H{m}M"); + "Ingestion repeatFrequency can only contain Days, Hours, and Minutes - example P{d}DT{h}H{m}M"); } @Test @@ -151,15 +146,16 @@ public class PipelineServiceResourceTest extends EntityResourceTest createEntity(create, ADMIN_AUTH_HEADERS)); - TestUtils.assertResponseContains( - exception, BAD_REQUEST, "Ingestion repeatFrequency is too short and must be more than 60 minutes"); + assertResponseContains( + () -> createEntity(create, ADMIN_AUTH_HEADERS), + BAD_REQUEST, + "Ingestion repeatFrequency is too short and must be more than 60 minutes"); create.withIngestionSchedule(schedule.withRepeatFrequency("PT59M")); // Repeat every 50 minutes 59 seconds - exception = assertThrows(HttpResponseException.class, () -> createEntity(create, ADMIN_AUTH_HEADERS)); - TestUtils.assertResponse( - exception, BAD_REQUEST, "Ingestion repeatFrequency is too short and must " + "be more than 60 minutes"); + assertResponse( + () -> createEntity(create, ADMIN_AUTH_HEADERS), + BAD_REQUEST, + "Ingestion repeatFrequency is too short and must be more than 60 minutes"); } @Test diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/tags/TagResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/tags/TagResourceTest.java index 9c4c4b1c853..04470a79b66 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/tags/TagResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/tags/TagResourceTest.java @@ -18,11 +18,12 @@ import static javax.ws.rs.core.Response.Status.CONFLICT; import static javax.ws.rs.core.Response.Status.NOT_FOUND; 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.exception.CatalogExceptionMessage.entityNotFound; import static org.openmetadata.catalog.security.SecurityUtil.authHeaders; import static org.openmetadata.catalog.util.TestUtils.ADMIN_AUTH_HEADERS; import static org.openmetadata.catalog.util.TestUtils.TEST_AUTH_HEADERS; +import static org.openmetadata.catalog.util.TestUtils.assertResponse; +import static org.openmetadata.catalog.util.TestUtils.assertResponseContains; import com.fasterxml.jackson.core.JsonProcessingException; import java.io.IOException; @@ -91,9 +92,8 @@ public class TagResourceTest extends CatalogApplicationTest { void get_nonExistentCategory_404() { // GET .../tags/{nonExistentCategory} returns 404 String nonExistent = "nonExistent"; - HttpResponseException exception = - assertThrows(HttpResponseException.class, () -> getCategory(nonExistent, ADMIN_AUTH_HEADERS)); - TestUtils.assertResponse(exception, NOT_FOUND, entityNotFound("TagCategory", nonExistent)); + assertResponse( + () -> getCategory(nonExistent, ADMIN_AUTH_HEADERS), NOT_FOUND, entityNotFound("TagCategory", nonExistent)); } @Test @@ -108,9 +108,7 @@ public class TagResourceTest extends CatalogApplicationTest { void get_nonExistentTag_404() { // GET .../tags/{category}/{nonExistent} returns 404 Not found String tagFQN = "User.NonExistent"; - HttpResponseException exception = - assertThrows(HttpResponseException.class, () -> getTag(tagFQN, ADMIN_AUTH_HEADERS)); - TestUtils.assertResponse(exception, NOT_FOUND, entityNotFound("Tag", tagFQN)); + assertResponse(() -> getTag(tagFQN, ADMIN_AUTH_HEADERS), NOT_FOUND, entityNotFound("Tag", tagFQN)); } @Test @@ -121,9 +119,7 @@ public class TagResourceTest extends CatalogApplicationTest { .withName("User") .withDescription("description") .withCategoryType(TagCategoryType.Descriptive); - HttpResponseException exception = - assertThrows(HttpResponseException.class, () -> createAndCheckCategory(create, ADMIN_AUTH_HEADERS)); - TestUtils.assertResponse(exception, CONFLICT, "Entity already exists"); + assertResponse(() -> createAndCheckCategory(create, ADMIN_AUTH_HEADERS), CONFLICT, "Entity already exists"); } @Test @@ -150,19 +146,18 @@ public class TagResourceTest extends CatalogApplicationTest { .withName(categoryName) .withDescription(null) .withCategoryType(TagCategoryType.Descriptive); - HttpResponseException exception = - assertThrows(HttpResponseException.class, () -> createAndCheckCategory(create, ADMIN_AUTH_HEADERS)); - TestUtils.assertResponseContains(exception, BAD_REQUEST, "description must not be null"); + assertResponseContains( + () -> createAndCheckCategory(create, ADMIN_AUTH_HEADERS), BAD_REQUEST, "description must not be null"); // Missing category create.withDescription("description").withCategoryType(null); - exception = assertThrows(HttpResponseException.class, () -> createAndCheckCategory(create, ADMIN_AUTH_HEADERS)); - TestUtils.assertResponseContains(exception, BAD_REQUEST, "categoryType must not be null"); + assertResponseContains( + () -> createAndCheckCategory(create, ADMIN_AUTH_HEADERS), BAD_REQUEST, "categoryType must not be null"); // Long name create.withName(TestUtils.LONG_ENTITY_NAME).withCategoryType(TagCategoryType.Descriptive); - exception = assertThrows(HttpResponseException.class, () -> createAndCheckCategory(create, ADMIN_AUTH_HEADERS)); - TestUtils.assertResponseContains(exception, BAD_REQUEST, "name size must be between 2 and 25"); + assertResponseContains( + () -> createAndCheckCategory(create, ADMIN_AUTH_HEADERS), BAD_REQUEST, "name size must be between 2 and 25"); } @Order(1) @@ -186,26 +181,25 @@ public class TagResourceTest extends CatalogApplicationTest { void post_invalidTags_400() { // Missing description in POST primary tag CreateTag create = new CreateTag().withName("noDescription").withDescription(null); - HttpResponseException exception = - assertThrows(HttpResponseException.class, () -> createPrimaryTag("User", create, ADMIN_AUTH_HEADERS)); - TestUtils.assertResponseContains(exception, BAD_REQUEST, "description must not be null"); + assertResponseContains( + () -> createPrimaryTag("User", create, ADMIN_AUTH_HEADERS), BAD_REQUEST, "description must not be null"); // Missing description in POST secondary tag - exception = - assertThrows( - HttpResponseException.class, () -> createSecondaryTag("User", "Address", create, ADMIN_AUTH_HEADERS)); - TestUtils.assertResponseContains(exception, BAD_REQUEST, "description must not be null"); + assertResponseContains( + () -> createSecondaryTag("User", "Address", create, ADMIN_AUTH_HEADERS), + BAD_REQUEST, + "description must not be null"); // Long primary tag name create.withDescription("description").withName(TestUtils.LONG_ENTITY_NAME); - exception = assertThrows(HttpResponseException.class, () -> createPrimaryTag("User", create, ADMIN_AUTH_HEADERS)); - TestUtils.assertResponseContains(exception, BAD_REQUEST, "name size must be between 2 and 25"); + assertResponseContains( + () -> createPrimaryTag("User", create, ADMIN_AUTH_HEADERS), BAD_REQUEST, "name size must be between 2 and 25"); // Long secondary tag name - exception = - assertThrows( - HttpResponseException.class, () -> createSecondaryTag("User", "Address", create, ADMIN_AUTH_HEADERS)); - TestUtils.assertResponseContains(exception, BAD_REQUEST, "name size must be between 2 and 25"); + assertResponseContains( + () -> createSecondaryTag("User", "Address", create, ADMIN_AUTH_HEADERS), + BAD_REQUEST, + "name size must be between 2 and 25"); } @Test @@ -213,15 +207,16 @@ public class TagResourceTest extends CatalogApplicationTest { // POST .../tags/{nonExistent}/{primaryTag} where category does not exist String nonExistent = "nonExistent"; CreateTag create = new CreateTag().withName("primary").withDescription("description"); - HttpResponseException exception = - assertThrows(HttpResponseException.class, () -> createPrimaryTag(nonExistent, create, ADMIN_AUTH_HEADERS)); - TestUtils.assertResponse(exception, NOT_FOUND, entityNotFound("TagCategory", nonExistent)); + assertResponse( + () -> createPrimaryTag(nonExistent, create, ADMIN_AUTH_HEADERS), + NOT_FOUND, + entityNotFound("TagCategory", nonExistent)); // POST .../tags/{user}/{nonExistent}/tag where primaryTag does not exist - exception = - assertThrows( - HttpResponseException.class, () -> createSecondaryTag("User", nonExistent, create, ADMIN_AUTH_HEADERS)); - TestUtils.assertResponse(exception, NOT_FOUND, entityNotFound("Tag", nonExistent)); + assertResponse( + () -> createSecondaryTag("User", nonExistent, create, ADMIN_AUTH_HEADERS), + NOT_FOUND, + entityNotFound("Tag", nonExistent)); } @Test @@ -249,14 +244,13 @@ public class TagResourceTest extends CatalogApplicationTest { .withName(newCategoryName) .withDescription(null) .withCategoryType(TagCategoryType.Descriptive); - HttpResponseException exception = - assertThrows(HttpResponseException.class, () -> updateCategory("User", create, ADMIN_AUTH_HEADERS)); - TestUtils.assertResponseContains(exception, BAD_REQUEST, "description must not be null"); + assertResponseContains( + () -> updateCategory("User", create, ADMIN_AUTH_HEADERS), BAD_REQUEST, "description must not be null"); // Long primary tag name create.withDescription("description").withName(TestUtils.LONG_ENTITY_NAME); - exception = assertThrows(HttpResponseException.class, () -> updateCategory("User", create, ADMIN_AUTH_HEADERS)); - TestUtils.assertResponseContains(exception, BAD_REQUEST, "name size must be between 2 and 25"); + assertResponseContains( + () -> updateCategory("User", create, ADMIN_AUTH_HEADERS), BAD_REQUEST, "name size must be between 2 and 25"); } @Test @@ -285,31 +279,29 @@ public class TagResourceTest extends CatalogApplicationTest { void put_tagInvalidRequest_404() { // Primary tag with missing description CreateTag create = new CreateTag().withName("AddressUpdated").withDescription(null); - HttpResponseException exception = - assertThrows( - HttpResponseException.class, () -> updatePrimaryTag("User", "Address", create, ADMIN_AUTH_HEADERS)); - TestUtils.assertResponseContains(exception, BAD_REQUEST, "description must not be null"); + assertResponseContains( + () -> updatePrimaryTag("User", "Address", create, ADMIN_AUTH_HEADERS), + BAD_REQUEST, + "description must not be null"); // Secondar tag with missing description - exception = - assertThrows( - HttpResponseException.class, - () -> updateSecondaryTag("User", "Address", "Secondary", create, ADMIN_AUTH_HEADERS)); - TestUtils.assertResponseContains(exception, BAD_REQUEST, "description must not be null"); + assertResponseContains( + () -> updateSecondaryTag("User", "Address", "Secondary", create, ADMIN_AUTH_HEADERS), + BAD_REQUEST, + "description must not be null"); // Long primary tag name create.withDescription("description").withName(TestUtils.LONG_ENTITY_NAME); - exception = - assertThrows( - HttpResponseException.class, () -> updatePrimaryTag("User", "Address", create, ADMIN_AUTH_HEADERS)); - TestUtils.assertResponseContains(exception, BAD_REQUEST, "name size must be between 2 and 25"); + assertResponseContains( + () -> updatePrimaryTag("User", "Address", create, ADMIN_AUTH_HEADERS), + BAD_REQUEST, + "name size must be between 2 and 25"); // Long secondary tag name - exception = - assertThrows( - HttpResponseException.class, - () -> updateSecondaryTag("User", "Address", "Secondary", create, ADMIN_AUTH_HEADERS)); - TestUtils.assertResponseContains(exception, BAD_REQUEST, "name size must be between 2 and 25"); + assertResponseContains( + () -> updateSecondaryTag("User", "Address", "Secondary", create, ADMIN_AUTH_HEADERS), + BAD_REQUEST, + "name size must be between 2 and 25"); } private TagCategory createAndCheckCategory(CreateTagCategory create, Map authHeaders) diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/teams/RoleResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/teams/RoleResourceTest.java index 106004e3537..3e5b96a33f0 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/teams/RoleResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/teams/RoleResourceTest.java @@ -15,7 +15,6 @@ package org.openmetadata.catalog.resources.teams; 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.util.TestUtils.ADMIN_AUTH_HEADERS; import static org.openmetadata.catalog.util.TestUtils.TEST_AUTH_HEADERS; import static org.openmetadata.catalog.util.TestUtils.assertListNotNull; @@ -84,10 +83,10 @@ public class RoleResourceTest extends EntityResourceTest { // Patching as a non-admin should is disallowed String originalJson = JsonUtils.pojoToJson(role); role.setDisplayName("newDisplayName"); - HttpResponseException exception = - assertThrows( - HttpResponseException.class, () -> patchEntity(role.getId(), originalJson, role, TEST_AUTH_HEADERS)); - assertResponse(exception, FORBIDDEN, "Principal: CatalogPrincipal{name='test'} is not admin"); + assertResponse( + () -> patchEntity(role.getId(), originalJson, role, TEST_AUTH_HEADERS), + FORBIDDEN, + "Principal: CatalogPrincipal{name='test'} is not admin"); } private static void validateRole( diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/teams/TeamResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/teams/TeamResourceTest.java index c899a7c5354..430c3c968a8 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/teams/TeamResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/teams/TeamResourceTest.java @@ -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.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.util.TestUtils.ADMIN_AUTH_HEADERS; import static org.openmetadata.catalog.util.TestUtils.TEST_AUTH_HEADERS; @@ -116,14 +115,16 @@ public class TeamResourceTest extends EntityResourceTest { Team team = createEntity(create, ADMIN_AUTH_HEADERS); // Empty query field .../teams?fields= - HttpResponseException exception = - assertThrows(HttpResponseException.class, () -> getEntity(team.getId(), "test", ADMIN_AUTH_HEADERS)); - assertResponse(exception, BAD_REQUEST, CatalogExceptionMessage.invalidField("test")); + assertResponse( + () -> getEntity(team.getId(), "test", ADMIN_AUTH_HEADERS), + BAD_REQUEST, + CatalogExceptionMessage.invalidField("test")); // .../teams?fields=invalidField - exception = - assertThrows(HttpResponseException.class, () -> getEntity(team.getId(), "invalidField", ADMIN_AUTH_HEADERS)); - assertResponse(exception, BAD_REQUEST, CatalogExceptionMessage.invalidField("invalidField")); + assertResponse( + () -> getEntity(team.getId(), "invalidField", ADMIN_AUTH_HEADERS), + BAD_REQUEST, + CatalogExceptionMessage.invalidField("invalidField")); } /** @@ -152,10 +153,10 @@ public class TeamResourceTest extends EntityResourceTest { // Patching as a non-admin should is disallowed String originalJson = JsonUtils.pojoToJson(team); team.setDisplayName("newDisplayName"); - HttpResponseException exception = - assertThrows( - HttpResponseException.class, () -> patchEntity(team.getId(), originalJson, team, TEST_AUTH_HEADERS)); - assertResponse(exception, FORBIDDEN, "Principal: CatalogPrincipal{name='test'} is not admin"); + assertResponse( + () -> patchEntity(team.getId(), originalJson, team, TEST_AUTH_HEADERS), + FORBIDDEN, + "Principal: CatalogPrincipal{name='test'} is not admin"); } @Test diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/teams/UserResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/teams/UserResourceTest.java index 41905be955c..67503c1d965 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/teams/UserResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/teams/UserResourceTest.java @@ -23,8 +23,8 @@ import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; 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.entityNotFound; import static org.openmetadata.catalog.security.SecurityUtil.authHeaders; import static org.openmetadata.catalog.util.TestUtils.ADMIN_AUTH_HEADERS; import static org.openmetadata.catalog.util.TestUtils.TEST_AUTH_HEADERS; @@ -32,6 +32,7 @@ import static org.openmetadata.catalog.util.TestUtils.UpdateType.MINOR_UPDATE; import static org.openmetadata.catalog.util.TestUtils.assertListNotNull; import static org.openmetadata.catalog.util.TestUtils.assertListNull; import static org.openmetadata.catalog.util.TestUtils.assertResponse; +import static org.openmetadata.catalog.util.TestUtils.assertResponseContains; import com.fasterxml.jackson.core.JsonProcessingException; import java.io.IOException; @@ -96,20 +97,19 @@ public class UserResourceTest extends EntityResourceTest { void post_userWithoutEmail_400_badRequest(TestInfo test) { // Create user with mandatory email field null CreateUser create = createRequest(test).withEmail(null); - HttpResponseException exception = - assertThrows(HttpResponseException.class, () -> createEntity(create, ADMIN_AUTH_HEADERS)); - assertResponse(exception, BAD_REQUEST, "[email must not be null]"); + assertResponse(() -> createEntity(create, ADMIN_AUTH_HEADERS), BAD_REQUEST, "[email must not be null]"); // Create user with mandatory email field empty create.withEmail(""); - exception = assertThrows(HttpResponseException.class, () -> createEntity(create, ADMIN_AUTH_HEADERS)); - TestUtils.assertResponseContains(exception, BAD_REQUEST, "email must match \"^\\S+@\\S+\\.\\S+$\""); - TestUtils.assertResponseContains(exception, BAD_REQUEST, "email size must be between 6 and 127"); + assertResponseContains( + () -> createEntity(create, ADMIN_AUTH_HEADERS), BAD_REQUEST, "email must match \"^\\S+@\\S+\\.\\S+$\""); + assertResponseContains( + () -> createEntity(create, ADMIN_AUTH_HEADERS), BAD_REQUEST, "email size must be between 6 and 127"); // Create user with mandatory email field with invalid email address create.withEmail("invalidEmail"); - exception = assertThrows(HttpResponseException.class, () -> createEntity(create, ADMIN_AUTH_HEADERS)); - TestUtils.assertResponseContains(exception, BAD_REQUEST, "[email must match \"^\\S+@\\S+\\.\\S+$\"]"); + assertResponseContains( + () -> createEntity(create, ADMIN_AUTH_HEADERS), BAD_REQUEST, "[email must match \"^\\S+@\\S+\\.\\S+$\"]"); } @Test @@ -117,9 +117,8 @@ public class UserResourceTest extends EntityResourceTest { CreateUser create = createRequest(test, 6).withDisplayName("displayName").withEmail("test@email.com").withIsAdmin(true); - HttpResponseException exception = - assertThrows(HttpResponseException.class, () -> createAndCheckEntity(create, null)); - assertResponse(exception, UNAUTHORIZED, "Not authorized; User's Email is not present"); + assertResponse( + () -> createAndCheckEntity(create, null), UNAUTHORIZED, "Not authorized; User's Email is not present"); } @Test @@ -171,9 +170,10 @@ public class UserResourceTest extends EntityResourceTest { .withEmail("test@email.com") .withIsAdmin(true); - HttpResponseException exception = - assertThrows(HttpResponseException.class, () -> createAndCheckEntity(create, TEST_AUTH_HEADERS)); - assertResponse(exception, FORBIDDEN, "Principal: CatalogPrincipal{name='test'} is not admin"); + assertResponse( + () -> createAndCheckEntity(create, TEST_AUTH_HEADERS), + FORBIDDEN, + "Principal: CatalogPrincipal{name='test'} is not admin"); } @Test @@ -275,14 +275,14 @@ public class UserResourceTest extends EntityResourceTest { User user = createEntity(createRequest(test), ADMIN_AUTH_HEADERS); // Empty query field .../users?fields= - HttpResponseException exception = - assertThrows(HttpResponseException.class, () -> getEntity(user.getId(), "test", ADMIN_AUTH_HEADERS)); - TestUtils.assertResponseContains(exception, BAD_REQUEST, "Invalid field name"); + assertResponseContains( + () -> getEntity(user.getId(), "test", ADMIN_AUTH_HEADERS), BAD_REQUEST, "Invalid field name"); // .../users?fields=invalidField - exception = - assertThrows(HttpResponseException.class, () -> getEntity(user.getId(), "invalidField", ADMIN_AUTH_HEADERS)); - assertResponse(exception, BAD_REQUEST, CatalogExceptionMessage.invalidField("invalidField")); + assertResponse( + () -> getEntity(user.getId(), "invalidField", ADMIN_AUTH_HEADERS), + BAD_REQUEST, + CatalogExceptionMessage.invalidField("invalidField")); } /** @@ -299,9 +299,10 @@ public class UserResourceTest extends EntityResourceTest { authHeaders("test23@email.com")); String userJson = JsonUtils.pojoToJson(user); user.setDisplayName("newName"); - HttpResponseException exception = - assertThrows(HttpResponseException.class, () -> patchUser(userJson, user, authHeaders("test100@email.com"))); - assertResponse(exception, FORBIDDEN, "Principal: CatalogPrincipal{name='test100'} does not have permissions"); + assertResponse( + () -> patchUser(userJson, user, authHeaders("test100@email.com")), + FORBIDDEN, + "Principal: CatalogPrincipal{name='test100'} does not have permissions"); } @Test @@ -313,9 +314,10 @@ public class UserResourceTest extends EntityResourceTest { authHeaders("test2@email.com")); String userJson = JsonUtils.pojoToJson(user); user.setIsAdmin(Boolean.TRUE); - HttpResponseException exception = - assertThrows(HttpResponseException.class, () -> patchUser(userJson, user, authHeaders("test100@email.com"))); - assertResponse(exception, FORBIDDEN, "Principal: CatalogPrincipal{name='test100'} is not admin"); + assertResponse( + () -> patchUser(userJson, user, authHeaders("test100@email.com")), + FORBIDDEN, + "Principal: CatalogPrincipal{name='test100'} is not admin"); } @Test @@ -469,11 +471,10 @@ public class UserResourceTest extends EntityResourceTest { tableResourceTest.checkFollowerDeleted(table.getId(), user.getId(), ADMIN_AUTH_HEADERS); // User can no longer follow other entities - HttpResponseException exception = - assertThrows( - HttpResponseException.class, - () -> tableResourceTest.addAndCheckFollower(table.getId(), user.getId(), CREATED, 1, ADMIN_AUTH_HEADERS)); - assertResponse(exception, NOT_FOUND, CatalogExceptionMessage.entityNotFound("user", user.getId())); + assertResponse( + () -> tableResourceTest.addAndCheckFollower(table.getId(), user.getId(), CREATED, 1, ADMIN_AUTH_HEADERS), + NOT_FOUND, + entityNotFound("user", user.getId())); // TODO deactivated user can't be made owner } diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/topics/TopicResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/topics/TopicResourceTest.java index 0c8835e1d85..bc3d0ce7d40 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/topics/TopicResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/topics/TopicResourceTest.java @@ -15,7 +15,6 @@ package org.openmetadata.catalog.resources.topics; import static javax.ws.rs.core.Response.Status.BAD_REQUEST; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; import static org.openmetadata.catalog.util.TestUtils.ADMIN_AUTH_HEADERS; import static org.openmetadata.catalog.util.TestUtils.assertListNotNull; import static org.openmetadata.catalog.util.TestUtils.assertResponse; @@ -70,23 +69,22 @@ public class TopicResourceTest extends EntityResourceTest { @Test void post_topicWithoutRequiredFields_4xx(TestInfo test) { // Service is required field - HttpResponseException exception = - assertThrows( - HttpResponseException.class, () -> createEntity(createRequest(test).withService(null), ADMIN_AUTH_HEADERS)); - assertResponse(exception, BAD_REQUEST, "[service must not be null]"); + assertResponse( + () -> createEntity(createRequest(test).withService(null), ADMIN_AUTH_HEADERS), + BAD_REQUEST, + "[service must not be null]"); // Partitions is required field - exception = - assertThrows( - HttpResponseException.class, - () -> createEntity(createRequest(test).withPartitions(null), ADMIN_AUTH_HEADERS)); - assertResponse(exception, BAD_REQUEST, "[partitions must not be null]"); + assertResponse( + () -> createEntity(createRequest(test).withPartitions(null), ADMIN_AUTH_HEADERS), + BAD_REQUEST, + "[partitions must not be null]"); // Partitions must be >= 1 - exception = - assertThrows( - HttpResponseException.class, () -> createEntity(createRequest(test).withPartitions(0), ADMIN_AUTH_HEADERS)); - assertResponse(exception, BAD_REQUEST, "[partitions must be greater than or equal to 1]"); + assertResponse( + () -> createEntity(createRequest(test).withPartitions(0), ADMIN_AUTH_HEADERS), + BAD_REQUEST, + "[partitions must be greater than or equal to 1]"); } @Test diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/usage/UsageResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/usage/UsageResourceTest.java index cefba934be4..d6310cd7453 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/usage/UsageResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/usage/UsageResourceTest.java @@ -16,8 +16,9 @@ package org.openmetadata.catalog.resources.usage; import static javax.ws.rs.core.Response.Status.BAD_REQUEST; import static javax.ws.rs.core.Response.Status.NOT_FOUND; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; import static org.openmetadata.catalog.Entity.TABLE; +import static org.openmetadata.catalog.exception.CatalogExceptionMessage.entityNotFound; +import static org.openmetadata.catalog.exception.CatalogExceptionMessage.entityTypeNotFound; import static org.openmetadata.catalog.util.TestUtils.ADMIN_AUTH_HEADERS; import static org.openmetadata.catalog.util.TestUtils.NON_EXISTENT_ENTITY; import static org.openmetadata.catalog.util.TestUtils.assertResponse; @@ -47,7 +48,6 @@ import org.openmetadata.catalog.Entity; import org.openmetadata.catalog.api.data.CreateTable; import org.openmetadata.catalog.entity.data.Database; import org.openmetadata.catalog.entity.data.Table; -import org.openmetadata.catalog.exception.CatalogExceptionMessage; import org.openmetadata.catalog.resources.databases.DatabaseResourceTest; import org.openmetadata.catalog.resources.databases.TableResourceTest; import org.openmetadata.catalog.type.DailyCount; @@ -76,39 +76,37 @@ public class UsageResourceTest extends CatalogApplicationTest { @Test public void post_usageWithNonExistentEntityId_4xx() { - HttpResponseException exception = - assertThrows( - HttpResponseException.class, - () -> reportUsage(TABLE, NON_EXISTENT_ENTITY, usageReport(), ADMIN_AUTH_HEADERS)); - assertResponse(exception, NOT_FOUND, CatalogExceptionMessage.entityNotFound(TABLE, NON_EXISTENT_ENTITY)); + assertResponse( + () -> reportUsage(TABLE, NON_EXISTENT_ENTITY, usageReport(), ADMIN_AUTH_HEADERS), + NOT_FOUND, + entityNotFound(TABLE, NON_EXISTENT_ENTITY)); } @Test public void post_usageInvalidEntityName_4xx() { String invalidEntityType = "invalid"; - HttpResponseException exception = - assertThrows( - HttpResponseException.class, - () -> reportUsage(invalidEntityType, UUID.randomUUID(), usageReport(), ADMIN_AUTH_HEADERS)); - assertResponse(exception, NOT_FOUND, CatalogExceptionMessage.entityTypeNotFound(invalidEntityType)); + assertResponse( + () -> reportUsage(invalidEntityType, UUID.randomUUID(), usageReport(), ADMIN_AUTH_HEADERS), + NOT_FOUND, + entityTypeNotFound(invalidEntityType)); } @Test public void post_usageWithNegativeCountName_4xx() { DailyCount dailyCount = usageReport().withCount(-1); // Negative usage count - HttpResponseException exception = - assertThrows( - HttpResponseException.class, () -> reportUsage(TABLE, UUID.randomUUID(), dailyCount, ADMIN_AUTH_HEADERS)); - assertResponse(exception, BAD_REQUEST, "[count must be greater than or equal to 0]"); + assertResponse( + () -> reportUsage(TABLE, UUID.randomUUID(), dailyCount, ADMIN_AUTH_HEADERS), + BAD_REQUEST, + "[count must be greater than or equal to 0]"); } @Test public void post_usageWithoutDate_4xx() { DailyCount usageReport = usageReport().withDate(null); // Negative usage count - HttpResponseException exception = - assertThrows( - HttpResponseException.class, () -> reportUsage(TABLE, UUID.randomUUID(), usageReport, ADMIN_AUTH_HEADERS)); - assertResponse(exception, BAD_REQUEST, "[date must not be null]"); + assertResponse( + () -> reportUsage(TABLE, UUID.randomUUID(), usageReport, ADMIN_AUTH_HEADERS), + BAD_REQUEST, + "[date must not be null]"); } @Test diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/util/TestUtils.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/util/TestUtils.java index 26be2b4dcb8..9dd87269cea 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/util/TestUtils.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/util/TestUtils.java @@ -140,19 +140,6 @@ public final class TestUtils { expectedReason + " not in actual " + exception.getReasonPhrase()); } - public static void assertResponse(HttpResponseException exception, Status expectedCode, String expectedReason) { - assertEquals(expectedCode.getStatusCode(), exception.getStatusCode()); - assertEquals(expectedReason, exception.getReasonPhrase()); - } - - public static void assertResponseContains( - HttpResponseException exception, Status expectedCode, String expectedReason) { - assertEquals(expectedCode.getStatusCode(), exception.getStatusCode()); - assertTrue( - exception.getReasonPhrase().contains(expectedReason), - expectedReason + " not in actual " + exception.getReasonPhrase()); - } - public static void assertEntityPagination(List allEntities, ResultList actual, int limit, int offset) { assertFalse(actual.getData().isEmpty()); if (actual.getPaging().getAfter() != null && actual.getPaging().getBefore() != null) {