use of com.github.dreamhead.moco.HttpServer in project webmagic by code4craft.
the class HttpClientDownloaderTest method test_set_site_cookie.
@Test
public void test_set_site_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");
Site site = Site.me().addCookie("cookie", "cookie-webmagic").setDomain("127.0.0.1");
Page page = httpClientDownloader.download(request, site.toTask());
assertThat(page.getRawText()).isEqualTo("ok");
}
});
}
use of com.github.dreamhead.moco.HttpServer in project webmagic by code4craft.
the class HttpClientDownloaderTest method test_disableCookieManagement.
@Test
public void test_disableCookieManagement() throws Exception {
HttpServer server = httpServer(13423);
server.get(not(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().setDisableCookieManagement(true).toTask());
assertThat(page.getRawText()).isEqualTo("ok");
}
});
}
use of com.github.dreamhead.moco.HttpServer in project webmagic by code4craft.
the class HttpClientDownloaderTest method test_download_binary_content.
@Test
public void test_download_binary_content() throws Exception {
HttpServer server = httpServer(13423);
server.response("binary");
Runner.running(server, new Runnable() {
@Override
public void run() throws Exception {
final HttpClientDownloader httpClientDownloader = new HttpClientDownloader();
Request request = new Request();
request.setBinaryContent(true);
request.setUrl("http://127.0.0.1:13423/");
Page page = httpClientDownloader.download(request, Site.me().toTask());
assertThat(page.getRawText()).isNull();
assertThat(page.getBytes()).isEqualTo("binary".getBytes());
}
});
}
use of com.github.dreamhead.moco.HttpServer 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, () -> assertThat(helper.get(remoteHttpsUrl("/foo/anything")), is("foo")));
}
use of com.github.dreamhead.moco.HttpServer in project moco by dreamhead.
the class ActualHttpServerTest method should_merge_https_server.
@Test
public void should_merge_https_server() throws Exception {
anotherServer = httpsServer(12306, DEFAULT_CERTIFICATE, context("/bar"));
HttpServer mergedServer = ((ActualHttpServer) anotherServer).mergeServer((ActualHttpServer) httpServer);
running(mergedServer, () -> assertThat(helper.get(remoteHttpsUrl("/foo/anything")), is("foo")));
}
Aggregations