use of com.github.dreamhead.moco.HttpRequest in project moco by dreamhead.
the class AbstractContentResponseHandler method writeToResponse.
@Override
public final void writeToResponse(final SessionContext context) {
Request request = context.getRequest();
Response response = context.getResponse();
if (HttpRequest.class.isInstance(request) && MutableHttpResponse.class.isInstance(response)) {
HttpRequest httpRequest = HttpRequest.class.cast(request);
MutableHttpResponse httpResponse = MutableHttpResponse.class.cast(response);
doWriteToResponse(httpRequest, httpResponse);
return;
}
MutableResponse mutableResponse = MutableResponse.class.cast(response);
mutableResponse.setContent(requireResponseContent(request));
}
use of com.github.dreamhead.moco.HttpRequest in project moco by dreamhead.
the class AbstractHttpResponseHandler method writeToResponse.
@Override
public final void writeToResponse(final SessionContext context) {
Request request = context.getRequest();
Response response = context.getResponse();
if (HttpRequest.class.isInstance(request) && MutableHttpResponse.class.isInstance(response)) {
HttpRequest httpRequest = HttpRequest.class.cast(request);
MutableHttpResponse httpResponse = MutableHttpResponse.class.cast(response);
doWriteToResponse(httpRequest, httpResponse);
}
}
use of com.github.dreamhead.moco.HttpRequest in project moco by dreamhead.
the class HttpRequestMatcherTest method should_be_match_if_failover_field_is_null.
@Test
public void should_be_match_if_failover_field_is_null() {
HttpRequest request = DefaultHttpRequest.builder().withUri("/uri").withVersion(HttpProtocolVersion.VERSION_1_1).withMethod(HttpMethod.POST).withTextContent("proxy").withHeaders(of("Cookie", "loggedIn=true", "Host", "localhost:12306")).build();
HttpRequest failover = DefaultHttpRequest.builder().withUri("/uri").withMethod(HttpMethod.POST).withTextContent("proxy").withHeaders(of("Cookie", "loggedIn=true", "Host", "localhost:12306")).build();
assertThat(new HttpRequestFailoverMatcher(failover).match(request), is(true));
}
use of com.github.dreamhead.moco.HttpRequest in project moco by dreamhead.
the class HttpRequestMatcherTest method should_be_match_even_if_target_request_has_more_headers.
@Test
public void should_be_match_even_if_target_request_has_more_headers() {
HttpRequest request = DefaultHttpRequest.builder().withUri("/uri").withVersion(HttpProtocolVersion.VERSION_1_1).withMethod(HttpMethod.POST).withTextContent("proxy").withHeaders(of("Cookie", "loggedIn=true", "Host", "localhost:12306")).build();
HttpRequest failover = DefaultHttpRequest.builder().withUri("/uri").withVersion(HttpProtocolVersion.VERSION_1_1).withMethod(HttpMethod.POST).withTextContent("proxy").withHeaders(of("Host", "localhost:12306")).build();
assertThat(new HttpRequestFailoverMatcher(failover).match(request), is(true));
}
use of com.github.dreamhead.moco.HttpRequest in project moco by dreamhead.
the class TemplateRequest method getQueries.
public ImmutableMap<String, String> getQueries() {
if (this.request instanceof HttpRequest) {
HttpRequest httpRequest = (HttpRequest) this.request;
ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
ImmutableMap<String, String[]> queries = httpRequest.getQueries();
for (String key : queries.keySet()) {
builder.put(key, queries.get(key)[0]);
}
return builder.build();
}
throw new IllegalArgumentException("Request is not HTTP request");
}
Aggregations