Search in sources :

Example 36 with MkGithub

use of com.jcabi.github.mock.MkGithub in project jcabi-github by jcabi.

the class RtBranchesTest method fetchesRepo.

/**
 * RtBranches can fetch its repository.
 * @throws IOException If there is any I/O problem
 */
@Test
public void fetchesRepo() throws IOException {
    final Repo repo = new MkGithub().randomRepo();
    final RtBranches branch = new RtBranches(new FakeRequest(), repo);
    final Coordinates coords = branch.repo().coordinates();
    MatcherAssert.assertThat(coords.user(), Matchers.equalTo(repo.coordinates().user()));
    MatcherAssert.assertThat(coords.repo(), Matchers.equalTo(repo.coordinates().repo()));
}
Also used : MkGithub(com.jcabi.github.mock.MkGithub) FakeRequest(com.jcabi.http.request.FakeRequest) Test(org.junit.Test)

Example 37 with MkGithub

use of com.jcabi.github.mock.MkGithub in project jcabi-github by jcabi.

the class RtCommentTest method returnsItsIssue.

/**
 * RtComment can return its issue (owner).
 * @throws Exception - if anything goes wrong.
 */
@Test
public void returnsItsIssue() throws Exception {
    final Repo repo = new MkGithub().randomRepo();
    final Issue issue = repo.issues().create("testing1", "issue1");
    final RtComment comment = new RtComment(new FakeRequest(), issue, 1);
    MatcherAssert.assertThat(comment.issue(), Matchers.is(issue));
}
Also used : MkGithub(com.jcabi.github.mock.MkGithub) FakeRequest(com.jcabi.http.request.FakeRequest) Test(org.junit.Test)

Example 38 with MkGithub

use of com.jcabi.github.mock.MkGithub in project jcabi-github by jcabi.

the class RtCommentTest method returnsItsNumber.

/**
 * RtComment can return its number.
 * @throws Exception - in case something goes wrong.
 */
@Test
public void returnsItsNumber() throws Exception {
    final Repo repo = new MkGithub().randomRepo();
    final Issue issue = repo.issues().create("testing2", "issue2");
    final int num = 10;
    final RtComment comment = new RtComment(new FakeRequest(), issue, num);
    MatcherAssert.assertThat(comment.number(), Matchers.is(num));
}
Also used : MkGithub(com.jcabi.github.mock.MkGithub) FakeRequest(com.jcabi.http.request.FakeRequest) Test(org.junit.Test)

Example 39 with MkGithub

use of com.jcabi.github.mock.MkGithub in project jcabi-github by jcabi.

the class RtCommentTest method givesToString.

/**
 * This tests that the toString() method is working fine.
 * @throws Exception - if anything goes wrong.
 */
@Test
public void givesToString() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "")).start(this.resource.port());
    final Repo repo = new MkGithub().randomRepo();
    final Issue issue = repo.issues().create("testing6", "issue6");
    final RtComment comment = new RtComment(new ApacheRequest(container.home()), issue, 10);
    try {
        final String stringComment = comment.toString();
        MatcherAssert.assertThat(stringComment, Matchers.not(Matchers.isEmptyOrNullString()));
        MatcherAssert.assertThat(stringComment, Matchers.endsWith("10"));
    } finally {
        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) Test(org.junit.Test)

Example 40 with MkGithub

use of com.jcabi.github.mock.MkGithub in project jcabi-github by jcabi.

the class RtCommitsTest method createsCommit.

/**
 * Tests creating a Commit.
 *
 * @throws Exception when an error occurs
 */
@Test
public final void createsCommit() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_CREATED, "{\"sha\":\"0abcd89jcabitest\"}")).start(this.resource.port());
    final Commits commits = new RtCommits(new ApacheRequest(container.home()), new MkGithub().randomRepo());
    final JsonObject author = Json.createObjectBuilder().add("name", "Scott").add("email", "scott@gmail.com").add("date", "2011-06-17T14:53:35-07:00").build();
    final JsonObject input = Json.createObjectBuilder().add("message", "initial version").add("author", author).build();
    try {
        final Commit newCommit = commits.create(input);
        MatcherAssert.assertThat(newCommit, Matchers.instanceOf(Commit.class));
        MatcherAssert.assertThat(container.take().method(), Matchers.equalTo(Request.POST));
        MatcherAssert.assertThat(newCommit.sha(), Matchers.equalTo("0abcd89jcabitest"));
    } 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)

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