@@ -319,6 +319,83 @@ public void testDeleteNoteBadId() throws IOException {
319319 }
320320
321321
322+ @ Test
323+ public void testExportNotebook () throws IOException {
324+ LOG .info ("testExportNotebook" );
325+ Note note = ZeppelinServer .notebook .createNote ();
326+ assertNotNull ("can't create new note" , note );
327+ note .setName ("source note for export" );
328+ Paragraph paragraph = note .addParagraph ();
329+ Map config = paragraph .getConfig ();
330+ config .put ("enabled" , true );
331+ paragraph .setConfig (config );
332+ paragraph .setText ("%md This is my new paragraph in my new note" );
333+ note .persist ();
334+ String sourceNoteID = note .getId ();
335+ // Call export Notebook REST API
336+ GetMethod get = httpGet ("/notebook/export/" + sourceNoteID );
337+ LOG .info ("testNotebookExport \n " + get .getResponseBodyAsString ());
338+ assertThat ("test notebook export method:" , get , isAllowed ());
339+
340+ Map <String , Object > resp = gson .fromJson (get .getResponseBodyAsString (), new TypeToken <Map <String , Object >>() {
341+ }.getType ());
342+
343+ String exportJSON = (String ) resp .get ("body" );
344+ assertNotNull ("Can not find new notejson" , exportJSON );
345+ LOG .info ("export JSON:=" + exportJSON );
346+ ZeppelinServer .notebook .removeNote (sourceNoteID );
347+ get .releaseConnection ();
348+
349+ }
350+
351+ @ Test
352+ public void testImportNotebook () throws IOException {
353+ Map <String , Object > resp ;
354+ String noteName ="source note for import" ;
355+ LOG .info ("testImortNotebook" );
356+ //create test notebook
357+ Note note = ZeppelinServer .notebook .createNote ();
358+ assertNotNull ("can't create new note" , note );
359+ note .setName (noteName );
360+ Paragraph paragraph = note .addParagraph ();
361+ Map config = paragraph .getConfig ();
362+ config .put ("enabled" , true );
363+ paragraph .setConfig (config );
364+ paragraph .setText ("%md This is my new paragraph in my new note" );
365+ note .persist ();
366+ String sourceNoteID = note .getId ();
367+ // get note content as JSON
368+ String oldJson = getNoteContent (sourceNoteID );
369+ //call notebook put
370+ PutMethod importPut = httpPut ("/notebook/import/" , oldJson );
371+ assertThat (importPut , isCreated ());
372+ resp = gson .fromJson (importPut .getResponseBodyAsString (), new TypeToken <Map <String , Object >>(){}.getType ());
373+ String importId = (String ) resp .get ("body" );
374+
375+ assertNotNull ("Did not get back a notebook id in body" , importId );
376+ Note newNote =ZeppelinServer .notebook .getNote (importId );
377+ assertEquals ("Compare note names" , noteName , newNote .getName ());
378+ assertEquals ("Compare paragraphs count" , note .getParagraphs ().size (), newNote .getParagraphs ().size ());
379+ //cleanup
380+ ZeppelinServer .notebook .removeNote (note .getId ());
381+ ZeppelinServer .notebook .removeNote (newNote .getId ());
382+ importPut .releaseConnection ();
383+ }
384+
385+ private String getNoteContent (String id ) throws IOException {
386+ GetMethod get = httpGet ("/notebook/export/" + id );
387+ assertThat (get , isAllowed ());
388+ get .addRequestHeader ("Origin" , "http://localhost" );
389+ Map <String , Object > resp = gson .fromJson (get .getResponseBodyAsString (),
390+ new TypeToken <Map <String , Object >>() {
391+ }.getType ());
392+ assertEquals (200 , get .getStatusCode ());
393+ String body = resp .get ("body" ).toString ();
394+ // System.out.println("Body is " + body);
395+ get .releaseConnection ();
396+ return body ;
397+ }
398+
322399 private void testDeleteNotebook (String notebookId ) throws IOException {
323400
324401 DeleteMethod delete = httpDelete (("/notebook/" + notebookId ));
0 commit comments