本文整理汇总了Java中com.jcabi.http.response.XmlResponse类的典型用法代码示例。如果您正苦于以下问题:Java XmlResponse类的具体用法?Java XmlResponse怎么用?Java XmlResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XmlResponse类属于com.jcabi.http.response包,在下文中一共展示了XmlResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: rendersHomePageViaHttp
import com.jcabi.http.response.XmlResponse; //导入依赖的package包/类
/**
* App can render front page.
* @throws Exception If some problem inside
*/
@Test
public void rendersHomePageViaHttp() throws Exception {
final Take app = new TkApp(new FakeBase());
new FtRemote(app).exec(
home -> {
new JdkRequest(home)
.fetch()
.as(RestResponse.class)
.assertStatus(HttpURLConnection.HTTP_OK)
.as(XmlResponse.class)
.assertXPath("/xhtml:html");
new JdkRequest(home)
.through(VerboseWire.class)
.header("Accept", "application/xml")
.fetch()
.as(RestResponse.class)
.assertStatus(HttpURLConnection.HTTP_OK)
.as(XmlResponse.class)
.assertXPath("/page/version");
}
);
}
示例2: rendersHomePageViaHttp
import com.jcabi.http.response.XmlResponse; //导入依赖的package包/类
@Test
public void rendersHomePageViaHttp() throws Exception {
final Take app = new TkApp(new FkBase());
new FtRemote(app).exec(
home -> {
new JdkRequest(home)
.fetch()
.as(RestResponse.class)
.assertStatus(HttpURLConnection.HTTP_OK)
.as(XmlResponse.class)
.assertXPath("/xhtml:html");
new JdkRequest(home)
.through(VerboseWire.class)
.header("accept", "application/xml")
.fetch()
.as(RestResponse.class)
.assertStatus(HttpURLConnection.HTTP_OK)
.as(XmlResponse.class)
.assertXPath("/page/version");
}
);
}
示例3: rendersHomePageViaHttp
import com.jcabi.http.response.XmlResponse; //导入依赖的package包/类
/**
* App can render front page.
* @throws Exception If some problem inside
*/
@Test
public void rendersHomePageViaHttp() throws Exception {
final Take app = new TkApp(new FkBase());
new FtRemote(app).exec(
home -> {
new JdkRequest(home)
.fetch()
.as(RestResponse.class)
.assertStatus(HttpURLConnection.HTTP_OK)
.as(XmlResponse.class)
.assertXPath("/xhtml:html");
new JdkRequest(home)
.through(VerboseWire.class)
.header("Accept", "application/xml")
.fetch()
.as(RestResponse.class)
.assertStatus(HttpURLConnection.HTTP_OK)
.as(XmlResponse.class)
.assertXPath("/page/version");
}
);
}
示例4: token
import com.jcabi.http.response.XmlResponse; //导入依赖的package包/类
/**
* Retrieve Github access token.
* @param home Home of this page
* @param code Github "authorization code"
* @return The token
* @throws IOException If failed
*/
private String token(final String home, final String code)
throws IOException {
final String uri = new Href(this.github)
.path(PsGithub.LOGIN).path("oauth").path(PsGithub.ACCESS_TOKEN)
.toString();
final List<String> tokens = new JdkRequest(uri)
.method("POST")
.header("Accept", "application/xml")
.body()
.formParam("client_id", this.app)
.formParam("redirect_uri", home)
.formParam("client_secret", this.key)
.formParam(PsGithub.CODE, code)
.back()
.fetch().as(RestResponse.class)
.assertStatus(HttpURLConnection.HTTP_OK)
.as(XmlResponse.class)
.xml().xpath("/OAuth/access_token/text()");
if (tokens.isEmpty()) {
throw new HttpException(
HttpURLConnection.HTTP_BAD_REQUEST, "No access token"
);
}
return tokens.get(0);
}
示例5: justWorks
import com.jcabi.http.response.XmlResponse; //导入依赖的package包/类
/**
* App can work.
* @throws Exception If some problem inside
*/
@Test
public void justWorks() throws Exception {
final File dir = this.temp.newFolder();
FileUtils.write(new File(dir, "hello.txt"), "hello, world!");
new FtRemote(new App(dir)).exec(
new FtRemote.Script() {
@Override
public void exec(final URI home) throws IOException {
new JdkRequest(home)
.uri().path("/f").back()
.through(VerboseWire.class)
.fetch()
.as(RestResponse.class)
.assertStatus(HttpURLConnection.HTTP_OK)
.as(XmlResponse.class)
.assertXPath("//xhtml:li[.='hello.txt: 13']");
}
}
);
}
示例6: launchesOnRandomPort
import com.jcabi.http.response.XmlResponse; //导入依赖的package包/类
/**
* Launches web server on random port.
* @throws Exception If fails
*/
@Test
public void launchesOnRandomPort() throws Exception {
final TkApp app = new TkApp(new MkBase());
new FtRemote(app).exec(
new FtRemote.Script() {
@Override
public void exec(final URI home) throws IOException {
new JdkRequest(home)
.fetch()
.as(RestResponse.class)
.assertStatus(HttpURLConnection.HTTP_OK)
.as(XmlResponse.class)
.assertXPath("/xhtml:html");
new JdkRequest(home)
.through(VerboseWire.class)
.header("Accept", "application/xml")
.fetch()
.as(RestResponse.class)
.assertStatus(HttpURLConnection.HTTP_OK)
.as(XmlResponse.class)
.assertXPath("/page/version");
}
}
);
}
示例7: launchesWebServerInNonLatinLocale
import com.jcabi.http.response.XmlResponse; //导入依赖的package包/类
/**
* TsApp can launch web server in non-latin locale.
* @throws Exception If fails
*/
@Test
public void launchesWebServerInNonLatinLocale() throws Exception {
final Locale def = Locale.getDefault();
try {
Locale.setDefault(Locale.CHINESE);
final TkApp app = new TkApp(new MkBase());
new FtRemote(app).exec(
new FtRemote.Script() {
@Override
public void exec(final URI home) throws IOException {
new JdkRequest(home)
.fetch()
.as(RestResponse.class)
.assertStatus(HttpURLConnection.HTTP_OK)
.as(XmlResponse.class)
.assertXPath("/xhtml:html");
}
}
);
} finally {
Locale.setDefault(def);
}
}
示例8: processed
import com.jcabi.http.response.XmlResponse; //导入依赖的package包/类
/**
* Return a response after real processing of the CSS.
* @param css The CSS stylesheet to check
* @return The response
* @throws IOException if fails
*/
private ValidationResponse processed(final String css) throws IOException {
final Request req = this.request(
AbstractBaseValidator.entity(
"file", DefaultCssValidator.filter(css), "text/css"
)
);
final Response response = DefaultCssValidator.correct(req.fetch());
return DefaultCssValidator.build(
response.as(XmlResponse.class)
.registerNs("env", "http://www.w3.org/2003/05/soap-envelope")
.registerNs("m", "http://www.w3.org/2005/07/css-validator")
.assertXPath("//m:validity")
.assertXPath("//m:checkedby")
.xml()
);
}
示例9: validate
import com.jcabi.http.response.XmlResponse; //导入依赖的package包/类
@Override
public ValidationResponse validate(final String html)
throws IOException {
final Request req = this.request(html);
final Response response = req.fetch();
if (response.status() != HttpURLConnection.HTTP_OK) {
throw new IOException(
response.reason()
);
}
return this.build(
response.as(XmlResponse.class)
.registerNs("nu", "http://n.validator.nu/messages/")
.assertXPath("//nu:messages")
.assertXPath("//nu:source")
.xml()
);
}
示例10: hitsAbsentPages
import com.jcabi.http.response.XmlResponse; //导入依赖的package包/类
/**
* IndexRs can hit not-found pages.
* @throws Exception If some problem inside
*/
@Test
@Ignore
public void hitsAbsentPages() throws Exception {
final String[] pages = {
"/page-doesnt-exist",
"/xsl/xsl-stylesheet-doesnt-exist.xsl",
"/css/stylesheet-is-absent.css",
};
for (final String page : pages) {
new JdkRequest(IndexRsITCase.HOME)
.uri().path(page).back()
.fetch()
.as(RestResponse.class)
.assertStatus(HttpURLConnection.HTTP_NOT_FOUND)
.as(XmlResponse.class)
.assertXPath("//xhtml:h1[contains(.,'Page not found')]");
}
}
示例11: renderAbsentPages
import com.jcabi.http.response.XmlResponse; //导入依赖的package包/类
/**
* IndexRs can render absent pages.
* @throws Exception If some problem inside
*/
@Test
@Ignore
public void renderAbsentPages() throws Exception {
final String[] pages = {
"/page-doesnt-exist",
"/xsl/xsl-stylesheet-doesnt-exist.xsl",
"/css/stylesheet-is-absent.css",
};
final Request request = new JdkRequest(HomeRsITCase.HOME);
for (final String page : pages) {
request.uri().path(page).back()
.method(Request.GET)
.fetch()
.as(RestResponse.class)
.assertStatus(HttpURLConnection.HTTP_NOT_FOUND)
.as(XmlResponse.class)
.assertXPath("//xhtml:title[contains(.,'page not found')]");
}
}
示例12: token
import com.jcabi.http.response.XmlResponse; //导入依赖的package包/类
/**
* Retrieve Github access token.
* @param code Github "authorization code"
* @return The token
* @throws IOException If failed
*/
private String token(final String code) throws IOException {
final URI uri = UriBuilder
.fromUri("https://github.com/login/oauth/access_token")
.queryParam("client_id", "{id}")
.queryParam("redirect_uri", "{uri}")
.queryParam("client_secret", "{secret}")
.queryParam("code", "{code}")
.build(
this.app,
this.redirectUri(),
this.key,
code
);
return new JdkRequest(uri)
.method(Request.POST)
.header(HttpHeaders.ACCEPT, MediaType.APPLICATION_XML)
.fetch().as(RestResponse.class)
.assertStatus(HttpURLConnection.HTTP_OK)
.as(XmlResponse.class)
.xml().xpath("/OAuth/access_token/text()").get(0);
}
示例13: justWorks
import com.jcabi.http.response.XmlResponse; //导入依赖的package包/类
/**
* App can work.
* @throws Exception If some problem inside
* @checkstyle NonStaticMethodCheck (2 lines)
*/
@Test
public void justWorks() throws Exception {
Assume.assumeNotNull(AppITCase.HOME);
new JdkRequest(String.format("%s/f", AppITCase.HOME))
.through(VerboseWire.class)
.fetch()
.as(RestResponse.class)
.assertStatus(HttpURLConnection.HTTP_OK)
.as(XmlResponse.class)
.assertXPath("//xhtml:html");
}
示例14: sendsHttpRequestAndProcessesHttpResponse
import com.jcabi.http.response.XmlResponse; //导入依赖的package包/类
/**
* BaseRequest can fetch HTTP request and process HTTP response.
* @throws Exception If something goes wrong inside
*/
@Test
public void sendsHttpRequestAndProcessesHttpResponse() throws Exception {
this.request(new URI("http://http.jcabi.com"))
.fetch().as(RestResponse.class)
.assertStatus(HttpURLConnection.HTTP_OK)
.as(XmlResponse.class)
.assertXPath("/xhtml:html");
}
示例15: assertsResponseBodyWithXpathQuery
import com.jcabi.http.response.XmlResponse; //导入依赖的package包/类
/**
* BaseRequest can assert response body content with XPath query.
* @throws Exception If something goes wrong inside.
*/
@Test
public void assertsResponseBodyWithXpathQuery() throws Exception {
final MkContainer container = new MkGrizzlyContainer().next(
new MkAnswer.Simple("<root><a>\u0443\u0440\u0430!</a></root>")
).start();
this.request(container.home())
.method(Request.GET)
.fetch().as(RestResponse.class)
.assertStatus(HttpURLConnection.HTTP_OK)
.as(XmlResponse.class)
.assertXPath("/root/a[contains(.,'!')]");
container.stop();
}