本文整理汇总了Java中com.github.dreamhead.moco.Runner类的典型用法代码示例。如果您正苦于以下问题:Java Runner类的具体用法?Java Runner怎么用?Java Runner使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Runner类属于com.github.dreamhead.moco包,在下文中一共展示了Runner类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test_set_request_cookie
import com.github.dreamhead.moco.Runner; //导入依赖的package包/类
@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");
}
});
}
示例2: test_disableCookieManagement
import com.github.dreamhead.moco.Runner; //导入依赖的package包/类
@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");
}
});
}
示例3: test_set_request_header
import com.github.dreamhead.moco.Runner; //导入依赖的package包/类
@Test
public void test_set_request_header() throws Exception {
HttpServer server = httpServer(13423);
server.get(eq(header("header"), "header-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.addHeader("header","header-webmagic");
Page page = httpClientDownloader.download(request, Site.me().toTask());
assertThat(page.getRawText()).isEqualTo("ok");
}
});
}
示例4: test_set_site_cookie
import com.github.dreamhead.moco.Runner; //导入依赖的package包/类
@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");
}
});
}
示例5: test_download_auth_by_SimpleProxyProvider
import com.github.dreamhead.moco.Runner; //导入依赖的package包/类
@Test
public void test_download_auth_by_SimpleProxyProvider() throws Exception {
HttpServer server = httpServer(13423);
server.get(eq(header("Proxy-Authorization"), "Basic dXNlcm5hbWU6cGFzc3dvcmQ=")).response("ok");
Runner.running(server, new Runnable() {
@Override
public void run() throws Exception {
HttpClientDownloader httpClientDownloader = new HttpClientDownloader();
httpClientDownloader.setProxyProvider(SimpleProxyProvider.from(new Proxy("127.0.0.1", 13423, "username", "password")));
Request request = new Request();
request.setUrl("http://www.baidu.com");
Page page = httpClientDownloader.download(request, Site.me().toTask());
assertThat(page.getRawText()).isEqualTo("ok");
}
});
}
示例6: test_download_binary_content
import com.github.dreamhead.moco.Runner; //导入依赖的package包/类
@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());
}
});
}
示例7: test_download_set_request_charset
import com.github.dreamhead.moco.Runner; //导入依赖的package包/类
@Test
public void test_download_set_request_charset() throws Exception {
HttpServer server = httpServer(13423);
server.response("hello world!");
Runner.running(server, new Runnable() {
@Override
public void run() throws Exception {
final HttpClientDownloader httpClientDownloader = new HttpClientDownloader();
Request request = new Request();
request.setCharset("utf-8");
request.setUrl("http://127.0.0.1:13423/");
Page page = httpClientDownloader.download(request, Site.me().setCharset("gbk").toTask());
assertThat(page.getCharset()).isEqualTo("utf-8");
}
});
}
示例8: test_set_site_header
import com.github.dreamhead.moco.Runner; //导入依赖的package包/类
@Test
public void test_set_site_header() throws Exception {
HttpServer server = httpServer(13423);
server.get(eq(header("header"), "header-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");
Page page = httpClientDownloader.download(request, Site.me().addHeader("header","header-webmagic").toTask());
assertThat(page.getRawText()).isEqualTo("ok");
}
});
}
示例9: test_download_when_task_is_null
import com.github.dreamhead.moco.Runner; //导入依赖的package包/类
@Test
public void test_download_when_task_is_null() throws Exception {
HttpServer server = httpServer(13423);
server.response("foo");
Runner.running(server, new Runnable() {
@Override
public void run() throws Exception {
final HttpClientDownloader httpClientDownloader = new HttpClientDownloader();
Request request = new Request();
request.setUrl("http://127.0.0.1:13423/");
Page page = httpClientDownloader.download(request, Site.me().toTask());
assertThat(page.getRawText()).isEqualTo("foo");
}
});
}
示例10: test_download_set_charset
import com.github.dreamhead.moco.Runner; //导入依赖的package包/类
@Test
public void test_download_set_charset() throws Exception {
HttpServer server = httpServer(13423);
server.response(header("Content-Type","text/html; charset=utf-8")).response("hello world!");
Runner.running(server, new Runnable() {
@Override
public void run() throws Exception {
final HttpClientDownloader httpClientDownloader = new HttpClientDownloader();
Request request = new Request();
request.setUrl("http://127.0.0.1:13423/");
Page page = httpClientDownloader.download(request, Site.me().toTask());
assertThat(page.getCharset()).isEqualTo("utf-8");
}
});
}
示例11: TestServerHelper
import com.github.dreamhead.moco.Runner; //导入依赖的package包/类
public TestServerHelper() {
server = httpserver(testPort);
runner = Runner.runner(server);
}