haizhou-zhao commented on code in PR #6045:
URL: https://github.com/apache/iceberg/pull/6045#discussion_r1021914426


##########
hive-metastore/src/test/java/org/apache/iceberg/hive/TestHiveCatalog.java:
##########
@@ -426,6 +510,194 @@ public void testSetNamespaceProperties() throws 
TException {
         });
   }
 
+  @Test
+  public void testSetNamespaceOwnership() throws TException {
+    setNamespaceOwnershipAndVerify(
+        "set_individual_ownership_on_default_owner",
+        ImmutableMap.of(),
+        ImmutableMap.of(
+            HiveCatalog.HMS_DB_OWNER,
+            "some_individual_owner",
+            HiveCatalog.HMS_DB_OWNER_TYPE,
+            PrincipalType.USER.name()),
+        System.getProperty("user.name"),
+        PrincipalType.USER,
+        "some_individual_owner",
+        PrincipalType.USER);
+
+    setNamespaceOwnershipAndVerify(
+        "set_group_ownership_on_default_owner",
+        ImmutableMap.of(),
+        ImmutableMap.of(
+            HiveCatalog.HMS_DB_OWNER,
+            "some_group_owner",
+            HiveCatalog.HMS_DB_OWNER_TYPE,
+            PrincipalType.GROUP.name()),
+        System.getProperty("user.name"),
+        PrincipalType.USER,
+        "some_group_owner",
+        PrincipalType.GROUP);
+
+    setNamespaceOwnershipAndVerify(
+        "change_individual_to_group_ownership",
+        ImmutableMap.of(HiveCatalog.HMS_DB_OWNER, "some_owner"),
+        ImmutableMap.of(
+            HiveCatalog.HMS_DB_OWNER,
+            "some_group_owner",
+            HiveCatalog.HMS_DB_OWNER_TYPE,
+            PrincipalType.GROUP.name()),
+        "some_owner",
+        PrincipalType.USER,
+        "some_group_owner",
+        PrincipalType.GROUP);
+
+    setNamespaceOwnershipAndVerify(
+        "change_group_to_individual_ownership",
+        ImmutableMap.of(
+            HiveCatalog.HMS_DB_OWNER,
+            "some_group_owner",
+            HiveCatalog.HMS_DB_OWNER_TYPE,
+            PrincipalType.GROUP.name()),
+        ImmutableMap.of(
+            HiveCatalog.HMS_DB_OWNER,
+            "some_individual_owner",
+            HiveCatalog.HMS_DB_OWNER_TYPE,
+            PrincipalType.USER.name()),
+        "some_group_owner",
+        PrincipalType.GROUP,
+        "some_individual_owner",
+        PrincipalType.USER);
+
+    AssertHelpers.assertThrows(
+        "Setting "
+            + HiveCatalog.HMS_DB_OWNER_TYPE
+            + " and "
+            + HiveCatalog.HMS_DB_OWNER
+            + " has to be performed together or not at all",
+        IllegalArgumentException.class,
+        () -> {
+          try {
+            setNamespaceOwnershipAndVerify(
+                "set_owner_without_setting_owner_type",
+                ImmutableMap.of(),
+                ImmutableMap.of(HiveCatalog.HMS_DB_OWNER, 
"some_individual_owner"),
+                System.getProperty("user.name"),
+                PrincipalType.USER,
+                "no_post_setting_expectation_due_to_exception_thrown",
+                null);
+          } catch (TException e) {
+            throw new RuntimeException("Unexpected Exception", e);
+          }
+        });
+
+    AssertHelpers.assertThrows(
+        "Setting "
+            + HiveCatalog.HMS_DB_OWNER_TYPE
+            + " and "
+            + HiveCatalog.HMS_DB_OWNER
+            + " has to be performed together or not at all",
+        IllegalArgumentException.class,
+        () -> {
+          try {
+            setNamespaceOwnershipAndVerify(
+                "set_owner_type_without_setting_owner",
+                ImmutableMap.of(HiveCatalog.HMS_DB_OWNER, "some_owner"),
+                ImmutableMap.of(HiveCatalog.HMS_DB_OWNER_TYPE, 
PrincipalType.GROUP.name()),
+                "some_owner",
+                PrincipalType.USER,
+                "no_post_setting_expectation_due_to_exception_thrown",
+                null);
+          } catch (TException e) {
+            throw new RuntimeException("Unexpected Exception", e);
+          }
+        });
+
+    AssertHelpers.assertThrows(
+        HiveCatalog.HMS_DB_OWNER_TYPE
+            + " has an invalid value of: "
+            + meta.get(HiveCatalog.HMS_DB_OWNER_TYPE)
+            + ". Acceptable values are: "
+            + 
Stream.of(PrincipalType.values()).map(Enum::name).collect(Collectors.joining(", 
")),
+        IllegalArgumentException.class,
+        () -> {
+          try {
+            setNamespaceOwnershipAndVerify(
+                "set_invalid_owner_type",
+                ImmutableMap.of(),
+                ImmutableMap.of(
+                    HiveCatalog.HMS_DB_OWNER, "iceberg",
+                    HiveCatalog.HMS_DB_OWNER_TYPE, "invalidOwnerType"),
+                System.getProperty("user.name"),
+                PrincipalType.USER,
+                "no_post_setting_expectation_due_to_exception_thrown",
+                null);
+          } catch (TException e) {
+            throw new RuntimeException("Unexpected Exception", e);
+          }
+        });
+  }
+
+  @Test
+  public void testSetNamespaceOwnershipNoop() throws TException {

Review Comment:
   see set_ownership_noop_4 at line 682 below



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to