Search in sources :

Example 46 with ApacheRequest

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

the class RtGistTest method fork.

/**
 * RtGist can fork itself.
 *
 * @throws IOException If there is a problem.
 */
@Test
public void fork() throws IOException {
    final String fileContent = "success";
    final MkContainer container = new MkGrizzlyContainer();
    container.next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "{\"files\":{\"hello\":{\"raw_url\":\"world\"}}}"));
    container.next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, fileContent));
    container.next(new MkAnswer.Simple(HttpURLConnection.HTTP_CREATED, "{\"id\": \"forked\"}"));
    container.next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "{\"files\":{\"hello\":{\"raw_url\":\"world\"}}}"));
    container.next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, fileContent));
    container.start();
    final Gist gist = new RtGist(new MkGithub(), new ApacheRequest(container.home()), "test");
    final String content = gist.read("hello");
    final Gist forkedGist = gist.fork();
    try {
        MatcherAssert.assertThat(forkedGist.read("hello"), Matchers.equalTo(content));
    } 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 47 with ApacheRequest

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

the class RtGistsTest method removesGistByName.

/**
 * RtGists can remove a gist by name.
 * @throws Exception - if something goes wrong.
 */
@Test
public void removesGistByName() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_NO_CONTENT, "")).start(this.resource.port());
    final Gists gists = new RtGists(new MkGithub(), new ApacheRequest(container.home()));
    try {
        gists.remove("12234");
        final MkQuery query = container.take();
        MatcherAssert.assertThat(query.method(), Matchers.equalTo(Request.DELETE));
    } finally {
        container.stop();
    }
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) MkQuery(com.jcabi.http.mock.MkQuery) MkGithub(com.jcabi.github.mock.MkGithub) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 48 with ApacheRequest

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

the class RtHookTest method performsValidRequest.

/**
 * RtHook should perform a JSON request to "/repos/:owner/:repo/hooks/:id".
 *
 * @throws Exception If a problem occurs.
 */
@Test
public void performsValidRequest() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "{\"test\":\"hook\"}")).start();
    try {
        final Hook hook = new RtHook(new ApacheRequest(container.home()), repo(), 1);
        MatcherAssert.assertThat(hook.json(), Matchers.notNullValue());
        MatcherAssert.assertThat(container.take().uri().toString(), Matchers.endsWith("/repos/test/repo/hooks/1"));
    } finally {
        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 49 with ApacheRequest

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

the class RtBlobsTest method canCreateBlob.

/**
 * RtBlobs can create a blob.
 *
 * @throws Exception if some problem inside
 */
@Test
public void canCreateBlob() throws Exception {
    final String content = "Content of the blob";
    final String body = blob().toString();
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_CREATED, body)).next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, body)).start();
    final RtBlobs blobs = new RtBlobs(new ApacheRequest(container.home()), repo());
    try {
        final Blob blob = blobs.create(content, "utf-8");
        MatcherAssert.assertThat(container.take().method(), Matchers.equalTo(Request.POST));
        MatcherAssert.assertThat(new Blob.Smart(blob).url(), Matchers.equalTo("http://localhost/1"));
    } finally {
        container.stop();
    }
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) MkAnswer(com.jcabi.http.mock.MkAnswer) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 50 with ApacheRequest

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

the class RtCommentTest method patchesComment.

/**
 * RtComment can patch a comment.
 * @throws Exception - if anything goes wrong.
 */
@Test
public void patchesComment() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "")).start(this.resource.port());
    final Repo repo = new MkGithub().randomRepo();
    final Issue issue = repo.issues().create("testing5", "issue5");
    final RtComment comment = new RtComment(new ApacheRequest(container.home()), issue, 10);
    final JsonObject jsonPatch = Json.createObjectBuilder().add("title", "test comment").build();
    try {
        comment.patch(jsonPatch);
        final MkQuery query = container.take();
        MatcherAssert.assertThat(query.method(), Matchers.equalTo(Request.PATCH));
    } finally {
        container.stop();
    }
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) MkQuery(com.jcabi.http.mock.MkQuery) JsonObject(javax.json.JsonObject) MkGithub(com.jcabi.github.mock.MkGithub) 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