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();
}
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();
}
}
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();
}
}
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();
}
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();
}
Aggregations