huage1994 commented on a change in pull request #4300:
URL: https://github.com/apache/zeppelin/pull/4300#discussion_r822732611



##########
File path: 
zeppelin-server/src/test/java/org/apache/zeppelin/rest/NotebookRestApiTest.java
##########
@@ -164,6 +165,112 @@ public void testGetNoteByPathWithPathNotExist() throws 
IOException {
     post.close();
   }
 
+  @Test
+  public void testGetNoteRevisionHistory() throws IOException {
+    LOG.info("Running testGetNoteRevisionHistory");
+    String note1Id = null;
+    Notebook notebook = TestUtils.getInstance(Notebook.class);
+    try {
+      String notePath = "note1";
+      note1Id = TestUtils.getInstance(Notebook.class).createNote(notePath, 
anonymous);

Review comment:
       Thanks for giving me the good advice!  I've changed all the code like 
this in this PR.

##########
File path: 
zeppelin-server/src/test/java/org/apache/zeppelin/rest/NotebookRestApiTest.java
##########
@@ -164,6 +165,112 @@ public void testGetNoteByPathWithPathNotExist() throws 
IOException {
     post.close();
   }
 
+  @Test
+  public void testGetNoteRevisionHistory() throws IOException {
+    LOG.info("Running testGetNoteRevisionHistory");
+    String note1Id = null;
+    Notebook notebook = TestUtils.getInstance(Notebook.class);
+    try {
+      String notePath = "note1";
+      note1Id = TestUtils.getInstance(Notebook.class).createNote(notePath, 
anonymous);
+
+      //Add a paragraph and commit
+      NotebookRepoWithVersionControl.Revision first_commit =
+              notebook.processNote(note1Id, note -> {
+                Paragraph p1 = note.addNewParagraph(anonymous);
+                p1.setText("text1");
+                notebook.saveNote(note, AuthenticationInfo.ANONYMOUS);
+                return notebook.checkpointNote(note.getId(), note.getPath(), 
"first commit", anonymous);
+              });
+
+      //Add a paragraph again
+      notebook.processNote(note1Id, note -> {
+        Paragraph p2 = note.addNewParagraph(anonymous);
+        p2.setText("text2");
+        notebook.saveNote(note, AuthenticationInfo.ANONYMOUS);
+        return null;
+      });
+
+      // Verify
+      CloseableHttpResponse get1 = httpGet("/notebook/" + note1Id + 
"/revision");
+
+      assertThat(get1, isAllowed());
+      Map<String, Object> resp = 
gson.fromJson(EntityUtils.toString(get1.getEntity(), StandardCharsets.UTF_8),
+              new TypeToken<Map<String, Object>>() {
+              }.getType());
+      List<Map<String, Object>> body = (List<Map<String, Object>>) 
resp.get("body");
+      assertEquals(1, body.size());
+      assertEquals(first_commit.id, body.get(0).get("id"));
+      get1.close();
+
+      // Second commit
+      NotebookRepoWithVersionControl.Revision second_commit = 
notebook.processNote(note1Id, note -> notebook.checkpointNote(note.getId(), 
note.getPath(), "Second commit", anonymous));
+
+      // Verify
+      CloseableHttpResponse get2 = httpGet("/notebook/" + note1Id + 
"/revision");
+
+      assertThat(get2, isAllowed());
+      resp = gson.fromJson(EntityUtils.toString(get2.getEntity(), 
StandardCharsets.UTF_8),
+              new TypeToken<Map<String, Object>>() {
+              }.getType());
+      body = (List<Map<String, Object>>) resp.get("body");
+      assertEquals(2, body.size());
+      assertEquals(second_commit.id, body.get(0).get("id"));
+      get2.close();
+
+    } finally {
+      // cleanup
+      if (null != note1Id) {
+        TestUtils.getInstance(Notebook.class).removeNote(note1Id, anonymous);
+      }
+    }
+  }
+
+  @Test
+  public void testGetNoteByRevision() throws IOException {
+    LOG.info("Running testGetNoteByRevision");
+    String note1Id = null;
+    Notebook notebook = TestUtils.getInstance(Notebook.class);
+    try {
+      String notePath = "note1";
+      note1Id = TestUtils.getInstance(Notebook.class).createNote(notePath, 
anonymous);

Review comment:
       Thanks for giving me the good advice!  I've changed all the code like 
this in this PR.




-- 
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: dev-unsubscr...@zeppelin.apache.org

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


Reply via email to