Search in sources :

Example 11 with MkGithub

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

the class RtMarkdownTest method returnsRawOutput.

/**
 * RtMarkdown should be able to return raw output.
 *
 * @throws Exception If a problem occurs.
 */
@Test
public void returnsRawOutput() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "Test Output").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.raw("Hello World!"), Matchers.equalTo("Test Output"));
        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)

Example 12 with MkGithub

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

the class RtCollaboratorsTest method repo.

/**
 * Create and return repo for testing.
 * @return Repo
 * @throws Exception If some problem inside
 */
private Repo repo() throws Exception {
    final Repo repo = Mockito.mock(Repo.class);
    Mockito.doReturn(new Coordinates.Simple("test", "collaboratorrepo")).when(repo).coordinates();
    Mockito.doReturn(new MkGithub(new MkStorage.InFile(), "userLogin")).when(repo).github();
    return repo;
}
Also used : MkGithub(com.jcabi.github.mock.MkGithub)

Example 13 with MkGithub

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

the class RtCommitTest method readsMessage.

/**
 * Commit.Smart can read message.
 * @throws Exception when an error occurs
 */
@Test
public final void readsMessage() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "{\"sha\":\"a0b1c3\",\"commit\":{\"message\":\"hello\"}}")).start(this.resource.port());
    try {
        final Commit.Smart commit = new Commit.Smart(new RtCommit(new JdkRequest(container.home()), new MkGithub().randomRepo(), "sha"));
        MatcherAssert.assertThat(commit.message(), Matchers.equalTo("hello"));
    } finally {
        container.stop();
    }
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) JdkRequest(com.jcabi.http.request.JdkRequest) MkGithub(com.jcabi.github.mock.MkGithub) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 14 with MkGithub

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

the class RtGistTest method canUnstarAGist.

/**
 * RtGist can unstar a starred Gist.
 * @throws Exception If something goes wrong.
 */
@Test
public void canUnstarAGist() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_NO_CONTENT, "")).start();
    final RtGist gist = new RtGist(new MkGithub(), new ApacheRequest(container.home()), "unstar");
    gist.unstar();
    final MkQuery query = container.take();
    MatcherAssert.assertThat(query.method(), Matchers.equalTo(Request.DELETE));
    MatcherAssert.assertThat(query.body(), Matchers.isEmptyOrNullString());
    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 15 with MkGithub

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

the class RtGistTest method executePatchRequest.

/**
 * RtGist can execute PATCH request.
 *
 * @throws Exception if there is any problem
 */
@Test
public void executePatchRequest() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "{\"msg\":\"hi\"}")).start();
    try {
        final RtGist gist = new RtGist(new MkGithub(), new ApacheRequest(container.home()), "patch");
        gist.patch(Json.createObjectBuilder().add("content", "hi you!").build());
        MatcherAssert.assertThat(container.take().method(), Matchers.equalTo(Request.PATCH));
    } 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)

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