Search in sources :

Example 11 with PostMethod

use of org.apache.commons.httpclient.methods.PostMethod in project zeppelin by apache.

the class InterpreterRestApiTest method testSettingsCreateWithEmptyJson.

@Test
public void testSettingsCreateWithEmptyJson() throws IOException {
    // Call Create Setting REST API
    PostMethod post = httpPost("/interpreter/setting/", "");
    LOG.info("testSettingCRUD create response\n" + post.getResponseBodyAsString());
    assertThat("test create method:", post, isBadRequest());
    post.releaseConnection();
}
Also used : PostMethod(org.apache.commons.httpclient.methods.PostMethod) Test(org.junit.Test)

Example 12 with PostMethod

use of org.apache.commons.httpclient.methods.PostMethod in project zeppelin by apache.

the class InterpreterRestApiTest method testAddDeleteRepository.

@Test
public void testAddDeleteRepository() throws IOException {
    // Call create repository API
    String repoId = "securecentral";
    String jsonRequest = "{\"id\":\"" + repoId + "\",\"url\":\"https://repo1.maven.org/maven2\",\"snapshot\":\"false\"}";
    PostMethod post = httpPost("/interpreter/repository/", jsonRequest);
    assertThat("Test create method:", post, isAllowed());
    post.releaseConnection();
    // Call delete repository API
    DeleteMethod delete = httpDelete("/interpreter/repository/" + repoId);
    assertThat("Test delete method:", delete, isAllowed());
    delete.releaseConnection();
}
Also used : DeleteMethod(org.apache.commons.httpclient.methods.DeleteMethod) PostMethod(org.apache.commons.httpclient.methods.PostMethod) Test(org.junit.Test)

Example 13 with PostMethod

use of org.apache.commons.httpclient.methods.PostMethod in project zeppelin by apache.

the class InterpreterRestApiTest method testCreatedInterpreterDependencies.

@Test
public void testCreatedInterpreterDependencies() throws IOException {
    // when: Create 2 interpreter settings `md1` and `md2` which have different dep.
    String md1Name = "md1";
    String md2Name = "md2";
    String md1Dep = "org.apache.drill.exec:drill-jdbc:jar:1.7.0";
    String md2Dep = "org.apache.drill.exec:drill-jdbc:jar:1.6.0";
    String reqBody1 = "{\"name\":\"" + md1Name + "\",\"group\":\"md\",\"properties\":{\"propname\":\"propvalue\"}," + "\"interpreterGroup\":[{\"class\":\"org.apache.zeppelin.markdown.Markdown\",\"name\":\"md\"}]," + "\"dependencies\":[ {\n" + "      \"groupArtifactVersion\": \"" + md1Dep + "\",\n" + "      \"exclusions\":[]\n" + "    }]," + "\"option\": { \"remote\": true, \"session\": false }}";
    PostMethod post = httpPost("/interpreter/setting", reqBody1);
    assertThat("test create method:", post, isAllowed());
    post.releaseConnection();
    String reqBody2 = "{\"name\":\"" + md2Name + "\",\"group\":\"md\",\"properties\":{\"propname\":\"propvalue\"}," + "\"interpreterGroup\":[{\"class\":\"org.apache.zeppelin.markdown.Markdown\",\"name\":\"md\"}]," + "\"dependencies\":[ {\n" + "      \"groupArtifactVersion\": \"" + md2Dep + "\",\n" + "      \"exclusions\":[]\n" + "    }]," + "\"option\": { \"remote\": true, \"session\": false }}";
    post = httpPost("/interpreter/setting", reqBody2);
    assertThat("test create method:", post, isAllowed());
    post.releaseConnection();
    // 1. Call settings API
    GetMethod get = httpGet("/interpreter/setting");
    String rawResponse = get.getResponseBodyAsString();
    get.releaseConnection();
    // 2. Parsing to List<InterpreterSettings>
    JsonObject responseJson = gson.fromJson(rawResponse, JsonElement.class).getAsJsonObject();
    JsonArray bodyArr = responseJson.getAsJsonArray("body");
    List<InterpreterSetting> settings = new Gson().fromJson(bodyArr, new TypeToken<ArrayList<InterpreterSetting>>() {
    }.getType());
    // 3. Filter interpreters out we have just created
    InterpreterSetting md1 = null;
    InterpreterSetting md2 = null;
    for (InterpreterSetting setting : settings) {
        if (md1Name.equals(setting.getName())) {
            md1 = setting;
        } else if (md2Name.equals(setting.getName())) {
            md2 = setting;
        }
    }
    // then: should get created interpreters which have different dependencies
    // 4. Validate each md interpreter has its own dependencies
    assertEquals(1, md1.getDependencies().size());
    assertEquals(1, md2.getDependencies().size());
    assertEquals(md1Dep, md1.getDependencies().get(0).getGroupArtifactVersion());
    assertEquals(md2Dep, md2.getDependencies().get(0).getGroupArtifactVersion());
}
Also used : JsonArray(com.google.gson.JsonArray) PostMethod(org.apache.commons.httpclient.methods.PostMethod) JsonElement(com.google.gson.JsonElement) TypeToken(com.google.gson.reflect.TypeToken) InterpreterSetting(org.apache.zeppelin.interpreter.InterpreterSetting) GetMethod(org.apache.commons.httpclient.methods.GetMethod) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson) Test(org.junit.Test)

Example 14 with PostMethod

use of org.apache.commons.httpclient.methods.PostMethod in project zeppelin by apache.

the class ZeppelinRestApiTest method testInsertParagraph.

@Test
public void testInsertParagraph() throws IOException {
    Note note = ZeppelinServer.notebook.createNote(anonymous);
    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());
    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(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" + post2.getResponseBodyAsString());
    assertThat("Test insert method:", post2, isAllowed());
    post2.releaseConnection();
    Paragraph paragraphAtIdx0 = note.getParagraphs().get(0);
    assertEquals("title2", paragraphAtIdx0.getTitle());
    assertEquals("text2", paragraphAtIdx0.getText());
    ZeppelinServer.notebook.removeNote(note.getId(), anonymous);
}
Also used : PostMethod(org.apache.commons.httpclient.methods.PostMethod) TypeToken(com.google.gson.reflect.TypeToken) Note(org.apache.zeppelin.notebook.Note) Paragraph(org.apache.zeppelin.notebook.Paragraph) Test(org.junit.Test)

Example 15 with PostMethod

use of org.apache.commons.httpclient.methods.PostMethod in project zeppelin by apache.

the class ZeppelinRestApiTest method testMoveParagraph.

@Test
public void testMoveParagraph() throws IOException {
    Note note = ZeppelinServer.notebook.createNote(anonymous);
    Paragraph p = note.addParagraph(AuthenticationInfo.ANONYMOUS);
    p.setTitle("title1");
    p.setText("text1");
    Paragraph p2 = note.addParagraph(AuthenticationInfo.ANONYMOUS);
    p2.setTitle("title2");
    p2.setText("text2");
    note.persist(anonymous);
    PostMethod post = httpPost("/notebook/" + note.getId() + "/paragraph/" + p2.getId() + "/move/" + 0, "");
    assertThat("Test post method: ", post, isAllowed());
    post.releaseConnection();
    Note retrNote = ZeppelinServer.notebook.getNote(note.getId());
    Paragraph paragraphAtIdx0 = retrNote.getParagraphs().get(0);
    assertEquals(p2.getId(), paragraphAtIdx0.getId());
    assertEquals(p2.getTitle(), paragraphAtIdx0.getTitle());
    assertEquals(p2.getText(), paragraphAtIdx0.getText());
    PostMethod post2 = httpPost("/notebook/" + note.getId() + "/paragraph/" + p2.getId() + "/move/" + 10, "");
    assertThat("Test post method: ", post2, isBadRequest());
    post.releaseConnection();
    ZeppelinServer.notebook.removeNote(note.getId(), anonymous);
}
Also used : PostMethod(org.apache.commons.httpclient.methods.PostMethod) Note(org.apache.zeppelin.notebook.Note) Paragraph(org.apache.zeppelin.notebook.Paragraph) Test(org.junit.Test)

Aggregations

PostMethod (org.apache.commons.httpclient.methods.PostMethod)203 HttpClient (org.apache.commons.httpclient.HttpClient)114 Test (org.junit.Test)55 IOException (java.io.IOException)32 MultipartRequestEntity (org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity)28 Part (org.apache.commons.httpclient.methods.multipart.Part)25 NameValuePair (org.apache.commons.httpclient.NameValuePair)24 FilePart (org.apache.commons.httpclient.methods.multipart.FilePart)23 Map (java.util.Map)21 GetMethod (org.apache.commons.httpclient.methods.GetMethod)21 StringRequestEntity (org.apache.commons.httpclient.methods.StringRequestEntity)21 StringPart (org.apache.commons.httpclient.methods.multipart.StringPart)21 HttpMethod (org.apache.commons.httpclient.HttpMethod)17 Header (org.apache.commons.httpclient.Header)16 Note (org.apache.zeppelin.notebook.Note)13 HttpException (org.apache.commons.httpclient.HttpException)12 File (java.io.File)11 InputStream (java.io.InputStream)11 ByteArrayRequestEntity (org.apache.commons.httpclient.methods.ByteArrayRequestEntity)11 JSONParser (org.json.simple.parser.JSONParser)11