本文整理汇总了Java中org.takes.rq.RqWithHeader类的典型用法代码示例。如果您正苦于以下问题:Java RqWithHeader类的具体用法?Java RqWithHeader怎么用?Java RqWithHeader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RqWithHeader类属于org.takes.rq包,在下文中一共展示了RqWithHeader类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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']"
)
);
}
开发者ID:yegor256,项目名称:rehttp,代码行数:29,代码来源:TkAppTest.java
示例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']"
)
);
}
开发者ID:yegor256,项目名称:jare,代码行数:29,代码来源:TkAppTest.java
示例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"
)
);
}
开发者ID:yegor256,项目名称:wring,代码行数:27,代码来源:TkIndexTest.java
示例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"
)
);
}
开发者ID:yegor256,项目名称:wring,代码行数:27,代码来源:TkEventsTest.java
示例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)
);
}
开发者ID:yegor256,项目名称:takes,代码行数:21,代码来源:FkContentTypeTest.java
示例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)
);
}
开发者ID:yegor256,项目名称:takes,代码行数:21,代码来源:FkContentTypeTest.java
示例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)
);
}
开发者ID:yegor256,项目名称:takes,代码行数:21,代码来源:FkContentTypeTest.java
示例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)
);
}
开发者ID:yegor256,项目名称:takes,代码行数:27,代码来源:FkEncodingTest.java
示例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)
);
}
开发者ID:yegor256,项目名称:takes,代码行数:27,代码来源:FkTypesTest.java
示例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)
);
}
开发者ID:yegor256,项目名称:takes,代码行数:26,代码来源:FkAuthenticatedTest.java
示例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));
}
开发者ID:yegor256,项目名称:takes,代码行数:29,代码来源:FkHitRefreshTest.java
示例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")
);
}
开发者ID:yegor256,项目名称:takes,代码行数:28,代码来源:PsBasicTest.java
示例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)
);
}
开发者ID:yegor256,项目名称:takes,代码行数:27,代码来源:TkSecureTest.java
示例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']"
)
);
}
开发者ID:yegor256,项目名称:takes,代码行数:29,代码来源:XeIdentityTest.java
示例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")
)
);
}
开发者ID:yegor256,项目名称:takes,代码行数:30,代码来源:TkAuthTest.java
示例16: logsUserOut
import org.takes.rq.RqWithHeader; //导入依赖的package包/类
/**
* TkAuth can logout a user.
* @throws IOException If some problem inside
*/
@Test
public void logsUserOut() throws IOException {
final Pass pass = new PsLogout();
final Take take = Mockito.mock(Take.class);
Mockito.doReturn(new RsText()).when(take)
.act(Mockito.any(Request.class));
new TkAuth(take, pass).act(
new RqWithHeader(
new RqFake(),
TkAuth.class.getSimpleName(),
"urn%3Atest%3A2"
)
);
final ArgumentCaptor<Request> captor =
ArgumentCaptor.forClass(Request.class);
Mockito.verify(take).act(captor.capture());
MatcherAssert.assertThat(
new RqHeaders.Base(captor.getValue()).header(
TkAuth.class.getSimpleName()
),
Matchers.emptyIterable()
);
}
开发者ID:yegor256,项目名称:takes,代码行数:28,代码来源:TkAuthTest.java
示例17: logsUserOutWithCookiePresent
import org.takes.rq.RqWithHeader; //导入依赖的package包/类
/**
* TkAuth can logout a user when a login cookie is present.
* @throws IOException If some problem inside
*/
@Test
public void logsUserOutWithCookiePresent() throws IOException {
final Pass pass = new PsChain(
new PsLogout(),
new PsCookie(new CcPlain())
);
MatcherAssert.assertThat(
new RsPrint(
new TkAuth(new TkText(), pass).act(
new RqWithHeader(
new RqFake(),
String.format(
"Cookie: %s=%s",
PsCookie.class.getSimpleName(),
"urn%3Atest%3A5"
)
)
)
).print(),
Matchers.containsString("Set-Cookie: PsCookie=")
);
}
开发者ID:yegor256,项目名称:takes,代码行数:27,代码来源:TkAuthTest.java
示例18: redirectsAndRemovesCookie
import org.takes.rq.RqWithHeader; //导入依赖的package包/类
/**
* TkReturn can redirect to return location
* and remove a return cookie.
* @throws IOException If some problem inside
*/
@Test
public void redirectsAndRemovesCookie() throws IOException {
final Take take = new TkReturn(new TkEmpty());
final String destination = "/return/to";
MatcherAssert.assertThat(
take.act(
new RqWithHeader(
new RqFake(),
String.format(
"Cookie: RsReturn=%s;",
URLEncoder.encode(
destination,
Charset.defaultCharset().name()
)
)
)
).head(),
Matchers.contains(
"HTTP/1.1 303 See Other",
String.format("Location: %s", destination),
"Set-Cookie: RsReturn=;"
)
);
}
开发者ID:yegor256,项目名称:takes,代码行数:30,代码来源:TkReturnTest.java
示例19: removesFlashCookie
import org.takes.rq.RqWithHeader; //导入依赖的package包/类
/**
* TkFlash can remove a flash cookie.
* @throws IOException If some problem inside
*/
@Test
public void removesFlashCookie() throws IOException {
final Take take = new TkFlash(new TkEmpty());
MatcherAssert.assertThat(
take.act(
new RqWithHeader(
new RqFake(),
"Cookie: RsFlash=Hello!"
)
).head(),
Matchers.hasItem(
Matchers.allOf(
Matchers.startsWith("Set-Cookie: RsFlash=deleted;"),
Matchers.containsString("Path=/;"),
Matchers.containsString(
"Expires=Thu, 01 Jan 1970 00:00:00 GMT"
)
)
)
);
}
开发者ID:yegor256,项目名称:takes,代码行数:26,代码来源:TkFlashTest.java
示例20: route
import org.takes.rq.RqWithHeader; //导入依赖的package包/类
/**
* Route.
* @param regex Regular expression
* @param take Take
* @param req Request
* @return Response or empty
* @throws IOException If fails
*/
private static Opt<Response> route(final String regex, final Take take,
final Request req) throws IOException {
return new FkRegex(
String.format("/d/([a-z\\-]+)%s", regex),
new TkRegex() {
@Override
public Response act(final RqRegex rreq) throws IOException {
final String name = rreq.matcher().group(1);
return FkDeck.redirect(name, take).act(
new RqWithHeader(rreq, "X-Thindeck-Deck", name)
);
}
}
).route(req);
}
开发者ID:yegor256,项目名称:thindeck,代码行数:24,代码来源:FkDeck.java
注:本文中的org.takes.rq.RqWithHeader类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论