本文整理汇总了Java中org.takes.tk.TkFixed类的典型用法代码示例。如果您正苦于以下问题:Java TkFixed类的具体用法?Java TkFixed怎么用?Java TkFixed使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TkFixed类属于org.takes.tk包,在下文中一共展示了TkFixed类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: failsOnUnsupportedAcceptHeader
import org.takes.tk.TkFixed; //导入依赖的package包/类
/**
* TkConsumes can fail on unsupported Content-Type header.
* @throws IOException If some problem inside
*/
@Test(expected = HttpException.class)
public void failsOnUnsupportedAcceptHeader() throws IOException {
final Take consumes = new TkConsumes(
new TkFixed(new RsJson(new RsEmpty())),
TkConsumesTest.APPLICATION_JSON
);
consumes.act(
new RqFake(
Arrays.asList(
"GET /?TkConsumes error",
"Content-Type: application/xml"
),
""
)
).head();
}
示例2: simplyWorks
import org.takes.tk.TkFixed; //导入依赖的package包/类
/**
* FtRemote can work.
* @throws Exception If some problem inside
*/
@Test
public void simplyWorks() throws Exception {
new FtRemote(new TkFixed(new RsText("simple answer"))).exec(
new FtRemote.Script() {
@Override
public void exec(final URI home) throws IOException {
new JdkRequest(home)
.fetch()
.as(RestResponse.class)
.assertStatus(HttpURLConnection.HTTP_OK)
.assertBody(Matchers.startsWith("simple"));
}
}
);
}
示例3: justWorks
import org.takes.tk.TkFixed; //导入依赖的package包/类
/**
* FtSecure can work.
* @throws Exception If some problem inside
*/
@Test
public void justWorks() throws Exception {
FtSecureTest.secure(new TkFixed("hello, world")).exec(
new FtRemote.Script() {
@Override
public void exec(final URI home) throws IOException {
new JdkRequest(home)
.fetch()
.as(RestResponse.class)
.assertStatus(HttpURLConnection.HTTP_OK)
.assertBody(Matchers.startsWith("hello"));
}
}
);
}
示例4: main
import org.takes.tk.TkFixed; //导入依赖的package包/类
/**
* Entry point.
* @param args Arguments
* @throws IOException If fails
*/
public static void main(final String... args) throws IOException {
final String html = new StringBuilder()
.append("<html><body>")
.append("<p>Hello, world!</p>")
.append("<p>Java version is ")
.append(System.getProperty("java.version"))
.append("</p>")
.append("<p>This page is hosted by <a href='http://www.thindeck.com'>thindeck.com</a>.</p>")
.append("<p>Source code is in <a href='https://github.com/yegor256/thindeck/tree/master/demo-docker-images/apache-php'>Github</a>.</p>")
.append("</body></html>")
.toString();
new FtCLI(
new Take() {
@Override
public Response act(final Request request) throws IOException {
return new TkFixed(new RsHTML(html)).act(request);
}
},
args
).start(Exit.NEVER);
}
示例5: acceptsCorrectContentTypeRequest
import org.takes.tk.TkFixed; //导入依赖的package包/类
/**
* TkConsumes can accept request with certain Content-Type.
* @throws IOException If some problem inside
*/
@Test
public void acceptsCorrectContentTypeRequest() throws IOException {
final String contenttype = "Content-Type: application/json";
final Take consumes = new TkConsumes(
new TkFixed(new RsJson(new RsEmpty())),
TkConsumesTest.APPLICATION_JSON
);
final Response response = consumes.act(
new RqFake(
Arrays.asList(
"GET /?TkConsumes",
contenttype
),
""
)
);
MatcherAssert.assertThat(
new RsPrint(response).print(),
Matchers.startsWith(
Joiner.on("\r\n").join(
"HTTP/1.1 200 OK",
contenttype
)
)
);
}
示例6: producesCorrectContentTypeResponse
import org.takes.tk.TkFixed; //导入依赖的package包/类
/**
* TkProduce can produce correct type response.
* @throws IOException If some problem inside
*/
@Test
public void producesCorrectContentTypeResponse() throws IOException {
final Take produces = new TkProduces(
new TkFixed(new RsJson(new RsEmpty())),
"text/json"
);
final Response response = produces.act(
new RqFake(
Arrays.asList(
"GET /hz09",
"Host: as.example.com",
"Accept: text/json"
),
""
)
);
MatcherAssert.assertThat(
new RsPrint(response).print(),
Matchers.equalTo(
Joiner.on("\r\n").join(
"HTTP/1.1 200 OK",
"Content-Type: application/json",
"",
""
)
)
);
}
示例7: reactsToCorrectStatus
import org.takes.tk.TkFixed; //导入依赖的package包/类
/**
* FbStatus can react to correct status.
* @throws Exception If some problem inside
*/
@Test
public void reactsToCorrectStatus() throws Exception {
final int status = HttpURLConnection.HTTP_NOT_FOUND;
final RqFallback req = new RqFallback.Fake(status);
MatcherAssert.assertThat(
new RsPrint(
new FbStatus(
status,
new TkFixed(new RsText("not found response"))
).route(req).get()
).printBody(),
Matchers.startsWith("not found")
);
}
示例8: ignoresDifferentStatus
import org.takes.tk.TkFixed; //导入依赖的package包/类
/**
* FbStatus can ignore different status.
* @throws Exception If some problem inside
*/
@Test
public void ignoresDifferentStatus() throws Exception {
final RqFallback req = new RqFallback.Fake(
HttpURLConnection.HTTP_NOT_FOUND
);
MatcherAssert.assertThat(
new FbStatus(
HttpURLConnection.HTTP_UNAUTHORIZED,
new TkFixed(new RsText("unauthorized"))
).route(req).has(),
Matchers.equalTo(false)
);
}
示例9: fallback
import org.takes.tk.TkFixed; //导入依赖的package包/类
/**
* Fallback.
* @param take Original take
* @return Take with fallback
*/
private static Take fallback(final Take take) {
return new TkFallback(
take,
new FbChain(
// @checkstyle MagicNumberCheck (1 line)
new FbStatus(404, new TkFixed(new RsNotFound())),
new FbError()
)
);
}
示例10: FkRegex
import org.takes.tk.TkFixed; //导入依赖的package包/类
/**
* Ctor.
* @param ptn Pattern
* @param rsp Response
* @since 0.16
*/
public FkRegex(final String ptn, final Response rsp) {
this(ptn, new TkFixed(rsp));
}
示例11: FkMethods
import org.takes.tk.TkFixed; //导入依赖的package包/类
/**
* Ctor.
* @param mtd Method
* @param rsp Response
* @since 0.22
*/
public FkMethods(final String mtd, final Response rsp) {
this(mtd, new TkFixed(rsp));
}
示例12: FkContentType
import org.takes.tk.TkFixed; //导入依赖的package包/类
/**
* Ctor.
* @param atype Accepted type
* @param response Response to return
*/
public FkContentType(final String atype, final Response response) {
this(atype, new TkFixed(response));
}
示例13: FbFixed
import org.takes.tk.TkFixed; //导入依赖的package包/类
/**
* Ctor.
* @param response Response to return
*/
public FbFixed(final Response response) {
this(new TkFixed(response));
}
示例14: FbStatus
import org.takes.tk.TkFixed; //导入依赖的package包/类
/**
* Ctor.
* @param code HTTP status code
* @param response Response
* @since 0.14
*/
public FbStatus(final int code, final Response response) {
this(code, new TkFixed(response));
}
示例15: main
import org.takes.tk.TkFixed; //导入依赖的package包/类
/**
* Main entry point.
* @param args Command line args
* @throws IOException If fails
*/
public static void main(final String... args) throws IOException {
new FtCli(new TkFixed("works fine!"), args).start(Exit.NEVER);
}