Search in sources :

Example 6 with Runnable

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

the class ActualHttpServerTest method should_throw_exception_for_merging_http_server_with_any_handler_one_side.

@Test(expected = HttpResponseException.class)
public void should_throw_exception_for_merging_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 {
            helper.get(remoteUrl("/bar/anything"));
        }
    });
}
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 7 with Runnable

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

the class ActualHttpServerTest method should_merge_http_server_with_different_port.

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

        @Override
        public void run() throws Exception {
            assertThat(mergedServer.port(), is(12307));
        }
    });
}
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 8 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_second_server.

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

        @Override
        public void run() throws Exception {
            assertThat(mergedServer.port(), is(12307));
        }
    });
}
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 9 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_other_side.

@Test
public void should_merge_http_server_with_any_handler_other_side() throws Exception {
    HttpServer mergedServer = ((ActualHttpServer) httpServer).mergeServer((ActualHttpServer) anotherServer);
    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 10 with Runnable

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

the class ActualHttpServerTest method should_merge_two_https_servers.

@Test
public void should_merge_two_https_servers() throws Exception {
    httpServer = httpsServer(12306, DEFAULT_CERTIFICATE, context("/foo"));
    httpServer.response("foo");
    anotherServer = httpsServer(12306, DEFAULT_CERTIFICATE, context("/bar"));
    anotherServer.request(by(uri("/bar"))).response("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"));
            assertThat(helper.get(remoteHttpsUrl("/bar/bar")), is("bar"));
        }
    });
}
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