huage1994 commented on a change in pull request #4292: URL: https://github.com/apache/zeppelin/pull/4292#discussion_r793685047
########## File path: zeppelin-server/src/test/java/org/apache/zeppelin/rest/NotebookRestApiTest.java ########## @@ -120,6 +120,55 @@ public void testGetReloadNote() throws IOException { } } } + + @Test + public void testGetNoteByPath() throws IOException { + LOG.info("Running testGetNoteByPath"); + String note1Id = null; + try { + String notePath = "dir1/note1"; + note1Id = TestUtils.getInstance(Notebook.class).createNote(notePath, anonymous); + TestUtils.getInstance(Notebook.class).processNote(note1Id, + note1 -> { + note1.addNewParagraph(AuthenticationInfo.ANONYMOUS); + TestUtils.getInstance(Notebook.class).saveNote(note1, anonymous); + return null; + }); + + CloseableHttpResponse post = httpPost("/notebook/getByPath" , "{\"notePath\":\""+ notePath + "\"}" ); + + assertThat(post, isAllowed()); + Map<String, Object> resp = gson.fromJson(EntityUtils.toString(post.getEntity(), StandardCharsets.UTF_8), + new TypeToken<Map<String, Object>>() {}.getType()); + Map<String, Object> noteObject = (Map<String, Object>) resp.get("body"); + assertEquals(notePath, ((String)noteObject.get("path")).substring(1)); + post.close(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + // cleanup + if (null != note1Id) { + TestUtils.getInstance(Notebook.class).removeNote(note1Id, anonymous); + } + } + } + + @Test + public void testGetNoteByPathWithPathNotExist() { + LOG.info("Running testGetNoteByPathWithPathNotExist"); + try { + String notePath = "A note that doesn't exist"; + CloseableHttpResponse post = httpPost("/notebook/getByPath" , "{\"notePath\":\""+ notePath + "\"}" ); + assertThat(post, isNotFound()); + Map<String, Object> resp = gson.fromJson(EntityUtils.toString(post.getEntity(), StandardCharsets.UTF_8), + new TypeToken<Map<String, Object>>() {}.getType()); + String status = (String) resp.get("status"); + assertEquals(status, "NOT_FOUND"); + post.close(); + } catch (IOException e) { + e.printStackTrace(); Review comment: > use Logger to log error instead of `e.printStackTrace()` I got it wrong. I find it should throw the IOException here like the other test case. And catch statement has been remove 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