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()));
}
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);
}
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));
}
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)));
}
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);
}
Aggregations