本文整理汇总了Java中org.takes.rs.RsPrint类的典型用法代码示例。如果您正苦于以下问题:Java RsPrint类的具体用法?Java RsPrint怎么用?Java RsPrint使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RsPrint类属于org.takes.rs包,在下文中一共展示了RsPrint类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: passesRequestThrough
import org.takes.rs.RsPrint; //导入依赖的package包/类
/**
* App can pass a request through.
* @throws Exception If some problem inside
*/
@Test
public void passesRequestThrough() throws Exception {
MatcherAssert.assertThat(
new RsPrint(
new TkApp(new FakeBase()).act(
new RqFake(
new ListOf<>(
String.format(
"GET /%s",
URLEncoder.encode(
"http://www.yegor256.com", "UTF-8"
)
),
"Host: p.rehttp.net"
),
""
)
)
).print(),
Matchers.startsWith("HTTP/1.1 200")
);
}
示例2: rendersHomePage
import org.takes.rs.RsPrint; //导入依赖的package包/类
/**
* App can render front page.
* @throws Exception If some problem inside
*/
@Test
public void rendersHomePage() throws Exception {
final Take take = new TkApp(new FakeBase());
MatcherAssert.assertThat(
XhtmlMatchers.xhtml(
new RsPrint(
take.act(
new RqWithHeader(
new RqFake("GET", "/"),
// @checkstyle MultipleStringLiteralsCheck (1 line)
"Accept",
"text/xml"
)
)
).printBody()
),
XhtmlMatchers.hasXPaths(
"/page/@date",
"/page/@sla",
"/page/millis",
"/page/links/link[@rel='self']"
)
);
}
示例3: rendersHomePage
import org.takes.rs.RsPrint; //导入依赖的package包/类
@Test
public void rendersHomePage() throws Exception {
final Take take = new TkApp(new FkBase());
MatcherAssert.assertThat(
XhtmlMatchers.xhtml(
new RsPrint(
take.act(
new RqWithHeaders(
new RqFake("GET", "/"),
"Accept: text/xml"
)
)
).printBody()
),
XhtmlMatchers.hasXPaths(
"/page/@date",
"/page/@sla",
"/page/millis",
"/page/links/link[@rel='self']"
)
);
}
示例4: pingsSimplePages
import org.takes.rs.RsPrint; //导入依赖的package包/类
@Test
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
public void pingsSimplePages() throws IOException {
final String[] pages = {
"/org/jpeek/web/layout.xsl",
"/org/jpeek/web/index.xsl",
"/jpeek.css",
"/",
"/mistakes",
"/robots.txt",
};
final Take app = new TkApp(Files.createTempDirectory("x"));
for (final String page : pages) {
final Response response = app.act(new RqFake("GET", page));
MatcherAssert.assertThat(
new RsPrint(response).print(),
response,
new HmRsStatus(HttpURLConnection.HTTP_OK)
);
}
}
示例5: rendersMistakesPageInXml
import org.takes.rs.RsPrint; //导入依赖的package包/类
@Test
public void rendersMistakesPageInXml() throws IOException {
MatcherAssert.assertThat(
XhtmlMatchers.xhtml(
new RsPrint(
new TkMistakes().act(
new RqWithHeaders(
new RqFake(),
"Accept: application/vnd.jpeek+xml"
)
)
).printBody()
),
XhtmlMatchers.hasXPath("/page/worst")
);
}
示例6: rendersOneReport
import org.takes.rs.RsPrint; //导入依赖的package包/类
@Test
public void rendersOneReport() throws Exception {
final ExecutorService service = Executors.newSingleThreadExecutor();
final BiFunc<String, String, Func<String, Response>> bifunc =
new AsyncReports(
new SolidBiFunc<>(
(first, second) -> service.submit(
() -> input -> {
TimeUnit.DAYS.sleep(1L);
return new RsText("done!");
}
)
)
);
final Response response =
bifunc.apply("org.jpeek", "jpeek").apply("index.html");
MatcherAssert.assertThat(
response,
new HmRsStatus(HttpURLConnection.HTTP_OK)
);
MatcherAssert.assertThat(
XhtmlMatchers.xhtml(new RsPrint(response).printBody()),
XhtmlMatchers.hasXPath("//xhtml:body")
);
service.shutdownNow();
}
示例7: rendersHomePageInHtml
import org.takes.rs.RsPrint; //导入依赖的package包/类
/**
* TkIndex can render home page in HTML.
* @throws Exception If some problem inside
*/
@Test
public void rendersHomePageInHtml() throws Exception {
final Take take = new TkAppAuth(new TkIndex(new FkBase()));
MatcherAssert.assertThat(
XhtmlMatchers.xhtml(
new RsPrint(
take.act(new RqFake("GET", "/"))
).printBody()
),
XhtmlMatchers.hasXPaths(
"/xhtml:html",
"/xhtml:html/xhtml:body"
)
);
}
示例8: rendersHomePage
import org.takes.rs.RsPrint; //导入依赖的package包/类
/**
* App can render front page.
* @throws Exception If some problem inside
*/
@Test
public void rendersHomePage() throws Exception {
final Take take = new TkApp(new FkBase());
MatcherAssert.assertThat(
XhtmlMatchers.xhtml(
new RsPrint(
take.act(
new RqWithHeader(
new RqFake("GET", "/"),
// @checkstyle MultipleStringLiteralsCheck (1 line)
"Accept",
"text/xml"
)
)
).printBody()
),
XhtmlMatchers.hasXPaths(
"/page/@date",
"/page/@sla",
"/page/millis",
"/page/links/link[@rel='takes:logout']"
)
);
}
示例9: rendersHomePage
import org.takes.rs.RsPrint; //导入依赖的package包/类
/**
* TkHome can render home page.
* @throws Exception If some problem inside
*/
@Test
public void rendersHomePage() throws Exception {
final Take take = new TkIndex(new FkBase());
MatcherAssert.assertThat(
XhtmlMatchers.xhtml(
new RsPrint(
take.act(
new RqWithHeader(
new RqFake("GET", "/"),
"Accept",
"text/xml"
)
)
).printBody()
),
XhtmlMatchers.hasXPaths(
"/page/millis",
"/page/links/link[@rel='takes:github']",
"/page/total"
)
);
}
示例10: rendersHomePage
import org.takes.rs.RsPrint; //导入依赖的package包/类
/**
* App can render front page.
* @throws Exception If some problem inside
*/
@Test
public void rendersHomePage() throws Exception {
final Take take = new TkApp(new FkBase());
MatcherAssert.assertThat(
XhtmlMatchers.xhtml(
new RsPrint(
take.act(
new RqWithHeaders(
new RqFake("GET", "/"),
"Accept: text/xml"
)
)
).printBody()
),
XhtmlMatchers.hasXPaths(
"/page/millis",
"/page/links/link[@rel='takes:github']"
)
);
}
示例11: rendersListOfEvents
import org.takes.rs.RsPrint; //导入依赖的package包/类
/**
* TkEvents can render list of events.
* @throws Exception If some problem inside
*/
@Test
public void rendersListOfEvents() throws Exception {
final Take take = new TkAppAuth(new TkEvents(new FkBase()));
MatcherAssert.assertThat(
XhtmlMatchers.xhtml(
new RsPrint(
take.act(
new RqWithHeader(
new RqFake("GET", "/"),
"Accept",
"text/xml"
)
)
).printBody()
),
XhtmlMatchers.hasXPaths(
"/page/millis",
"/page/events/event",
"/page/events/@total"
)
);
}
示例12: testGETAllRegisteredServicesAsXML
import org.takes.rs.RsPrint; //导入依赖的package包/类
@Test
public void testGETAllRegisteredServicesAsXML() throws Exception {
Response response = getAllServices("text/xml");
assertThat(response.head()).contains(HTTP_OK);
assertThat(new RsPrint(response).printBody()).contains("<services/>");
registerService();
response = getAllServices("text/xml");
assertThat(response.head()).contains(HTTP_OK);
assertThat(new RsPrint(response).printBody()).contains(
"<service>",
"<service><name>example-service</name><env>dev</env><endpoint>http://www.example-service.com/dev</endpoint></service>",
"</services>"
);
}
示例13: dispatchesByRegularExpression
import org.takes.rs.RsPrint; //导入依赖的package包/类
/**
* TkFork can dispatch by regular expression.
* @throws IOException If some problem inside
*/
@Test
public void dispatchesByRegularExpression() throws IOException {
final String body = "hello, world!";
MatcherAssert.assertThat(
new RsPrint(
new TkFork(new FkRegex("/h[a-z]{2}", body)).act(
new RqFake("GET", "/hey?yu", "")
)
).print(),
Matchers.equalTo(
Joiner.on("\r\n").join(
"HTTP/1.1 200 OK",
String.format("Content-Length: %s", body.length()),
"Content-Type: text/plain",
"",
body
)
)
);
}
示例14: dispatchesByRegularExpression
import org.takes.rs.RsPrint; //导入依赖的package包/类
/**
* FkChain can dispatch by regular expression.
* @throws Exception If some problem inside
*/
@Test
public void dispatchesByRegularExpression() throws Exception {
final String body = "hello test!";
MatcherAssert.assertThat(
new RsPrint(
new FkChain(
new FkRegex("/g[a-z]{2}", ""),
new FkRegex("/h[a-z]{2}", body),
new FkRegex("/i[a-z]{2}", "")
).route(new RqFake("GET", "/hey?yu")).get()
).print(),
Matchers.equalTo(
Joiner.on("\r\n").join(
"HTTP/1.1 200 OK",
String.format("Content-Length: %s", body.length()),
"Content-Type: text/plain",
"",
body
)
)
);
}
示例15: negotiatesContent
import org.takes.rs.RsPrint; //导入依赖的package包/类
/**
* RsFork can route by the Accept header.
* @throws IOException If some problem inside
*/
@Test
public void negotiatesContent() throws IOException {
final Request req = new RqFake(
Arrays.asList(
"GET /hello.html",
"Accept: text/xml; q=0.3, text/plain; q=0.1",
"Accept: */*; q=0.05"
),
""
);
MatcherAssert.assertThat(
new RsPrint(
new RsFork(
req,
new FkTypes("text/plain", new RsText("it's a text")),
new FkTypes("image/*", new RsText("it's an image"))
)
).printBody(),
Matchers.endsWith("a text")
);
}