Search in sources :

Example 6 with GetMethod

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();
}
Also used : TypeToken(com.google.gson.reflect.TypeToken) GetMethod(org.apache.commons.httpclient.methods.GetMethod) List(java.util.List) Test(org.junit.Test)

Example 7 with GetMethod

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();
}
Also used : TypeToken(com.google.gson.reflect.TypeToken) Note(org.apache.zeppelin.notebook.Note) GetMethod(org.apache.commons.httpclient.methods.GetMethod) Map(java.util.Map) Paragraph(org.apache.zeppelin.notebook.Paragraph) Test(org.junit.Test)

Example 8 with GetMethod

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);
}
Also used : TypeToken(com.google.gson.reflect.TypeToken) Note(org.apache.zeppelin.notebook.Note) GetMethod(org.apache.commons.httpclient.methods.GetMethod) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) Paragraph(org.apache.zeppelin.notebook.Paragraph) Test(org.junit.Test)

Example 9 with GetMethod

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);
}
Also used : Set(java.util.Set) TypeToken(com.google.gson.reflect.TypeToken) Note(org.apache.zeppelin.notebook.Note) GetMethod(org.apache.commons.httpclient.methods.GetMethod) Map(java.util.Map) Test(org.junit.Test)

Example 10 with GetMethod

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);
}
Also used : PostMethod(org.apache.commons.httpclient.methods.PostMethod) TypeToken(com.google.gson.reflect.TypeToken) Note(org.apache.zeppelin.notebook.Note) GetMethod(org.apache.commons.httpclient.methods.GetMethod) Map(java.util.Map) Test(org.junit.Test)

Aggregations

GetMethod (org.apache.commons.httpclient.methods.GetMethod)357 HttpClient (org.apache.commons.httpclient.HttpClient)216 HttpMethod (org.apache.commons.httpclient.HttpMethod)93 IOException (java.io.IOException)82 Test (org.junit.Test)70 InputStream (java.io.InputStream)65 HttpException (org.apache.commons.httpclient.HttpException)41 Map (java.util.Map)39 ArrayList (java.util.ArrayList)37 HashMap (java.util.HashMap)36 JSONParser (org.json.simple.parser.JSONParser)34 JSONObject (org.json.simple.JSONObject)31 Header (org.apache.commons.httpclient.Header)22 Element (org.w3c.dom.Element)22 PostMethod (org.apache.commons.httpclient.methods.PostMethod)21 TypeToken (com.google.gson.reflect.TypeToken)20 List (java.util.List)19 HttpState (org.apache.commons.httpclient.HttpState)18 URI (java.net.URI)17 JSONArray (org.json.simple.JSONArray)17