Search in sources :

Example 11 with HttpHeader

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

the class AbstractHttpResponseImplTest method it_should_get_location_header.

@Test
void it_should_get_location_header() {
    final String name = "Location";
    final String value = "http://localhost:8080";
    final V response = createHttpResponseWithHeader(name, value);
    final HttpHeader header = response.getLocation();
    assertHeader(header, name, value);
}
Also used : HttpHeader(com.github.mjeanroy.junit.servers.client.HttpHeader) Test(org.junit.jupiter.api.Test)

Example 12 with HttpHeader

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

the class AbstractHttpResponseImplTest method it_should_get_header_and_return_null_if_header_is_not_set.

@Test
void it_should_get_header_and_return_null_if_header_is_not_set() {
    final HttpHeader h1 = HttpHeader.header("Content-Type", "text/html; charset=utf-8");
    final HttpHeader h2 = HttpHeader.header("Status", "200");
    final V response = createHttpResponseWithHeaders(h1, h2);
    final HttpHeader header = response.getHeader("FooBar");
    assertThat(header).isNull();
}
Also used : HttpHeader(com.github.mjeanroy.junit.servers.client.HttpHeader) Test(org.junit.jupiter.api.Test)

Example 13 with HttpHeader

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

the class AbstractHttpResponseImplTest method it_should_get_header_case_insensitively.

@Test
void it_should_get_header_case_insensitively() {
    final HttpHeader h1 = HttpHeader.header("Content-Type", "text/html; charset=utf-8");
    final HttpHeader h2 = HttpHeader.header("Status", "200");
    final V response = createHttpResponseWithHeaders(h1, h2);
    final HttpHeader header = response.getHeader(h1.getName());
    assertThat(response.getHeader(h1.getName().toLowerCase())).isEqualTo(header);
    assertThat(response.getHeader(h1.getName().toUpperCase())).isEqualTo(header);
}
Also used : HttpHeader(com.github.mjeanroy.junit.servers.client.HttpHeader) Test(org.junit.jupiter.api.Test)

Example 14 with HttpHeader

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

the class AbstractHttpResponseImplTest method it_should_get_cache_control_header.

@Test
void it_should_get_cache_control_header() {
    final String name = "Cache-Control";
    final String value = "nocache";
    final V response = createHttpResponseWithHeader(name, value);
    final HttpHeader header = response.getCacheControl();
    assertHeader(header, name, value);
}
Also used : HttpHeader(com.github.mjeanroy.junit.servers.client.HttpHeader) Test(org.junit.jupiter.api.Test)

Example 15 with HttpHeader

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

the class AbstractHttpClient method prepareRequest.

@Override
public HttpRequest prepareRequest(HttpMethod httpMethod, String endpoint) {
    log.debug("Preparing HTTP request: {} -- {}", httpMethod, endpoint);
    notNull(endpoint, "endpoint");
    if (isDestroyed()) {
        log.error("Attempt to create HTTP request but HTTP client has already been destroyed");
        throw new IllegalStateException("Cannot create request from a destroyed client");
    }
    final HttpUrl requestEndpoint;
    if (startsWithHttpScheme(endpoint)) {
        requestEndpoint = HttpUrl.parse(endpoint);
    } else {
        String serverPath = server.getPath();
        requestEndpoint = new HttpUrl.Builder().withScheme(server.getScheme()).withHost(server.getHost()).withPort(server.getPort()).withPath(concatenatePath(serverPath, removePrefix(endpoint, serverPath))).build();
    }
    HttpRequest rq = buildRequest(httpMethod, requestEndpoint);
    // Add default headers.
    log.debug("Adding default headers");
    for (HttpHeader header : configuration.getDefaultHeaders().values()) {
        log.trace("Adding default header: {}", header);
        rq = rq.addHeader(header);
    }
    // Add default cookies.
    log.debug("Adding default cookies");
    for (Cookie cookie : configuration.getDefaultCookies()) {
        log.trace("Adding default cookie: {}", cookie);
        rq = rq.addCookie(cookie);
    }
    return rq;
}
Also used : HttpRequest(com.github.mjeanroy.junit.servers.client.HttpRequest) Cookie(com.github.mjeanroy.junit.servers.client.Cookie) HttpHeader(com.github.mjeanroy.junit.servers.client.HttpHeader) HttpUrl(com.github.mjeanroy.junit.servers.client.HttpUrl)

Aggregations

HttpHeader (com.github.mjeanroy.junit.servers.client.HttpHeader)31 Test (org.junit.jupiter.api.Test)21 ArrayList (java.util.ArrayList)4 Cookie (com.github.mjeanroy.junit.servers.client.Cookie)3 HttpResponse (com.github.mjeanroy.junit.servers.client.HttpResponse)2 Pair (com.github.mjeanroy.junit.servers.utils.commons.Pair)2 WireMockTest (com.github.mjeanroy.junit.servers.utils.jupiter.WireMockTest)2 Map (java.util.Map)2 Header (org.apache.http.Header)2 HttpClientConfiguration (com.github.mjeanroy.junit.servers.client.HttpClientConfiguration)1 HttpRequest (com.github.mjeanroy.junit.servers.client.HttpRequest)1 HttpRequestBodies.multipartBuilder (com.github.mjeanroy.junit.servers.client.HttpRequestBodies.multipartBuilder)1 HttpUrl (com.github.mjeanroy.junit.servers.client.HttpUrl)1 ToStringBuilder (com.github.mjeanroy.junit.servers.commons.lang.ToStringBuilder)1 EmbeddedServerMockBuilder (com.github.mjeanroy.junit.servers.utils.builders.EmbeddedServerMockBuilder)1 FluentCaseInsensitiveStringsMap (com.ning.http.client.FluentCaseInsensitiveStringsMap)1 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)1 HashMap (java.util.HashMap)1 List (java.util.List)1