Example usage for io.netty.handler.codec.http HttpMethod GET

List of usage examples for io.netty.handler.codec.http HttpMethod GET

Introduction

In this page you can find the example usage for io.netty.handler.codec.http HttpMethod GET.

Prototype

HttpMethod GET

To view the source code for io.netty.handler.codec.http HttpMethod GET.

Click Source Link

Document

The GET method means retrieve whatever information (in the form of an entity) is identified by the Request-URI.

Usage

From source file:io.selendroid.driver.MultipleWebviewHandlingTests.java

License:Apache License

@Test
public void shouldGetContexts() throws Exception {
    openMultipleWebViewActivity();//from   ww  w .  j  a  v  a  2 s  .co  m
    SelendroidDriver driver = driver();
    String uri = "http://localhost:8080/wd/hub/session/" + driver.getSessionId() + "/contexts";

    JSONObject response = HttpClientUtil.parseJsonResponse(HttpClientUtil.executeRequest(uri, HttpMethod.GET));
    JSONArray contexts = response.getJSONArray("value");
    Assert.assertEquals(NATIVE_APP, contexts.get(0));
    Assert.assertEquals("WEBVIEW_1", contexts.get(1));
    Assert.assertEquals("WEBVIEW_0", contexts.get(2));
}

From source file:io.selendroid.driver.MultipleWebviewHandlingTests.java

License:Apache License

@Test
public void shouldSwitchContext() throws Exception {
    openMultipleWebViewActivity();//from  w  w w  . j ava 2s  . c om
    SelendroidDriver driver = driver();
    String uri = "/wd/hub/session/" + driver.getSessionId() + "/context";

    HttpClientUtil.parseJsonResponse(
            HttpClientUtil.executeRequestWithPayload(uri, 8080, HttpMethod.POST, "{'name':'WEBVIEW_0'}"));
    String getContextUri = "http://localhost:8080/wd/hub/session/" + driver.getSessionId() + "/context";

    JSONObject response = HttpClientUtil
            .parseJsonResponse(HttpClientUtil.executeRequest(getContextUri, HttpMethod.GET));
    Assert.assertEquals("WEBVIEW_0", response.getString("value"));
}

From source file:io.selendroid.server.BaseTest.java

License:Apache License

public HttpResponse executeRequest(String url, HttpMethod method) throws Exception {
    HttpRequestBase request;//  w  ww .ja va 2  s .co  m
    if (HttpMethod.GET.equals(method)) {
        request = new HttpGet(url);
    } else if (HttpMethod.POST.equals(method)) {
        request = new HttpPost(url);
    } else if (HttpMethod.DELETE.equals(method)) {
        request = new HttpDelete(url);
    } else {
        throw new RuntimeException("Provided HttpMethod not supported");
    }
    return executeRequest(request);
}

From source file:io.selendroid.server.CreateSessionHandlerTest.java

License:Apache License

@Test
public void assertNewTestSessionCreationAndGetCapabilties() throws Exception {
    HttpResponse sessionResponse = executeCreateSessionRequest();
    JSONObject json = parseJsonResponse(sessionResponse);
    String sessionId = json.getString("sessionId");

    // Get capabilities of session
    HttpResponse getCapaResp = executeRequest("http://" + host + ":" + port + "/wd/hub/session/" + sessionId,
            HttpMethod.GET);
    SelendroidAssert.assertResponseIsOk(getCapaResp);
    JSONObject capa = parseJsonResponse(getCapaResp);
    Assert.assertEquals(sessionId, capa.getString("sessionId"));
    Assert.assertEquals(0, capa.getInt("status"));

    Assert.assertEquals("selendroid", capa.getJSONObject("value").getString(Capabilities.NAME));
}

From source file:io.selendroid.server.GetStatusTest.java

License:Apache License

@Test
public void assertThatGetStatusHandlerIsRegistered() throws Exception {
    String url = "http://" + host + ":" + server.getPort() + "/wd/hub/status";
    HttpResponse response = executeRequest(url, HttpMethod.GET);
    SelendroidAssert.assertResponseIsOk(response);
    JSONObject result = parseJsonResponse(response);
    SelendroidAssert.assertResponseIsOk(response);

    Assert.assertFalse(result.has("sessionId"));
    JSONObject value = result.getJSONObject("value");
    Assert.assertEquals("0.2", value.getJSONObject("build").getString("version"));
}

From source file:io.selendroid.server.handler.InspectorTreeHandler.java

License:Apache License

@Override
public Response handle(HttpRequest request) throws JSONException {
    String sessionId = getSessionId(request);
    log.info("inspector tree handler, sessionId: " + sessionId);

    ActiveSession session;/*from w w  w .  j  a va  2  s .  c  o m*/
    if (sessionId == null || sessionId.isEmpty()) {
        if (getSelendroidDriver(request).getActiveSessions() != null
                && getSelendroidDriver(request).getActiveSessions().size() >= 1) {
            session = getSelendroidDriver(request).getActiveSessions().get(0);
            log.info("Selected sessionId: " + session.getSessionKey());
        } else {
            return new UiResponse("",
                    "Selendroid inspector can only be used if there is an active test session running. "
                            + "To start a test session, add a break point into your test code and run the test in debug mode.");
        }
    } else {
        session = getSelendroidDriver(request).getActiveSession(sessionId);
    }

    try {
        HttpResponse r = HttpClientUtil.executeRequest(
                "http://localhost:" + session.getSelendroidServerPort() + "/inspector/tree", HttpMethod.GET);
        return new JsResult(EntityUtils.toString(r.getEntity(), Charset.forName("UTF-8")));
    } catch (Exception e) {
        e.printStackTrace();
        throw new SelendroidException(e);
    }
}

From source file:io.selendroid.server.handler.RequestRedirectHandler.java

License:Apache License

private JSONObject redirectRequest(HttpRequest request, ActiveSession session, String url, String method)
        throws Exception {

    HttpResponse r = null;/* w  w w  .ja  v  a2s  . c o m*/
    if ("get".equalsIgnoreCase(method)) {
        log.info("GET redirect to: " + url);
        r = HttpClientUtil.executeRequest(url, HttpMethod.GET);
    } else if ("post".equalsIgnoreCase(method)) {
        log.info("POST redirect to: " + url);
        JSONObject payload = getPayload(request);
        log.info("Payload? " + payload);
        r = HttpClientUtil.executeRequestWithPayload(url, session.getSelendroidServerPort(), HttpMethod.POST,
                payload.toString());
    } else if ("delete".equalsIgnoreCase(method)) {
        log.info("DELETE redirect to: " + url);
        r = HttpClientUtil.executeRequest(url, HttpMethod.DELETE);
    } else {
        throw new SelendroidException("HTTP method not supported: " + method);
    }
    return HttpClientUtil.parseJsonResponse(r);
}

From source file:io.selendroid.server.HandlerRegisteredTest.java

License:Apache License

@Test
public void getFindElementHandlerRegistered() throws Exception {
    JSONObject payload = new JSONObject();
    payload.put("using", "id");
    payload.put("value", "my_button_bar");

    String url = "http://" + host + ":" + port + "/wd/hub/session/1234567890/element";
    HttpResponse response = executeRequestWithPayload(url, HttpMethod.GET, payload.toString());
    SelendroidAssert.assertResponseIsOk(response);

    JSONObject responseJSON = parseJsonResponse(response);
    assertEquals("0", responseJSON.getString("status"));
    assertEquals("sessionId#1234567890 using#id value#my_button_bar", responseJSON.getString("value"));
}

From source file:io.selendroid.server.SelendroidSatusHandlerTest.java

License:Apache License

public void assertThatGetStatusHandlerIsRegistered() throws Exception {
    HttpResponse response = HttpClientUtil.executeRequest(URL, HttpMethod.GET);
    SelendroidAssert.assertResponseIsOk(response);
    JSONObject result = HttpClientUtil.parseJsonResponse(response);
    SelendroidAssert.assertResponseIsOk(response);

    Assert.assertFalse(result.has("sessionId"));
    JSONObject value = result.getJSONObject("value");
    Assert.assertEquals("dev", value.getJSONObject("build").getString("version"));
}

From source file:io.selendroid.server.support.DeviceForTest.java

License:Apache License

@Override
public boolean isSelendroidRunning() {
    if (selendroidDeviceServerStub == null) {
        return false;
    }/*w  w w  .j  a  v a 2  s  .  c o  m*/
    int status;

    try {
        HttpResponse r = HttpClientUtil.executeRequest(
                "http://localhost:" + selendroidDeviceServerStub.getPort() + "/wd/hub/status", HttpMethod.GET);
        JSONObject response = HttpClientUtil.parseJsonResponse(r);
        status = response.getInt("status");
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return 0 == status ? true : false;
}