Search in sources :

Example 16 with Runnable

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

the class ActualHttpServerTest method should_merge_http_server_with_same_port.

@Test
public void should_merge_http_server_with_same_port() throws Exception {
    httpServer = httpServer(12306, context("/foo"));
    anotherServer = httpServer(12306, 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)

Example 17 with Runnable

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

the class ActualHttpServerTest method should_config_handler_correctly_while_merging.

@Test
public void should_config_handler_correctly_while_merging() throws Exception {
    httpServer = httpServer(12306, fileRoot("src/test/resources"));
    httpServer.response(file("foo.response"));
    HttpServer mergedServer = ((ActualHttpServer) anotherServer).mergeServer((ActualHttpServer) httpServer);
    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 18 with Runnable

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

the class ActualHttpServerTest method should_merge_https_server_into_http_server.

@Test
public void should_merge_https_server_into_http_server() throws Exception {
    httpServer = httpsServer(12306, DEFAULT_CERTIFICATE, context("/foo"));
    httpServer.response("foo");
    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 19 with Runnable

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

the class ActualSocketServerTest method should_merge_socket_servers_with_first_port.

@Test
public void should_merge_socket_servers_with_first_port() throws Exception {
    SocketServer server = socketServer(12306);
    SocketServer secondServer = socketServer();
    final SocketServer newServer = ((ActualSocketServer) server).mergeServer((ActualSocketServer) secondServer);
    running(newServer, new Runnable() {

        @Override
        public void run() throws Exception {
            assertThat(newServer.port(), is(12306));
        }
    });
}
Also used : SocketServer(com.github.dreamhead.moco.SocketServer) Runnable(com.github.dreamhead.moco.Runnable) Test(org.junit.Test)

Example 20 with Runnable

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

the class ActualSocketServerTest method should_merge_socket_servers.

@Test
public void should_merge_socket_servers() throws Exception {
    SocketServer server = socketServer(12306);
    SocketServer secondServer = socketServer(12306);
    server.request(by("foo")).response(line("bar"));
    secondServer.request(by("foo1")).response(line("bar1"));
    SocketServer newServer = ((ActualSocketServer) server).mergeServer((ActualSocketServer) secondServer);
    running(newServer, new Runnable() {

        @Override
        public void run() throws Exception {
            helper.connect();
            assertThat(helper.send("foo"), is("bar"));
            assertThat(helper.send("foo1"), is("bar1"));
            helper.close();
        }
    });
}
Also used : SocketServer(com.github.dreamhead.moco.SocketServer) Runnable(com.github.dreamhead.moco.Runnable) 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