Search in sources :

Example 51 with MkContainer

use of com.jcabi.http.mock.MkContainer 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 52 with MkContainer

use of com.jcabi.http.mock.MkContainer 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)

Example 53 with MkContainer

use of com.jcabi.http.mock.MkContainer 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 54 with MkContainer

use of com.jcabi.http.mock.MkContainer 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 55 with MkContainer

use of com.jcabi.http.mock.MkContainer 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)

Aggregations

MkContainer (com.jcabi.http.mock.MkContainer)136 MkGrizzlyContainer (com.jcabi.http.mock.MkGrizzlyContainer)136 Test (org.junit.Test)136 ApacheRequest (com.jcabi.http.request.ApacheRequest)105 MkGithub (com.jcabi.github.mock.MkGithub)40 MkQuery (com.jcabi.http.mock.MkQuery)34 MkAnswer (com.jcabi.http.mock.MkAnswer)32 JdkRequest (com.jcabi.http.request.JdkRequest)31 JsonObject (javax.json.JsonObject)19 Request (com.jcabi.http.Request)5 JsonArray (javax.json.JsonArray)3 FakeRequest (com.jcabi.http.request.FakeRequest)2 ArrayMap (com.jcabi.immutable.ArrayMap)2 InputStream (java.io.InputStream)2 RestResponse (com.jcabi.http.response.RestResponse)1 StringReader (java.io.StringReader)1 EnumMap (java.util.EnumMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1