Package com.github.kevinsawicki.http

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


    }
    HttpRequest request = createRequest(pBankRequest, pMethod);
    if (HttpRequest.METHOD_POST.equals(pMethod)) {
      request.form(pBankRequest.getParams());
    }
    request.code();
    BankResponse response = new DefaultBankResponse(request);
    getCache().put(pBankRequest, response);
    return response;
  }
View Full Code Here


        request.contentType(HttpRequest.CONTENT_TYPE_JSON);
        request.acceptJson();
        request.send(postData.toString());

        // We force method call
        int statusCode = request.code();

        if( statusCode != 200 ) {
            // Here, user failed to provide a valid URL so either, method or service is incorrect
            throw new OpenERPServiceOrMethodException("URL="+url);
        };
View Full Code Here

    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" );
    headers.put( "test", values );
View Full Code Here

    String fullUrl = serverUrl + path;
    try {
      Logs.debug("Download " + fullUrl + " to " + toFile.getAbsolutePath());
      HttpRequest httpRequest = newHttpRequest(new URL(fullUrl));
      if (!httpRequest.ok()) {
        throw new IOException(MessageFormat.format(STATUS_RETURNED_BY_URL_IS_INVALID, fullUrl, httpRequest.code()));
      }
      httpRequest.receive(toFile);

    } catch (Exception e) {
      if (e.getCause() instanceof ConnectException || e.getCause() instanceof UnknownHostException) {
View Full Code Here

      String charset = getCharsetFromContentType(httpRequest.contentType());
      if (charset == null || "".equals(charset)) {
        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) {
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 {
View Full Code Here

    }

    @Test
    public void should_return_not_found() throws Exception {
        HttpRequest httpRequest = server.client().authenticatedAs("admin").GET("/api/optional/isEmpty");
        assertThat(httpRequest.code()).isEqualTo(404);
    }

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

    }

    @Test
    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_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

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.