本文整理汇总了Java中org.takes.rq.RqWithHeader类的典型用法代码示例。如果您正苦于以下问题:Java RqWithHeader类的具体用法?Java RqWithHeader怎么用?Java RqWithHeader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RqWithHeader类属于org.takes.rq包,在下文中一共展示了RqWithHeader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: rendersHomePage
import org.takes.rq.RqWithHeader; //导入依赖的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']"
)
);
}
示例2: rendersHomePage
import org.takes.rq.RqWithHeader; //导入依赖的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']"
)
);
}
示例3: rendersHomePage
import org.takes.rq.RqWithHeader; //导入依赖的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"
)
);
}
示例4: rendersListOfEvents
import org.takes.rq.RqWithHeader; //导入依赖的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"
)
);
}
示例5: matchesDifferentTypes
import org.takes.rq.RqWithHeader; //导入依赖的package包/类
/**
* FkContentType can match by Content-Type header with different types.
* @throws IOException If some problem inside
*/
@Test
public void matchesDifferentTypes() throws IOException {
MatcherAssert.assertThat(
new FkContentType(
"application/json charset=utf-8",
FkContentTypeTest.emptyResponse()
).route(
new RqWithHeader(
new RqFake(),
FkContentTypeTest.CONTENT_TYPE,
"images/*"
)
).has(),
Matchers.is(false)
);
}
示例6: matchesIdenticalTypes
import org.takes.rq.RqWithHeader; //导入依赖的package包/类
/**
* FkContentType can match by Content-Type header with identical types.
* @throws IOException If some problem inside
*/
@Test
public void matchesIdenticalTypes() throws IOException {
MatcherAssert.assertThat(
new FkContentType(
FkContentTypeTest.CTYPE,
FkContentTypeTest.emptyResponse()
).route(
new RqWithHeader(
new RqFake(),
FkContentTypeTest.CONTENT_TYPE,
FkContentTypeTest.CTYPE
)
).has(),
Matchers.is(true)
);
}
示例7: matchesDifferentEncodingsTypes
import org.takes.rq.RqWithHeader; //导入依赖的package包/类
/**
* FkContentType can match by Content-Type header with different encodings.
* @throws IOException If some problem inside
*/
@Test
public void matchesDifferentEncodingsTypes() throws IOException {
MatcherAssert.assertThat(
new FkContentType(
FkContentTypeTest.CTYPE,
FkContentTypeTest.emptyResponse()
).route(
new RqWithHeader(
new RqFake(),
FkContentTypeTest.CONTENT_TYPE,
"text/html charset=utf8"
)
).has(),
Matchers.is(false)
);
}
示例8: matchesByAcceptEncodingHeader
import org.takes.rq.RqWithHeader; //导入依赖的package包/类
/**
* FkEncoding can match by Accept-Encoding header.
* @throws IOException If some problem inside
*/
@Test
public void matchesByAcceptEncodingHeader() throws IOException {
final String header = "Accept-Encoding";
MatcherAssert.assertThat(
new FkEncoding("gzip", new RsEmpty()).route(
new RqWithHeader(new RqFake(), header, "gzip,deflate")
).has(),
Matchers.is(true)
);
MatcherAssert.assertThat(
new FkEncoding("", new RsEmpty()).route(
new RqWithHeader(new RqFake(), header, "xz,gzip,exi")
).has(),
Matchers.is(true)
);
MatcherAssert.assertThat(
new FkEncoding("deflate", new RsEmpty()).route(
new RqWithHeader(new RqFake(), header, "gzip,exi")
).has(),
Matchers.is(false)
);
}
示例9: matchesByAcceptHeader
import org.takes.rq.RqWithHeader; //导入依赖的package包/类
/**
* FkTypes can match by Accept header.
* @throws IOException If some problem inside
*/
@Test
public void matchesByAcceptHeader() throws IOException {
final String accept = "Accept";
MatcherAssert.assertThat(
new FkTypes("text/xml", new RsEmpty()).route(
new RqWithHeader(new RqFake(), accept, "*/* ")
).has(),
Matchers.is(true)
);
MatcherAssert.assertThat(
new FkTypes("application/json", new RsEmpty()).route(
new RqWithHeader(new RqFake(), accept, "image/*")
).has(),
Matchers.is(false)
);
MatcherAssert.assertThat(
new FkTypes("*/*", new RsEmpty()).route(
new RqWithHeader(new RqFake(), accept, "text/html")
).has(),
Matchers.is(true)
);
}
示例10: matchesIfAuthenticatedUser
import org.takes.rq.RqWithHeader; //导入依赖的package包/类
/**
* FkAuthenticated can match by user status.
* @throws IOException If some problem inside
*/
@Test
public void matchesIfAuthenticatedUser() throws IOException {
MatcherAssert.assertThat(
new FkAuthenticated(new TkEmpty()).route(
new RqFake("GET", "/hel?a=1")
).has(),
Matchers.is(false)
);
MatcherAssert.assertThat(
new FkAuthenticated(new TkEmpty()).route(
new RqWithHeader(
new RqFake("PUT", "/hello"),
TkAuth.class.getSimpleName(),
new String(
new CcPlain().encode(new Identity.Simple("urn:test:1"))
)
)
).has(),
Matchers.is(true)
);
}
示例11: refreshesOnDemand
import org.takes.rq.RqWithHeader; //导入依赖的package包/类
/**
* FkHitRefresh can refresh on demand.
* @throws Exception If some problem inside
*/
@Test
public void refreshesOnDemand() throws Exception {
final Request req = new RqWithHeader(
new RqFake(), "X-Takes-HitRefresh: yes"
);
final AtomicBoolean done = new AtomicBoolean(false);
final Fork fork = new FkHitRefresh(
this.temp.getRoot(),
new Runnable() {
@Override
public void run() {
done.set(true);
}
},
new TkEmpty()
);
TimeUnit.SECONDS.sleep(2L);
FileUtils.touch(this.temp.newFile("hey.txt"));
MatcherAssert.assertThat(
fork.route(req).has(),
Matchers.is(true)
);
MatcherAssert.assertThat(done.get(), Matchers.is(true));
}
示例12: authenticatesUser
import org.takes.rq.RqWithHeader; //导入依赖的package包/类
/**
* PsBasic can authenticate a user.
* @throws Exception If some problem inside
*/
@Test
public void authenticatesUser() throws Exception {
final Take take = new TkAuth(
new TkSecure(
new TkText("secured")
),
new PsBasic(
"myrealm",
new PsBasic.Default("mike secret11 urn:users:michael")
)
);
MatcherAssert.assertThat(
new RsPrint(
take.act(
new RqWithHeader(
new RqFake(),
PsBasicTest.header("mike", "secret11")
)
)
).print(),
Matchers.containsString("HTTP/1.1 200 OK")
);
}
示例13: passesOnRegisteredUser
import org.takes.rq.RqWithHeader; //导入依赖的package包/类
/**
* TkSecure can pass on registered user.
* @throws IOException If some problem inside
*/
@Test
public void passesOnRegisteredUser() throws IOException {
MatcherAssert.assertThat(
new TkSecure(
new Take() {
@Override
public Response act(final Request request) {
return new RsEmpty();
}
}
).act(
new RqWithHeader(
new RqFake(),
TkAuth.class.getSimpleName(),
new String(
new CcPlain().encode(new Identity.Simple("urn:test:2"))
)
)
),
Matchers.instanceOf(RsEmpty.class)
);
}
示例14: generatesIdentityInXml
import org.takes.rq.RqWithHeader; //导入依赖的package包/类
/**
* XeIdentity can create a correct link.
* @throws IOException If some problem inside
*/
@Test
public void generatesIdentityInXml() throws IOException {
MatcherAssert.assertThat(
IOUtils.toString(
new RsXembly(
new XeAppend(
"root",
new XeIdentity(
new RqWithHeader(
new RqFake(),
TkAuth.class.getSimpleName(),
"urn:test:1;name=Jeff"
)
)
)
).body(),
StandardCharsets.UTF_8
),
XhtmlMatchers.hasXPaths(
"/root/identity[urn='urn:test:1']",
"/root/identity[name='Jeff']"
)
);
}
示例15: logsInUserViaCookie
import org.takes.rq.RqWithHeader; //导入依赖的package包/类
/**
* TkAuth can login a user via cookie.
* @throws IOException If some problem inside
*/
@Test
public void logsInUserViaCookie() throws IOException {
final Pass pass = new PsChain(
new PsCookie(new CcPlain()),
new PsLogout()
);
MatcherAssert.assertThat(
new RsPrint(
new TkAuth(new TkText(), pass).act(
new RqWithHeader(
new RqFake(),
String.format(
"Cookie: %s=%s",
PsCookie.class.getSimpleName(),
"urn%3Atest%3A0"
)
)
)
).print(),
Matchers.allOf(
Matchers.startsWith("HTTP/1.1 200 "),
Matchers.containsString("Set-Cookie: PsCookie=urn%3Atest%3A0")
)
);
}