Package com.github.kevinsawicki.http

Examples of com.github.kevinsawicki.http.HttpRequest.body()


        // We retrieve and store werkzeug session cookie
        String cookies = firstConnection.header("Set-Cookie");
        _cookies = HttpCookie.parse(cookies);

        // We retrieve and store OpenERP session_id
        JSONObject body = new JSONObject(firstConnection.body());
        this._sessionId = (String) body.getJSONObject("result").get("session_id");
    }

    public JSONObject getDefaultContext() {
        return _defaultContext;
View Full Code Here


        if(this._sessionId!=null) {
            params.put("session_id", this._sessionId);
        }

        HttpRequest request = JsonRpc( url, method, params);
        JSONObject jsonResponse = new JSONObject(request.body());

        if (logger.isTraceEnabled()) logger.trace("OpenERP Response: {} ", jsonResponse );

        try {
            Object result = jsonResponse.get("result");
View Full Code Here

  private HttpRequest mockRequest() throws MalformedURLException {
    HttpRequest httpRequest = mock( HttpRequest.class );
    HttpURLConnection connection = mock( HttpURLConnection.class );
    when( connection.getURL() ).thenReturn( new URL( "http://test.com" ) );
    when( httpRequest.getConnection() ).thenReturn( connection );
    when( httpRequest.body() ).thenReturn( "test" );
    when( httpRequest.code() ).thenReturn( 200 );
    when( httpRequest.contentType() ).thenReturn( MediaType.TEXT_PLAIN.toString() );
    HashMap<String, List<String>> headers = new HashMap<String, List<String>>();
    List<String> values = new ArrayList<String>();
    values.add( "test" );
View Full Code Here

        charset = "UTF-8";
      }
      if (!httpRequest.ok()) {
        throw new IOException(MessageFormat.format(STATUS_RETURNED_BY_URL_IS_INVALID, fullUrl, httpRequest.code()));
      }
      return httpRequest.body(charset);

    } catch (HttpRequest.HttpRequestException e) {
      if (e.getCause() instanceof ConnectException || e.getCause() instanceof UnknownHostException) {
        Logs.error(MessageFormat.format(SONAR_SERVER_CAN_NOT_BE_REACHED, serverUrl));
      }
View Full Code Here

     */
    boolean isReady() {
      try {
        HttpRequest httpRequest = HttpRequest.get("http://localhost:" + httpPort + "/ping")
          .readTimeout(2000).connectTimeout(2000);
        return httpRequest.ok() && httpRequest.body().equals("ping");
      } catch (HttpRequest.HttpRequestException e) {
        return false;
      }
    }

View Full Code Here

    @Test
    public void should_static_content_be_served_from_classpath() throws IOException {
        HttpRequest httpRequest = HttpRequest.get(restxServer.getServer().baseUrl() + "/web/hello.txt");

        Assertions.assertThat(httpRequest.code()).isEqualTo(200);
        Assertions.assertThat(httpRequest.body().trim()).isEqualTo("Hello world !");
    }
}
View Full Code Here

    @Test
    public void should_return_content() throws Exception {
        HttpRequest httpRequest = server.client().authenticatedAs("admin").GET("/api/optional/hasContent");
        assertThat(httpRequest.code()).isEqualTo(200);
        assertThat(httpRequest.body().trim()).isEqualTo("hello");
    }

    @Test
    public void should_return_not_found() throws Exception {
        HttpRequest httpRequest = server.client().authenticatedAs("admin").GET("/api/optional/isEmpty");
View Full Code Here

    public void should_return_optional_parameter() throws Exception {
        HttpRequest httpRequest = server.client().authenticatedAs("admin").GET("/api/optional/optionalParam");
        assertThat(httpRequest.code()).isEqualTo(404);
        httpRequest = server.client().authenticatedAs("admin").GET("/api/optional/optionalParam?param=hello");
        assertThat(httpRequest.code()).isEqualTo(200);
        assertThat(httpRequest.body().trim()).isEqualTo("hello");
    }

}
View Full Code Here

    @Test
    public void should_find_key2() throws Exception {
        HttpRequest httpRequest = server.client().authenticatedAs("admin").GET("/api/optional/settings/key2");
        assertThat(httpRequest.code()).isEqualTo(200);
        assertThat(httpRequest.body().trim()).isEqualTo("key2");
    }

}
View Full Code Here

    @Test
    public void should_not_find_foo() throws Exception {
        HttpRequest httpRequest = server.client().authenticatedAs("admin").GET("/api/optional/dependency/foo");
        assertThat(httpRequest.code()).isEqualTo(200);
        assertThat(httpRequest.body()).isEqualTo("false");
    }

    @Test
    public void should_find_bar() throws Exception {
        HttpRequest httpRequest = server.client().authenticatedAs("admin").GET("/api/optional/dependency/bar");
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.