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


##########
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:
   This looks reasonable to me.



-- 
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