Skip to content

Commit 070bc2d

Browse files
committed
fix more in ZeppelinRestApiTest.java
1 parent 24822a3 commit 070bc2d

File tree

1 file changed

+45
-47
lines changed

1 file changed

+45
-47
lines changed

zeppelin-server/src/test/java/org/apache/zeppelin/rest/ZeppelinRestApiTest.java

Lines changed: 45 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,8 @@
2727
import org.apache.commons.httpclient.methods.PostMethod;
2828
import org.apache.commons.httpclient.methods.PutMethod;
2929
import org.apache.commons.lang3.StringUtils;
30-
import org.apache.zeppelin.interpreter.InterpreterSetting;
3130
import org.apache.zeppelin.notebook.Note;
3231
import org.apache.zeppelin.notebook.Paragraph;
33-
import org.apache.zeppelin.scheduler.Job.Status;
3432
import org.apache.zeppelin.server.ZeppelinServer;
3533
import org.apache.zeppelin.user.AuthenticationInfo;
3634
import org.junit.AfterClass;
@@ -75,8 +73,8 @@ public void getApiRoot() throws IOException {
7573
}
7674

7775
@Test
78-
public void testGetNotebookInfo() throws IOException {
79-
LOG.info("testGetNotebookInfo");
76+
public void testGetNoteInfo() throws IOException {
77+
LOG.info("testGetNoteInfo");
8078
// Create note to get info
8179
Note note = ZeppelinServer.notebook.createNote(null);
8280
assertNotNull("can't create new note", note);
@@ -91,8 +89,8 @@ public void testGetNotebookInfo() throws IOException {
9189

9290
String sourceNoteId = note.getId();
9391
GetMethod get = httpGet("/notebook/" + sourceNoteId);
94-
LOG.info("testGetNotebookInfo \n" + get.getResponseBodyAsString());
95-
assertThat("test notebook get method:", get, isAllowed());
92+
LOG.info("testGetNoteInfo \n" + get.getResponseBodyAsString());
93+
assertThat("test note get method:", get, isAllowed());
9694

9795
Map<String, Object> resp = gson.fromJson(get.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() {
9896
}.getType());
@@ -120,7 +118,7 @@ public void testNoteCreateNoName() throws IOException {
120118

121119
@Test
122120
public void testNoteCreateWithParagraphs() throws IOException {
123-
// Call Create Notebook REST API
121+
// Call Create Note REST API
124122
String noteName = "test";
125123
String jsonRequest = "{\"name\":\"" + noteName + "\", \"paragraphs\": [" +
126124
"{\"title\": \"title1\", \"text\": \"text1\"}," +
@@ -159,11 +157,11 @@ public void testNoteCreateWithParagraphs() throws IOException {
159157
}
160158

161159
private void testNoteCreate(String noteName) throws IOException {
162-
// Call Create Notebook REST API
160+
// Call Create Note REST API
163161
String jsonRequest = "{\"name\":\"" + noteName + "\"}";
164162
PostMethod post = httpPost("/notebook/", jsonRequest);
165163
LOG.info("testNoteCreate \n" + post.getResponseBodyAsString());
166-
assertThat("test notebook create method:", post, isCreated());
164+
assertThat("test note create method:", post, isCreated());
167165

168166
Map<String, Object> resp = gson.fromJson(post.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() {
169167
}.getType());
@@ -216,10 +214,10 @@ public void testexportNote() throws IOException {
216214
paragraph.setText("%md This is my new paragraph in my new note");
217215
note.persist(null);
218216
String sourceNoteId = note.getId();
219-
// Call export Notebook REST API
217+
// Call export Note REST API
220218
GetMethod get = httpGet("/notebook/export/" + sourceNoteId);
221-
LOG.info("testNotebookExport \n" + get.getResponseBodyAsString());
222-
assertThat("test notebook export method:", get, isAllowed());
219+
LOG.info("testNoteExport \n" + get.getResponseBodyAsString());
220+
assertThat("test note export method:", get, isAllowed());
223221

224222
Map<String, Object> resp =
225223
gson.fromJson(get.getResponseBodyAsString(),
@@ -237,8 +235,8 @@ public void testexportNote() throws IOException {
237235
public void testImportNotebook() throws IOException {
238236
Map<String, Object> resp;
239237
String noteName = "source note for import";
240-
LOG.info("testImortNotebook");
241-
// create test notebook
238+
LOG.info("testImortNote");
239+
// create test note
242240
Note note = ZeppelinServer.notebook.createNote(null);
243241
assertNotNull("can't create new note", note);
244242
note.setName(noteName);
@@ -251,15 +249,15 @@ public void testImportNotebook() throws IOException {
251249
String sourceNoteId = note.getId();
252250
// get note content as JSON
253251
String oldJson = getNoteContent(sourceNoteId);
254-
// call notebook post
252+
// call note post
255253
PostMethod importPost = httpPost("/notebook/import/", oldJson);
256254
assertThat(importPost, isCreated());
257255
resp =
258256
gson.fromJson(importPost.getResponseBodyAsString(),
259257
new TypeToken<Map<String, Object>>() {}.getType());
260258
String importId = (String) resp.get("body");
261259

262-
assertNotNull("Did not get back a notebook id in body", importId);
260+
assertNotNull("Did not get back a note id in body", importId);
263261
Note newNote = ZeppelinServer.notebook.getNote(importId);
264262
assertEquals("Compare note names", noteName, newNote.getName());
265263
assertEquals("Compare paragraphs count", note.getParagraphs().size(), newNote.getParagraphs()
@@ -313,11 +311,11 @@ public void testCloneNote() throws IOException, CloneNotSupportedException, Ille
313311
String sourceNoteId = note.getId();
314312

315313
String noteName = "clone Note Name";
316-
// Call Clone Notebook REST API
314+
// Call Clone Note REST API
317315
String jsonRequest = "{\"name\":\"" + noteName + "\"}";
318316
PostMethod post = httpPost("/notebook/" + sourceNoteId, jsonRequest);
319-
LOG.info("testNotebookClone \n" + post.getResponseBodyAsString());
320-
assertThat("test notebook clone method:", post, isCreated());
317+
LOG.info("testNoteClone \n" + post.getResponseBodyAsString());
318+
assertThat("test note clone method:", post, isCreated());
321319

322320
Map<String, Object> resp = gson.fromJson(post.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() {
323321
}.getType());
@@ -335,16 +333,16 @@ public void testCloneNote() throws IOException, CloneNotSupportedException, Ille
335333
}
336334

337335
@Test
338-
public void testListNotebooks() throws IOException {
339-
LOG.info("testListNotebooks");
336+
public void testListNotes() throws IOException {
337+
LOG.info("testListNotes");
340338
GetMethod get = httpGet("/notebook/ ");
341-
assertThat("List notebooks method", get, isAllowed());
339+
assertThat("List notes method", get, isAllowed());
342340
Map<String, Object> resp = gson.fromJson(get.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() {
343341
}.getType());
344342
List<Map<String, String>> body = (List<Map<String, String>>) resp.get("body");
345343
//TODO(khalid): anonymous or specific user notes?
346344
AuthenticationInfo subject = new AuthenticationInfo("anonymous");
347-
assertEquals("List notebooks are equal", ZeppelinServer.notebook.getAllNotes(subject).size(), body.size());
345+
assertEquals("List notes are equal", ZeppelinServer.notebook.getAllNotes(subject).size(), body.size());
348346
get.releaseConnection();
349347
}
350348

@@ -376,14 +374,14 @@ public void testNoteJobs() throws IOException, InterruptedException {
376374
}
377375
}
378376

379-
// Call Run Notebook Jobs REST API
377+
// Call Run note jobs REST API
380378
PostMethod postNoteJobs = httpPost("/notebook/job/" + noteId, "");
381-
assertThat("test notebook jobs run:", postNoteJobs, isAllowed());
379+
assertThat("test note jobs run:", postNoteJobs, isAllowed());
382380
postNoteJobs.releaseConnection();
383381

384-
// Call Stop Notebook Jobs REST API
382+
// Call Stop note jobs REST API
385383
DeleteMethod deleteNoteJobs = httpDelete("/notebook/job/" + noteId);
386-
assertThat("test notebook stop:", deleteNoteJobs, isAllowed());
384+
assertThat("test note stop:", deleteNoteJobs, isAllowed());
387385
deleteNoteJobs.releaseConnection();
388386
Thread.sleep(1000);
389387

@@ -404,8 +402,8 @@ public void testNoteJobs() throws IOException, InterruptedException {
404402
}
405403

406404
@Test
407-
public void testGetNotebookJob() throws IOException, InterruptedException {
408-
LOG.info("testGetNotebookJob");
405+
public void testGetNoteJob() throws IOException, InterruptedException {
406+
LOG.info("testGetNoteJob");
409407
// Create note to run test.
410408
Note note = ZeppelinServer.notebook.createNote(null);
411409
assertNotNull("can't create new note", note);
@@ -429,11 +427,11 @@ public void testGetNotebookJob() throws IOException, InterruptedException {
429427

430428
// assume that status of the paragraph is running
431429
GetMethod get = httpGet("/notebook/job/" + noteId);
432-
assertThat("test get notebook job: ", get, isAllowed());
430+
assertThat("test get note job: ", get, isAllowed());
433431
String responseBody = get.getResponseBodyAsString();
434432
get.releaseConnection();
435433

436-
LOG.info("test get notebook job: \n" + responseBody);
434+
LOG.info("test get note job: \n" + responseBody);
437435
Map<String, Object> resp = gson.fromJson(responseBody, new TypeToken<Map<String, Object>>() {
438436
}.getType());
439437

@@ -448,7 +446,7 @@ public void testGetNotebookJob() throws IOException, InterruptedException {
448446
while (!paragraph.isTerminated()) {
449447
Thread.sleep(100);
450448
if (timeout++ > 10) {
451-
LOG.info("testGetNotebookJob timeout job.");
449+
LOG.info("testGetNoteJob timeout job.");
452450
break;
453451
}
454452
}
@@ -562,7 +560,7 @@ public void testRegressionZEPPELIN_527() throws IOException {
562560
note.persist(null);
563561

564562
GetMethod getNoteJobs = httpGet("/notebook/job/" + note.getId());
565-
assertThat("test notebook jobs run:", getNoteJobs, isAllowed());
563+
assertThat("test note jobs run:", getNoteJobs, isAllowed());
566564
Map<String, Object> resp = gson.fromJson(getNoteJobs.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() {
567565
}.getType());
568566
List<Map<String, String>> body = (List<Map<String, String>>) resp.get("body");
@@ -710,13 +708,13 @@ public void testSearch() throws IOException {
710708

711709
Note note1 = ZeppelinServer.notebook.createNote(null);
712710
String jsonRequest = "{\"title\": \"title1\", \"text\": \"ThisIsToTestSearchMethodWithPermissions 1\"}";
713-
PostMethod postNotebookText = httpPost("/notebook/" + note1.getId() + "/paragraph", jsonRequest);
714-
postNotebookText.releaseConnection();
711+
PostMethod postNoteText = httpPost("/notebook/" + note1.getId() + "/paragraph", jsonRequest);
712+
postNoteText.releaseConnection();
715713

716714
Note note2 = ZeppelinServer.notebook.createNote(null);
717715
jsonRequest = "{\"title\": \"title1\", \"text\": \"ThisIsToTestSearchMethodWithPermissions 2\"}";
718-
postNotebookText = httpPost("/notebook/" + note2.getId() + "/paragraph", jsonRequest);
719-
postNotebookText.releaseConnection();
716+
postNoteText = httpPost("/notebook/" + note2.getId() + "/paragraph", jsonRequest);
717+
postNoteText.releaseConnection();
720718

721719
String jsonPermissions = "{\"owners\":[\"" + username + "\"],\"readers\":[\"" + username + "\"],\"writers\":[\"" + username + "\"]}";
722720
PutMethod putPermission = httpPut("/notebook/" + note1.getId() + "/permissions", jsonPermissions);
@@ -726,9 +724,9 @@ public void testSearch() throws IOException {
726724
putPermission = httpPut("/notebook/" + note2.getId() + "/permissions", jsonPermissions);
727725
putPermission.releaseConnection();
728726

729-
GetMethod searchNotebook = httpGet("/notebook/search?q='ThisIsToTestSearchMethodWithPermissions'");
730-
searchNotebook.addRequestHeader("Origin", "http://localhost");
731-
Map<String, Object> respSearchResult = gson.fromJson(searchNotebook.getResponseBodyAsString(),
727+
GetMethod searchNote = httpGet("/notebook/search?q='ThisIsToTestSearchMethodWithPermissions'");
728+
searchNote.addRequestHeader("Origin", "http://localhost");
729+
Map<String, Object> respSearchResult = gson.fromJson(searchNote.getResponseBodyAsString(),
732730
new TypeToken<Map<String, Object>>() {
733731
}.getType());
734732
ArrayList searchBody = (ArrayList) respSearchResult.get("body");
@@ -754,7 +752,7 @@ public void testSearch() throws IOException {
754752
}
755753
getPermission.releaseConnection();
756754
}
757-
searchNotebook.releaseConnection();
755+
searchNote.releaseConnection();
758756
ZeppelinServer.notebook.removeNote(note1.getId(), null);
759757
ZeppelinServer.notebook.removeNote(note2.getId(), null);
760758
}
@@ -763,12 +761,12 @@ public void testSearch() throws IOException {
763761
public void testTitleSearch() throws IOException {
764762
Note note = ZeppelinServer.notebook.createNote(null);
765763
String jsonRequest = "{\"title\": \"testTitleSearchOfParagraph\", \"text\": \"ThisIsToTestSearchMethodWithTitle \"}";
766-
PostMethod postNotebookText = httpPost("/notebook/" + note.getId() + "/paragraph", jsonRequest);
767-
postNotebookText.releaseConnection();
764+
PostMethod postNoteText = httpPost("/notebook/" + note.getId() + "/paragraph", jsonRequest);
765+
postNoteText.releaseConnection();
768766

769-
GetMethod searchNotebook = httpGet("/notebook/search?q='testTitleSearchOfParagraph'");
770-
searchNotebook.addRequestHeader("Origin", "http://localhost");
771-
Map<String, Object> respSearchResult = gson.fromJson(searchNotebook.getResponseBodyAsString(),
767+
GetMethod searchNote = httpGet("/notebook/search?q='testTitleSearchOfParagraph'");
768+
searchNote.addRequestHeader("Origin", "http://localhost");
769+
Map<String, Object> respSearchResult = gson.fromJson(searchNote.getResponseBodyAsString(),
772770
new TypeToken<Map<String, Object>>() {
773771
}.getType());
774772
ArrayList searchBody = (ArrayList) respSearchResult.get("body");
@@ -781,7 +779,7 @@ public void testTitleSearch() throws IOException {
781779
}
782780
}
783781
assertEquals("Paragraph title hits must be at-least one", true, numberOfTitleHits >= 1);
784-
searchNotebook.releaseConnection();
782+
searchNote.releaseConnection();
785783
ZeppelinServer.notebook.removeNote(note.getId(), null);
786784
}
787785

0 commit comments

Comments
 (0)