kbendick commented on code in PR #4632:
URL: https://github.com/apache/iceberg/pull/4632#discussion_r859059722


##########
core/src/test/java/org/apache/iceberg/TestMetadataUpdateParser.java:
##########
@@ -60,15 +82,119 @@ public void testUpgradeFormatVersionFromJson() {
         expected, MetadataUpdateParser.toJson(actual));
   }
 
+  @Test
+  public void testAddSchemaFromJson() {
+    String action = "add-schema";
+    Schema schema = ID_DATA_SCHEMA;
+    int lastColumnId = schema.highestFieldId();
+    String json = 
String.format("{\"action\":\"add-schema\",\"schema\":%s,\"last-column-id\":%d}",
+        SchemaParser.toJson(schema), lastColumnId);
+    MetadataUpdate actualUpdate = new MetadataUpdate.AddSchema(schema, 
lastColumnId);
+    assertEquals(action, actualUpdate, MetadataUpdateParser.fromJson(json));
+  }
+
+  @Test
+  public void testAddSchemaToJson() {
+    Schema schema = ID_DATA_SCHEMA;
+    int lastColumnId = schema.highestFieldId();
+    String expected = 
String.format("{\"action\":\"add-schema\",\"schema\":%s,\"last-column-id\":%d}",
+        SchemaParser.toJson(schema), lastColumnId);
+    MetadataUpdate update = new MetadataUpdate.AddSchema(schema, lastColumnId);
+    String actual = MetadataUpdateParser.toJson(update);
+    Assert.assertEquals("Add schema should convert to the correct JSON value", 
expected, actual);
+  }
+
+  @Test
+  public void testSetCurrentSchemaFromJson() {
+    String action = SET_CURRENT_SCHEMA;
+    int schemaId = 6;
+    String json = String.format("{\"action\":\"%s\",\"schema-id\":%d}", 
action, schemaId);
+    MetadataUpdate.SetCurrentSchema expected = new 
MetadataUpdate.SetCurrentSchema(schemaId);
+    assertEquals(action, expected, MetadataUpdateParser.fromJson(json));
+  }
+
+  @Test
+  public void testSetCurrentSchemaToJson() {
+    String action = SET_CURRENT_SCHEMA;
+    int schemaId = 6;
+    String expected = String.format("{\"action\":\"%s\",\"schema-id\":%d}", 
action, schemaId);
+    MetadataUpdate update = new MetadataUpdate.SetCurrentSchema(schemaId);
+    String actual = MetadataUpdateParser.toJson(update);
+    Assert.assertEquals("Set current schema should convert to the correct JSON 
value", expected, actual);
+  }
+
+  @Test
+  public void testSetDefaultPartitionSpecToJson() {
+    String action = SET_DEFAULT_PARTITION_SPEC;
+    int specId = 4;
+    String expected = String.format("{\"action\":\"%s\",\"spec-id\":%d}", 
action, specId);
+    MetadataUpdate update = new MetadataUpdate.SetDefaultPartitionSpec(specId);
+    String actual = MetadataUpdateParser.toJson(update);
+    Assert.assertEquals("Set default partition spec should serialize to the 
correct JSON value", expected, actual);
+  }
+
+  @Test
+  public void testSetDefaultPartitionSpecFromJson() {
+    String action = SET_DEFAULT_PARTITION_SPEC;
+    int specId = 4;
+    String json = String.format("{\"action\":\"%s\",\"spec-id\":%d}", action, 
specId);
+    MetadataUpdate.SetDefaultPartitionSpec expected = new 
MetadataUpdate.SetDefaultPartitionSpec(specId);
+    assertEquals(action, expected, MetadataUpdateParser.fromJson(json));
+  }
+
   public void assertEquals(String action, MetadataUpdate expectedUpdate, 
MetadataUpdate actualUpdate) {

Review Comment:
   We could just have each unit test call the correct `assertEquals` function 
based on the type.
   
   However, this tests comparing two `MetadataUpdate` objects first and 
foremost. As we'll mostly be working with `MetadataUpdate` and not the specific 
subtype, I went with this.
   
   I am open to suggestions here 🙂 



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to