use of org.apache.zeppelin.interpreter.thrift.ParagraphInfo in project zeppelin by apache.
the class NotebookServerTest method testGetParagraphList.
@Test
public void testGetParagraphList() throws IOException {
String noteId = null;
try {
noteId = notebook.createNote("note1", anonymous);
notebook.processNote(noteId, note -> {
Paragraph p1 = note.addNewParagraph(anonymous);
p1.setText("%md start remote interpreter process");
p1.setAuthenticationInfo(anonymous);
notebook.saveNote(note, anonymous);
return null;
});
String user1Id = "user1", user2Id = "user2";
// test user1 can get anonymous's note
List<ParagraphInfo> paragraphList0 = null;
try {
paragraphList0 = notebookServer.getParagraphList(user1Id, noteId);
} catch (ServiceException e) {
e.printStackTrace();
} catch (TException e) {
e.printStackTrace();
}
assertNotNull(user1Id + " can get anonymous's note", paragraphList0);
// test user1 cannot get user2's note
authorizationService.setOwners(noteId, new HashSet<>(Arrays.asList(user2Id)));
authorizationService.setReaders(noteId, new HashSet<>(Arrays.asList(user2Id)));
authorizationService.setRunners(noteId, new HashSet<>(Arrays.asList(user2Id)));
authorizationService.setWriters(noteId, new HashSet<>(Arrays.asList(user2Id)));
List<ParagraphInfo> paragraphList1 = null;
try {
paragraphList1 = notebookServer.getParagraphList(user1Id, noteId);
} catch (ServiceException e) {
e.printStackTrace();
} catch (TException e) {
e.printStackTrace();
}
assertNull(user1Id + " cannot get " + user2Id + "'s note", paragraphList1);
// test user1 can get user2's shared note
authorizationService.setOwners(noteId, new HashSet<>(Arrays.asList(user2Id)));
authorizationService.setReaders(noteId, new HashSet<>(Arrays.asList(user1Id, user2Id)));
authorizationService.setRunners(noteId, new HashSet<>(Arrays.asList(user2Id)));
authorizationService.setWriters(noteId, new HashSet<>(Arrays.asList(user2Id)));
List<ParagraphInfo> paragraphList2 = null;
try {
paragraphList2 = notebookServer.getParagraphList(user1Id, noteId);
} catch (ServiceException e) {
e.printStackTrace();
} catch (TException e) {
e.printStackTrace();
}
assertNotNull(user1Id + " can get " + user2Id + "'s shared note", paragraphList2);
} finally {
if (null != noteId) {
notebook.removeNote(noteId, anonymous);
}
}
}
Aggregations