Search in sources :

Example 21 with HttpServer

use of com.github.dreamhead.moco.HttpServer 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, () -> assertThat(helper.get(remoteUrl("/foo/anything")), is("foo")));
}
Also used : HttpServer(com.github.dreamhead.moco.HttpServer) AbstractMocoHttpTest(com.github.dreamhead.moco.AbstractMocoHttpTest) Test(org.junit.Test)

Example 22 with HttpServer

use of com.github.dreamhead.moco.HttpServer 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, () -> assertThat(mergedServer.port(), is(12306)));
}
Also used : HttpServer(com.github.dreamhead.moco.HttpServer) AbstractMocoHttpTest(com.github.dreamhead.moco.AbstractMocoHttpTest) Test(org.junit.Test)

Example 23 with HttpServer

use of com.github.dreamhead.moco.HttpServer 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, () -> assertThat(helper.get(root()), is("foo.response")));
}
Also used : HttpServer(com.github.dreamhead.moco.HttpServer) AbstractMocoHttpTest(com.github.dreamhead.moco.AbstractMocoHttpTest) Test(org.junit.Test)

Example 24 with HttpServer

use of com.github.dreamhead.moco.HttpServer 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, () -> {
        assertThat(helper.get(remoteHttpsUrl("/foo/anything")), is("foo"));
        assertThat(helper.get(remoteHttpsUrl("/bar/bar")), is("bar"));
    });
}
Also used : HttpServer(com.github.dreamhead.moco.HttpServer) AbstractMocoHttpTest(com.github.dreamhead.moco.AbstractMocoHttpTest) Test(org.junit.Test)

Example 25 with HttpServer

use of com.github.dreamhead.moco.HttpServer 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, () -> assertThat(mergedServer.port(), is(12306)));
}
Also used : HttpServer(com.github.dreamhead.moco.HttpServer) AbstractMocoHttpTest(com.github.dreamhead.moco.AbstractMocoHttpTest) Test(org.junit.Test)

Aggregations

HttpServer (com.github.dreamhead.moco.HttpServer)27 Test (org.junit.Test)25 AbstractMocoHttpTest (com.github.dreamhead.moco.AbstractMocoHttpTest)13 Runnable (com.github.dreamhead.moco.Runnable)12 IOException (java.io.IOException)12 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)12 Request (us.codecraft.webmagic.Request)12 UnsupportedEncodingException (java.io.UnsupportedEncodingException)11 Page (us.codecraft.webmagic.Page)10 Site (us.codecraft.webmagic.Site)3 ActualHttpServer (com.github.dreamhead.moco.internal.ActualHttpServer)2 RunnerSetting.aRunnerSetting (com.github.dreamhead.moco.runner.RunnerSetting.aRunnerSetting)1 Map (java.util.Map)1 HashedMap (org.apache.commons.collections.map.HashedMap)1 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)1 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)1 Proxy (us.codecraft.webmagic.proxy.Proxy)1