Search in sources :

Example 56 with MkGrizzlyContainer

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

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

Example 58 with MkGrizzlyContainer

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

use of com.jcabi.http.mock.MkGrizzlyContainer in project jcabi-github by jcabi.

the class RtHookTest method performsValidRequest.

/**
 * RtHook should perform a JSON request to "/repos/:owner/:repo/hooks/:id".
 *
 * @throws Exception If a problem occurs.
 */
@Test
public void performsValidRequest() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "{\"test\":\"hook\"}")).start();
    try {
        final Hook hook = new RtHook(new ApacheRequest(container.home()), repo(), 1);
        MatcherAssert.assertThat(hook.json(), Matchers.notNullValue());
        MatcherAssert.assertThat(container.take().uri().toString(), Matchers.endsWith("/repos/test/repo/hooks/1"));
    } finally {
        container.stop();
    }
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 60 with MkGrizzlyContainer

use of com.jcabi.http.mock.MkGrizzlyContainer in project jcabi-github by jcabi.

the class RtHooksTest method canDeleteHook.

/**
 * RtHooks can delete a hook.
 *
 * @throws Exception if something goes wrong.
 */
@Test
public void canDeleteHook() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_NO_CONTENT, "")).start();
    final Hooks hooks = new RtHooks(new JdkRequest(container.home()), RtHooksTest.repo());
    hooks.remove(1);
    try {
        final MkQuery query = container.take();
        MatcherAssert.assertThat(query.method(), Matchers.equalTo(Request.DELETE));
        MatcherAssert.assertThat(query.body(), Matchers.isEmptyString());
    } finally {
        container.stop();
    }
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) JdkRequest(com.jcabi.http.request.JdkRequest) MkQuery(com.jcabi.http.mock.MkQuery) 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