Search in sources :

Example 16 with MkGithub

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

the class RtGistTest method readsFileWithContents.

/**
 * RtGist should be able to do reads.
 *
 * @throws Exception if there is a problem.
 * @checkstyle MultipleStringLiteralsCheck (20 lines)
 */
@Test
public void readsFileWithContents() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "{\"files\":{\"hello\":{\"raw_url\":\"world\"}}}")).next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "success!")).start();
    final RtGist gist = new RtGist(new MkGithub(), new ApacheRequest(container.home()), "test");
    try {
        MatcherAssert.assertThat(gist.read("hello"), Matchers.equalTo("success!"));
    } 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 17 with MkGithub

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

the class RtGistTest method canIterateFiles.

/**
 * Gist.Smart can iterate through its files.
 *
 * @throws Exception if something goes wrong.
 */
@Test
public void canIterateFiles() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "{\"files\":{\"something\":{\"filename\":\"not null\"}}}")).start();
    final Gist.Smart smart = new Gist.Smart(new RtGist(new MkGithub(), new ApacheRequest(container.home()), "testGetFiles"));
    try {
        MatcherAssert.assertThat(smart.files(), Matchers.notNullValue());
        MatcherAssert.assertThat(container.take().uri().toString(), Matchers.endsWith("/gists/testGetFiles"));
    } 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 18 with MkGithub

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

the class RtGistTest method canRepresentAsString.

/**
 * RtGist can return a String representation correctly reflecting its URI.
 *
 * @throws Exception If something goes wrong.
 */
@Test
public void canRepresentAsString() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().start();
    final RtGist gist = new RtGist(new MkGithub(), new ApacheRequest(container.home()), "testToString");
    try {
        MatcherAssert.assertThat(gist.toString(), Matchers.endsWith("/gists/testToString"));
    } 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 19 with MkGithub

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

the class RtGistTest method writesFileContents.

/**
 * RtGist should be able to do writes.
 * @throws Exception if there is a problem.
 */
@Test
public void writesFileContents() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "testFileWrite")).start();
    final RtGist gist = new RtGist(new MkGithub(), new ApacheRequest(container.home()), "testWrite");
    gist.write("testFile", "testContent");
    try {
        MatcherAssert.assertThat(container.take().body(), Matchers.containsString("\"testFile\":{\"content\":\"testContent\"}"));
    } 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 20 with MkGithub

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

the class RtGistTest method fork.

/**
 * RtGist can fork itself.
 *
 * @throws IOException If there is a problem.
 */
@Test
public void fork() throws IOException {
    final String fileContent = "success";
    final MkContainer container = new MkGrizzlyContainer();
    container.next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "{\"files\":{\"hello\":{\"raw_url\":\"world\"}}}"));
    container.next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, fileContent));
    container.next(new MkAnswer.Simple(HttpURLConnection.HTTP_CREATED, "{\"id\": \"forked\"}"));
    container.next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "{\"files\":{\"hello\":{\"raw_url\":\"world\"}}}"));
    container.next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, fileContent));
    container.start();
    final Gist gist = new RtGist(new MkGithub(), new ApacheRequest(container.home()), "test");
    final String content = gist.read("hello");
    final Gist forkedGist = gist.fork();
    try {
        MatcherAssert.assertThat(forkedGist.read("hello"), Matchers.equalTo(content));
    } 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