use of com.jcabi.http.request.ApacheRequest in project jcabi-github by jcabi.
the class RtRepoTest method iteratesEvents.
/**
* RtRepo can fetch events.
*
* @throws Exception If some problem inside
*/
@Test
public void iteratesEvents() throws Exception {
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, Json.createArrayBuilder().add(event(Event.ASSIGNED)).add(event(Event.MENTIONED)).build().toString())).start();
final Repo repo = RtRepoTest.repo(new ApacheRequest(container.home()));
MatcherAssert.assertThat(repo.issueEvents().iterate(), Matchers.<Event>iterableWithSize(2));
container.stop();
}
use of com.jcabi.http.request.ApacheRequest in project jcabi-github by jcabi.
the class RtRepoTest method iteratesLanguages.
/**
* RtRepo can iterate languages.
*
* @throws Exception If some problem inside
*/
@Test
public void iteratesLanguages() throws Exception {
final String lang = "C";
final String other = "Java";
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, Json.createObjectBuilder().add(lang, 1).add(other, 2).build().toString())).start();
final Repo repo = RtRepoTest.repo(new ApacheRequest(container.home()));
try {
final Iterator<Language> iter = repo.languages().iterator();
MatcherAssert.assertThat(iter.hasNext(), Matchers.is(true));
MatcherAssert.assertThat(iter.next().name(), Matchers.is(lang));
MatcherAssert.assertThat(iter.hasNext(), Matchers.is(true));
MatcherAssert.assertThat(iter.next().name(), Matchers.is(other));
MatcherAssert.assertThat(iter.hasNext(), Matchers.is(false));
} finally {
container.stop();
}
}
use of com.jcabi.http.request.ApacheRequest in project jcabi-github by jcabi.
the class RtReposTest method removeRepo.
/**
* RtRepos can remove a repo.
* @throws Exception if some problem inside
*/
@Test
public void removeRepo() throws Exception {
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_NO_CONTENT, "")).start();
final Repos repos = new RtRepos(Mockito.mock(Github.class), new ApacheRequest(container.home()));
repos.remove(new Coordinates.Simple("", ""));
try {
final MkQuery query = container.take();
MatcherAssert.assertThat(query.method(), Matchers.equalTo(Request.DELETE));
MatcherAssert.assertThat(query.body(), Matchers.isEmptyString());
} finally {
container.stop();
}
}
use of com.jcabi.http.request.ApacheRequest in project jcabi-github by jcabi.
the class RtOrganizationTest method canRepresentAsString.
/**
* RtOrganization can return a String representation correctly reflecting
* its URI.
*
* @throws Exception if something goes wrong.
*/
@Test
public void canRepresentAsString() throws Exception {
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "blah")).start();
final RtOrganization org = new RtOrganization(new MkGithub(), new ApacheRequest(container.home()), "testToString");
try {
MatcherAssert.assertThat(org.toString(), Matchers.endsWith("/orgs/testToString"));
} finally {
container.stop();
}
}
use of com.jcabi.http.request.ApacheRequest in project jcabi-github by jcabi.
the class RtPullCommentTest method canDescribeAsJson.
/**
* RtPullComment can return its JSON description.
* @throws Exception If a problem occurs.
*/
@Test
public void canDescribeAsJson() throws Exception {
final String body = "{\"body\":\"test\"}";
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, body)).start();
final Pull pull = Mockito.mock(Pull.class);
Mockito.doReturn(repo()).when(pull).repo();
final RtPullComment comment = new RtPullComment(new ApacheRequest(container.home()), pull, 1);
try {
final JsonObject json = comment.json();
MatcherAssert.assertThat(json.getString("body"), Matchers.is("test"));
MatcherAssert.assertThat(container.take().uri().toString(), Matchers.endsWith("/repos/joe/blueharvest/pulls/comments/1"));
} finally {
container.stop();
}
}
Aggregations