Search in sources :

Example 6 with HttpRequest

use of com.github.mjeanroy.junit.servers.client.HttpRequest 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));
}
Also used : HttpRequest(com.github.mjeanroy.junit.servers.client.HttpRequest) HttpClient(com.github.mjeanroy.junit.servers.client.HttpClient) HttpMethod(com.github.mjeanroy.junit.servers.client.HttpMethod) Test(org.junit.jupiter.api.Test)

Example 7 with HttpRequest

use of com.github.mjeanroy.junit.servers.client.HttpRequest in project junit-servers by mjeanroy.

the class BaseHttpClientTest method it_should_create_post_request.

@Test
void it_should_create_post_request() {
    final HttpClient client = createDefaultClient(server);
    final HttpRequest httpRequest = client.preparePost("/foo");
    assertThat(httpRequest.getMethod()).isEqualTo(HttpMethod.POST);
}
Also used : HttpRequest(com.github.mjeanroy.junit.servers.client.HttpRequest) HttpClient(com.github.mjeanroy.junit.servers.client.HttpClient) Test(org.junit.jupiter.api.Test)

Example 8 with HttpRequest

use of com.github.mjeanroy.junit.servers.client.HttpRequest 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));
}
Also used : HttpRequest(com.github.mjeanroy.junit.servers.client.HttpRequest) HttpClient(com.github.mjeanroy.junit.servers.client.HttpClient) HttpMethod(com.github.mjeanroy.junit.servers.client.HttpMethod) Test(org.junit.jupiter.api.Test)

Example 9 with HttpRequest

use of com.github.mjeanroy.junit.servers.client.HttpRequest 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));
}
Also used : HttpRequest(com.github.mjeanroy.junit.servers.client.HttpRequest) HttpClient(com.github.mjeanroy.junit.servers.client.HttpClient) HttpMethod(com.github.mjeanroy.junit.servers.client.HttpMethod) Test(org.junit.jupiter.api.Test)

Example 10 with HttpRequest

use of com.github.mjeanroy.junit.servers.client.HttpRequest in project junit-servers by mjeanroy.

the class BaseHttpClientTest method it_should_create_get_request.

@Test
void it_should_create_get_request() {
    final HttpClient client = createDefaultClient(server);
    final HttpRequest httpRequest = client.prepareGet("/foo");
    assertThat(httpRequest.getMethod()).isEqualTo(HttpMethod.GET);
}
Also used : HttpRequest(com.github.mjeanroy.junit.servers.client.HttpRequest) HttpClient(com.github.mjeanroy.junit.servers.client.HttpClient) Test(org.junit.jupiter.api.Test)

Aggregations

HttpRequest (com.github.mjeanroy.junit.servers.client.HttpRequest)16 Test (org.junit.jupiter.api.Test)11 HttpClient (com.github.mjeanroy.junit.servers.client.HttpClient)9 HttpMethod (com.github.mjeanroy.junit.servers.client.HttpMethod)5 HttpResponse (com.github.mjeanroy.junit.servers.client.HttpResponse)4 Pair (com.github.mjeanroy.junit.servers.utils.commons.Pair)3 WireMockTest (com.github.mjeanroy.junit.servers.utils.jupiter.WireMockTest)2 Cookie (com.github.mjeanroy.junit.servers.client.Cookie)1 HttpHeader (com.github.mjeanroy.junit.servers.client.HttpHeader)1 HttpUrl (com.github.mjeanroy.junit.servers.client.HttpUrl)1