use of com.github.dreamhead.moco.HttpServer 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, () -> assertThat(mergedServer.port(), is(12307)));
}
use of com.github.dreamhead.moco.HttpServer 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, () -> assertThat(mergedServer.port(), is(12307)));
}
use of com.github.dreamhead.moco.HttpServer 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, () -> helper.get(remoteUrl("/bar/anything")));
}
use of com.github.dreamhead.moco.HttpServer in project moco by dreamhead.
the class JsonRunner method createBaseHttpServer.
private HttpServer createBaseHttpServer(final Iterable<? extends RunnerSetting> settings, final StartArgs startArgs) {
HttpServer targetServer = createHttpServer(startArgs);
for (RunnerSetting setting : settings) {
HttpServer parsedServer = httpParser.parseServer(setting.getStreams(), startArgs.getPort().orElse(0), toConfigs(setting));
targetServer = mergeServer(targetServer, parsedServer);
}
return targetServer;
}
use of com.github.dreamhead.moco.HttpServer in project webmagic by code4craft.
the class HttpClientDownloaderTest method test_set_request_cookie.
@Test
public void test_set_request_cookie() throws Exception {
HttpServer server = httpServer(13423);
server.get(eq(cookie("cookie"), "cookie-webmagic")).response("ok");
Runner.running(server, new Runnable() {
@Override
public void run() throws Exception {
HttpClientDownloader httpClientDownloader = new HttpClientDownloader();
Request request = new Request();
request.setUrl("http://127.0.0.1:13423");
request.addCookie("cookie", "cookie-webmagic");
Page page = httpClientDownloader.download(request, Site.me().toTask());
assertThat(page.getRawText()).isEqualTo("ok");
}
});
}
Aggregations