Search in sources :

Example 86 with ApacheRequest

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

the class RtValuePaginationTest method jumpNextPage.

/**
 * RtPagination can jump to next page of results.
 * @throws Exception if there is any problem
 */
@Test
public void jumpNextPage() throws Exception {
    final String jeff = "Jeff";
    final String mark = "Mark";
    final String judy = "Judy";
    final String jessy = "Jessy";
    final MkContainer container = new MkGrizzlyContainer().next(RtValuePaginationTest.simple(jeff, mark).withHeader("Link", "</s?page=3&per_page=100>; rel=\"next\"")).next(RtValuePaginationTest.simple(judy, jessy)).start();
    final Request request = new ApacheRequest(container.home());
    final RtValuePagination<JsonObject, JsonArray> page = new RtValuePagination<JsonObject, JsonArray>(request, new RtValuePagination.Mapping<JsonObject, JsonArray>() {

        @Override
        public JsonObject map(final JsonArray object) {
            return Json.createObjectBuilder().add("id1", object.getString(0)).add("id2", object.getString(1)).build();
        }
    });
    final Iterator<JsonObject> iterator = page.iterator();
    MatcherAssert.assertThat(iterator.next().toString(), Matchers.allOf(Matchers.containsString(jeff), Matchers.containsString(mark)));
    MatcherAssert.assertThat(iterator.next().toString(), Matchers.allOf(Matchers.containsString(judy), Matchers.containsString(jessy)));
    container.stop();
}
Also used : JsonArray(javax.json.JsonArray) 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 87 with ApacheRequest

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

the class RtValuePaginationTest method throwsIfNoMoreElement.

/**
 * RtValuePagination 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 String jeff = "other Jeff";
    final String mark = "other Mark";
    final MkContainer container = new MkGrizzlyContainer().next(RtValuePaginationTest.simple(jeff, mark)).start();
    try {
        final Request request = new ApacheRequest(container.home());
        final RtValuePagination<JsonObject, JsonArray> page = new RtValuePagination<JsonObject, JsonArray>(request, new RtValuePagination.Mapping<JsonObject, JsonArray>() {

            @Override
            public JsonObject map(final JsonArray object) {
                return Json.createObjectBuilder().add("id3", object.getString(0)).add("id4", object.getString(1)).build();
            }
        });
        final Iterator<JsonObject> iterator = page.iterator();
        iterator.next();
        MatcherAssert.assertThat(iterator.next(), Matchers.notNullValue());
    } finally {
        container.stop();
    }
}
Also used : JsonArray(javax.json.JsonArray) 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 88 with ApacheRequest

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

the class RtUserOrganizationsTest method canIterateOrganizationsForUnauthUser.

/**
 * RtUserOrganizations can iterate organizations for
 * an unauthenticated user.
 *
 * @throws Exception If a problem occurs
 */
@Test
public void canIterateOrganizationsForUnauthUser() throws Exception {
    final String username = "octopus";
    final Github github = new MkGithub();
    final User user = github.users().get(username);
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, Json.createArrayBuilder().add(org(Tv.THREE, "org11")).add(org(Tv.FOUR, "org12")).add(org(Tv.FIVE, "org13")).build().toString())).start();
    try {
        final UserOrganizations orgs = new RtUserOrganizations(github, new ApacheRequest(container.home()), user);
        MatcherAssert.assertThat(orgs.iterate(), Matchers.<Organization>iterableWithSize(Tv.THREE));
        MatcherAssert.assertThat(container.take().uri().toString(), Matchers.endsWith(String.format("/users/%s/orgs", username)));
    } finally {
        container.stop();
    }
}
Also used : MkGithub(com.jcabi.github.mock.MkGithub) 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 89 with ApacheRequest

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

the class RtUsersTest method getSingleUser.

/**
 * RtUsers can get a single user.
 *
 * @throws Exception  if there is any error
 */
@Test
public void getSingleUser() throws Exception {
    final String login = "mark";
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, RtUsersTest.json(login, "3").toString())).start();
    final Users users = new RtUsers(Mockito.mock(Github.class), new ApacheRequest(container.home()));
    MatcherAssert.assertThat(users.get(login).login(), Matchers.equalTo(login));
    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 90 with ApacheRequest

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

the class RtPaginationTest method jumpNextPage.

/**
 * RtPagination can jump to next page of results.
 *
 * @throws Exception if there is any problem
 */
@Test
public void jumpNextPage() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(RtPaginationTest.simple("Hi Jeff").withHeader("Link", "</s?page=3&per_page=100>; rel=\"next\"")).next(RtPaginationTest.simple("Hi Mark")).start();
    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();
    MatcherAssert.assertThat(iterator.next().toString(), Matchers.containsString("Jeff"));
    MatcherAssert.assertThat(iterator.next().toString(), Matchers.containsString("Mark"));
    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)

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