private HttpUriRequest createAuthenticationRequest() { final Map<String, String> parameters = new HashMap<>(); parameters.put("username", username); parameters.put("password", password); return HttpUriRequestBuilder.create() .method(HttpMethods.POST) .methodParameters(parameters) .path(loginUrl) .build(); }
private CloseableHttpResponse createAndExecuteRequest(final HttpMethods method, final String path, final Map<String, String> parameters, final Optional<String> jsonPayLoad) throws CloudstackRESTException { final HttpUriRequest httpRequest = HttpUriRequestBuilder.create() .path(path) .parameters(parameters) .jsonPayload(jsonPayLoad) .method(method) .build(); if (jsonPayLoad.isPresent()) { s_logger.debug("Built request '" + httpRequest + "' with payload: " + jsonPayLoad); } return executeRequest(httpRequest); }
@Test public void testBuildSimpleRequest() throws Exception { final HttpUriRequest request = HttpUriRequestBuilder.create() .method(HttpMethods.GET) .path("/path") .build(); assertThat(request, notNullValue()); assertThat(request.getURI().getPath(), equalTo("/path")); assertThat(request.getURI().getScheme(), nullValue()); assertThat(request.getURI().getQuery(), nullValue()); assertThat(request.getURI().getHost(), nullValue()); assertThat(request.getMethod(), equalTo(HttpGet.METHOD_NAME)); }
@Test public void testBuildRequestWithParameters() throws Exception { final HashMap<String, String> parameters = new HashMap<String, String>(); parameters.put("key1", "value1"); final HttpUriRequest request = HttpUriRequestBuilder.create() .method(HttpMethods.GET) .path("/path") .parameters(parameters) .build(); assertThat(request, notNullValue()); assertThat(request.getURI().getPath(), equalTo("/path")); assertThat(request.getURI().getQuery(), equalTo("key1=value1")); assertThat(request.getURI().getScheme(), nullValue()); assertThat(request.getURI().getHost(), nullValue()); assertThat(request.getMethod(), equalTo(HttpGet.METHOD_NAME)); }
@Test public void testBuildRequestWithJsonPayload() throws Exception { final HttpUriRequest request = HttpUriRequestBuilder.create() .method(HttpMethods.GET) .path("/path") .jsonPayload(Optional.of("{'key1':'value1'}")) .build(); assertThat(request, notNullValue()); assertThat(request.getURI().getPath(), equalTo("/path")); assertThat(request.getURI().getScheme(), nullValue()); assertThat(request.getURI().getQuery(), nullValue()); assertThat(request.getURI().getHost(), nullValue()); assertThat(request.getMethod(), equalTo(HttpGet.METHOD_NAME)); assertThat(request.containsHeader(HttpConstants.CONTENT_TYPE), equalTo(true)); assertThat(request.getFirstHeader(HttpConstants.CONTENT_TYPE).getValue(), equalTo(HttpConstants.JSON_CONTENT_TYPE)); assertThat(request, HttpUriRequestPayloadMatcher.hasPayload("{'key1':'value1'}")); }
@Test(expected = IllegalArgumentException.class) public void testBuildWithNullPath() throws Exception { HttpUriRequestBuilder.create().method(HttpMethods.GET).build(); }
@BeforeClass public static void setupClass() throws Exception { request = HttpUriRequestBuilder.create() .method(HttpMethods.GET) .path("/path") .build(); httpClient = spy(HttpClientHelper.createHttpClient(2)); }
@Test(expected = IllegalArgumentException.class) public void testBuildWithIlegalPath() throws Exception { HttpUriRequestBuilder.create() .method(HttpMethods.GET) .path("path") .build(); }
@Test(expected = IllegalArgumentException.class) public void testBuildWithEmptyPath() throws Exception { HttpUriRequestBuilder.create() .method(HttpMethods.GET) .path("") .build(); }
private CloseableHttpResponse createAndExecuteRequest(final HttpMethods method, final String path, final Map<String, String> parameters, final Optional<String> jsonPayLoad) throws CosmicRESTException { final HttpUriRequest httpRequest = HttpUriRequestBuilder.create() .path(path) .parameters(parameters) .jsonPayload(jsonPayLoad) .method(method) .build(); if (jsonPayLoad.isPresent()) { s_logger.debug("Built request '" + httpRequest + "' with payload: " + jsonPayLoad); } return executeRequest(httpRequest); }
@Test public void testBuildSimpleRequest() throws Exception { final HttpUriRequest request = HttpUriRequestBuilder.create() .method(HttpMethods.GET) .path("/path") .build(); assertThat(request, notNullValue()); assertThat(request.getURI().getPath(), equalTo("/path")); assertThat(request.getURI().getScheme(), nullValue()); assertThat(request.getURI().getQuery(), nullValue()); assertThat(request.getURI().getHost(), nullValue()); assertThat(request.getMethod(), equalTo(HttpGet.METHOD_NAME)); }
@Test public void testBuildRequestWithParameters() throws Exception { final HashMap<String, String> parameters = new HashMap<>(); parameters.put("key1", "value1"); final HttpUriRequest request = HttpUriRequestBuilder.create() .method(HttpMethods.GET) .path("/path") .parameters(parameters) .build(); assertThat(request, notNullValue()); assertThat(request.getURI().getPath(), equalTo("/path")); assertThat(request.getURI().getQuery(), equalTo("key1=value1")); assertThat(request.getURI().getScheme(), nullValue()); assertThat(request.getURI().getHost(), nullValue()); assertThat(request.getMethod(), equalTo(HttpGet.METHOD_NAME)); }
@Test public void testBuildRequestWithJsonPayload() throws Exception { final HttpUriRequest request = HttpUriRequestBuilder.create() .method(HttpMethods.GET) .path("/path") .jsonPayload(Optional.of("{'key1':'value1'}")) .build(); assertThat(request, notNullValue()); assertThat(request.getURI().getPath(), equalTo("/path")); assertThat(request.getURI().getScheme(), nullValue()); assertThat(request.getURI().getQuery(), nullValue()); assertThat(request.getURI().getHost(), nullValue()); assertThat(request.getMethod(), equalTo(HttpGet.METHOD_NAME)); assertThat(request.containsHeader(HttpConstants.CONTENT_TYPE), equalTo(true)); assertThat(request.getFirstHeader(HttpConstants.CONTENT_TYPE).getValue(), equalTo(HttpConstants.JSON_CONTENT_TYPE)); assertThat(request, HttpUriRequestPayloadMatcher.hasPayload("{'key1':'value1'}")); } }
@Test(expected = IllegalArgumentException.class) public void testBuildWithNullPath() throws Exception { HttpUriRequestBuilder.create().method(HttpMethods.GET).build(); }
@BeforeClass public static void setupClass() throws Exception { request = HttpUriRequestBuilder.create() .method(HttpMethods.GET) .path("/path") .build(); httpClient = spy(HttpClientHelper.createHttpClient(2)); }
@Test(expected = IllegalArgumentException.class) public void testBuildWithEmptyPath() throws Exception { HttpUriRequestBuilder.create() .method(HttpMethods.GET) .path("") .build(); }
@Test(expected = IllegalArgumentException.class) public void testBuildWithIlegalPath() throws Exception { HttpUriRequestBuilder.create() .method(HttpMethods.GET) .path("path") .build(); }