Search in sources :

Example 56 with ApacheRequest

use of com.jcabi.http.request.ApacheRequest in project jcabi-github by jcabi.

the class RtGistsTest method canCreateFiles.

/**
 * RtGists can create new files.
 *
 * @throws Exception if a problem occurs.
 */
@Test
public void canCreateFiles() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_CREATED, "{\"id\":\"1\"}")).start(this.resource.port());
    final Gists gists = new RtGists(new MkGithub(), new ApacheRequest(container.home()));
    try {
        MatcherAssert.assertThat(gists.create(Collections.singletonMap("test", ""), false), Matchers.notNullValue());
        MatcherAssert.assertThat(container.take().body(), Matchers.startsWith("{\"files\":{\"test\":{\"content\":"));
    } finally {
        container.stop();
    }
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) MkGithub(com.jcabi.github.mock.MkGithub) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 57 with ApacheRequest

use of com.jcabi.http.request.ApacheRequest in project jcabi-github by jcabi.

the class RtGistsTest method canIterateThrouRtGists.

/**
 * RtGists can iterate through its contents.
 *
 * @throws Exception if a problem occurs.
 */
@Test
public void canIterateThrouRtGists() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "[{\"id\":\"hello\"}]")).start(this.resource.port());
    final Gists gists = new RtGists(new MkGithub(), new ApacheRequest(container.home()));
    try {
        MatcherAssert.assertThat(gists.iterate().iterator().next(), Matchers.notNullValue());
    } finally {
        container.stop();
    }
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) MkGithub(com.jcabi.github.mock.MkGithub) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 58 with ApacheRequest

use of com.jcabi.http.request.ApacheRequest in project jcabi-github by jcabi.

the class RtGistsTest method canRetrieveSpecificGist.

/**
 * RtGists can retrieve a specific Gist.
 *
 * @throws Exception if a problem occurs.
 */
@Test
public void canRetrieveSpecificGist() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "testing")).start(this.resource.port());
    final Gists gists = new RtGists(new MkGithub(), new ApacheRequest(container.home()));
    try {
        MatcherAssert.assertThat(gists.get("gist"), Matchers.notNullValue());
    } finally {
        container.stop();
    }
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) MkGithub(com.jcabi.github.mock.MkGithub) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 59 with ApacheRequest

use of com.jcabi.http.request.ApacheRequest in project jcabi-github by jcabi.

the class RtIssueTest method patchWithJson.

/**
 * RtIssue should be able to perform a patch request.
 *
 * @throws Exception if a problem occurs.
 */
@Test
public void patchWithJson() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "response")).start(this.resource.port());
    final RtIssue issue = new RtIssue(new ApacheRequest(container.home()), this.repo(), 1);
    issue.patch(Json.createObjectBuilder().add("patch", "test").build());
    final MkQuery query = container.take();
    try {
        MatcherAssert.assertThat(query.method(), Matchers.equalTo(Request.PATCH));
        MatcherAssert.assertThat(query.body(), Matchers.equalTo("{\"patch\":\"test\"}"));
    } finally {
        container.stop();
    }
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) MkQuery(com.jcabi.http.mock.MkQuery) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 60 with ApacheRequest

use of com.jcabi.http.request.ApacheRequest in project jcabi-github by jcabi.

the class RtContentTest method patchWithJson.

/**
 * RtContent should be able to perform a patch request.
 *
 * @throws Exception if a problem occurs.
 */
@Test
public void patchWithJson() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "response")).start(this.resource.port());
    final RtContent content = new RtContent(new ApacheRequest(container.home()), this.repo(), "path");
    content.patch(Json.createObjectBuilder().add("patch", "test").build());
    final MkQuery query = container.take();
    try {
        MatcherAssert.assertThat(query.method(), Matchers.equalTo(Request.PATCH));
        MatcherAssert.assertThat(query.body(), Matchers.equalTo("{\"patch\":\"test\"}"));
    } finally {
        container.stop();
    }
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) MkQuery(com.jcabi.http.mock.MkQuery) 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