HttpCallImplWithConnectionPooling implements HttpCall<T> { @Override public T makeRequest(final String httpMethod, final String url, final Object data, final Class<T> toMap, final Map<String, String> headers, final Map<String, String> queryParams, final String accept, final String type, final int expectedStatus) { return (T) makeRequest(httpMethod, HttpCallConfig.Builder.aHttpCallConfig() .withUrl(url) .withData(data) .withToMap(toMap) .withHeaders(headers) .withQueryParams(queryParams) .withAccept(accept) .withType(type) .withExpectedStatus(expectedStatus).build()); } @Inject  HttpCallImplWithConnectionPooling(); @Override T makeRequest(final String httpMethod, final String url, final Object data, final Class<T> toMap,
                         final Map<String, String> headers, final Map<String, String> queryParams,
                         final String accept, final String type, final int expectedStatus); @Override T makeRequest(final String httpMethod, final HttpCallConfig<T> config); @Override WebResource.Builder addHeaders(final WebResource webResource, final Map<String, String> headers,
                                          final String accept, final String type); @Override WebResource addQueryParams(final WebResource webResource, Map<String, String> queryParams); @Override T doGet(final String url, final Class<T> toMap, final Map<String, String> headers,
                   final Map<String, String> queryParams, final String accept, final int expectedStatus); @Override T doPost(final String url, final Object data, final Class<T> toMap, final Map<String, String> headers,
                    final Map<String, String> queryParams, final String accept, final String type,
                    final int expectedStatus); @Override T doPost(final HttpCallConfig<T> httpCallConfig); @Override T doGet(final HttpCallConfig<T> httpCallConfig); @Override T doPut(final HttpCallConfig<T> httpCallConfig); @Override T doDelete(final HttpCallConfig<T> httpCallConfig); @Override T doPut(final String url, final Object data, final Class<T> toMap, final Map<String, String> headers,
                   final Map<String, String> queryParams, final String accept, final String type,
                   final int expectedStatus); @Override T doDelete(final String url, final Class<T> toMap, final Map<String, String> headers,
                      final Map<String, String> queryParams, final String accept, final int expectedStatus);  }
@Test public void testMakeRequest() throws Exception { try { httpCallsImpl.makeRequest(OPTIONS, url, null, ClientResponse.class, map, map, accept, type, ORDINAL_200_OK); fail(); } catch (UnsupportedOperationException ignored) { } try { httpCallsImpl.makeRequest(HEAD, url, null, ClientResponse.class, map, map, accept, type, ORDINAL_200_OK); fail(); } catch (UnsupportedOperationException ignored) { } stubFor(get(urlEqualTo("/test")) .withHeader(ACCEPT, equalTo(accept)) .withHeader(CONTENT_TYPE, equalTo(type)) .withHeader("foo", equalTo(map.get("foo"))) .withHeader("dead", equalTo(map.get("dead"))) .willReturn(aResponse().withStatus(ORDINAL_200_OK))); ClientResponse response = httpCallsImpl.makeRequest(GET, url, null, ClientResponse.class, map, null, accept, type, ORDINAL_200_OK); assertThat(response.getStatus(), is(ORDINAL_200_OK)); try { httpCallsImpl.makeRequest(GET, url, null, ClientResponse.class, map, null, accept, type, ORDINAL_201_Created); fail(); } catch (RuntimeException ignored) { } response = httpCallsImpl.makeRequest(GET, url, null, null, null, null, accept, type, ORDINAL_404_Not_Found); assertThat(response.getStatus(), is(ORDINAL_404_Not_Found)); }
@Test public void testMakeRequestGet() throws Exception { stubFor(get(urlEqualTo("/test")) .withHeader(ACCEPT, equalTo(accept)) .withHeader(CONTENT_TYPE, equalTo(type)) .withHeader("foo", equalTo(map.get("foo"))) .withHeader("dead", equalTo(map.get("dead"))) .willReturn(aResponse().withStatus(ORDINAL_200_OK))); ClientResponse response = httpCallsImpl.makeRequest(GET, url, null, ClientResponse.class, map, null, accept, type, ORDINAL_200_OK); assertThat(response.getStatus(), is(ORDINAL_200_OK)); try { httpCallsImpl.makeRequest(GET, url, null, null, map, null, accept, type, ORDINAL_201_Created); fail(); } catch (RuntimeException ignored) { } response = httpCallsImpl.makeRequest(GET, url, null, ClientResponse.class, null, null, accept, type, ORDINAL_404_Not_Found); assertThat(response.getStatus(), is(ORDINAL_404_Not_Found)); }
@Test public void testMakeRequestPost() throws Exception { stubFor(post(urlEqualTo("/test")) .withHeader(ACCEPT, equalTo(accept)) .withHeader(CONTENT_TYPE, equalTo(type)) .withHeader("foo", equalTo(map.get("foo"))) .withHeader("dead", equalTo(map.get("dead"))) .willReturn(aResponse().withStatus(ORDINAL_200_OK))); ClientResponse response = httpCallsImpl.makeRequest(POST, url, null, ClientResponse.class, map, null, accept, type, ORDINAL_200_OK); assertThat(response.getStatus(), is(ORDINAL_200_OK)); }
@Test public void testMakeRequestPut() throws Exception { stubFor(put(urlEqualTo("/test")) .withHeader(ACCEPT, equalTo(accept)) .withHeader(CONTENT_TYPE, equalTo(type)) .withHeader("foo", equalTo(map.get("foo"))) .withHeader("dead", equalTo(map.get("dead"))) .willReturn(aResponse().withStatus(ORDINAL_200_OK))); ClientResponse response = httpCallsImpl.makeRequest(PUT, url, null, ClientResponse.class, map, null, accept, type, ORDINAL_200_OK); assertThat(response.getStatus(), is(ORDINAL_200_OK)); }
@Test public void testMakeRequestDelete() throws Exception { stubFor(delete(urlEqualTo("/test")) .withHeader(ACCEPT, equalTo(accept)) .withHeader(CONTENT_TYPE, equalTo(type)) .withHeader("foo", equalTo(map.get("foo"))) .withHeader("dead", equalTo(map.get("dead"))) .willReturn(aResponse().withStatus(ORDINAL_200_OK))); ClientResponse response = httpCallsImpl.makeRequest(DELETE, url, null, ClientResponse.class, map, null, accept, type, ORDINAL_200_OK); assertThat(response.getStatus(), is(ORDINAL_200_OK)); }