Search in sources :

Example 6 with ParagraphInfo

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);
        }
    }
}
Also used : TException(org.apache.thrift.TException) ServiceException(org.apache.zeppelin.interpreter.thrift.ServiceException) Mockito.anyString(org.mockito.Mockito.anyString) Paragraph(org.apache.zeppelin.notebook.Paragraph) ParagraphInfo(org.apache.zeppelin.interpreter.thrift.ParagraphInfo) Test(org.junit.Test)

Aggregations

ParagraphInfo (org.apache.zeppelin.interpreter.thrift.ParagraphInfo)6 ServiceException (org.apache.zeppelin.interpreter.thrift.ServiceException)3 Paragraph (org.apache.zeppelin.notebook.Paragraph)3 File (java.io.File)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 TException (org.apache.thrift.TException)2 Test (org.junit.Test)2 Jinjava (com.hubspot.jinjava.Jinjava)1 FileWriter (java.io.FileWriter)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Properties (java.util.Properties)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 CommandLine (org.apache.commons.exec.CommandLine)1 DefaultExecuteResultHandler (org.apache.commons.exec.DefaultExecuteResultHandler)1 DefaultExecutor (org.apache.commons.exec.DefaultExecutor)1