Search in sources :

Example 21 with MkGithub

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

the class RtGistsTest method removesGistByName.

/**
 * RtGists can remove a gist by name.
 * @throws Exception - if something goes wrong.
 */
@Test
public void removesGistByName() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_NO_CONTENT, "")).start(this.resource.port());
    final Gists gists = new RtGists(new MkGithub(), new ApacheRequest(container.home()));
    try {
        gists.remove("12234");
        final MkQuery query = container.take();
        MatcherAssert.assertThat(query.method(), Matchers.equalTo(Request.DELETE));
    } finally {
        container.stop();
    }
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) MkQuery(com.jcabi.http.mock.MkQuery) MkGithub(com.jcabi.github.mock.MkGithub) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 22 with MkGithub

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

the class RtBranchesTest method iteratesOverBranches.

/**
 * RtBranches can iterate over all branches.
 * @throws Exception if there is any error
 */
@Test
public void iteratesOverBranches() throws Exception {
    final String firstname = "first";
    final String firstsha = "a971b1aca044105897297b87b0b0983a54dd5817";
    final String secondname = "second";
    final String secondsha = "5d8dc2acf9c95d0d4e8881eebe04c2f0cbb249ff";
    final MkAnswer answer = new MkAnswer.Simple(HttpURLConnection.HTTP_OK, Json.createArrayBuilder().add(branch(firstname, firstsha)).add(branch(secondname, secondsha)).build().toString());
    final MkContainer container = new MkGrizzlyContainer().next(answer).next(answer).start(this.resource.port());
    final RtBranches branches = new RtBranches(new JdkRequest(container.home()), new MkGithub().randomRepo());
    MatcherAssert.assertThat(branches.iterate(), Matchers.<Branch>iterableWithSize(2));
    final Iterator<Branch> iter = branches.iterate().iterator();
    final Branch first = iter.next();
    MatcherAssert.assertThat(first.name(), Matchers.equalTo(firstname));
    MatcherAssert.assertThat(first.commit().sha(), Matchers.equalTo(firstsha));
    final Branch second = iter.next();
    MatcherAssert.assertThat(second.name(), Matchers.equalTo(secondname));
    MatcherAssert.assertThat(second.commit().sha(), Matchers.equalTo(secondsha));
    container.stop();
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) JdkRequest(com.jcabi.http.request.JdkRequest) MkAnswer(com.jcabi.http.mock.MkAnswer) MkGithub(com.jcabi.github.mock.MkGithub) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 23 with MkGithub

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

the class RtCommentTest method canCompareInstances.

/**
 * RtComment should be able to compare different instances.
 * @throws Exception when a problem occurs.
 */
@Test
public void canCompareInstances() throws Exception {
    final Repo repo = new MkGithub().randomRepo();
    final Issue issue = repo.issues().create("title", "body");
    final RtComment less = new RtComment(new FakeRequest(), issue, 1);
    final RtComment greater = new RtComment(new FakeRequest(), issue, 2);
    MatcherAssert.assertThat(less.compareTo(greater), Matchers.lessThan(0));
    MatcherAssert.assertThat(greater.compareTo(less), Matchers.greaterThan(0));
}
Also used : MkGithub(com.jcabi.github.mock.MkGithub) FakeRequest(com.jcabi.http.request.FakeRequest) Test(org.junit.Test)

Example 24 with MkGithub

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

the class RtCommentTest method patchesComment.

/**
 * RtComment can patch a comment.
 * @throws Exception - if anything goes wrong.
 */
@Test
public void patchesComment() 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("testing5", "issue5");
    final RtComment comment = new RtComment(new ApacheRequest(container.home()), issue, 10);
    final JsonObject jsonPatch = Json.createObjectBuilder().add("title", "test comment").build();
    try {
        comment.patch(jsonPatch);
        final MkQuery query = container.take();
        MatcherAssert.assertThat(query.method(), Matchers.equalTo(Request.PATCH));
    } finally {
        container.stop();
    }
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) MkQuery(com.jcabi.http.mock.MkQuery) JsonObject(javax.json.JsonObject) MkGithub(com.jcabi.github.mock.MkGithub) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 25 with MkGithub

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

the class RtCommentTest method removesComment.

/**
 * This tests that the remove() method is working fine.
 * @throws Exception - in case something goes wrong.
 */
@Test
public void removesComment() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_NO_CONTENT, "")).start(this.resource.port());
    final Repo repo = new MkGithub().randomRepo();
    final Issue issue = repo.issues().create("testing3", "issue3");
    final RtComment comment = new RtComment(new ApacheRequest(container.home()), issue, 10);
    try {
        comment.remove();
        final MkQuery query = container.take();
        MatcherAssert.assertThat(query.method(), Matchers.equalTo(Request.DELETE));
    } finally {
        container.stop();
    }
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) MkQuery(com.jcabi.http.mock.MkQuery) 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