Reamer commented on a change in pull request #4300: URL: https://github.com/apache/zeppelin/pull/4300#discussion_r822359880
########## File path: zeppelin-server/src/main/java/org/apache/zeppelin/service/NotebookService.java ########## @@ -1012,12 +1012,12 @@ public void setNoteRevision(String noteId, } - public void getNotebyRevision(String noteId, + public Note getNotebyRevision(String noteId, Review comment: Could you please put the following comment to this method. `notebook.getNoteByRevision(...) does not use the NoteCache, so we can return a Note object here.` ########## 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: use `notebook` here. ########## 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: Use `notebook` 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: dev-unsubscr...@zeppelin.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org