Search in sources :

Example 21 with HttpHeader

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

the class AsyncHttpResponse method getHeaders.

@Override
public Collection<HttpHeader> getHeaders() {
    HttpHeaders headers = response.getHeaders();
    List<HttpHeader> results = new ArrayList<>(headers.size());
    for (Map.Entry<String, String> entry : headers) {
        String name = entry.getKey();
        List<String> values = headers.getAll(name);
        results.add(HttpHeader.header(name, values));
    }
    return results;
}
Also used : HttpHeaders(io.netty.handler.codec.http.HttpHeaders) HttpHeader(com.github.mjeanroy.junit.servers.client.HttpHeader) ArrayList(java.util.ArrayList) Map(java.util.Map)

Example 22 with HttpHeader

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

the class BaseHttpClientTest method testRequestWithDefaultHeaderObject.

@Test
void testRequestWithDefaultHeaderObject() {
    final String name = "X-Custom-Header";
    final String value = "FooBar";
    final HttpHeader header = HttpHeader.header(name, value);
    final HttpClientConfiguration configuration = new HttpClientConfiguration.Builder().addDefaultHeader(header).build();
    stubDefaultRequest(ENDPOINT);
    testRequestHeader(createCustomClient(configuration), name, value, rq -> {
    });
}
Also used : HttpHeader(com.github.mjeanroy.junit.servers.client.HttpHeader) EmbeddedServerMockBuilder(com.github.mjeanroy.junit.servers.utils.builders.EmbeddedServerMockBuilder) HttpRequestBodies.multipartBuilder(com.github.mjeanroy.junit.servers.client.HttpRequestBodies.multipartBuilder) HttpClientConfiguration(com.github.mjeanroy.junit.servers.client.HttpClientConfiguration) WireMockTest(com.github.mjeanroy.junit.servers.utils.jupiter.WireMockTest) Test(org.junit.jupiter.api.Test)

Example 23 with HttpHeader

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

the class BaseHttpClientTest method testResponseWithSeveralValues.

private void testResponseWithSeveralValues(String name, List<String> values, MapperFunction<HttpResponse, HttpHeader> func) {
    // GIVEN
    final String endpoint = ENDPOINT;
    final int status = 200;
    final String body = null;
    final Collection<Pair> headers = singleton(pair(name, values));
    stubGetRequest(endpoint, status, headers, body);
    // WHEN
    final HttpResponse rsp = createDefaultClient().prepareGet(endpoint).addAcceptEncoding("identity").executeJson();
    // THEN
    final HttpHeader header = rsp.getHeader(name);
    assertThat(rsp.containsHeader(name)).isTrue();
    assertThat(func.apply(rsp)).isEqualTo(header);
    assertThat(header.getName()).isEqualTo(name);
    assertThat(header.getValues()).isEqualTo(values);
    assertThat(header.getFirstValue()).isEqualTo(values.get(0));
    assertThat(header.getLastValue()).isEqualTo(values.get(values.size() - 1));
    assertThat(rsp.getHeaders()).extracting("name", "values").contains(tuple(name, values));
}
Also used : HttpHeader(com.github.mjeanroy.junit.servers.client.HttpHeader) HttpResponse(com.github.mjeanroy.junit.servers.client.HttpResponse) Pair(com.github.mjeanroy.junit.servers.utils.commons.Pair)

Example 24 with HttpHeader

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

the class AbstractHttpResponseImplTest method it_should_get_etag_header.

@Test
void it_should_get_etag_header() {
    final String name = "ETag";
    final String value = UUID.randomUUID().toString();
    final V response = createHttpResponseWithHeader(name, value);
    final HttpHeader header = response.getETag();
    assertHeader(header, name, value);
}
Also used : HttpHeader(com.github.mjeanroy.junit.servers.client.HttpHeader) Test(org.junit.jupiter.api.Test)

Example 25 with HttpHeader

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

the class AbstractHttpResponseImplTest method it_should_get_content_security_policy_header.

@Test
void it_should_get_content_security_policy_header() {
    final String name = "Content-Security-Policy";
    final String value = "default-src 'self'";
    final V response = createHttpResponseWithHeader(name, value);
    final HttpHeader header = response.getContentSecurityPolicy();
    assertHeader(header, name, value);
}
Also used : HttpHeader(com.github.mjeanroy.junit.servers.client.HttpHeader) Test(org.junit.jupiter.api.Test)

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