Search in sources :

Example 26 with MkGithub

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();
    }
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) JsonObject(javax.json.JsonObject) MkGithub(com.jcabi.github.mock.MkGithub) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 27 with MkGithub

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));
}
Also used : MkGithub(com.jcabi.github.mock.MkGithub) Test(org.junit.Test)

Example 28 with MkGithub

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));
}
Also used : MkGithub(com.jcabi.github.mock.MkGithub) Test(org.junit.Test)

Example 29 with MkGithub

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();
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) MkAnswer(com.jcabi.http.mock.MkAnswer) MkGithub(com.jcabi.github.mock.MkGithub) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 30 with MkGithub

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();
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) MkGithub(com.jcabi.github.mock.MkGithub) MkContainer(com.jcabi.http.mock.MkContainer) FakeRequest(com.jcabi.http.request.FakeRequest) Test(org.junit.Test)

Aggregations

MkGithub (com.jcabi.github.mock.MkGithub)57 Test (org.junit.Test)55 MkContainer (com.jcabi.http.mock.MkContainer)40 MkGrizzlyContainer (com.jcabi.http.mock.MkGrizzlyContainer)40 ApacheRequest (com.jcabi.http.request.ApacheRequest)38 FakeRequest (com.jcabi.http.request.FakeRequest)10 MkAnswer (com.jcabi.http.mock.MkAnswer)7 MkQuery (com.jcabi.http.mock.MkQuery)6 JsonObject (javax.json.JsonObject)5 JdkRequest (com.jcabi.http.request.JdkRequest)2 Request (com.jcabi.http.Request)1 StringReader (java.io.StringReader)1