Search in sources :

Example 71 with MkContainer

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

the class RtGistCommentsTest method postComment.

/**
 * RtGistComments can create a comment.
 * @throws Exception if there is any error
 */
@Test
public void postComment() throws Exception {
    final String body = "new commenting";
    final MkAnswer answer = new MkAnswer.Simple(HttpURLConnection.HTTP_OK, comment(body).toString());
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_CREATED, comment(body).toString())).next(answer).start(this.resource.port());
    final Gist gist = Mockito.mock(Gist.class);
    Mockito.doReturn("3").when(gist).identifier();
    final RtGistComments comments = new RtGistComments(new JdkRequest(container.home()), gist);
    final GistComment comment = comments.post(body);
    MatcherAssert.assertThat(container.take().method(), Matchers.equalTo(Request.POST));
    MatcherAssert.assertThat(new GistComment.Smart(comment).body(), Matchers.equalTo(body));
    container.stop();
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) JdkRequest(com.jcabi.http.request.JdkRequest) MkAnswer(com.jcabi.http.mock.MkAnswer) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 72 with MkContainer

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

the class RtGistsTest method canCreateFiles.

/**
 * RtGists can create new files.
 *
 * @throws Exception if a problem occurs.
 */
@Test
public void canCreateFiles() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_CREATED, "{\"id\":\"1\"}")).start(this.resource.port());
    final Gists gists = new RtGists(new MkGithub(), new ApacheRequest(container.home()));
    try {
        MatcherAssert.assertThat(gists.create(Collections.singletonMap("test", ""), false), Matchers.notNullValue());
        MatcherAssert.assertThat(container.take().body(), Matchers.startsWith("{\"files\":{\"test\":{\"content\":"));
    } 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 73 with MkContainer

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

the class RtGistsTest method canIterateThrouRtGists.

/**
 * RtGists can iterate through its contents.
 *
 * @throws Exception if a problem occurs.
 */
@Test
public void canIterateThrouRtGists() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "[{\"id\":\"hello\"}]")).start(this.resource.port());
    final Gists gists = new RtGists(new MkGithub(), new ApacheRequest(container.home()));
    try {
        MatcherAssert.assertThat(gists.iterate().iterator().next(), Matchers.notNullValue());
    } 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 74 with MkContainer

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

the class RtGistsTest method canRetrieveSpecificGist.

/**
 * RtGists can retrieve a specific Gist.
 *
 * @throws Exception if a problem occurs.
 */
@Test
public void canRetrieveSpecificGist() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "testing")).start(this.resource.port());
    final Gists gists = new RtGists(new MkGithub(), new ApacheRequest(container.home()));
    try {
        MatcherAssert.assertThat(gists.get("gist"), Matchers.notNullValue());
    } 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 75 with MkContainer

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

the class RtHooksTest method canFetchNonEmptyListOfHooks.

/**
 * RtHooks can fetch non empty list of hooks.
 * @throws Exception if some problem inside
 */
@Test
public void canFetchNonEmptyListOfHooks() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, Json.createArrayBuilder().add(hook("hook 1", Collections.<String, String>emptyMap())).add(hook("hook 2", Collections.<String, String>emptyMap())).build().toString())).start();
    final RtHooks hooks = new RtHooks(new JdkRequest(container.home()), RtHooksTest.repo());
    MatcherAssert.assertThat(hooks.iterate(), Matchers.<Hook>iterableWithSize(2));
    container.stop();
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) JdkRequest(com.jcabi.http.request.JdkRequest) 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