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