diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/UserRepository.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/UserRepository.java index 3b998da1ef0..a29302bf226 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/UserRepository.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/UserRepository.java @@ -40,7 +40,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.json.JsonPatch; -import javax.json.JsonStructure; import java.io.IOException; import java.security.GeneralSecurityException; import java.text.ParseException; @@ -50,8 +49,9 @@ import java.util.List; import java.util.Optional; import java.util.UUID; -import static org.openmetadata.catalog.jdbi3.Relationship.*; - +import static org.openmetadata.catalog.jdbi3.Relationship.CONTAINS; +import static org.openmetadata.catalog.jdbi3.Relationship.FOLLOWS; +import static org.openmetadata.catalog.jdbi3.Relationship.OWNS; public abstract class UserRepository { public static final Logger LOG = LoggerFactory.getLogger(UserRepository.class); @@ -167,7 +167,7 @@ public abstract class UserRepository { @Transaction public User patch(String id, JsonPatch patch) throws IOException { User original = setFields(validateUser(id), USER_PATCH_FIELDS); // Query 1 - find user by Id - JsonStructure targetJson = JsonUtils.getJsonStructure(original); + JsonUtils.getJsonStructure(original); User updated = JsonUtils.applyPatch(original, patch, User.class); patch(original, updated); return updated; 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 454e9356462..3c0426883c0 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 @@ -2,7 +2,6 @@ package org.openmetadata.catalog.resources.databases; import com.fasterxml.jackson.core.JsonProcessingException; import org.apache.http.client.HttpResponseException; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInfo; @@ -34,12 +33,22 @@ import javax.ws.rs.core.Response.Status; import java.util.Map; import java.util.UUID; -import static javax.ws.rs.core.Response.Status.*; -import static org.junit.jupiter.api.Assertions.*; -import static org.openmetadata.catalog.CatalogApplicationTest.getResource; +import static javax.ws.rs.core.Response.Status.BAD_REQUEST; +import static javax.ws.rs.core.Response.Status.CONFLICT; +import static javax.ws.rs.core.Response.Status.CREATED; +import static javax.ws.rs.core.Response.Status.FORBIDDEN; +import static javax.ws.rs.core.Response.Status.NOT_FOUND; +import static javax.ws.rs.core.Response.Status.OK; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.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.readOnlyAttribute; -import static org.openmetadata.catalog.util.TestUtils.*; +import static org.openmetadata.catalog.util.TestUtils.adminAuthHeaders; +import static org.openmetadata.catalog.util.TestUtils.assertEntityPagination; +import static org.openmetadata.catalog.util.TestUtils.assertResponse; +import static org.openmetadata.catalog.util.TestUtils.authHeaders; public class DatabaseResourceTest extends CatalogApplicationTest { private static final Logger LOG = LoggerFactory.getLogger(DatabaseResourceTest.class); @@ -84,7 +93,7 @@ public class DatabaseResourceTest extends CatalogApplicationTest { CreateDatabase create = create(test).withName(TestUtils.LONG_ENTITY_NAME); HttpResponseException exception = assertThrows(HttpResponseException.class, () -> createDatabase(create, adminAuthHeaders())); - TestUtils.assertResponse(exception, BAD_REQUEST, "[name size must be between 1 and 64]"); + assertResponse(exception, BAD_REQUEST, "[name size must be between 1 and 64]"); } @Test @@ -93,7 +102,7 @@ public class DatabaseResourceTest extends CatalogApplicationTest { CreateDatabase create = create(test).withName(""); HttpResponseException exception = assertThrows(HttpResponseException.class, () -> createDatabase(create, adminAuthHeaders())); - TestUtils.assertResponse(exception, BAD_REQUEST, "[name size must be between 1 and 64]"); + assertResponse(exception, BAD_REQUEST, "[name size must be between 1 and 64]"); } @Test @@ -102,7 +111,7 @@ public class DatabaseResourceTest extends CatalogApplicationTest { createDatabase(create, adminAuthHeaders()); HttpResponseException exception = assertThrows(HttpResponseException.class, () -> createDatabase(create, adminAuthHeaders())); - TestUtils.assertResponse(exception, CONFLICT, CatalogExceptionMessage.ENTITY_ALREADY_EXISTS); + assertResponse(exception, CONFLICT, CatalogExceptionMessage.ENTITY_ALREADY_EXISTS); } @Test @@ -130,7 +139,7 @@ public class DatabaseResourceTest extends CatalogApplicationTest { CreateDatabase create = create(test); HttpResponseException exception = assertThrows(HttpResponseException.class, () -> createDatabase(create, authHeaders("test@open-metadata.org"))); - TestUtils.assertResponse(exception, FORBIDDEN, "Principal: CatalogPrincipal{name='test'} is not admin"); + assertResponse(exception, FORBIDDEN, "Principal: CatalogPrincipal{name='test'} is not admin"); } @Test @@ -157,7 +166,7 @@ public class DatabaseResourceTest extends CatalogApplicationTest { CreateDatabase create = create(test).withOwner(owner); HttpResponseException exception = assertThrows(HttpResponseException.class, () -> createDatabase(create, adminAuthHeaders())); - TestUtils.assertResponse(exception, NOT_FOUND, entityNotFound("User", TestUtils.NON_EXISTENT_ENTITY)); + assertResponse(exception, NOT_FOUND, entityNotFound("User", TestUtils.NON_EXISTENT_ENTITY)); } @Test @@ -178,7 +187,7 @@ public class DatabaseResourceTest extends CatalogApplicationTest { } @Test - public void get_databaseListWithInvalidLimitOffet_4xx() { + public void get_databaseListWithInvalidLimitOffset_4xx() { // Limit must be >= 1 and <= 1000,000 HttpResponseException exception = assertThrows(HttpResponseException.class, () -> listDatabases(null, null, -1, null, null, adminAuthHeaders())); @@ -202,7 +211,7 @@ public class DatabaseResourceTest extends CatalogApplicationTest { } @Test - public void get_databaseListWithValidLimitOffet_4xx(TestInfo test) throws HttpResponseException { + public void get_databaseListWithValidLimitOffset_4xx(TestInfo test) throws HttpResponseException { // Create a large number of databases int maxDatabases = 40; for (int i = 0; i < maxDatabases; i++) { @@ -214,7 +223,7 @@ public class DatabaseResourceTest extends CatalogApplicationTest { int totalRecords = allDatabases.getData().size(); printDatabases(allDatabases); - // List limit number databases at a time at varous offsets and ensure right results are returned + // List limit number databases at a time at various offsets and ensure right results are returned for (int limit = 1; limit < maxDatabases; limit++) { String after = null; String before; @@ -230,7 +239,7 @@ public class DatabaseResourceTest extends CatalogApplicationTest { before = forwardPage.getPaging().getBefore(); assertEntityPagination(allDatabases.getData(), forwardPage, limit, indexInAllDatabases); - if (pageCount == 0) { // CASE 0 - First page is being returned. There is no before cursort + if (pageCount == 0) { // CASE 0 - First page is being returned. There is no before cursor assertNull(before); } else { // Make sure scrolling back based on before cursor returns the correct result @@ -340,7 +349,7 @@ public class DatabaseResourceTest extends CatalogApplicationTest { public void get_nonExistentDatabase_404_notFound() { HttpResponseException exception = assertThrows(HttpResponseException.class, () -> getDatabase(TestUtils.NON_EXISTENT_ENTITY, adminAuthHeaders())); - TestUtils.assertResponse(exception, NOT_FOUND, + assertResponse(exception, NOT_FOUND, entityNotFound(Entity.DATABASE, TestUtils.NON_EXISTENT_ENTITY)); } @@ -394,13 +403,13 @@ public class DatabaseResourceTest extends CatalogApplicationTest { database.setId(UUID.randomUUID()); HttpResponseException exception = assertThrows(HttpResponseException.class, () -> patchDatabase(databaseId, databaseJson, database, adminAuthHeaders())); - TestUtils.assertResponse(exception, BAD_REQUEST, readOnlyAttribute(Entity.DATABASE, "id")); + assertResponse(exception, BAD_REQUEST, readOnlyAttribute(Entity.DATABASE, "id")); // ID can't be deleted database.setId(null); exception = assertThrows(HttpResponseException.class, () -> patchDatabase(databaseId, databaseJson, database, adminAuthHeaders())); - TestUtils.assertResponse(exception, BAD_REQUEST, readOnlyAttribute(Entity.DATABASE, "id")); + assertResponse(exception, BAD_REQUEST, readOnlyAttribute(Entity.DATABASE, "id")); } @Test @@ -411,13 +420,13 @@ public class DatabaseResourceTest extends CatalogApplicationTest { database.setName("newName"); HttpResponseException exception = assertThrows(HttpResponseException.class, () -> patchDatabase(databaseJson, database, adminAuthHeaders())); - TestUtils.assertResponse(exception, BAD_REQUEST, readOnlyAttribute(Entity.DATABASE, "name")); + assertResponse(exception, BAD_REQUEST, readOnlyAttribute(Entity.DATABASE, "name")); // Name can't be removed database.setName(null); exception = assertThrows(HttpResponseException.class, () -> patchDatabase(databaseJson, database, adminAuthHeaders())); - TestUtils.assertResponse(exception, BAD_REQUEST, readOnlyAttribute(Entity.DATABASE, "name")); + assertResponse(exception, BAD_REQUEST, readOnlyAttribute(Entity.DATABASE, "name")); } @Test @@ -430,13 +439,13 @@ public class DatabaseResourceTest extends CatalogApplicationTest { database.setService(MYSQL_REFERENCE); HttpResponseException exception = assertThrows(HttpResponseException.class, () -> patchDatabase(databaseJson, database, adminAuthHeaders())); - TestUtils.assertResponse(exception, BAD_REQUEST, readOnlyAttribute(Entity.DATABASE, "service")); + assertResponse(exception, BAD_REQUEST, readOnlyAttribute(Entity.DATABASE, "service")); // Service relationship can't be removed database.setService(null); exception = assertThrows(HttpResponseException.class, () -> patchDatabase(databaseJson, database, adminAuthHeaders())); - TestUtils.assertResponse(exception, BAD_REQUEST, readOnlyAttribute(Entity.DATABASE, "service")); + assertResponse(exception, BAD_REQUEST, readOnlyAttribute(Entity.DATABASE, "service")); } // TODO listing tables test:1 @@ -457,7 +466,7 @@ public class DatabaseResourceTest extends CatalogApplicationTest { public void delete_nonExistentDatabase_404() { HttpResponseException exception = assertThrows(HttpResponseException.class, () -> deleteDatabase(TestUtils.NON_EXISTENT_ENTITY, adminAuthHeaders())); - TestUtils.assertResponse(exception, NOT_FOUND, entityNotFound(Entity.DATABASE, TestUtils.NON_EXISTENT_ENTITY)); + assertResponse(exception, NOT_FOUND, entityNotFound(Entity.DATABASE, TestUtils.NON_EXISTENT_ENTITY)); } public static Database createAndCheckDatabase(CreateDatabase create, @@ -542,16 +551,16 @@ public class DatabaseResourceTest extends CatalogApplicationTest { // Validate owner if (expectedOwner != null) { TestUtils.validateEntityReference(database.getOwner()); - Assertions.assertEquals(expectedOwner.getId(), database.getOwner().getId()); - Assertions.assertEquals(expectedOwner.getType(), database.getOwner().getType()); + assertEquals(expectedOwner.getId(), database.getOwner().getId()); + assertEquals(expectedOwner.getType(), database.getOwner().getType()); assertNotNull(database.getOwner().getHref()); } // Validate service if (expectedService != null) { TestUtils.validateEntityReference(database.getService()); - Assertions.assertEquals(expectedService.getId(), database.getService().getId()); - Assertions.assertEquals(expectedService.getType(), database.getService().getType()); + assertEquals(expectedService.getId(), database.getService().getId()); + assertEquals(expectedService.getType(), database.getService().getType()); } return database; } @@ -630,7 +639,7 @@ public class DatabaseResourceTest extends CatalogApplicationTest { // Ensure deleted database does not exist HttpResponseException exception = assertThrows(HttpResponseException.class, () -> getDatabase(id, authHeaders)); - TestUtils.assertResponse(exception, NOT_FOUND, entityNotFound(Entity.DATABASE, id)); + assertResponse(exception, NOT_FOUND, entityNotFound(Entity.DATABASE, id)); } public static String getDatabaseName(TestInfo 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 207509b5c6b..6a17d9b05fd 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 @@ -57,12 +57,27 @@ import java.util.Map; import java.util.UUID; import static java.util.Collections.singletonList; -import static javax.ws.rs.core.Response.Status.*; -import static org.junit.jupiter.api.Assertions.*; +import static javax.ws.rs.core.Response.Status.BAD_REQUEST; +import static javax.ws.rs.core.Response.Status.CONFLICT; +import static javax.ws.rs.core.Response.Status.CREATED; +import static javax.ws.rs.core.Response.Status.FORBIDDEN; +import static javax.ws.rs.core.Response.Status.NOT_FOUND; +import static javax.ws.rs.core.Response.Status.OK; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +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.resources.databases.DatabaseResourceTest.createAndCheckDatabase; import static org.openmetadata.catalog.resources.services.DatabaseServiceResourceTest.createService; import static org.openmetadata.catalog.util.RestUtil.DATE_FORMAT; -import static org.openmetadata.catalog.util.TestUtils.*; +import static org.openmetadata.catalog.util.TestUtils.NON_EXISTENT_ENTITY; +import static org.openmetadata.catalog.util.TestUtils.adminAuthHeaders; +import static org.openmetadata.catalog.util.TestUtils.assertEntityPagination; +import static org.openmetadata.catalog.util.TestUtils.assertResponse; +import static org.openmetadata.catalog.util.TestUtils.authHeaders; +import static org.openmetadata.catalog.util.TestUtils.userAuthHeaders; import static org.openmetadata.common.utils.CommonUtil.getDateStringByOffset; @TestMethodOrder(MethodOrderer.OrderAnnotation.class) 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 66a7ceddd77..93b12781735 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 @@ -1,7 +1,6 @@ package org.openmetadata.catalog.resources.feeds; import org.apache.http.client.HttpResponseException; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.MethodOrderer; import org.junit.jupiter.api.Test; @@ -30,7 +29,9 @@ import java.util.UUID; 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.*; +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.resources.databases.TableResourceTest.createAndCheckTable; import static org.openmetadata.catalog.util.TestUtils.adminAuthHeaders; @@ -221,7 +222,7 @@ public class FeedResourceTest extends CatalogApplicationTest { Post firstPost = thread.getPosts().get(0); assertEquals(message, firstPost.getMessage()); assertEquals(from, firstPost.getFrom()); - Assertions.assertEquals(about, thread.getAbout()); + assertEquals(about, thread.getAbout()); } private static void validatePost(Thread expected, Thread actual, Post expectedPost) { 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 6b0c765e7b9..055016f2fce 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 @@ -21,8 +21,14 @@ import java.util.Date; import java.util.Map; import java.util.UUID; -import static javax.ws.rs.core.Response.Status.*; -import static org.junit.jupiter.api.Assertions.*; +import static javax.ws.rs.core.Response.Status.BAD_REQUEST; +import static javax.ws.rs.core.Response.Status.CONFLICT; +import static javax.ws.rs.core.Response.Status.FORBIDDEN; +import static javax.ws.rs.core.Response.Status.NOT_FOUND; +import static javax.ws.rs.core.Response.Status.OK; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.openmetadata.catalog.util.TestUtils.adminAuthHeaders; import static org.openmetadata.catalog.util.TestUtils.authHeaders; @@ -141,7 +147,7 @@ public class DatabaseServiceResourceTest extends CatalogApplicationTest { } @Test - public void put_updateNonExistentService_404(TestInfo test) { + public void put_updateNonExistentService_404() { // Update database description and ingestion service that are null UpdateDatabaseService update = new UpdateDatabaseService().withDescription("description1"); HttpResponseException exception = assertThrows(HttpResponseException.class, () @@ -174,7 +180,7 @@ public class DatabaseServiceResourceTest extends CatalogApplicationTest { DatabaseService dbService = createAndCheckService(create(test).withDescription(null).withIngestionSchedule(null), authHeaders); String id = dbService.getId().toString(); - String startDate = RestUtil.DATE_TIME_FORMAT.format(new Date()); + RestUtil.DATE_TIME_FORMAT.format(new Date()); // Update database description and ingestion service that are null UpdateDatabaseService update = new UpdateDatabaseService().withDescription("description1"); 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 cb3efd5a7ff..3d8741987fc 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 @@ -9,7 +9,6 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInfo; import org.junit.jupiter.api.TestMethodOrder; import org.openmetadata.catalog.CatalogApplicationTest; -import org.openmetadata.catalog.exception.CatalogExceptionMessage; import org.openmetadata.catalog.resources.tags.TagResource.CategoryList; import org.openmetadata.catalog.type.CreateTag; import org.openmetadata.catalog.type.CreateTagCategory; @@ -30,8 +29,12 @@ import java.util.List; import java.util.Map; import java.util.Optional; -import static javax.ws.rs.core.Response.Status.*; -import static org.junit.jupiter.api.Assertions.*; +import static javax.ws.rs.core.Response.Status.BAD_REQUEST; +import static javax.ws.rs.core.Response.Status.CONFLICT; +import static javax.ws.rs.core.Response.Status.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.util.TestUtils.adminAuthHeaders; import static org.openmetadata.catalog.util.TestUtils.authHeaders; diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/teams/TeamResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/teams/TeamResourceTest.java index 4add5950356..8d3bd6f3914 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 @@ -32,11 +32,21 @@ import java.util.Map; import java.util.Optional; import java.util.UUID; -import static javax.ws.rs.core.Response.Status.*; -import static org.junit.jupiter.api.Assertions.*; +import static javax.ws.rs.core.Response.Status.BAD_REQUEST; +import static javax.ws.rs.core.Response.Status.CONFLICT; +import static javax.ws.rs.core.Response.Status.FORBIDDEN; +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.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.resources.teams.UserResourceTest.createUser; -import static org.openmetadata.catalog.util.TestUtils.*; +import static org.openmetadata.catalog.util.TestUtils.adminAuthHeaders; +import static org.openmetadata.catalog.util.TestUtils.assertEntityPagination; +import static org.openmetadata.catalog.util.TestUtils.assertResponse; +import static org.openmetadata.catalog.util.TestUtils.authHeaders; public class TeamResourceTest extends CatalogApplicationTest { private static final Logger LOG = LoggerFactory.getLogger(TeamResourceTest.class); @@ -47,7 +57,7 @@ public class TeamResourceTest extends CatalogApplicationTest { // Create team with mandatory name field empty HttpResponseException exception = assertThrows(HttpResponseException.class, () -> createTeam(create(test).withName(TestUtils.LONG_ENTITY_NAME), adminAuthHeaders())); - TestUtils.assertResponse(exception, BAD_REQUEST, "[name size must be between 1 and 64]"); + assertResponse(exception, BAD_REQUEST, "[name size must be between 1 and 64]"); } @Test @@ -55,7 +65,7 @@ public class TeamResourceTest extends CatalogApplicationTest { // Create team with mandatory name field empty HttpResponseException exception = assertThrows(HttpResponseException.class, () -> createTeam(create(test).withName(""), adminAuthHeaders())); - TestUtils.assertResponse(exception, BAD_REQUEST, "[name size must be between 1 and 64]"); + assertResponse(exception, BAD_REQUEST, "[name size must be between 1 and 64]"); } @Test @@ -64,7 +74,7 @@ public class TeamResourceTest extends CatalogApplicationTest { createTeam(create, adminAuthHeaders()); HttpResponseException exception = assertThrows(HttpResponseException.class, () -> createTeam(create, adminAuthHeaders())); - TestUtils.assertResponse(exception, CONFLICT, CatalogExceptionMessage.ENTITY_ALREADY_EXISTS); + assertResponse(exception, CONFLICT, CatalogExceptionMessage.ENTITY_ALREADY_EXISTS); } @Test @@ -93,7 +103,7 @@ public class TeamResourceTest extends CatalogApplicationTest { CreateTeam create = create(test, 1); HttpResponseException exception = assertThrows(HttpResponseException.class, () -> createAndCheckTeam(create, authHeaders)); - TestUtils.assertResponse(exception, FORBIDDEN, "Principal: CatalogPrincipal{name='test'} is not admin"); + assertResponse(exception, FORBIDDEN, "Principal: CatalogPrincipal{name='test'} is not admin"); } @Test @@ -119,7 +129,7 @@ public class TeamResourceTest extends CatalogApplicationTest { public void get_nonExistentTeam_404_notFound() { HttpResponseException exception = assertThrows(HttpResponseException.class, () -> getTeam(TestUtils.NON_EXISTENT_ENTITY, adminAuthHeaders())); - TestUtils.assertResponse(exception, NOT_FOUND, entityNotFound("Team", TestUtils.NON_EXISTENT_ENTITY)); + assertResponse(exception, NOT_FOUND, entityNotFound("Team", TestUtils.NON_EXISTENT_ENTITY)); } @Test @@ -153,12 +163,12 @@ public class TeamResourceTest extends CatalogApplicationTest { // Empty query field .../teams?fields= HttpResponseException exception = assertThrows(HttpResponseException.class, () -> getTeam(team.getId(), "", adminAuthHeaders())); - TestUtils.assertResponse(exception, BAD_REQUEST, CatalogExceptionMessage.invalidField("")); + assertResponse(exception, BAD_REQUEST, CatalogExceptionMessage.invalidField("")); // .../teams?fields=invalidField exception = assertThrows(HttpResponseException.class, () -> getTeam(team.getId(), "invalidField", adminAuthHeaders())); - TestUtils.assertResponse(exception, BAD_REQUEST, CatalogExceptionMessage.invalidField("invalidField")); + assertResponse(exception, BAD_REQUEST, CatalogExceptionMessage.invalidField("invalidField")); } @Test @@ -268,7 +278,7 @@ public class TeamResourceTest extends CatalogApplicationTest { // Make sure team is no longer there HttpResponseException exception = assertThrows(HttpResponseException.class, () -> getTeam(team.getId(), adminAuthHeaders())); - TestUtils.assertResponse(exception, NOT_FOUND, entityNotFound("Team", team.getId())); + assertResponse(exception, NOT_FOUND, entityNotFound("Team", team.getId())); // Make sure user does not have relationship to this team User user = UserResourceTest.getUser(user1.getId(), "teams", adminAuthHeaders()); @@ -284,7 +294,7 @@ public class TeamResourceTest extends CatalogApplicationTest { Team team = createAndCheckTeam(create, adminAuthHeaders()); HttpResponseException exception = assertThrows(HttpResponseException.class, () -> deleteTeam(team.getId(), authHeaders("test@open-metadata.org"))); - TestUtils.assertResponse(exception, FORBIDDEN, "Principal: CatalogPrincipal{name='test'} is not admin"); + assertResponse(exception, FORBIDDEN, "Principal: CatalogPrincipal{name='test'} is not admin"); } @@ -292,7 +302,7 @@ public class TeamResourceTest extends CatalogApplicationTest { public void delete_nonExistentTeam_404_notFound() { HttpResponseException exception = assertThrows(HttpResponseException.class, () -> deleteTeam(TestUtils.NON_EXISTENT_ENTITY, adminAuthHeaders())); - TestUtils.assertResponse(exception, NOT_FOUND, entityNotFound("Team", TestUtils.NON_EXISTENT_ENTITY)); + assertResponse(exception, NOT_FOUND, entityNotFound("Team", TestUtils.NON_EXISTENT_ENTITY)); } @Test @@ -304,7 +314,7 @@ public class TeamResourceTest extends CatalogApplicationTest { team.setId(UUID.randomUUID()); HttpResponseException exception = assertThrows(HttpResponseException.class, () -> patchTeam(oldTeamId, teamJson, team, adminAuthHeaders())); - TestUtils.assertResponse(exception, BAD_REQUEST, CatalogExceptionMessage.readOnlyAttribute("Team", "id")); + assertResponse(exception, BAD_REQUEST, CatalogExceptionMessage.readOnlyAttribute("Team", "id")); } @Test @@ -315,7 +325,7 @@ public class TeamResourceTest extends CatalogApplicationTest { team.setName("newName"); HttpResponseException exception = assertThrows(HttpResponseException.class, () -> patchTeam(teamJson, team, adminAuthHeaders())); - TestUtils.assertResponse(exception, BAD_REQUEST, CatalogExceptionMessage.readOnlyAttribute("Team", "name")); + assertResponse(exception, BAD_REQUEST, CatalogExceptionMessage.readOnlyAttribute("Team", "name")); } @Test @@ -326,7 +336,7 @@ public class TeamResourceTest extends CatalogApplicationTest { team.setDeleted(true); HttpResponseException exception = assertThrows(HttpResponseException.class, () -> patchTeam(teamJson, team, adminAuthHeaders())); - TestUtils.assertResponse(exception, BAD_REQUEST, CatalogExceptionMessage.readOnlyAttribute("Team", "deleted")); + assertResponse(exception, BAD_REQUEST, CatalogExceptionMessage.readOnlyAttribute("Team", "deleted")); } @Test @@ -382,7 +392,7 @@ public class TeamResourceTest extends CatalogApplicationTest { HttpResponseException exception = assertThrows(HttpResponseException.class, () -> patchTeamAttributesAndCheck(team, "displayName", "description", profile, users, authHeaders("test@open-metadata.org"))); - TestUtils.assertResponse(exception, FORBIDDEN, "Principal: CatalogPrincipal{name='test'} is not admin"); + assertResponse(exception, FORBIDDEN, "Principal: CatalogPrincipal{name='test'} is not admin"); } // @Test // public void patch_updateInvalidUsers_404_notFound(TestInfo test) throws HttpResponseException { 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 f139275c601..20ace3dfe64 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 @@ -33,11 +33,26 @@ import java.util.Map; import java.util.Optional; import java.util.UUID; -import static javax.ws.rs.core.Response.Status.*; -import static org.junit.jupiter.api.Assertions.*; -import static org.openmetadata.catalog.exception.CatalogExceptionMessage.*; +import static javax.ws.rs.core.Response.Status.BAD_REQUEST; +import static javax.ws.rs.core.Response.Status.CONFLICT; +import static javax.ws.rs.core.Response.Status.CREATED; +import static javax.ws.rs.core.Response.Status.FORBIDDEN; +import static javax.ws.rs.core.Response.Status.NOT_FOUND; +import static javax.ws.rs.core.Response.Status.UNAUTHORIZED; +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.deactivatedUser; +import static org.openmetadata.catalog.exception.CatalogExceptionMessage.entityNotFound; +import static org.openmetadata.catalog.exception.CatalogExceptionMessage.readOnlyAttribute; import static org.openmetadata.catalog.resources.teams.TeamResourceTest.createTeam; -import static org.openmetadata.catalog.util.TestUtils.*; +import static org.openmetadata.catalog.util.TestUtils.LONG_ENTITY_NAME; +import static org.openmetadata.catalog.util.TestUtils.adminAuthHeaders; +import static org.openmetadata.catalog.util.TestUtils.assertEntityPagination; +import static org.openmetadata.catalog.util.TestUtils.assertResponse; +import static org.openmetadata.catalog.util.TestUtils.authHeaders; public class UserResourceTest extends CatalogApplicationTest { public static final Logger LOG = LoggerFactory.getLogger(UserResourceTest.class); 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 33d273c892c..5bebd1e2caa 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 @@ -38,7 +38,9 @@ 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.util.TestUtils.*; +import static org.openmetadata.catalog.util.TestUtils.NON_EXISTENT_ENTITY; +import static org.openmetadata.catalog.util.TestUtils.adminAuthHeaders; +import static org.openmetadata.catalog.util.TestUtils.assertResponse; import static org.openmetadata.common.utils.CommonUtil.getDateStringByOffset; @TestMethodOrder(MethodOrderer.OrderAnnotation.class) diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/util/RestUtilTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/util/RestUtilTest.java index ab484764eda..599141e76df 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/util/RestUtilTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/util/RestUtilTest.java @@ -8,7 +8,8 @@ import org.junit.jupiter.api.Test; import java.util.Arrays; import java.util.List; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; public class RestUtilTest { @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 90251067f4c..a9de73513a1 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 @@ -16,9 +16,17 @@ import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; import java.net.URI; import java.net.URISyntaxException; -import java.util.*; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.UUID; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; public class TestUtils { // Entity name length allowed is 64 characters. This is a 65 char length invalid entity name