This is an automated email from the ASF dual-hosted git repository.
jshao 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 531c0b5488 [MINOR] improvement(api): Add test cases for XXXChange
(#9488)
531c0b5488 is described below
commit 531c0b5488f9d8bb294cde3358c92b9016b190b4
Author: Lord of Abyss <[email protected]>
AuthorDate: Thu Dec 18 09:46:09 2025 +0800
[MINOR] improvement(api): Add test cases for XXXChange (#9488)
### What changes were proposed in this pull request?
Add test cases for XXXChange
### Why are the changes needed?
Fix: MINOR
### Does this PR introduce _any_ user-facing change?
no
### How was this patch tested?
local test
---
.../gravitino/authorization/TestRoleChange.java | 130 ++++++++++++++++++++
.../apache/gravitino/file/TestFilesetChange.java | 132 +++++++++++++++++++++
.../gravitino/messaging/TestTopicChange.java | 106 +++++++++++++++++
.../apache/gravitino/policy/TestPolicyChange.java | 119 +++++++++++++++++++
.../org/apache/gravitino/tag/TestTagChange.java | 127 ++++++++++++++++++++
5 files changed, 614 insertions(+)
diff --git
a/api/src/test/java/org/apache/gravitino/authorization/TestRoleChange.java
b/api/src/test/java/org/apache/gravitino/authorization/TestRoleChange.java
new file mode 100644
index 0000000000..43e8a6f3fd
--- /dev/null
+++ b/api/src/test/java/org/apache/gravitino/authorization/TestRoleChange.java
@@ -0,0 +1,130 @@
+/*
+ * 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.authorization;
+
+import com.google.common.collect.Lists;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class TestRoleChange {
+
+ @Test
+ void testAddSecurableObject() {
+ SecurableObject securableObject =
+ SecurableObjects.ofCatalog("catalog",
Lists.newArrayList(Privileges.UseCatalog.allow()));
+ RoleChange.AddSecurableObject change =
+ (RoleChange.AddSecurableObject) RoleChange.addSecurableObject("role1",
securableObject);
+
+ Assertions.assertEquals(securableObject, change.getSecurableObject());
+ Assertions.assertEquals("role1", change.getRoleName());
+ }
+
+ @Test
+ void testRemoveSecurableObject() {
+ SecurableObject securableObject =
+ SecurableObjects.ofCatalog("catalog",
Lists.newArrayList(Privileges.UseCatalog.allow()));
+ RoleChange.RemoveSecurableObject change =
+ (RoleChange.RemoveSecurableObject)
+ RoleChange.removeSecurableObject("role1", securableObject);
+
+ Assertions.assertEquals("role1", change.getRoleName());
+ Assertions.assertEquals(securableObject, change.getSecurableObject());
+ }
+
+ @Test
+ void testUpdateSecurableObject() {
+ SecurableObject oldSecurableObject =
+ SecurableObjects.ofCatalog("catalog",
Lists.newArrayList(Privileges.UseCatalog.allow()));
+ SecurableObject newSecurableObject =
+ SecurableObjects.ofCatalog("catalog",
Lists.newArrayList(Privileges.UseCatalog.deny()));
+ SecurableObject diffMetadataSecurableObject =
+ SecurableObjects.ofCatalog("other",
Lists.newArrayList(Privileges.UseCatalog.deny()));
+ SecurableObject samePrivilegeSecurableObject =
+ SecurableObjects.ofCatalog("catalog",
Lists.newArrayList(Privileges.UseCatalog.allow()));
+
+ RoleChange.UpdateSecurableObject change =
+ (RoleChange.UpdateSecurableObject)
+ RoleChange.updateSecurableObject("role1", oldSecurableObject,
newSecurableObject);
+
+ Assertions.assertEquals("role1", change.getRoleName());
+ Assertions.assertEquals(oldSecurableObject, change.getSecurableObject());
+ Assertions.assertEquals(newSecurableObject,
change.getNewSecurableObject());
+
+ Assertions.assertThrowsExactly(
+ IllegalArgumentException.class,
+ () ->
+ RoleChange.updateSecurableObject(
+ "role", oldSecurableObject, diffMetadataSecurableObject));
+
+ Assertions.assertThrowsExactly(
+ IllegalArgumentException.class,
+ () ->
+ RoleChange.updateSecurableObject(
+ "role", oldSecurableObject, samePrivilegeSecurableObject));
+ }
+
+ @Test
+ void testEqualsAndHashCode() {
+ SecurableObject securableObject =
+ SecurableObjects.ofCatalog("catalog",
Lists.newArrayList(Privileges.UseCatalog.allow()));
+ // AddSecurableObject
+ RoleChange change1 = RoleChange.addSecurableObject("role1",
securableObject);
+ RoleChange change2 = RoleChange.addSecurableObject("role1",
securableObject);
+ RoleChange change3 = RoleChange.addSecurableObject("role2",
securableObject);
+
+ Assertions.assertEquals(change1, change2);
+ Assertions.assertEquals(change1.hashCode(), change2.hashCode());
+ Assertions.assertNotEquals(change1, change3);
+ Assertions.assertNotEquals(change1.hashCode(), change3.hashCode());
+ Assertions.assertNotEquals(change2, change3);
+ Assertions.assertNotEquals(change2.hashCode(), change3.hashCode());
+
+ // RemoveSecurableObject
+ RoleChange change4 = RoleChange.removeSecurableObject("role1",
securableObject);
+ RoleChange change5 = RoleChange.removeSecurableObject("role1",
securableObject);
+ RoleChange change6 = RoleChange.removeSecurableObject("role2",
securableObject);
+
+ Assertions.assertEquals(change4, change5);
+ Assertions.assertEquals(change4.hashCode(), change5.hashCode());
+ Assertions.assertNotEquals(change4, change6);
+ Assertions.assertNotEquals(change4.hashCode(), change6.hashCode());
+ Assertions.assertNotEquals(change5, change6);
+ Assertions.assertNotEquals(change5.hashCode(), change6.hashCode());
+
+ // UpdateSecurableObject
+ SecurableObject updatedSecurableObject1 =
+ SecurableObjects.ofCatalog("catalog",
Lists.newArrayList(Privileges.UseCatalog.deny()));
+ SecurableObject updatedSecurableObject2 =
+ SecurableObjects.ofCatalog("catalog",
Lists.newArrayList(Privileges.CreateSchema.deny()));
+ RoleChange change7 =
+ RoleChange.updateSecurableObject("role1", securableObject,
updatedSecurableObject1);
+ RoleChange change8 =
+ RoleChange.updateSecurableObject("role1", securableObject,
updatedSecurableObject1);
+ RoleChange change9 =
+ RoleChange.updateSecurableObject("role1", securableObject,
updatedSecurableObject2);
+
+ Assertions.assertEquals(change7, change8);
+ Assertions.assertEquals(change7.hashCode(), change8.hashCode());
+ Assertions.assertNotEquals(change7, change9);
+ Assertions.assertNotEquals(change7.hashCode(), change9.hashCode());
+ Assertions.assertNotEquals(change8, change9);
+ Assertions.assertNotEquals(change8.hashCode(), change9.hashCode());
+ }
+}
diff --git a/api/src/test/java/org/apache/gravitino/file/TestFilesetChange.java
b/api/src/test/java/org/apache/gravitino/file/TestFilesetChange.java
new file mode 100644
index 0000000000..fd8a96ffe1
--- /dev/null
+++ b/api/src/test/java/org/apache/gravitino/file/TestFilesetChange.java
@@ -0,0 +1,132 @@
+/*
+ * 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.file;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class TestFilesetChange {
+ @Test
+ void testRemovePropertyChange() {
+ String property = "property1";
+ FilesetChange change = FilesetChange.removeProperty(property);
+
+ Assertions.assertInstanceOf(FilesetChange.RemoveProperty.class, change);
+ FilesetChange.RemoveProperty removePropertyChange =
(FilesetChange.RemoveProperty) change;
+ Assertions.assertEquals(property, removePropertyChange.getProperty());
+ }
+
+ @Test
+ void testSetPropertyChange() {
+ String property = "property1";
+ String value = "value1";
+ FilesetChange filesetChange = FilesetChange.setProperty(property, value);
+
+ Assertions.assertInstanceOf(FilesetChange.SetProperty.class,
filesetChange);
+ FilesetChange.SetProperty setPropertyChange = (FilesetChange.SetProperty)
filesetChange;
+ Assertions.assertEquals(property, setPropertyChange.getProperty());
+ Assertions.assertEquals(value, setPropertyChange.getValue());
+ }
+
+ @Test
+ void testUpdateCommentChange() {
+ String comment = "comment1";
+ FilesetChange filesetChange = FilesetChange.updateComment(comment);
+
+ Assertions.assertInstanceOf(FilesetChange.UpdateFilesetComment.class,
filesetChange);
+ FilesetChange.UpdateFilesetComment updateCommentChange =
+ (FilesetChange.UpdateFilesetComment) filesetChange;
+ Assertions.assertEquals(comment, updateCommentChange.getNewComment());
+ }
+
+ @Test
+ void testRenameFilesetChange() {
+ String name = "name1";
+ FilesetChange rename = FilesetChange.rename(name);
+
+ Assertions.assertInstanceOf(FilesetChange.RenameFileset.class, rename);
+ FilesetChange.RenameFileset renameChange = (FilesetChange.RenameFileset)
rename;
+ Assertions.assertEquals(name, renameChange.getNewName());
+ }
+
+ @Test
+ void testEqualsAndHashCode() {
+ // Remove property
+ String property = "property1";
+ FilesetChange removePropertyChange1 =
FilesetChange.removeProperty(property);
+ FilesetChange removePropertyChange2 =
FilesetChange.removeProperty(property);
+ FilesetChange removePropertyChange3 =
FilesetChange.removeProperty("property2");
+
+ Assertions.assertEquals(removePropertyChange1, removePropertyChange2);
+ Assertions.assertEquals(removePropertyChange1.hashCode(),
removePropertyChange2.hashCode());
+
+ Assertions.assertNotEquals(removePropertyChange1, removePropertyChange3);
+ Assertions.assertNotEquals(removePropertyChange1.hashCode(),
removePropertyChange3.hashCode());
+
+ Assertions.assertNotEquals(removePropertyChange2, removePropertyChange3);
+ Assertions.assertNotEquals(removePropertyChange2.hashCode(),
removePropertyChange3.hashCode());
+
+ // Rename fileset
+ String name = "name1";
+ FilesetChange renameChange1 = FilesetChange.rename(name);
+ FilesetChange renameChange2 = FilesetChange.rename(name);
+ FilesetChange renameChange3 = FilesetChange.rename("name2");
+
+ Assertions.assertEquals(renameChange1, renameChange2);
+ Assertions.assertEquals(renameChange1.hashCode(),
renameChange2.hashCode());
+
+ Assertions.assertNotEquals(renameChange1, renameChange3);
+ Assertions.assertNotEquals(renameChange1.hashCode(),
renameChange3.hashCode());
+
+ Assertions.assertNotEquals(renameChange2, renameChange3);
+ Assertions.assertNotEquals(renameChange2.hashCode(),
renameChange3.hashCode());
+
+ // Update comment
+ String comment = "comment1";
+ FilesetChange updateCommentChange1 = FilesetChange.updateComment(comment);
+ FilesetChange updateCommentChange2 = FilesetChange.updateComment(comment);
+ FilesetChange updateCommentChange3 =
FilesetChange.updateComment("comment2");
+
+ Assertions.assertEquals(updateCommentChange1, updateCommentChange2);
+ Assertions.assertEquals(updateCommentChange1.hashCode(),
updateCommentChange2.hashCode());
+
+ Assertions.assertNotEquals(updateCommentChange1, updateCommentChange3);
+ Assertions.assertNotEquals(updateCommentChange1.hashCode(),
updateCommentChange3.hashCode());
+
+ Assertions.assertNotEquals(updateCommentChange2, updateCommentChange3);
+ Assertions.assertNotEquals(updateCommentChange2.hashCode(),
updateCommentChange3.hashCode());
+
+ // Set property
+ String property2 = "property2";
+ String value = "value1";
+ FilesetChange setPropertyChange1 = FilesetChange.setProperty(property2,
value);
+ FilesetChange setPropertyChange2 = FilesetChange.setProperty(property2,
value);
+ FilesetChange setPropertyChange3 = FilesetChange.setProperty("property3",
"value2");
+
+ Assertions.assertEquals(setPropertyChange1, setPropertyChange2);
+ Assertions.assertEquals(setPropertyChange1.hashCode(),
setPropertyChange2.hashCode());
+
+ Assertions.assertNotEquals(setPropertyChange1, setPropertyChange3);
+ Assertions.assertNotEquals(setPropertyChange1.hashCode(),
setPropertyChange3.hashCode());
+
+ Assertions.assertNotEquals(setPropertyChange2, setPropertyChange3);
+ Assertions.assertNotEquals(setPropertyChange2.hashCode(),
setPropertyChange3.hashCode());
+ }
+}
diff --git
a/api/src/test/java/org/apache/gravitino/messaging/TestTopicChange.java
b/api/src/test/java/org/apache/gravitino/messaging/TestTopicChange.java
new file mode 100644
index 0000000000..142543471e
--- /dev/null
+++ b/api/src/test/java/org/apache/gravitino/messaging/TestTopicChange.java
@@ -0,0 +1,106 @@
+/*
+ * 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.messaging;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class TestTopicChange {
+
+ @Test
+ void testRemovePropertyChange() {
+ String property = "property1";
+ TopicChange topicChange = TopicChange.removeProperty(property);
+
+ Assertions.assertInstanceOf(TopicChange.RemoveProperty.class, topicChange);
+ TopicChange.RemoveProperty removeProperty = (TopicChange.RemoveProperty)
topicChange;
+ Assertions.assertEquals(property, removeProperty.getProperty());
+ }
+
+ @Test
+ void testUpdateCommentChange() {
+ String comment = "comment1";
+ TopicChange topicChange = TopicChange.updateComment(comment);
+
+ Assertions.assertInstanceOf(TopicChange.UpdateTopicComment.class,
topicChange);
+ TopicChange.UpdateTopicComment updateComment =
(TopicChange.UpdateTopicComment) topicChange;
+ Assertions.assertEquals(comment, updateComment.getNewComment());
+ }
+
+ @Test
+ void testSetPropertyChange() {
+ String property = "property1";
+ String value = "value1";
+ TopicChange topicChange = TopicChange.setProperty(property, value);
+
+ Assertions.assertInstanceOf(TopicChange.SetProperty.class, topicChange);
+ TopicChange.SetProperty setProperty = (TopicChange.SetProperty)
topicChange;
+ Assertions.assertEquals(property, setProperty.getProperty());
+ Assertions.assertEquals(value, setProperty.getValue());
+ }
+
+ @Test
+ void testEqualsAndHashCode() {
+ // remove property
+ String property = "property1";
+ TopicChange removeProperty1 = TopicChange.removeProperty(property);
+ TopicChange removeProperty2 = TopicChange.removeProperty(property);
+ TopicChange removeProperty3 = TopicChange.removeProperty("property2");
+
+ Assertions.assertEquals(removeProperty1, removeProperty2);
+ Assertions.assertEquals(removeProperty1.hashCode(),
removeProperty2.hashCode());
+
+ Assertions.assertNotEquals(removeProperty1, removeProperty3);
+ Assertions.assertNotEquals(removeProperty1.hashCode(),
removeProperty3.hashCode());
+
+ Assertions.assertNotEquals(removeProperty2, removeProperty3);
+ Assertions.assertNotEquals(removeProperty2.hashCode(),
removeProperty3.hashCode());
+
+ // update comment
+ String comment = "comment1";
+ TopicChange updateComment1 = TopicChange.updateComment(comment);
+ TopicChange updateComment2 = TopicChange.updateComment(comment);
+ TopicChange updateComment3 = TopicChange.updateComment("comment2");
+
+ Assertions.assertEquals(updateComment1, updateComment2);
+ Assertions.assertEquals(updateComment1.hashCode(),
updateComment2.hashCode());
+
+ Assertions.assertNotEquals(updateComment1, updateComment3);
+ Assertions.assertNotEquals(updateComment1.hashCode(),
updateComment3.hashCode());
+
+ Assertions.assertNotEquals(updateComment2, updateComment3);
+ Assertions.assertNotEquals(updateComment2.hashCode(),
updateComment3.hashCode());
+
+ // set property
+ String value = "value1";
+ TopicChange setProperty1 = TopicChange.setProperty(property, value);
+ TopicChange setProperty2 = TopicChange.setProperty(property, value);
+ TopicChange setProperty3 = TopicChange.setProperty("property2", "value2");
+
+ Assertions.assertEquals(setProperty1, setProperty2);
+ Assertions.assertEquals(setProperty1.hashCode(), setProperty2.hashCode());
+
+ Assertions.assertNotEquals(setProperty1, setProperty3);
+ Assertions.assertNotEquals(setProperty1.hashCode(),
setProperty3.hashCode());
+
+ Assertions.assertNotEquals(setProperty2, setProperty3);
+ Assertions.assertNotEquals(setProperty2.hashCode(),
setProperty3.hashCode());
+ }
+}
diff --git
a/api/src/test/java/org/apache/gravitino/policy/TestPolicyChange.java
b/api/src/test/java/org/apache/gravitino/policy/TestPolicyChange.java
new file mode 100644
index 0000000000..3db585de7f
--- /dev/null
+++ b/api/src/test/java/org/apache/gravitino/policy/TestPolicyChange.java
@@ -0,0 +1,119 @@
+/*
+ * 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.policy;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+import org.apache.gravitino.MetadataObject;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class TestPolicyChange {
+
+ @Test
+ void testRenamePolicyChange() {
+ String name = "name1";
+ PolicyChange policyChange = PolicyChange.rename(name);
+
+ Assertions.assertInstanceOf(PolicyChange.RenamePolicy.class, policyChange);
+ PolicyChange.RenamePolicy renamePolicy = (PolicyChange.RenamePolicy)
policyChange;
+ Assertions.assertEquals(name, renamePolicy.getNewName());
+ }
+
+ @Test
+ void testUpdateCommentChange() {
+ String comment = "comment1";
+ PolicyChange policyChange = PolicyChange.updateComment(comment);
+
+ Assertions.assertInstanceOf(PolicyChange.UpdatePolicyComment.class,
policyChange);
+ PolicyChange.UpdatePolicyComment updateComment =
+ (PolicyChange.UpdatePolicyComment) policyChange;
+ Assertions.assertEquals(comment, updateComment.getNewComment());
+ }
+
+ @Test
+ void testUpdateContentChange() {
+ PolicyContent newContent =
+ PolicyContents.custom(
+ ImmutableMap.of("rule2", "value2"),
+ ImmutableSet.of(MetadataObject.Type.TABLE),
+ ImmutableMap.of("key1", "value1"));
+ PolicyChange policyChange = PolicyChange.updateContent("custom",
newContent);
+
+ Assertions.assertInstanceOf(PolicyChange.UpdateContent.class,
policyChange);
+ PolicyChange.UpdateContent updateContent = (PolicyChange.UpdateContent)
policyChange;
+ Assertions.assertEquals("custom", updateContent.getPolicyType());
+ Assertions.assertEquals(newContent, updateContent.getContent());
+ }
+
+ @Test
+ void testEqualsAndHashCode() {
+ // RenamePolicy
+ PolicyChange rename1 = PolicyChange.rename("name1");
+ PolicyChange rename2 = PolicyChange.rename("name1");
+ PolicyChange rename3 = PolicyChange.rename("name2");
+
+ Assertions.assertEquals(rename1, rename2);
+ Assertions.assertEquals(rename1.hashCode(), rename2.hashCode());
+
+ Assertions.assertNotEquals(rename1, rename3);
+ Assertions.assertNotEquals(rename1.hashCode(), rename3.hashCode());
+
+ Assertions.assertNotEquals(rename2, rename3);
+ Assertions.assertNotEquals(rename2.hashCode(), rename3.hashCode());
+
+ // UpdateCommentPolicy
+ PolicyChange updateComment1 = PolicyChange.updateComment("comment1");
+ PolicyChange updateComment2 = PolicyChange.updateComment("comment1");
+ PolicyChange updateComment3 = PolicyChange.updateComment("comment2");
+
+ Assertions.assertEquals(updateComment1, updateComment2);
+ Assertions.assertEquals(updateComment1.hashCode(),
updateComment2.hashCode());
+
+ Assertions.assertNotEquals(updateComment1, updateComment3);
+ Assertions.assertNotEquals(updateComment1.hashCode(),
updateComment3.hashCode());
+
+ Assertions.assertNotEquals(updateComment2, updateComment3);
+ Assertions.assertNotEquals(updateComment2.hashCode(),
updateComment3.hashCode());
+
+ // UpdateContentPolicy
+ PolicyContent content =
+ PolicyContents.custom(
+ ImmutableMap.of("rule2", "value2"),
+ ImmutableSet.of(MetadataObject.Type.TABLE),
+ ImmutableMap.of("key1", "value1"));
+ PolicyContent diffContent =
+ PolicyContents.custom(
+ ImmutableMap.of("rule2", "value2"),
+ ImmutableSet.of(MetadataObject.Type.TABLE),
+ ImmutableMap.of("key2", "value2"));
+
+ PolicyChange updateContent1 = PolicyChange.updateContent("custom",
content);
+ PolicyChange updateContent2 = PolicyChange.updateContent("custom",
content);
+ PolicyChange updateContent3 = PolicyChange.updateContent("custom",
diffContent);
+
+ Assertions.assertEquals(updateContent1, updateContent2);
+ Assertions.assertEquals(updateContent1.hashCode(),
updateContent2.hashCode());
+
+ Assertions.assertNotEquals(updateContent1, updateContent3);
+
+ Assertions.assertNotEquals(updateContent2, updateContent3);
+ }
+}
diff --git a/api/src/test/java/org/apache/gravitino/tag/TestTagChange.java
b/api/src/test/java/org/apache/gravitino/tag/TestTagChange.java
new file mode 100644
index 0000000000..cd77cae48f
--- /dev/null
+++ b/api/src/test/java/org/apache/gravitino/tag/TestTagChange.java
@@ -0,0 +1,127 @@
+/*
+ * 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.tag;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class TestTagChange {
+
+ @Test
+ void testUpdateCommentChange() {
+ String comment = "comment1";
+ TagChange tagChange = TagChange.updateComment(comment);
+
+ Assertions.assertInstanceOf(TagChange.UpdateTagComment.class, tagChange);
+ TagChange.UpdateTagComment updateTagComment = (TagChange.UpdateTagComment)
tagChange;
+ Assertions.assertEquals(comment, updateTagComment.getNewComment());
+ }
+
+ @Test
+ void testRemovePropertyChange() {
+ String property = "property1";
+ TagChange tagChange = TagChange.removeProperty(property);
+
+ Assertions.assertInstanceOf(TagChange.RemoveProperty.class, tagChange);
+ TagChange.RemoveProperty removeTagProperty = (TagChange.RemoveProperty)
tagChange;
+ Assertions.assertEquals(property, removeTagProperty.getProperty());
+ }
+
+ @Test
+ void testRenameChange() {
+ String name = "name1";
+ TagChange tagChange = TagChange.rename(name);
+
+ Assertions.assertInstanceOf(TagChange.RenameTag.class, tagChange);
+ TagChange.RenameTag renameTag = (TagChange.RenameTag) tagChange;
+ Assertions.assertEquals(name, renameTag.getNewName());
+ }
+
+ @Test
+ void testSetPropertyChange() {
+ String property = "property1";
+ String value = "value1";
+ TagChange tagChange = TagChange.setProperty(property, value);
+
+ Assertions.assertInstanceOf(TagChange.SetProperty.class, tagChange);
+ TagChange.SetProperty setTagProperty = (TagChange.SetProperty) tagChange;
+ Assertions.assertEquals(property, setTagProperty.getProperty());
+ Assertions.assertEquals(value, setTagProperty.getValue());
+ }
+
+ @Test
+ void testEqualsAndHashCode() {
+ // Update comment
+ TagChange updateComment1 = TagChange.updateComment("comment1");
+ TagChange updateComment2 = TagChange.updateComment("comment1");
+ TagChange updateComment3 = TagChange.updateComment("comment2");
+
+ Assertions.assertEquals(updateComment1, updateComment2);
+ Assertions.assertEquals(updateComment1.hashCode(),
updateComment2.hashCode());
+
+ Assertions.assertNotEquals(updateComment1, updateComment3);
+ Assertions.assertNotEquals(updateComment1.hashCode(),
updateComment3.hashCode());
+
+ Assertions.assertNotEquals(updateComment2, updateComment3);
+ Assertions.assertNotEquals(updateComment2.hashCode(),
updateComment3.hashCode());
+
+ // Remove property
+ TagChange removeProperty1 = TagChange.removeProperty("property1");
+ TagChange removeProperty2 = TagChange.removeProperty("property1");
+ TagChange removeProperty3 = TagChange.removeProperty("property2");
+
+ Assertions.assertEquals(removeProperty1, removeProperty2);
+ Assertions.assertEquals(removeProperty1.hashCode(),
removeProperty2.hashCode());
+
+ Assertions.assertNotEquals(removeProperty1, removeProperty3);
+ Assertions.assertNotEquals(removeProperty1.hashCode(),
removeProperty3.hashCode());
+
+ Assertions.assertNotEquals(removeProperty2, removeProperty3);
+ Assertions.assertNotEquals(removeProperty2.hashCode(),
removeProperty3.hashCode());
+
+ // Rename
+ TagChange rename1 = TagChange.rename("name1");
+ TagChange rename2 = TagChange.rename("name1");
+ TagChange rename3 = TagChange.rename("name2");
+
+ Assertions.assertEquals(rename1, rename2);
+ Assertions.assertEquals(rename1.hashCode(), rename2.hashCode());
+
+ Assertions.assertNotEquals(rename1, rename3);
+ Assertions.assertNotEquals(rename1.hashCode(), rename3.hashCode());
+
+ Assertions.assertNotEquals(rename2, rename3);
+ Assertions.assertNotEquals(rename2.hashCode(), rename3.hashCode());
+
+ // Set property
+ TagChange setProperty1 = TagChange.setProperty("property1", "value1");
+ TagChange setProperty2 = TagChange.setProperty("property1", "value1");
+ TagChange setProperty3 = TagChange.setProperty("property2", "value2");
+
+ Assertions.assertEquals(setProperty1, setProperty2);
+ Assertions.assertEquals(setProperty1.hashCode(), setProperty2.hashCode());
+
+ Assertions.assertNotEquals(setProperty1, setProperty3);
+ Assertions.assertNotEquals(setProperty1.hashCode(),
setProperty3.hashCode());
+
+ Assertions.assertNotEquals(setProperty2, setProperty3);
+ Assertions.assertNotEquals(setProperty2.hashCode(),
setProperty3.hashCode());
+ }
+}