Search in sources :

Example 6 with MkGithub

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

the class RtReferencesTest method iteratesTags.

/**
 * RtReferences should be able to iterate over tags.
 * @throws Exception - If something goes wrong.
 */
@Test
public void iteratesTags() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "[{\"ref\":\"refs/tags/feature-b\"}]")).start();
    final References refs = new RtReferences(new ApacheRequest(container.home()), new MkGithub().randomRepo());
    try {
        MatcherAssert.assertThat(refs.tags(), Matchers.<Reference>iterableWithSize(1));
        MatcherAssert.assertThat(container.take().uri().toString(), Matchers.endsWith("/git/refs/tags"));
    } 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 7 with MkGithub

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

the class RtReferencesTest method iteratesHeads.

/**
 * RtReferences should be able to iterate over heads.
 * @throws Exception - If something goes wrong.
 */
@Test
public void iteratesHeads() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "[{\"ref\":\"refs/heads/feature-c\"}]")).start();
    final References refs = new RtReferences(new ApacheRequest(container.home()), new MkGithub().randomRepo());
    try {
        MatcherAssert.assertThat(refs.heads(), Matchers.<Reference>iterableWithSize(1));
        MatcherAssert.assertThat(container.take().uri().toString(), Matchers.endsWith("/git/refs/heads"));
    } 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 8 with MkGithub

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

the class RtStatusesTest method fetchesCommit.

/**
 * RtStatuses can fetch its commit.
 * @throws IOException If there is an I/O problem.
 */
@Test
public void fetchesCommit() throws IOException {
    final Commit original = new MkGithub().randomRepo().git().commits().get("5e8d65e0dbfab0716db16493e03a0baba480625a");
    MatcherAssert.assertThat(new RtStatuses(new FakeRequest(), original).commit(), Matchers.equalTo(original));
}
Also used : MkGithub(com.jcabi.github.mock.MkGithub) FakeRequest(com.jcabi.http.request.FakeRequest) Test(org.junit.Test)

Example 9 with MkGithub

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

the class RtTagsTest method createsTag.

/**
 * RtTags can create a tag.
 * @throws Exception - If something goes wrong.
 * @checkstyle IndentationCheck (20 lines)
 */
@Test
public void createsTag() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_CREATED, "{\"sha\":\"0abcd89jcabitest\",\"tag\":\"v.0.1\"}")).next(new MkAnswer.Simple(HttpURLConnection.HTTP_CREATED, "{\"ref\":\"refs/heads/feature-a\"}")).start();
    final Tags tags = new RtTags(new ApacheRequest(container.home()), new MkGithub().randomRepo());
    final JsonObject tagger = 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("tag", "v.0.1").add("message", "initial version").add("object", "07cd4r45Test444").add("type", "commit").add("tagger", tagger).build();
    try {
        MatcherAssert.assertThat(tags.create(input), Matchers.instanceOf(Tag.class));
        MatcherAssert.assertThat(container.take().method(), Matchers.equalTo(Request.POST));
        MatcherAssert.assertThat(container.take().method(), Matchers.equalTo(Request.POST));
    } finally {
        container.stop();
    }
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) MkAnswer(com.jcabi.http.mock.MkAnswer) JsonObject(javax.json.JsonObject) MkGithub(com.jcabi.github.mock.MkGithub) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 10 with MkGithub

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

the class RtMarkdownTest method returnsJsonOutput.

/**
 * RtMarkdown should be able to return JSON output.
 *
 * @throws Exception If a problem occurs.
 */
@Test
public void returnsJsonOutput() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "{\"a\":\"b\"}").withHeader(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_HTML)).start(this.resource.port());
    final RtMarkdown markdown = new RtMarkdown(new MkGithub(), new ApacheRequest(container.home()));
    try {
        MatcherAssert.assertThat(markdown.render(Json.createObjectBuilder().add("hello", "world").build()), Matchers.equalTo("{\"a\":\"b\"}"));
        MatcherAssert.assertThat(container.take().body(), Matchers.equalTo("{\"hello\":\"world\"}"));
    } finally {
        container.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)

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