ZEPPELIN-511 "insert paragraph" api: return created paragraph id

* also change http status code to 201 CREATED
This commit is contained in:
Jungtaek Lim 2015-12-18 10:03:45 +09:00
parent 3658b009b1
commit cc71e06097
2 changed files with 17 additions and 5 deletions

View file

@ -250,7 +250,7 @@ public class NotebookRestApi {
note.persist();
notebookServer.broadcastNote(note);
return new JsonResponse(Status.OK, "").build();
return new JsonResponse(Status.CREATED, "", p.getId()).build();
}
/**

View file

@ -610,18 +610,30 @@ public class ZeppelinRestApiTest extends AbstractTestRestApi {
String jsonRequest = "{\"title\": \"title1\", \"text\": \"text1\"}";
PostMethod post = httpPost("/notebook/" + note.getId() + "/paragraph", jsonRequest);
LOG.info("testInsertParagraph response\n" + post.getResponseBodyAsString());
assertThat("Test insert method:", post, isAllowed());
assertThat("Test insert method:", post, isCreated());
post.releaseConnection();
Map<String, Object> resp = gson.fromJson(post.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() {
}.getType());
String newParagraphId = (String) resp.get("body");
LOG.info("newParagraphId:=" + newParagraphId);
Note retrNote = ZeppelinServer.notebook.getNote(note.getId());
Paragraph newParagraph = retrNote.getParagraph(newParagraphId);
assertNotNull("Can not find new paragraph by id", newParagraph);
assertEquals("title1", newParagraph.getTitle());
assertEquals("text1", newParagraph.getText());
Paragraph lastParagraph = note.getLastParagraph();
assertEquals("title1", lastParagraph.getTitle());
assertEquals("text1", lastParagraph.getText());
assertEquals(newParagraph.getId(), lastParagraph.getId());
// insert to index 0
String jsonRequest2 = "{\"index\": 0, \"title\": \"title2\", \"text\": \"text2\"}";
PostMethod post2 = httpPost("/notebook/" + note.getId() + "/paragraph", jsonRequest2);
LOG.info("testInsertParagraph response2\n" + post.getResponseBodyAsString());
assertThat("Test insert method:", post, isAllowed());
assertThat("Test insert method:", post, isCreated());
post.releaseConnection();
Paragraph paragraphAtIdx0 = note.getParagraphs().get(0);