use of com.jcabi.http.request.ApacheRequest in project jcabi-github by jcabi.
the class RtJsonTest method sendHttpRequest.
/**
* RtJson can fetch HTTP request.
*
* @throws Exception if there is any problem
*/
@Test
public void sendHttpRequest() throws Exception {
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "{\"body\":\"hi\"}")).start();
final RtJson json = new RtJson(new ApacheRequest(container.home()));
MatcherAssert.assertThat(json.fetch().getString("body"), Matchers.equalTo("hi"));
container.stop();
}
use of com.jcabi.http.request.ApacheRequest in project jcabi-github by jcabi.
the class RtMarkdownTest method returnsJsonOutput.
/**
* RtMarkdown should be able to return JSON output.
*
* @throws Exception If a problem occurs.
*/
@Test
public void returnsJsonOutput() throws Exception {
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "{\"a\":\"b\"}").withHeader(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_HTML)).start(this.resource.port());
final RtMarkdown markdown = new RtMarkdown(new MkGithub(), new ApacheRequest(container.home()));
try {
MatcherAssert.assertThat(markdown.render(Json.createObjectBuilder().add("hello", "world").build()), Matchers.equalTo("{\"a\":\"b\"}"));
MatcherAssert.assertThat(container.take().body(), Matchers.equalTo("{\"hello\":\"world\"}"));
} finally {
container.stop();
}
}
use of com.jcabi.http.request.ApacheRequest in project jcabi-github by jcabi.
the class RtMarkdownTest method returnsRawOutput.
/**
* RtMarkdown should be able to return raw output.
*
* @throws Exception If a problem occurs.
*/
@Test
public void returnsRawOutput() throws Exception {
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "Test Output").withHeader(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_HTML)).start(this.resource.port());
final RtMarkdown markdown = new RtMarkdown(new MkGithub(), new ApacheRequest(container.home()));
try {
MatcherAssert.assertThat(markdown.raw("Hello World!"), Matchers.equalTo("Test Output"));
MatcherAssert.assertThat(container.take().body(), Matchers.equalTo("Hello World!"));
} finally {
container.stop();
}
}
use of com.jcabi.http.request.ApacheRequest in project jcabi-github by jcabi.
the class RtLabelTest method executePatchRequest.
/**
* GhLabel can execute PATCH request.
*
* @throws Exception if there is any problem
*/
@Test
public void executePatchRequest() throws Exception {
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "{\"msg\":\"hi\"}")).start();
final RtLabel label = new RtLabel(new ApacheRequest(container.home()), RtLabelTest.repo(), "enhance");
label.patch(Json.createObjectBuilder().add("content", "hi you!").build());
MatcherAssert.assertThat(container.take().method(), Matchers.equalTo(Request.PATCH));
container.stop();
}
use of com.jcabi.http.request.ApacheRequest in project jcabi-github by jcabi.
the class RtContentTest method fetchesRawContent.
/**
* RtContent should be able to fetch raw content.
*
* @throws Exception if a problem occurs.
*/
@Test
public void fetchesRawContent() throws Exception {
final String raw = "the raw \u20ac";
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, raw)).start(this.resource.port());
final InputStream stream = new RtContent(new ApacheRequest(container.home()), this.repo(), "raw").raw();
try {
MatcherAssert.assertThat(IOUtils.toString(stream, StandardCharsets.UTF_8), Matchers.is(raw));
MatcherAssert.assertThat(container.take().headers().get(HttpHeaders.ACCEPT).get(0), Matchers.is("application/vnd.github.v3.raw"));
} finally {
stream.close();
container.stop();
}
}
Aggregations