本文整理匯總了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);
}