use of org.apache.commons.httpclient.methods.GetMethod in project zeppelin by apache.
the class SecurityRestApiTest method testGetUserList.
@Test
public void testGetUserList() throws IOException {
GetMethod get = httpGet("/security/userlist/admi", "admin", "password1");
get.addRequestHeader("Origin", "http://localhost");
Map<String, Object> resp = gson.fromJson(get.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() {
}.getType());
List<String> userList = (List) ((Map) resp.get("body")).get("users");
collector.checkThat("Search result size", userList.size(), CoreMatchers.equalTo(1));
collector.checkThat("Search result contains admin", userList.contains("admin"), CoreMatchers.equalTo(true));
get.releaseConnection();
GetMethod notUser = httpGet("/security/userlist/randomString", "admin", "password1");
notUser.addRequestHeader("Origin", "http://localhost");
Map<String, Object> notUserResp = gson.fromJson(notUser.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() {
}.getType());
List<String> emptyUserList = (List) ((Map) notUserResp.get("body")).get("users");
collector.checkThat("Search result size", emptyUserList.size(), CoreMatchers.equalTo(0));
notUser.releaseConnection();
}
use of org.apache.commons.httpclient.methods.GetMethod in project zeppelin by apache.
the class ZeppelinRestApiTest method testexportNote.
@Test
public void testexportNote() throws IOException {
LOG.info("testexportNote");
Note note = ZeppelinServer.notebook.createNote(anonymous);
assertNotNull("can't create new note", note);
note.setName("source note for export");
Paragraph paragraph = note.addParagraph(AuthenticationInfo.ANONYMOUS);
Map config = paragraph.getConfig();
config.put("enabled", true);
paragraph.setConfig(config);
paragraph.setText("%md This is my new paragraph in my new note");
note.persist(anonymous);
String sourceNoteId = note.getId();
// Call export Note REST API
GetMethod get = httpGet("/notebook/export/" + sourceNoteId);
LOG.info("testNoteExport \n" + get.getResponseBodyAsString());
assertThat("test note export method:", get, isAllowed());
Map<String, Object> resp = gson.fromJson(get.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() {
}.getType());
String exportJSON = (String) resp.get("body");
assertNotNull("Can not find new notejson", exportJSON);
LOG.info("export JSON:=" + exportJSON);
ZeppelinServer.notebook.removeNote(sourceNoteId, anonymous);
get.releaseConnection();
}
use of org.apache.commons.httpclient.methods.GetMethod in project zeppelin by apache.
the class ZeppelinRestApiTest method testGetNoteInfo.
@Test
public void testGetNoteInfo() throws IOException {
LOG.info("testGetNoteInfo");
// Create note to get info
Note note = ZeppelinServer.notebook.createNote(anonymous);
assertNotNull("can't create new note", note);
note.setName("note");
Paragraph paragraph = note.addParagraph(AuthenticationInfo.ANONYMOUS);
Map config = paragraph.getConfig();
config.put("enabled", true);
paragraph.setConfig(config);
String paragraphText = "%md This is my new paragraph in my new note";
paragraph.setText(paragraphText);
note.persist(anonymous);
String sourceNoteId = note.getId();
GetMethod get = httpGet("/notebook/" + sourceNoteId);
LOG.info("testGetNoteInfo \n" + get.getResponseBodyAsString());
assertThat("test note get method:", get, isAllowed());
Map<String, Object> resp = gson.fromJson(get.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() {
}.getType());
assertNotNull(resp);
assertEquals("OK", resp.get("status"));
Map<String, Object> body = (Map<String, Object>) resp.get("body");
List<Map<String, Object>> paragraphs = (List<Map<String, Object>>) body.get("paragraphs");
assertTrue(paragraphs.size() > 0);
assertEquals(paragraphText, paragraphs.get(0).get("text"));
//
ZeppelinServer.notebook.removeNote(sourceNoteId, anonymous);
}
use of org.apache.commons.httpclient.methods.GetMethod in project zeppelin by apache.
the class NotebookRestApiTest method testGetNoteParagraphJobStatus.
@Test
public void testGetNoteParagraphJobStatus() throws IOException {
Note note1 = ZeppelinServer.notebook.createNote(anonymous);
note1.addParagraph(AuthenticationInfo.ANONYMOUS);
String paragraphId = note1.getLastParagraph().getId();
GetMethod get = httpGet("/notebook/job/" + note1.getId() + "/" + paragraphId);
assertThat(get, isAllowed());
Map<String, Object> resp = gson.fromJson(get.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() {
}.getType());
Map<String, Set<String>> paragraphStatus = (Map<String, Set<String>>) resp.get("body");
// Check id and status have proper value
assertEquals(paragraphStatus.get("id"), paragraphId);
assertEquals(paragraphStatus.get("status"), "READY");
//cleanup
ZeppelinServer.notebook.removeNote(note1.getId(), anonymous);
}
use of org.apache.commons.httpclient.methods.GetMethod in project zeppelin by apache.
the class NotebookRestApiTest method testCloneNote.
@Test
public void testCloneNote() throws IOException {
Note note1 = ZeppelinServer.notebook.createNote(anonymous);
PostMethod post = httpPost("/notebook/" + note1.getId(), "");
LOG.info("testCloneNote response\n" + post.getResponseBodyAsString());
assertThat(post, isAllowed());
Map<String, Object> resp = gson.fromJson(post.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() {
}.getType());
String clonedNoteId = (String) resp.get("body");
post.releaseConnection();
GetMethod get = httpGet("/notebook/" + clonedNoteId);
assertThat(get, isAllowed());
Map<String, Object> resp2 = gson.fromJson(get.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() {
}.getType());
Map<String, Object> resp2Body = (Map<String, Object>) resp2.get("body");
assertEquals((String) resp2Body.get("name"), "Note " + clonedNoteId);
get.releaseConnection();
//cleanup
ZeppelinServer.notebook.removeNote(note1.getId(), anonymous);
ZeppelinServer.notebook.removeNote(clonedNoteId, anonymous);
}
Aggregations