Search in sources :

Example 6 with ApacheRequest

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

the class RtPublicMembersTest method iteratesPublicMembers.

/**
 * RtPublicMembers can list the public members of the organization.
 * @throws IOException If there is an I/O problem
 */
@Test
public void iteratesPublicMembers() throws IOException {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "[{\"login\":\"octobat\"}]")).next(new MkAnswer.Simple(HttpURLConnection.HTTP_INTERNAL_ERROR)).start();
    try {
        final RtPublicMembers members = new RtPublicMembers(new ApacheRequest(container.home()), organization());
        members.iterate().iterator().next();
        final MkQuery req = container.take();
        MatcherAssert.assertThat(req.method(), Matchers.equalTo(Request.GET));
        MatcherAssert.assertThat(req.uri().toString(), Matchers.endsWith(MEMBERS_URL));
        this.thrown.expect(AssertionError.class);
        members.iterate().iterator().next();
    } finally {
        container.stop();
    }
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) MkAnswer(com.jcabi.http.mock.MkAnswer) MkQuery(com.jcabi.http.mock.MkQuery) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 7 with ApacheRequest

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

the class RtPublicMembersTest method concealsMembers.

/**
 * RtPublicMembers can conceal a user's membership in the organization.
 * @throws IOException If there is an I/O problem
 */
@Test
public void concealsMembers() throws IOException {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_NO_CONTENT)).next(new MkAnswer.Simple(HttpURLConnection.HTTP_INTERNAL_ERROR)).start();
    try {
        final RtPublicMembers members = new RtPublicMembers(new ApacheRequest(container.home()), organization());
        members.conceal(user());
        final MkQuery req = container.take();
        MatcherAssert.assertThat(req.method(), Matchers.equalTo(Request.DELETE));
        MatcherAssert.assertThat(req.body(), Matchers.isEmptyOrNullString());
        MatcherAssert.assertThat(req.uri().toString(), Matchers.endsWith(MEMBER_URL));
        this.thrown.expect(AssertionError.class);
        members.conceal(user());
    } finally {
        container.stop();
    }
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) MkAnswer(com.jcabi.http.mock.MkAnswer) MkQuery(com.jcabi.http.mock.MkQuery) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 8 with ApacheRequest

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

the class RtPullCommentsTest method createsPullComment.

/**
 * RtPullComments can post a new a pull comment.
 *
 * @throws Exception If something goes wrong.
 */
@Test
public void createsPullComment() throws Exception {
    // @checkstyle MultipleStringLiterals (3 line)
    final String body = "test-body";
    final String commit = "test-commit-id";
    final String path = "test-path";
    final int position = 4;
    final String response = pulls(body, commit, path, position).toString();
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_CREATED, response)).next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, response)).start(this.resource.port());
    final Pull pull = Mockito.mock(Pull.class);
    Mockito.doReturn(repo()).when(pull).repo();
    final RtPullComments pullComments = new RtPullComments(new ApacheRequest(container.home()), pull);
    try {
        final PullComment pullComment = pullComments.post(body, commit, path, position);
        MatcherAssert.assertThat(container.take().method(), Matchers.equalTo(Request.POST));
        MatcherAssert.assertThat(new PullComment.Smart(pullComment).commitId(), Matchers.equalTo(commit));
    } 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 9 with ApacheRequest

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

the class RtPullCommentsTest method createsPullCommentReply.

/**
 * RtPullComments can reply to an existing pull comment.
 *
 * @throws Exception If something goes wrong.
 */
@Test
public void createsPullCommentReply() throws Exception {
    final String body = "test-body";
    final int number = 4;
    final String response = Json.createObjectBuilder().add("id", Tv.BILLION).add("body", body).add("in_reply_to", number).build().toString();
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_CREATED, response)).next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, response)).start(this.resource.port());
    final Pull pull = Mockito.mock(Pull.class);
    Mockito.doReturn(repo()).when(pull).repo();
    final RtPullComments pullComments = new RtPullComments(new ApacheRequest(container.home()), pull);
    try {
        final PullComment pullComment = pullComments.reply(body, number);
        MatcherAssert.assertThat(container.take().method(), Matchers.equalTo(Request.POST));
        MatcherAssert.assertThat(new PullComment.Smart(pullComment).reply(), Matchers.equalTo(number));
    } 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 10 with ApacheRequest

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

the class RtPullsTest method getSinglePull.

/**
 * RtPulls can get a single pull request.
 * @throws Exception if some problem inside
 */
@Test
public void getSinglePull() throws Exception {
    final String title = "new-feature";
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, pull(title).toString())).start();
    final RtPulls pulls = new RtPulls(new ApacheRequest(container.home()), repo());
    final Pull pull = pulls.get(Tv.BILLION);
    MatcherAssert.assertThat(new Pull.Smart(pull).title(), Matchers.equalTo(title));
    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)

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