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