Search in sources :

Example 16 with GetMethod

use of org.apache.commons.httpclient.methods.GetMethod 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 17 with GetMethod

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

the class AbstractTestRestApi method checkIfServerIsRunning.

protected static boolean checkIfServerIsRunning() {
    GetMethod request = null;
    boolean isRunning = true;
    try {
        request = httpGet("/version");
        isRunning = request.getStatusCode() == 200;
    } catch (IOException e) {
        LOG.error("AbstractTestRestApi.checkIfServerIsRunning() fails .. ZeppelinServer is not running");
        isRunning = false;
    } finally {
        if (request != null) {
            request.releaseConnection();
        }
    }
    return isRunning;
}
Also used : GetMethod(org.apache.commons.httpclient.methods.GetMethod) IOException(java.io.IOException)

Example 18 with GetMethod

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

the class DirAccessTest method testDirAccessOk.

@Test
public void testDirAccessOk() throws Exception {
    synchronized (this) {
        System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_SERVER_DEFAULT_DIR_ALLOWED.getVarName(), "true");
        AbstractTestRestApi.startUp();
        HttpClient httpClient = new HttpClient();
        GetMethod getMethod = new GetMethod(getUrlToTest() + "/app/");
        httpClient.executeMethod(getMethod);
        AbstractTestRestApi.shutDown();
        assert getMethod.getStatusCode() == HttpStatus.SC_OK;
    }
}
Also used : HttpClient(org.apache.commons.httpclient.HttpClient) GetMethod(org.apache.commons.httpclient.methods.GetMethod) Test(org.junit.Test)

Example 19 with GetMethod

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

the class DirAccessTest method testDirAccessForbidden.

@Test
public void testDirAccessForbidden() throws Exception {
    synchronized (this) {
        System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_SERVER_DEFAULT_DIR_ALLOWED.getVarName(), "false");
        AbstractTestRestApi.startUp();
        HttpClient httpClient = new HttpClient();
        GetMethod getMethod = new GetMethod(getUrlToTest() + "/app/");
        httpClient.executeMethod(getMethod);
        AbstractTestRestApi.shutDown();
        assert getMethod.getStatusCode() == HttpStatus.SC_FORBIDDEN;
    }
}
Also used : HttpClient(org.apache.commons.httpclient.HttpClient) GetMethod(org.apache.commons.httpclient.methods.GetMethod) Test(org.junit.Test)

Example 20 with GetMethod

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

the class ZeppelinRestApiTest method getApiRoot.

/***
   * ROOT API TEST
   ***/
@Test
public void getApiRoot() throws IOException {
    // when
    GetMethod httpGetRoot = httpGet("/");
    // then
    assertThat(httpGetRoot, isAllowed());
    httpGetRoot.releaseConnection();
}
Also used : GetMethod(org.apache.commons.httpclient.methods.GetMethod) 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