Search in sources :

Example 26 with HttpServer

use of com.github.dreamhead.moco.HttpServer 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, () -> 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 27 with HttpServer

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

the class JsonRunner method createHttpServer.

private HttpServer createHttpServer(final Iterable<? extends RunnerSetting> settings, final StartArgs startArgs) {
    HttpServer targetServer = createBaseHttpServer(settings, startArgs);
    targetServer.request(by(uri("/favicon.ico"))).response(with(pathResource("favicon.png")), with(header(HttpHeaders.CONTENT_TYPE, MediaType.PNG.toString())));
    return targetServer;
}
Also used : ActualHttpServer(com.github.dreamhead.moco.internal.ActualHttpServer) HttpServer(com.github.dreamhead.moco.HttpServer)

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