Search in sources :

Example 11 with Runnable

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

the class MocoConnectionTest method should_not_keep_alive_for_close_request.

@Test
public void should_not_keep_alive_for_close_request() throws Exception {
    server.response("foo");
    running(server, new Runnable() {

        @Override
        public void run() throws Exception {
            Response response = Request.Get(root()).addHeader("Connection", "close").execute();
            assertThat(response.returnResponse().getFirstHeader("Connection"), nullValue());
        }
    });
}
Also used : Response(org.apache.http.client.fluent.Response) Runnable(com.github.dreamhead.moco.Runnable) AbstractMocoHttpTest(com.github.dreamhead.moco.AbstractMocoHttpTest) Test(org.junit.Test)

Example 12 with Runnable

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

the class ActualHttpServerTest method should_merge_http_server_with_any_handler_one_side.

@Test
public void should_merge_http_server_with_any_handler_one_side() throws Exception {
    HttpServer mergedServer = ((ActualHttpServer) anotherServer).mergeServer((ActualHttpServer) httpServer);
    running(mergedServer, new Runnable() {

        @Override
        public void run() throws Exception {
            assertThat(helper.get(remoteUrl("/foo/anything")), is("foo"));
        }
    });
}
Also used : Runnable(com.github.dreamhead.moco.Runnable) HttpServer(com.github.dreamhead.moco.HttpServer) HttpResponseException(org.apache.http.client.HttpResponseException) IOException(java.io.IOException) AbstractMocoHttpTest(com.github.dreamhead.moco.AbstractMocoHttpTest) Test(org.junit.Test)

Example 13 with Runnable

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

the class ActualHttpServerTest method should_merge_https_server.

@Test
public void should_merge_https_server() throws Exception {
    anotherServer = httpsServer(12306, DEFAULT_CERTIFICATE, context("/bar"));
    HttpServer mergedServer = ((ActualHttpServer) anotherServer).mergeServer((ActualHttpServer) httpServer);
    running(mergedServer, new Runnable() {

        @Override
        public void run() throws Exception {
            assertThat(helper.get(remoteHttpsUrl("/foo/anything")), is("foo"));
        }
    });
}
Also used : Runnable(com.github.dreamhead.moco.Runnable) HttpServer(com.github.dreamhead.moco.HttpServer) HttpResponseException(org.apache.http.client.HttpResponseException) IOException(java.io.IOException) AbstractMocoHttpTest(com.github.dreamhead.moco.AbstractMocoHttpTest) Test(org.junit.Test)

Example 14 with Runnable

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

the class ActualHttpServerTest method should_config_handler_correctly_other_side_while_merging.

@Test
public void should_config_handler_correctly_other_side_while_merging() throws Exception {
    httpServer = httpServer(12306, fileRoot("src/test/resources"));
    httpServer.response(file("foo.response"));
    HttpServer mergedServer = ((ActualHttpServer) httpServer).mergeServer((ActualHttpServer) anotherServer);
    running(mergedServer, new Runnable() {

        @Override
        public void run() throws IOException {
            assertThat(helper.get(root()), is("foo.response"));
        }
    });
}
Also used : Runnable(com.github.dreamhead.moco.Runnable) HttpServer(com.github.dreamhead.moco.HttpServer) IOException(java.io.IOException) AbstractMocoHttpTest(com.github.dreamhead.moco.AbstractMocoHttpTest) Test(org.junit.Test)

Example 15 with Runnable

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

the class ActualHttpServerTest method should_merge_http_server_without_port_for_first_server.

@Test
public void should_merge_http_server_without_port_for_first_server() throws Exception {
    httpServer = httpServer(12306, context("/foo"));
    anotherServer = httpServer(context("/bar"));
    final HttpServer mergedServer = ((ActualHttpServer) anotherServer).mergeServer((ActualHttpServer) httpServer);
    running(mergedServer, new Runnable() {

        @Override
        public void run() throws Exception {
            assertThat(mergedServer.port(), is(12306));
        }
    });
}
Also used : Runnable(com.github.dreamhead.moco.Runnable) HttpServer(com.github.dreamhead.moco.HttpServer) HttpResponseException(org.apache.http.client.HttpResponseException) IOException(java.io.IOException) AbstractMocoHttpTest(com.github.dreamhead.moco.AbstractMocoHttpTest) Test(org.junit.Test)

Aggregations

Runnable (com.github.dreamhead.moco.Runnable)21 Test (org.junit.Test)21 HttpServer (com.github.dreamhead.moco.HttpServer)16 IOException (java.io.IOException)16 AbstractMocoHttpTest (com.github.dreamhead.moco.AbstractMocoHttpTest)15 HttpResponseException (org.apache.http.client.HttpResponseException)11 SocketServer (com.github.dreamhead.moco.SocketServer)3 Request (us.codecraft.webmagic.Request)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Response (org.apache.http.client.fluent.Response)2 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)1 RequestBuilder (org.apache.http.client.methods.RequestBuilder)1 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)1 Page (us.codecraft.webmagic.Page)1 Site (us.codecraft.webmagic.Site)1