This is an automated email from the ASF dual-hosted git repository.

jmclean pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gravitino.git


The following commit(s) were added to refs/heads/main by this push:
     new 72245254fc [#6136] improvement(CLI): Move check for enable and disable 
command in Gravitino CLI to command (#6535)
72245254fc is described below

commit 72245254fcd488b2bb62cfa630d5b4f077f77229
Author: Lord of Abyss <[email protected]>
AuthorDate: Thu Feb 27 12:26:17 2025 +0800

    [#6136] improvement(CLI): Move check for enable and disable command in 
Gravitino CLI to command (#6535)
    
    ### What changes were proposed in this pull request?
    
    Move check for enable and disable command in Gravitino CLI to command
    
    ### Why are the changes needed?
    
    Fix: #6136
    
    ### Does this PR introduce _any_ user-facing change?
    
    No
    
    ### How was this patch tested?
    
    local test
    ```bash
    gcli metalake update -m demo_metalake --disable -i
    demo_metalake has been disabled.
    
    gcli metalake update -m demo_metalake --enable -i
    demo_metalake has been enabled.
    
    gcli metalake update -m demo_metalake --enable --disable -i
    Unable to us --enable and --disable at the same time
    
     gcli metalake update -m demo_metalake --enable --all  -i
    demo_metalake has been enabled. and all catalogs in this metalake have been 
enabled.
    
    gcli catalog update -m demo_metalake --name Hive_catalog --disable -i
    demo_metalake.Hive_catalog has been disabled.
    
    gcli catalog update -m demo_metalake --name Hive_catalog --enable -i
    demo_metalake.Hive_catalog has been enabled.
    
    gcli catalog update -m demo_metalake --name Hive_catalog --enable --disable 
-i
    Unable to us --enable and --disable at the same time
    ```
    
    ---------
    
    Co-authored-by: Justin Mclean <[email protected]>
---
 .../gravitino/cli/CatalogCommandHandler.java       | 16 ++----
 .../org/apache/gravitino/cli/CommandContext.java   |  8 +++
 .../org/apache/gravitino/cli/ErrorMessages.java    |  2 +-
 .../gravitino/cli/MetalakeCommandHandler.java      | 15 +-----
 .../apache/gravitino/cli/TestableCommandLine.java  | 24 +++------
 .../gravitino/cli/commands/CatalogDisable.java     | 62 ----------------------
 .../{CatalogEnable.java => ManageCatalog.java}     | 60 +++++++++++++++++----
 .../{MetalakeEnable.java => ManageMetalake.java}   | 56 +++++++++++++++----
 .../gravitino/cli/commands/MetalakeDisable.java    | 56 -------------------
 .../apache/gravitino/cli/TestCatalogCommands.java  | 28 ++++------
 .../apache/gravitino/cli/TestMetalakeCommands.java | 28 ++++------
 11 files changed, 136 insertions(+), 219 deletions(-)

diff --git 
a/clients/cli/src/main/java/org/apache/gravitino/cli/CatalogCommandHandler.java 
b/clients/cli/src/main/java/org/apache/gravitino/cli/CatalogCommandHandler.java
index 4e5a50fd37..f8749720cd 100644
--- 
a/clients/cli/src/main/java/org/apache/gravitino/cli/CatalogCommandHandler.java
+++ 
b/clients/cli/src/main/java/org/apache/gravitino/cli/CatalogCommandHandler.java
@@ -175,19 +175,9 @@ public class CatalogCommandHandler extends CommandHandler {
 
   /** Handles the "UPDATE" command. */
   private void handleUpdateCommand() {
-    if (line.hasOption(GravitinoOptions.ENABLE) && 
line.hasOption(GravitinoOptions.DISABLE)) {
-      System.err.println(ErrorMessages.INVALID_ENABLE_DISABLE);
-      Main.exit(-1);
-    }
-    if (line.hasOption(GravitinoOptions.ENABLE)) {
-      boolean enableMetalake = line.hasOption(GravitinoOptions.ALL);
-      gravitinoCommandLine
-          .newCatalogEnable(context, metalake, catalog, enableMetalake)
-          .validate()
-          .handle();
-    }
-    if (line.hasOption(GravitinoOptions.DISABLE)) {
-      gravitinoCommandLine.newCatalogDisable(context, metalake, 
catalog).validate().handle();
+
+    if (line.hasOption(GravitinoOptions.ENABLE) || 
line.hasOption(GravitinoOptions.DISABLE)) {
+      gravitinoCommandLine.newManageCatalog(context, metalake, 
catalog).validate().handle();
     }
 
     if (line.hasOption(GravitinoOptions.COMMENT)) {
diff --git 
a/clients/cli/src/main/java/org/apache/gravitino/cli/CommandContext.java 
b/clients/cli/src/main/java/org/apache/gravitino/cli/CommandContext.java
index 6f41e3697e..1f92dd62c9 100644
--- a/clients/cli/src/main/java/org/apache/gravitino/cli/CommandContext.java
+++ b/clients/cli/src/main/java/org/apache/gravitino/cli/CommandContext.java
@@ -115,6 +115,14 @@ public class CommandContext {
     return auth;
   }
 
+  /**
+   * Returns the command line.
+   *
+   * @return The command line.
+   */
+  public CommandLine line() {
+    return line;
+  }
   /**
    * Retrieves the Gravitino URL from the command line options or the 
GRAVITINO_URL environment
    * variable or the Gravitino config file.
diff --git 
a/clients/cli/src/main/java/org/apache/gravitino/cli/ErrorMessages.java 
b/clients/cli/src/main/java/org/apache/gravitino/cli/ErrorMessages.java
index 554f3a8503..0ba98c0c77 100644
--- a/clients/cli/src/main/java/org/apache/gravitino/cli/ErrorMessages.java
+++ b/clients/cli/src/main/java/org/apache/gravitino/cli/ErrorMessages.java
@@ -39,7 +39,7 @@ public class ErrorMessages {
   public static final String ENTITY_IN_USE = " in use, please disable it 
first.";
 
   public static final String INVALID_ENABLE_DISABLE =
-      "Unable to us --enable and --disable at the same time";
+      "Unable to use --enable and --disable at the same time.";
   public static final String INVALID_OWNER_COMMAND =
       "Unsupported combination of options either use --user or --group.";
   public static final String INVALID_REMOVE_COMMAND =
diff --git 
a/clients/cli/src/main/java/org/apache/gravitino/cli/MetalakeCommandHandler.java
 
b/clients/cli/src/main/java/org/apache/gravitino/cli/MetalakeCommandHandler.java
index 218f6e1458..c76f875279 100644
--- 
a/clients/cli/src/main/java/org/apache/gravitino/cli/MetalakeCommandHandler.java
+++ 
b/clients/cli/src/main/java/org/apache/gravitino/cli/MetalakeCommandHandler.java
@@ -159,19 +159,8 @@ public class MetalakeCommandHandler extends CommandHandler 
{
 
   /** Handles the "UPDATE" command. */
   private void handleUpdateCommand() {
-    if (line.hasOption(GravitinoOptions.ENABLE) && 
line.hasOption(GravitinoOptions.DISABLE)) {
-      System.err.println(ErrorMessages.INVALID_ENABLE_DISABLE);
-      Main.exit(-1);
-    }
-    if (line.hasOption(GravitinoOptions.ENABLE)) {
-      boolean enableAllCatalogs = line.hasOption(GravitinoOptions.ALL);
-      gravitinoCommandLine
-          .newMetalakeEnable(context, metalake, enableAllCatalogs)
-          .validate()
-          .handle();
-    }
-    if (line.hasOption(GravitinoOptions.DISABLE)) {
-      gravitinoCommandLine.newMetalakeDisable(context, 
metalake).validate().handle();
+    if (line.hasOption(GravitinoOptions.ENABLE) || 
line.hasOption(GravitinoOptions.DISABLE)) {
+      gravitinoCommandLine.newManageMetalake(context, 
metalake).validate().handle();
     }
 
     if (line.hasOption(GravitinoOptions.COMMENT)) {
diff --git 
a/clients/cli/src/main/java/org/apache/gravitino/cli/TestableCommandLine.java 
b/clients/cli/src/main/java/org/apache/gravitino/cli/TestableCommandLine.java
index 346e2691f4..dcb8e1bc24 100644
--- 
a/clients/cli/src/main/java/org/apache/gravitino/cli/TestableCommandLine.java
+++ 
b/clients/cli/src/main/java/org/apache/gravitino/cli/TestableCommandLine.java
@@ -26,8 +26,6 @@ import org.apache.gravitino.cli.commands.AddRoleToGroup;
 import org.apache.gravitino.cli.commands.AddRoleToUser;
 import org.apache.gravitino.cli.commands.CatalogAudit;
 import org.apache.gravitino.cli.commands.CatalogDetails;
-import org.apache.gravitino.cli.commands.CatalogDisable;
-import org.apache.gravitino.cli.commands.CatalogEnable;
 import org.apache.gravitino.cli.commands.ClientVersion;
 import org.apache.gravitino.cli.commands.ColumnAudit;
 import org.apache.gravitino.cli.commands.CreateCatalog;
@@ -78,10 +76,10 @@ import org.apache.gravitino.cli.commands.ListTagProperties;
 import org.apache.gravitino.cli.commands.ListTopicProperties;
 import org.apache.gravitino.cli.commands.ListTopics;
 import org.apache.gravitino.cli.commands.ListUsers;
+import org.apache.gravitino.cli.commands.ManageCatalog;
+import org.apache.gravitino.cli.commands.ManageMetalake;
 import org.apache.gravitino.cli.commands.MetalakeAudit;
 import org.apache.gravitino.cli.commands.MetalakeDetails;
-import org.apache.gravitino.cli.commands.MetalakeDisable;
-import org.apache.gravitino.cli.commands.MetalakeEnable;
 import org.apache.gravitino.cli.commands.ModelAudit;
 import org.apache.gravitino.cli.commands.ModelDetails;
 import org.apache.gravitino.cli.commands.OwnerDetails;
@@ -839,23 +837,13 @@ public class TestableCommandLine {
     return new RevokeAllPrivileges(context, metalake, role, entity);
   }
 
-  protected MetalakeEnable newMetalakeEnable(
-      CommandContext context, String metalake, boolean enableAllCatalogs) {
-    return new MetalakeEnable(context, metalake, enableAllCatalogs);
+  protected ManageMetalake newManageMetalake(CommandContext context, String 
metalake) {
+    return new ManageMetalake(context, metalake);
   }
 
-  protected MetalakeDisable newMetalakeDisable(CommandContext context, String 
metalake) {
-    return new MetalakeDisable(context, metalake);
-  }
-
-  protected CatalogEnable newCatalogEnable(
-      CommandContext context, String metalake, String catalog, boolean 
enableMetalake) {
-    return new CatalogEnable(context, metalake, catalog, enableMetalake);
-  }
-
-  protected CatalogDisable newCatalogDisable(
+  protected ManageCatalog newManageCatalog(
       CommandContext context, String metalake, String catalog) {
-    return new CatalogDisable(context, metalake, catalog);
+    return new ManageCatalog(context, metalake, catalog);
   }
 
   protected ListModel newListModel(
diff --git 
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CatalogDisable.java
 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CatalogDisable.java
deleted file mode 100644
index 7a9954b1ee..0000000000
--- 
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CatalogDisable.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.gravitino.cli.commands;
-
-import org.apache.gravitino.cli.CommandContext;
-import org.apache.gravitino.cli.ErrorMessages;
-import org.apache.gravitino.client.GravitinoClient;
-import org.apache.gravitino.exceptions.NoSuchCatalogException;
-import org.apache.gravitino.exceptions.NoSuchMetalakeException;
-
-/** Disable catalog. */
-public class CatalogDisable extends Command {
-
-  private final String metalake;
-  private final String catalog;
-
-  /**
-   * Disable catalog
-   *
-   * @param context The command context.
-   * @param metalake The name of the metalake.
-   * @param catalog The name of the catalog.
-   */
-  public CatalogDisable(CommandContext context, String metalake, String 
catalog) {
-    super(context);
-    this.metalake = metalake;
-    this.catalog = catalog;
-  }
-
-  /** Disable catalog. */
-  @Override
-  public void handle() {
-    try {
-      GravitinoClient client = buildClient(metalake);
-      client.disableCatalog(catalog);
-    } catch (NoSuchMetalakeException noSuchMetalakeException) {
-      exitWithError(ErrorMessages.UNKNOWN_METALAKE);
-    } catch (NoSuchCatalogException noSuchCatalogException) {
-      exitWithError(ErrorMessages.UNKNOWN_CATALOG);
-    } catch (Exception exp) {
-      exitWithError(exp.getMessage());
-    }
-
-    printInformation(metalake + "." + catalog + " has been disabled.");
-  }
-}
diff --git 
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CatalogEnable.java
 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ManageCatalog.java
similarity index 58%
rename from 
clients/cli/src/main/java/org/apache/gravitino/cli/commands/CatalogEnable.java
rename to 
clients/cli/src/main/java/org/apache/gravitino/cli/commands/ManageCatalog.java
index 8c5ca51354..2e56351391 100644
--- 
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CatalogEnable.java
+++ 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ManageCatalog.java
@@ -16,41 +16,63 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.gravitino.cli.commands;
 
+import org.apache.commons.cli.CommandLine;
 import org.apache.gravitino.cli.CommandContext;
 import org.apache.gravitino.cli.ErrorMessages;
+import org.apache.gravitino.cli.GravitinoOptions;
 import org.apache.gravitino.client.GravitinoAdminClient;
 import org.apache.gravitino.client.GravitinoClient;
 import org.apache.gravitino.exceptions.MetalakeNotInUseException;
 import org.apache.gravitino.exceptions.NoSuchCatalogException;
 import org.apache.gravitino.exceptions.NoSuchMetalakeException;
 
-/** Enable catalog. */
-public class CatalogEnable extends Command {
+/** Disable or enable a catalog. */
+public class ManageCatalog extends Command {
   private final String metalake;
   private final String catalog;
+  private final CommandLine line;
   private final boolean enableMetalake;
 
   /**
-   * Enable catalog
+   * Constrcut a new instance of the {@code ManageCatalog}.
    *
-   * @param context The command context.
-   * @param metalake The name of the metalake.
-   * @param catalog The name of the catalog.
-   * @param enableMetalake Whether to enable it's metalake
+   * @param context the command context.
+   * @param metalake the metalake name.
+   * @param catalog the catalog name.
    */
-  public CatalogEnable(
-      CommandContext context, String metalake, String catalog, boolean 
enableMetalake) {
+  public ManageCatalog(CommandContext context, String metalake, String 
catalog) {
     super(context);
     this.metalake = metalake;
     this.catalog = catalog;
-    this.enableMetalake = enableMetalake;
+    this.line = context.line();
+    this.enableMetalake = line.hasOption(GravitinoOptions.ALL);
   }
 
-  /** Enable catalog. */
+  /** Disable or enable a catalog. */
   @Override
   public void handle() {
+    if (line.hasOption(GravitinoOptions.ENABLE)) {
+      enableCatalog();
+    } else if (line.hasOption(GravitinoOptions.DISABLE)) {
+      disableCatalog();
+    }
+  }
+
+  /** {@inheritDoc} */
+  @Override
+  public Command validate() {
+    if (line.hasOption(GravitinoOptions.ENABLE) && 
line.hasOption(GravitinoOptions.DISABLE)) {
+      exitWithError(ErrorMessages.INVALID_ENABLE_DISABLE);
+    }
+
+    return super.validate();
+  }
+
+  /** Enable a catalog. */
+  private void enableCatalog() {
     try {
       if (enableMetalake) {
         GravitinoAdminClient adminClient = buildAdminClient();
@@ -71,4 +93,20 @@ public class CatalogEnable extends Command {
 
     printInformation(metalake + "." + catalog + " has been enabled.");
   }
+
+  /** Disable a catalog. */
+  private void disableCatalog() {
+    try {
+      GravitinoClient client = buildClient(metalake);
+      client.disableCatalog(catalog);
+    } catch (NoSuchMetalakeException noSuchMetalakeException) {
+      exitWithError(ErrorMessages.UNKNOWN_METALAKE);
+    } catch (NoSuchCatalogException noSuchCatalogException) {
+      exitWithError(ErrorMessages.UNKNOWN_CATALOG);
+    } catch (Exception exp) {
+      exitWithError(exp.getMessage());
+    }
+
+    printInformation(metalake + "." + catalog + " has been disabled.");
+  }
 }
diff --git 
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/MetalakeEnable.java
 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ManageMetalake.java
similarity index 58%
rename from 
clients/cli/src/main/java/org/apache/gravitino/cli/commands/MetalakeEnable.java
rename to 
clients/cli/src/main/java/org/apache/gravitino/cli/commands/ManageMetalake.java
index f402c37608..35651838b5 100644
--- 
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/MetalakeEnable.java
+++ 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ManageMetalake.java
@@ -20,34 +20,56 @@
 package org.apache.gravitino.cli.commands;
 
 import java.util.Arrays;
+import org.apache.commons.cli.CommandLine;
 import org.apache.gravitino.cli.CommandContext;
 import org.apache.gravitino.cli.ErrorMessages;
+import org.apache.gravitino.cli.GravitinoOptions;
 import org.apache.gravitino.client.GravitinoAdminClient;
 import org.apache.gravitino.client.GravitinoMetalake;
 import org.apache.gravitino.exceptions.NoSuchMetalakeException;
 
-/** Enable metalake. */
-public class MetalakeEnable extends Command {
-
+/** Disable or enable metalake. */
+public class ManageMetalake extends Command {
   private final String metalake;
+  private final CommandLine line;
   private Boolean enableAllCatalogs;
 
   /**
-   * Enable a metalake
+   * Construct a new instance of the {@code ManageMetalake}.
    *
-   * @param context The command context.
-   * @param metalake The name of the metalake.
-   * @param enableAllCatalogs Whether to enable all catalogs.
+   * @param context the command context.
+   * @param metalake the name of the metalake.
    */
-  public MetalakeEnable(CommandContext context, String metalake, boolean 
enableAllCatalogs) {
+  public ManageMetalake(CommandContext context, String metalake) {
     super(context);
     this.metalake = metalake;
-    this.enableAllCatalogs = enableAllCatalogs;
+    this.line = context.line();
+
+    this.enableAllCatalogs = line.hasOption(GravitinoOptions.ALL);
   }
 
-  /** Enable metalake. */
+  /** Disable or enable the metalake. */
   @Override
   public void handle() {
+    if (line.hasOption(GravitinoOptions.ENABLE)) {
+      enableMetalake();
+    } else if (line.hasOption(GravitinoOptions.DISABLE)) {
+      disableMetalake();
+    }
+  }
+
+  /** {@inheritDoc} */
+  @Override
+  public Command validate() {
+    if (line.hasOption(GravitinoOptions.ENABLE) && 
line.hasOption(GravitinoOptions.DISABLE)) {
+      exitWithError(ErrorMessages.INVALID_ENABLE_DISABLE);
+    }
+
+    return super.validate();
+  }
+
+  /** Enable the metalake. */
+  private void enableMetalake() {
     StringBuilder msgBuilder = new StringBuilder(metalake);
     try {
       GravitinoAdminClient client = buildAdminClient();
@@ -68,4 +90,18 @@ public class MetalakeEnable extends Command {
 
     printInformation(msgBuilder.toString());
   }
+
+  /** Disable the metalake. */
+  private void disableMetalake() {
+    try {
+      GravitinoAdminClient client = buildAdminClient();
+      client.disableMetalake(metalake);
+    } catch (NoSuchMetalakeException err) {
+      exitWithError(ErrorMessages.UNKNOWN_METALAKE);
+    } catch (Exception exp) {
+      exitWithError(exp.getMessage());
+    }
+
+    printInformation(metalake + " has been disabled.");
+  }
 }
diff --git 
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/MetalakeDisable.java
 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/MetalakeDisable.java
deleted file mode 100644
index ad05d29343..0000000000
--- 
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/MetalakeDisable.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.gravitino.cli.commands;
-
-import org.apache.gravitino.cli.CommandContext;
-import org.apache.gravitino.cli.ErrorMessages;
-import org.apache.gravitino.client.GravitinoAdminClient;
-import org.apache.gravitino.exceptions.NoSuchMetalakeException;
-
-/** Disable metalake. */
-public class MetalakeDisable extends Command {
-  private String metalake;
-
-  /**
-   * Disable metalake
-   *
-   * @param context The command context.
-   * @param metalake The name of the metalake.
-   */
-  public MetalakeDisable(CommandContext context, String metalake) {
-    super(context);
-    this.metalake = metalake;
-  }
-
-  /** Disable metalake. */
-  @Override
-  public void handle() {
-    try {
-      GravitinoAdminClient client = buildAdminClient();
-      client.disableMetalake(metalake);
-    } catch (NoSuchMetalakeException err) {
-      exitWithError(ErrorMessages.UNKNOWN_METALAKE);
-    } catch (Exception exp) {
-      exitWithError(exp.getMessage());
-    }
-
-    printInformation(metalake + " has been disabled.");
-  }
-}
diff --git 
a/clients/cli/src/test/java/org/apache/gravitino/cli/TestCatalogCommands.java 
b/clients/cli/src/test/java/org/apache/gravitino/cli/TestCatalogCommands.java
index 26639368a6..553820db1b 100644
--- 
a/clients/cli/src/test/java/org/apache/gravitino/cli/TestCatalogCommands.java
+++ 
b/clients/cli/src/test/java/org/apache/gravitino/cli/TestCatalogCommands.java
@@ -21,9 +21,7 @@ package org.apache.gravitino.cli;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.assertTrue;
 import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyBoolean;
 import static org.mockito.ArgumentMatchers.argThat;
 import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.doReturn;
@@ -41,17 +39,17 @@ import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.Options;
 import org.apache.gravitino.cli.commands.CatalogAudit;
 import org.apache.gravitino.cli.commands.CatalogDetails;
-import org.apache.gravitino.cli.commands.CatalogDisable;
-import org.apache.gravitino.cli.commands.CatalogEnable;
 import org.apache.gravitino.cli.commands.CreateCatalog;
 import org.apache.gravitino.cli.commands.DeleteCatalog;
 import org.apache.gravitino.cli.commands.ListCatalogProperties;
 import org.apache.gravitino.cli.commands.ListCatalogs;
+import org.apache.gravitino.cli.commands.ManageCatalog;
 import org.apache.gravitino.cli.commands.RemoveCatalogProperty;
 import org.apache.gravitino.cli.commands.SetCatalogProperty;
 import org.apache.gravitino.cli.commands.UpdateCatalogComment;
 import org.apache.gravitino.cli.commands.UpdateCatalogName;
 import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
@@ -419,7 +417,7 @@ class TestCatalogCommands {
 
   @Test
   void testEnableCatalogCommand() {
-    CatalogEnable mockEnable = mock(CatalogEnable.class);
+    ManageCatalog mockEnable = mock(ManageCatalog.class);
     
when(mockCommandLine.hasOption(GravitinoOptions.METALAKE)).thenReturn(true);
     
when(mockCommandLine.getOptionValue(GravitinoOptions.METALAKE)).thenReturn("metalake_demo");
     when(mockCommandLine.hasOption(GravitinoOptions.NAME)).thenReturn(true);
@@ -432,8 +430,7 @@ class TestCatalogCommands {
                 mockCommandLine, mockOptions, CommandEntities.CATALOG, 
CommandActions.UPDATE));
     doReturn(mockEnable)
         .when(commandLine)
-        .newCatalogEnable(
-            any(CommandContext.class), eq("metalake_demo"), eq("catalog"), 
anyBoolean());
+        .newManageCatalog(any(CommandContext.class), eq("metalake_demo"), 
eq("catalog"));
     doReturn(mockEnable).when(mockEnable).validate();
     commandLine.handleCommandLine();
     verify(mockEnable).handle();
@@ -441,7 +438,7 @@ class TestCatalogCommands {
 
   @Test
   void testEnableCatalogCommandWithRecursive() {
-    CatalogEnable mockEnable = mock(CatalogEnable.class);
+    ManageCatalog mockEnable = mock(ManageCatalog.class);
     
when(mockCommandLine.hasOption(GravitinoOptions.METALAKE)).thenReturn(true);
     
when(mockCommandLine.getOptionValue(GravitinoOptions.METALAKE)).thenReturn("metalake_demo");
     when(mockCommandLine.hasOption(GravitinoOptions.NAME)).thenReturn(true);
@@ -455,8 +452,7 @@ class TestCatalogCommands {
                 mockCommandLine, mockOptions, CommandEntities.CATALOG, 
CommandActions.UPDATE));
     doReturn(mockEnable)
         .when(commandLine)
-        .newCatalogEnable(
-            any(CommandContext.class), eq("metalake_demo"), eq("catalog"), 
anyBoolean());
+        .newManageCatalog(any(CommandContext.class), eq("metalake_demo"), 
eq("catalog"));
     doReturn(mockEnable).when(mockEnable).validate();
     commandLine.handleCommandLine();
     verify(mockEnable).handle();
@@ -464,7 +460,7 @@ class TestCatalogCommands {
 
   @Test
   void testDisableCatalogCommand() {
-    CatalogDisable mockDisable = mock(CatalogDisable.class);
+    ManageCatalog mockDisable = mock(ManageCatalog.class);
     
when(mockCommandLine.hasOption(GravitinoOptions.METALAKE)).thenReturn(true);
     
when(mockCommandLine.getOptionValue(GravitinoOptions.METALAKE)).thenReturn("metalake_demo");
     when(mockCommandLine.hasOption(GravitinoOptions.NAME)).thenReturn(true);
@@ -477,7 +473,7 @@ class TestCatalogCommands {
                 mockCommandLine, mockOptions, CommandEntities.CATALOG, 
CommandActions.UPDATE));
     doReturn(mockDisable)
         .when(commandLine)
-        .newCatalogDisable(any(CommandContext.class), eq("metalake_demo"), 
eq("catalog"));
+        .newManageCatalog(any(CommandContext.class), eq("metalake_demo"), 
eq("catalog"));
     doReturn(mockDisable).when(mockDisable).validate();
     commandLine.handleCommandLine();
     verify(mockDisable).handle();
@@ -500,11 +496,7 @@ class TestCatalogCommands {
                 mockCommandLine, mockOptions, CommandEntities.CATALOG, 
CommandActions.UPDATE));
 
     assertThrows(RuntimeException.class, commandLine::handleCommandLine);
-    verify(commandLine, never())
-        .newCatalogEnable(
-            any(CommandContext.class), eq("metalake_demo"), eq("catalog"), 
anyBoolean());
-    verify(commandLine, never())
-        .newCatalogDisable(any(CommandContext.class), eq("metalake_demo"), 
eq("catalog"));
-    
assertTrue(errContent.toString().contains(ErrorMessages.INVALID_ENABLE_DISABLE));
+    String errorOutput = new String(errContent.toByteArray(), 
StandardCharsets.UTF_8).trim();
+    Assertions.assertEquals(ErrorMessages.INVALID_ENABLE_DISABLE, errorOutput);
   }
 }
diff --git 
a/clients/cli/src/test/java/org/apache/gravitino/cli/TestMetalakeCommands.java 
b/clients/cli/src/test/java/org/apache/gravitino/cli/TestMetalakeCommands.java
index e01b652c64..4707d24387 100644
--- 
a/clients/cli/src/test/java/org/apache/gravitino/cli/TestMetalakeCommands.java
+++ 
b/clients/cli/src/test/java/org/apache/gravitino/cli/TestMetalakeCommands.java
@@ -21,13 +21,11 @@ package org.apache.gravitino.cli;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.assertTrue;
 import static org.mockito.Mockito.any;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.eq;
 import static org.mockito.Mockito.isNull;
 import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
@@ -41,16 +39,15 @@ import org.apache.gravitino.cli.commands.CreateMetalake;
 import org.apache.gravitino.cli.commands.DeleteMetalake;
 import org.apache.gravitino.cli.commands.ListMetalakeProperties;
 import org.apache.gravitino.cli.commands.ListMetalakes;
+import org.apache.gravitino.cli.commands.ManageMetalake;
 import org.apache.gravitino.cli.commands.MetalakeAudit;
 import org.apache.gravitino.cli.commands.MetalakeDetails;
-import org.apache.gravitino.cli.commands.MetalakeDisable;
-import org.apache.gravitino.cli.commands.MetalakeEnable;
 import org.apache.gravitino.cli.commands.RemoveMetalakeProperty;
 import org.apache.gravitino.cli.commands.SetMetalakeProperty;
 import org.apache.gravitino.cli.commands.UpdateMetalakeComment;
 import org.apache.gravitino.cli.commands.UpdateMetalakeName;
-import org.junit.Assert;
 import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
@@ -374,7 +371,7 @@ class TestMetalakeCommands {
 
   @Test
   void testEnableMetalakeCommand() {
-    MetalakeEnable mockEnable = mock(MetalakeEnable.class);
+    ManageMetalake mockEnable = mock(ManageMetalake.class);
     
when(mockCommandLine.hasOption(GravitinoOptions.METALAKE)).thenReturn(true);
     
when(mockCommandLine.getOptionValue(GravitinoOptions.METALAKE)).thenReturn("metalake_demo");
     when(mockCommandLine.hasOption(GravitinoOptions.ENABLE)).thenReturn(true);
@@ -384,7 +381,7 @@ class TestMetalakeCommands {
                 mockCommandLine, mockOptions, CommandEntities.METALAKE, 
CommandActions.UPDATE));
     doReturn(mockEnable)
         .when(commandLine)
-        .newMetalakeEnable(any(CommandContext.class), eq("metalake_demo"), 
eq(false));
+        .newManageMetalake(any(CommandContext.class), eq("metalake_demo"));
     doReturn(mockEnable).when(mockEnable).validate();
     commandLine.handleCommandLine();
     verify(mockEnable).handle();
@@ -392,7 +389,7 @@ class TestMetalakeCommands {
 
   @Test
   void testEnableMetalakeCommandWithRecursive() {
-    MetalakeEnable mockEnable = mock(MetalakeEnable.class);
+    ManageMetalake mockEnable = mock(ManageMetalake.class);
     
when(mockCommandLine.hasOption(GravitinoOptions.METALAKE)).thenReturn(true);
     
when(mockCommandLine.getOptionValue(GravitinoOptions.METALAKE)).thenReturn("metalake_demo");
     when(mockCommandLine.hasOption(GravitinoOptions.ALL)).thenReturn(true);
@@ -403,7 +400,7 @@ class TestMetalakeCommands {
                 mockCommandLine, mockOptions, CommandEntities.METALAKE, 
CommandActions.UPDATE));
     doReturn(mockEnable)
         .when(commandLine)
-        .newMetalakeEnable(any(CommandContext.class), eq("metalake_demo"), 
eq(true));
+        .newManageMetalake(any(CommandContext.class), eq("metalake_demo"));
     doReturn(mockEnable).when(mockEnable).validate();
     commandLine.handleCommandLine();
     verify(mockEnable).handle();
@@ -411,7 +408,7 @@ class TestMetalakeCommands {
 
   @Test
   void testDisableMetalakeCommand() {
-    MetalakeDisable mockDisable = mock(MetalakeDisable.class);
+    ManageMetalake mockDisable = mock(ManageMetalake.class);
     
when(mockCommandLine.hasOption(GravitinoOptions.METALAKE)).thenReturn(true);
     
when(mockCommandLine.getOptionValue(GravitinoOptions.METALAKE)).thenReturn("metalake_demo");
     when(mockCommandLine.hasOption(GravitinoOptions.DISABLE)).thenReturn(true);
@@ -422,7 +419,7 @@ class TestMetalakeCommands {
                 mockCommandLine, mockOptions, CommandEntities.METALAKE, 
CommandActions.UPDATE));
     doReturn(mockDisable)
         .when(commandLine)
-        .newMetalakeDisable(any(CommandContext.class), eq("metalake_demo"));
+        .newManageMetalake(any(CommandContext.class), eq("metalake_demo"));
     doReturn(mockDisable).when(mockDisable).validate();
     commandLine.handleCommandLine();
     verify(mockDisable).handle();
@@ -442,11 +439,8 @@ class TestMetalakeCommands {
             new GravitinoCommandLine(
                 mockCommandLine, mockOptions, CommandEntities.METALAKE, 
CommandActions.UPDATE));
 
-    Assert.assertThrows(RuntimeException.class, 
commandLine::handleCommandLine);
-    verify(commandLine, never())
-        .newMetalakeEnable(any(CommandContext.class), eq("metalake_demo"), 
eq(false));
-    verify(commandLine, never())
-        .newMetalakeEnable(any(CommandContext.class), eq("metalake_demo"), 
eq(false));
-    
assertTrue(errContent.toString().contains(ErrorMessages.INVALID_ENABLE_DISABLE));
+    Assertions.assertThrows(RuntimeException.class, 
commandLine::handleCommandLine);
+    String errorOutput = new String(errContent.toByteArray(), 
StandardCharsets.UTF_8).trim();
+    Assertions.assertEquals(ErrorMessages.INVALID_ENABLE_DISABLE, errorOutput);
   }
 }

Reply via email to