Search in sources :

Example 91 with ApacheRequest

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

the class RtPaginationTest method throwsIfNoMoreElement.

/**
 * RtPagination can throw if there is no more elements in pagination.
 *
 * @throws Exception if there is any problem
 */
@Test(expected = NoSuchElementException.class)
public void throwsIfNoMoreElement() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(simple("Hi there")).start();
    try {
        final Request request = new ApacheRequest(container.home());
        final RtPagination<JsonObject> page = new RtPagination<JsonObject>(request, new RtValuePagination.Mapping<JsonObject, JsonObject>() {

            @Override
            public JsonObject map(final JsonObject object) {
                return object;
            }
        });
        final Iterator<JsonObject> iterator = page.iterator();
        iterator.next();
        MatcherAssert.assertThat(iterator.next(), Matchers.notNullValue());
    } finally {
        container.stop();
    }
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) Request(com.jcabi.http.Request) ApacheRequest(com.jcabi.http.request.ApacheRequest) JsonObject(javax.json.JsonObject) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 92 with ApacheRequest

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

the class RtPublicKeysTest method canFetchSingleKey.

/**
 * RtPublicKeys should be able to obtain a single key.
 *
 * @throws Exception if a problem occurs.
 */
@Test
public void canFetchSingleKey() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "")).start();
    final RtPublicKeys keys = new RtPublicKeys(new ApacheRequest(container.home()), Mockito.mock(User.class));
    try {
        MatcherAssert.assertThat(keys.get(1), Matchers.notNullValue());
    } 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 93 with ApacheRequest

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

the class RtPublicMembersTest method publicizesMembers.

/**
 * RtPublicMembers can publicize the membership of
 * a user in the organization.
 * @throws IOException If there is an I/O problem
 */
@Test
public void publicizesMembers() 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.publicize(user());
        final MkQuery req = container.take();
        MatcherAssert.assertThat(req.method(), Matchers.equalTo(Request.PUT));
        MatcherAssert.assertThat(req.uri().toString(), Matchers.endsWith(MEMBER_URL));
        this.thrown.expect(AssertionError.class);
        members.publicize(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 94 with ApacheRequest

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

the class RtPublicMembersTest method checkPublicMembership.

/**
 * RtPublicMembers can check whether a user
 * is a public member of the organization.
 * @throws IOException If there is an I/O problem
 */
@Test
public void checkPublicMembership() throws IOException {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_NOT_FOUND)).next(new MkAnswer.Simple(HttpURLConnection.HTTP_NOT_FOUND)).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.contains(user());
        final MkQuery req = container.take();
        MatcherAssert.assertThat(req.method(), Matchers.equalTo(Request.GET));
        MatcherAssert.assertThat(req.uri().toString(), Matchers.endsWith(MEMBER_URL));
        MatcherAssert.assertThat("404 is interpreted as the user not being a public member", !members.contains(user()));
        MatcherAssert.assertThat("204 is interpreted as the user being a public member", members.contains(user()));
        this.thrown.expect(AssertionError.class);
        members.contains(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 95 with ApacheRequest

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

the class RtPullCommentsTest method removesPullComment.

/**
 * RtPullComments can remove a pull comment.
 *
 * @throws Exception If something goes wrong.
 */
@Test
public void removesPullComment() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_NO_CONTENT, "")).start(this.resource.port());
    final Pull pull = Mockito.mock(Pull.class);
    final Repo repository = repo();
    Mockito.doReturn(repository).when(pull).repo();
    final RtPullComments comments = new RtPullComments(new ApacheRequest(container.home()), pull);
    try {
        comments.remove(2);
        final MkQuery query = container.take();
        MatcherAssert.assertThat(query.method(), Matchers.equalTo(Request.DELETE));
        MatcherAssert.assertThat(query.uri().toString(), Matchers.endsWith(String.format("/repos/johnny/%s/pulls/0/comments/2", repository.coordinates().repo())));
    } 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