use of com.github.mjeanroy.junit.servers.client.HttpMethod in project junit-servers by mjeanroy.
the class BaseHttpClientTest method it_should_create_request_and_do_not_prepend_server_url.
@Test
void it_should_create_request_and_do_not_prepend_server_url() {
final HttpClient client = createDefaultClient(server);
final String endpoint = "/foo";
final String absoluteUrl = server.getUrl() + endpoint;
final HttpMethod httpMethod = HttpMethod.POST;
final HttpRequest httpRequest = client.prepareRequest(httpMethod, absoluteUrl);
assertThat(httpRequest.getMethod()).isEqualTo(httpMethod);
assertThat(httpRequest.getEndpoint()).isNotNull();
assertThat(httpRequest.getEndpoint().getScheme()).isEqualTo(scheme);
assertThat(httpRequest.getEndpoint().getHost()).isEqualTo(host);
assertThat(httpRequest.getEndpoint().getPort()).isEqualTo(port);
assertThat(httpRequest.getEndpoint().getPath()).isEqualTo(path + endpoint);
assertThat(httpRequest.getEndpoint().toString()).isEqualTo(url(scheme, host, port, path + endpoint));
}
use of com.github.mjeanroy.junit.servers.client.HttpMethod in project junit-servers by mjeanroy.
the class BaseHttpClientTest method it_should_create_request_with_root_path.
@Test
void it_should_create_request_with_root_path() {
final String serverUrl = url(scheme, host, 8080, "");
final String path = "/";
when(server.getUrl()).thenReturn(serverUrl);
when(server.getPath()).thenReturn(path);
final HttpClient client = createDefaultClient(server);
final HttpMethod httpMethod = HttpMethod.GET;
final HttpRequest httpRequest = client.prepareRequest(httpMethod, path);
assertThat(httpRequest.getEndpoint()).isNotNull();
assertThat(httpRequest.getEndpoint().getScheme()).isEqualTo(scheme);
assertThat(httpRequest.getEndpoint().getHost()).isEqualTo(host);
assertThat(httpRequest.getEndpoint().getPort()).isEqualTo(port);
assertThat(httpRequest.getEndpoint().getPath()).isEqualTo(path);
assertThat(httpRequest.getEndpoint().toString()).isEqualTo(localUrl(port));
}
use of com.github.mjeanroy.junit.servers.client.HttpMethod in project junit-servers by mjeanroy.
the class BaseHttpClientTest method it_should_create_request_and_set_path_separator.
@Test
void it_should_create_request_and_set_path_separator() {
final String serverUrl = url(scheme, host, port, "");
when(server.getUrl()).thenReturn(serverUrl);
when(server.getPath()).thenReturn("/");
final HttpClient client = createDefaultClient(server);
final String path = "/foo";
final HttpMethod httpMethod = HttpMethod.GET;
final HttpRequest httpRequest = client.prepareRequest(httpMethod, path);
assertThat(httpRequest.getEndpoint()).isNotNull();
assertThat(httpRequest.getEndpoint().getScheme()).isEqualTo(scheme);
assertThat(httpRequest.getEndpoint().getHost()).isEqualTo(host);
assertThat(httpRequest.getEndpoint().getPort()).isEqualTo(port);
assertThat(httpRequest.getEndpoint().getPath()).isEqualTo(path);
assertThat(httpRequest.getEndpoint().toString()).isEqualTo(url(scheme, host, port, path));
}
use of com.github.mjeanroy.junit.servers.client.HttpMethod in project junit-servers by mjeanroy.
the class BaseHttpClientTest method it_should_create_request_and_do_not_prepend_server_path.
@Test
void it_should_create_request_and_do_not_prepend_server_path() {
final HttpClient client = createDefaultClient(server);
final String endpoint = "/foo";
final String fullPath = server.getPath() + endpoint;
final HttpMethod httpMethod = HttpMethod.POST;
final HttpRequest httpRequest = client.prepareRequest(httpMethod, fullPath);
assertThat(httpRequest.getMethod()).isEqualTo(httpMethod);
assertThat(httpRequest.getEndpoint()).isNotNull();
assertThat(httpRequest.getEndpoint().getScheme()).isEqualTo(scheme);
assertThat(httpRequest.getEndpoint().getHost()).isEqualTo(host);
assertThat(httpRequest.getEndpoint().getPort()).isEqualTo(port);
assertThat(httpRequest.getEndpoint().getPath()).isEqualTo(fullPath);
assertThat(httpRequest.getEndpoint().toString()).isEqualTo(url(scheme, host, port, fullPath));
}
use of com.github.mjeanroy.junit.servers.client.HttpMethod in project junit-servers by mjeanroy.
the class ApacheHttpRequest method doExecute.
@Override
protected HttpResponse doExecute() throws Exception {
final HttpMethod method = getMethod();
final HttpRequestBase httpRequest = FACTORY.create(method);
httpRequest.setURI(createRequestURI());
handleBody(httpRequest);
handleHeaders(httpRequest);
handleCookies(httpRequest);
final long start = nanoTime();
final org.apache.http.HttpResponse httpResponse = client.execute(httpRequest);
final long duration = nanoTime() - start;
return ApacheHttpResponseFactory.of(httpResponse, duration);
}
Aggregations