Search in sources :

Example 31 with ApacheRequest

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();
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 32 with ApacheRequest

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();
    }
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) MkAnswer(com.jcabi.http.mock.MkAnswer) MkGithub(com.jcabi.github.mock.MkGithub) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 33 with ApacheRequest

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();
    }
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) MkAnswer(com.jcabi.http.mock.MkAnswer) MkGithub(com.jcabi.github.mock.MkGithub) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 34 with ApacheRequest

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();
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 35 with ApacheRequest

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();
    }
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) InputStream(java.io.InputStream) ApacheRequest(com.jcabi.http.request.ApacheRequest) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Aggregations

ApacheRequest (com.jcabi.http.request.ApacheRequest)106 MkContainer (com.jcabi.http.mock.MkContainer)105 MkGrizzlyContainer (com.jcabi.http.mock.MkGrizzlyContainer)105 Test (org.junit.Test)105 MkGithub (com.jcabi.github.mock.MkGithub)38 MkQuery (com.jcabi.http.mock.MkQuery)30 MkAnswer (com.jcabi.http.mock.MkAnswer)24 JsonObject (javax.json.JsonObject)19 Request (com.jcabi.http.Request)5 JsonArray (javax.json.JsonArray)3 FakeRequest (com.jcabi.http.request.FakeRequest)2 InputStream (java.io.InputStream)2 ArrayMap (com.jcabi.immutable.ArrayMap)1 StringReader (java.io.StringReader)1