Search in sources :

Example 11 with HttpRequest

use of com.github.dreamhead.moco.HttpRequest in project moco by dreamhead.

the class HttpRequestMatcherTest method should_not_be_match_if_request_is_different.

@Test
public void should_not_be_match_if_request_is_different() {
    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 another = DefaultHttpRequest.builder().withUri("/uri").withVersion(HttpProtocolVersion.VERSION_1_1).withMethod(HttpMethod.POST).withTextContent("different").withHeaders(of("Cookie", "loggedIn=true", "Host", "localhost:12306")).build();
    assertThat(new HttpRequestFailoverMatcher(request).match(another), is(false));
}
Also used : HttpRequest(com.github.dreamhead.moco.HttpRequest) DefaultHttpRequest(com.github.dreamhead.moco.model.DefaultHttpRequest) HttpRequestFailoverMatcher(com.github.dreamhead.moco.model.HttpRequestFailoverMatcher) Test(org.junit.Test)

Example 12 with HttpRequest

use of com.github.dreamhead.moco.HttpRequest in project moco by dreamhead.

the class MocoHandler method handleRequest.

private FullHttpResponse handleRequest(final FullHttpRequest message) {
    HttpRequest request = DefaultHttpRequest.newRequest(message);
    DefaultMutableHttpResponse httpResponse = getHttpResponse(request);
    FullHttpResponse response = httpResponse.toFullResponse();
    prepareForKeepAlive(message, response);
    monitor.onMessageLeave(httpResponse);
    return response;
}
Also used : HttpRequest(com.github.dreamhead.moco.HttpRequest) DefaultHttpRequest(com.github.dreamhead.moco.model.DefaultHttpRequest) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) DefaultMutableHttpResponse(com.github.dreamhead.moco.model.DefaultMutableHttpResponse) FullHttpResponse(io.netty.handler.codec.http.FullHttpResponse)

Example 13 with HttpRequest

use of com.github.dreamhead.moco.HttpRequest in project moco by dreamhead.

the class XmlRequestMatcherTest method should_return_false_for_empty_content.

@Test
public void should_return_false_for_empty_content() {
    XmlRequestMatcher unitUnderTest = new XmlRequestMatcher(new ContentRequestExtractor(), text("<request><parameters><id>1</id></parameters></request>"));
    HttpRequest request = DefaultHttpRequest.builder().withContent(MessageContent.content("")).build();
    assertThat(unitUnderTest.match(request), is(false));
}
Also used : HttpRequest(com.github.dreamhead.moco.HttpRequest) DefaultHttpRequest(com.github.dreamhead.moco.model.DefaultHttpRequest) ContentRequestExtractor(com.github.dreamhead.moco.extractor.ContentRequestExtractor) Test(org.junit.Test)

Aggregations

HttpRequest (com.github.dreamhead.moco.HttpRequest)13 DefaultHttpRequest (com.github.dreamhead.moco.model.DefaultHttpRequest)10 Test (org.junit.Test)8 HttpRequestFailoverMatcher (com.github.dreamhead.moco.model.HttpRequestFailoverMatcher)5 MutableHttpResponse (com.github.dreamhead.moco.MutableHttpResponse)2 Request (com.github.dreamhead.moco.Request)2 Response (com.github.dreamhead.moco.Response)2 MutableResponse (com.github.dreamhead.moco.MutableResponse)1 ContentRequestExtractor (com.github.dreamhead.moco.extractor.ContentRequestExtractor)1 DefaultMutableHttpResponse (com.github.dreamhead.moco.model.DefaultMutableHttpResponse)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)1 FullHttpResponse (io.netty.handler.codec.http.FullHttpResponse)1