nastra commented on code in PR #11354:
URL: https://github.com/apache/iceberg/pull/11354#discussion_r1812068112


##########
core/src/test/java/org/apache/iceberg/TestSnapshotJson.java:
##########
@@ -35,6 +40,58 @@ public class TestSnapshotJson {
 
   public TableOperations ops = new LocalTableOperations(temp);
 
+  @Test
+  public void testToJson() throws IOException {
+    int snapshotId = 23;
+    Long parentId = null;
+    String manifestList = createManifestListWithManifestFiles(snapshotId, 
parentId);
+
+    Snapshot expected =
+        new BaseSnapshot(
+            0, snapshotId, parentId, System.currentTimeMillis(), null, null, 
1, manifestList);
+    String json = SnapshotParser.toJson(expected);
+
+    // Assert that summary field is not present in the JSON
+    ObjectMapper objectMapper = new ObjectMapper();
+    JsonNode jsonNode = objectMapper.readTree(json);
+    assertThat(jsonNode.has("summary")).isFalse();
+  }
+
+  @Test
+  public void testToJsonWithOperation() throws IOException {
+    long parentId = 1;
+    long id = 2;
+
+    String manifestList = createManifestListWithManifestFiles(id, parentId);
+
+    Snapshot expected =
+        new BaseSnapshot(
+            0,
+            id,
+            parentId,
+            System.currentTimeMillis(),
+            DataOperations.REPLACE,
+            ImmutableMap.of("files-added", "4", "files-deleted", "100"),
+            3,
+            manifestList);
+
+    String json = SnapshotParser.toJson(expected);
+
+    // Assert that the JSON contains the expected summary
+    ObjectMapper objectMapper = new ObjectMapper();
+    JsonNode jsonNode = objectMapper.readTree(json);
+    Map<String, String> actualSummary =
+        objectMapper.convertValue(
+            jsonNode.get("summary"), new TypeReference<Map<String, String>>() 
{});
+    Map<String, String> expectedSummary =
+        ImmutableMap.<String, String>builder()
+            .putAll(expected.summary())
+            .put("operation", expected.operation()) // operation is part of 
the summary
+            .build();
+    assertThat(jsonNode.has("summary")).isTrue();

Review Comment:
   I guess it's already too late for this assertion, since you're already 
relying on its existence in L85



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