Search in sources :

Example 6 with MkContainer

use of com.jcabi.http.mock.MkContainer in project jcabi-github by jcabi.

the class RtPublicKeysTest method retrievesKeys.

/**
 * RtPublicKeys should be able to iterate its keys.
 *
 * @throws Exception if a problem occurs.
 */
@Test
public void retrievesKeys() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, Json.createArrayBuilder().add(key(1)).add(key(2)).build().toString())).start();
    final RtPublicKeys keys = new RtPublicKeys(new ApacheRequest(container.home()), Mockito.mock(User.class));
    MatcherAssert.assertThat(keys.iterate(), Matchers.<PublicKey>iterableWithSize(2));
    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 7 with MkContainer

use of com.jcabi.http.mock.MkContainer 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 8 with MkContainer

use of com.jcabi.http.mock.MkContainer 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 9 with MkContainer

use of com.jcabi.http.mock.MkContainer 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 10 with MkContainer

use of com.jcabi.http.mock.MkContainer 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)

Aggregations

MkContainer (com.jcabi.http.mock.MkContainer)136 MkGrizzlyContainer (com.jcabi.http.mock.MkGrizzlyContainer)136 Test (org.junit.Test)136 ApacheRequest (com.jcabi.http.request.ApacheRequest)105 MkGithub (com.jcabi.github.mock.MkGithub)40 MkQuery (com.jcabi.http.mock.MkQuery)34 MkAnswer (com.jcabi.http.mock.MkAnswer)32 JdkRequest (com.jcabi.http.request.JdkRequest)31 JsonObject (javax.json.JsonObject)19 Request (com.jcabi.http.Request)5 JsonArray (javax.json.JsonArray)3 FakeRequest (com.jcabi.http.request.FakeRequest)2 ArrayMap (com.jcabi.immutable.ArrayMap)2 InputStream (java.io.InputStream)2 RestResponse (com.jcabi.http.response.RestResponse)1 StringReader (java.io.StringReader)1 EnumMap (java.util.EnumMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1