World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
[#4197] improvement(common): CatalogListResponse should implement the method validate (#4223)
jingjia881e8511ae63df
diff --git a/common/src/main/java/org/apache/gravitino/dto/responses/CatalogListResponse.java b/common/src/main/java/org/apache/gravitino/dto/responses/CatalogListResponse.javaindex dfb31417a6..6d069ae46f 100644--- a/common/src/main/java/org/apache/gravitino/dto/responses/CatalogListResponse.java+++ b/common/src/main/java/org/apache/gravitino/dto/responses/CatalogListResponse.java@@ -19,9 +19,12 @@package org.apache.gravitino.dto.responses;import com.fasterxml.jackson.annotation.JsonProperty;+import com.google.common.base.Preconditions;+import java.util.Arrays;import lombok.EqualsAndHashCode;import lombok.Getter;import lombok.ToString;+import org.apache.commons.lang3.StringUtils;import org.apache.gravitino.dto.CatalogDTO;/** Represents a response for a list of catalogs with their information. */@@ -51,4 +54,27 @@ public class CatalogListResponse extends BaseResponse {super();this.catalogs = null;}++ /**+ * Validates the response data.+ *+ * @throws IllegalArgumentException if name, type or audit information is not set.+ */+ @Override+ public void validate() throws IllegalArgumentException {+ super.validate();++ Preconditions.checkArgument(catalogs != null, "catalogs must be non-null");+ Arrays.stream(catalogs)+ .forEach(+ catalog -> {+ Preconditions.checkArgument(+ StringUtils.isNotBlank(catalog.name()),+ "catalog 'name' must not be null and empty");+ Preconditions.checkArgument(+ catalog.type() != null, "catalog 'type' must not be null");+ Preconditions.checkArgument(+ catalog.auditInfo() != null, "catalog 'audit' must not be null");+ });+ }}diff --git a/common/src/test/java/org/apache/gravitino/dto/responses/TestResponses.java b/common/src/test/java/org/apache/gravitino/dto/responses/TestResponses.javaindex 8d7c52808d..7f9ebfeb7d 100644--- a/common/src/test/java/org/apache/gravitino/dto/responses/TestResponses.java+++ b/common/src/test/java/org/apache/gravitino/dto/responses/TestResponses.java@@ -146,6 +146,28 @@ public class TestResponses {assertThrows(IllegalArgumentException.class, () -> catalog.validate());}+ @Test+ void testCatalogListResponse() throws IllegalArgumentException {+ AuditDTO audit =+ AuditDTO.builder().withCreator("creator").withCreateTime(Instant.now()).build();+ CatalogDTO catalog =+ CatalogDTO.builder()+ .withName("CatalogA")+ .withComment("comment")+ .withType(Catalog.Type.RELATIONAL)+ .withProvider("test")+ .withAudit(audit)+ .build();+ CatalogListResponse response = new CatalogListResponse(new CatalogDTO[] {catalog});+ response.validate(); // No exception thrown+ }++ @Test+ void testCatalogListException() throws IllegalArgumentException {+ CatalogListResponse response = new CatalogListResponse();+ assertThrows(IllegalArgumentException.class, () -> response.validate());+ }+@Testvoid testSchemaResponse() throws IllegalArgumentException {AuditDTO audit =