当前位置: 首页>>代码示例>>Java>>正文


Java Runner类代码示例

本文整理汇总了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");
        }
    });
}
 
开发者ID:code4craft,项目名称:webmagic,代码行数:17,代码来源:HttpClientDownloaderTest.java

示例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");
        }
    });
}
 
开发者ID:code4craft,项目名称:webmagic,代码行数:17,代码来源:HttpClientDownloaderTest.java

示例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");
        }
    });
}
 
开发者ID:code4craft,项目名称:webmagic,代码行数:17,代码来源:HttpClientDownloaderTest.java

示例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");
        }
    });
}
 
开发者ID:code4craft,项目名称:webmagic,代码行数:17,代码来源:HttpClientDownloaderTest.java

示例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");
        }
    });
}
 
开发者ID:code4craft,项目名称:webmagic,代码行数:17,代码来源:HttpClientDownloaderTest.java

示例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());
        }
    });
}
 
开发者ID:code4craft,项目名称:webmagic,代码行数:18,代码来源:HttpClientDownloaderTest.java

示例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");
        }
    });
}
 
开发者ID:code4craft,项目名称:webmagic,代码行数:17,代码来源:HttpClientDownloaderTest.java

示例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");
        }
    });
}
 
开发者ID:code4craft,项目名称:webmagic,代码行数:16,代码来源:HttpClientDownloaderTest.java

示例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");
        }
    });
}
 
开发者ID:code4craft,项目名称:webmagic,代码行数:16,代码来源:HttpClientDownloaderTest.java

示例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");
        }
    });
}
 
开发者ID:code4craft,项目名称:webmagic,代码行数:16,代码来源:HttpClientDownloaderTest.java

示例11: TestServerHelper

import com.github.dreamhead.moco.Runner; //导入依赖的package包/类
public TestServerHelper() {
	server = httpserver(testPort);
	runner = Runner.runner(server);
}
 
开发者ID:grantjforrester,项目名称:bdd-rest,代码行数:5,代码来源:TestServerHelper.java


注:本文中的com.github.dreamhead.moco.Runner类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。