Search in sources :

Example 1 with HttpHeader

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

the class DefaultHttpResponseTest method it_should_create_http_response.

@Test
void it_should_create_http_response() {
    final long duration = 1000L;
    final int status = 200;
    final String body = "The response body";
    final HttpHeader header = header("Content-Type", "text/plain");
    final Set<HttpHeader> headers = singleton(header);
    final DefaultHttpResponse response = DefaultHttpResponse.of(duration, status, body, headers);
    assertThat(response).isNotNull();
    assertThat(response.getRequestDuration()).isEqualTo(duration);
    assertThat(response.status()).isEqualTo(status);
    assertThat(response.body()).isEqualTo(body);
    assertThat(response.getHeaders()).hasSize(1).extracting("name", "values").containsOnly(tuple(header.getName(), header.getValues()));
}
Also used : HttpHeader(com.github.mjeanroy.junit.servers.client.HttpHeader) Test(org.junit.jupiter.api.Test)

Example 2 with HttpHeader

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

the class DefaultHttpResponseTest method it_should_get_header_case_insensitively.

@Test
void it_should_get_header_case_insensitively() {
    final long duration = 1000L;
    final int status = 200;
    final String body = "The response body";
    final HttpHeader header = header("Content-Type", "text/plain");
    final Set<HttpHeader> headers = singleton(header);
    final DefaultHttpResponse response = DefaultHttpResponse.of(duration, status, body, headers);
    assertThat(response.getHeader("Content-Type")).isEqualTo(header);
    assertThat(response.getHeader("content-type")).isEqualTo(header);
    assertThat(response.getHeader("CONTENT-TYPE")).isEqualTo(header);
}
Also used : HttpHeader(com.github.mjeanroy.junit.servers.client.HttpHeader) Test(org.junit.jupiter.api.Test)

Example 3 with HttpHeader

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

the class BaseHttpClientTest method testRequest_with_custom_header_instance.

@Test
void testRequest_with_custom_header_instance() {
    final String name = "X-Custom-Header";
    final String value = "FooBar";
    final HttpHeader header = HttpHeader.header(name, value);
    testRequestHeader(name, value, rq -> rq.addHeader(header));
}
Also used : HttpHeader(com.github.mjeanroy.junit.servers.client.HttpHeader) WireMockTest(com.github.mjeanroy.junit.servers.utils.jupiter.WireMockTest) Test(org.junit.jupiter.api.Test)

Example 4 with HttpHeader

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

the class BaseHttpClientTest method testResponseHeader.

private void testResponseHeader(String name, String value, MapperFunction<HttpResponse, HttpHeader> func) {
    final String endpoint = ENDPOINT;
    final int status = 200;
    final Collection<Pair> headers = singleton(pair(name, value));
    final String body = null;
    stubGetRequest(endpoint, status, headers, body);
    final HttpResponse rsp = createDefaultClient().prepareGet(endpoint).addAcceptEncoding("identity").executeJson();
    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(singletonList(value));
    assertThat(header.getFirstValue()).isEqualTo(value);
    assertThat(header.getLastValue()).isEqualTo(value);
    assertThat(rsp.getHeaders()).extracting("name", "values").contains(tuple(name, singletonList(value)));
}
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 5 with HttpHeader

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

the class AbstractHttpResponseImplTest method it_should_get_strict_transport_security_header.

@Test
void it_should_get_strict_transport_security_header() {
    final String name = "Strict-Transport-Security";
    final String value = "max-age=3600; includeSubDomains; preload";
    final V response = createHttpResponseWithHeader(name, value);
    final HttpHeader header = response.getStrictTransportSecurity();
    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