use of com.jcabi.github.mock.MkGithub in project jcabi-github by jcabi.
the class RtCommentTest method returnsItsJSon.
/**
* RtComment can return its JSon description.
* @throws Exception - if something goes wrong.
*/
@Test
public void returnsItsJSon() throws Exception {
final String body = "{\"body\":\"test5\"}";
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, body)).start(this.resource.port());
final Repo repo = new MkGithub().randomRepo();
final Issue issue = repo.issues().create("testing4", "issue4");
final RtComment comment = new RtComment(new ApacheRequest(container.home()), issue, 10);
try {
final JsonObject json = comment.json();
MatcherAssert.assertThat(json.getString("body"), Matchers.is("test5"));
} finally {
container.stop();
}
}
use of com.jcabi.github.mock.MkGithub in project jcabi-github by jcabi.
the class PullRefTest method fetchesCommit.
/**
* PullRef.Smart can fetch its commit.
* @throws IOException If there is an I/O problem.
*/
@Test
public void fetchesCommit() throws IOException {
final Repo repo = new MkGithub().randomRepo();
final Commit commit = PullRefTest.pullRef(repo).commit();
MatcherAssert.assertThat(commit.repo().coordinates(), Matchers.equalTo(repo.coordinates()));
MatcherAssert.assertThat(commit.sha(), Matchers.equalTo(PullRefTest.SHA));
}
use of com.jcabi.github.mock.MkGithub in project jcabi-github by jcabi.
the class PullTest method getsAuthor.
/**
* Pull.Smart can get the author.
* @throws IOException If some problem inside
*/
@Test
public void getsAuthor() throws IOException {
final String login = "rose";
final Repo repo = Mockito.mock(Repo.class);
Mockito.when(repo.github()).thenReturn(new MkGithub());
final Pull pull = Mockito.mock(Pull.class);
Mockito.when(pull.json()).thenReturn(Json.createObjectBuilder().add("user", Json.createObjectBuilder().add("login", login).build()).build());
Mockito.when(pull.repo()).thenReturn(repo);
MatcherAssert.assertThat(new Pull.Smart(pull).author().login(), Matchers.equalTo(login));
}
use of com.jcabi.github.mock.MkGithub in project jcabi-github by jcabi.
the class RtGistCommentTest method patchAndCheckJsonGistComment.
/**
* RtGistComment can patch comment and return new json.
* @throws IOException if has some problems with json parsing.
*/
@Test
public final void patchAndCheckJsonGistComment() throws IOException {
final int identifier = 1;
final String idString = "id";
final String bodyString = "body";
final String body = "somebody";
final String patchedBody = "some patchedbody";
final MkAnswer first = new MkAnswer.Simple(HttpURLConnection.HTTP_OK, Json.createObjectBuilder().add(bodyString, body).add(idString, identifier).build().toString());
final MkAnswer second = new MkAnswer.Simple(HttpURLConnection.HTTP_OK, Json.createObjectBuilder().add(bodyString, patchedBody).add(idString, identifier).build().toString());
final MkAnswer third = new MkAnswer.Simple(HttpURLConnection.HTTP_OK, Json.createObjectBuilder().add(bodyString, body).add(idString, identifier).build().toString());
final MkContainer container = new MkGrizzlyContainer().next(first).next(second).next(third).start(this.resource.port());
final MkContainer gistContainer = new MkGrizzlyContainer().start(this.resource.port());
final RtGist gist = new RtGist(new MkGithub(), new ApacheRequest(gistContainer.home()), "someName");
final RtGistComment comment = new RtGistComment(new ApacheRequest(container.home()), gist, identifier);
comment.patch(Json.createObjectBuilder().add(bodyString, patchedBody).add(idString, identifier).build());
MatcherAssert.assertThat(comment.json().getString(bodyString), Matchers.equalTo(patchedBody));
container.stop();
gistContainer.stop();
}
use of com.jcabi.github.mock.MkGithub in project jcabi-github by jcabi.
the class RtGistCommentTest method removeGistComment.
/**
* RtGistComment can remove comment.
* @throws IOException if has some problems with json parsing.
*/
@Test
public final void removeGistComment() throws IOException {
final int identifier = 1;
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_NO_CONTENT, "")).start(this.resource.port());
final RtGist gist = new RtGist(new MkGithub(), new FakeRequest().withStatus(HttpURLConnection.HTTP_NO_CONTENT), "gistName");
final RtGistComment comment = new RtGistComment(new ApacheRequest(container.home()), gist, identifier);
comment.remove();
MatcherAssert.assertThat(container.take().method(), Matchers.equalTo(Request.DELETE));
container.stop();
}
Aggregations