Search in sources :

Example 11 with JdkRequest

use of com.jcabi.http.request.JdkRequest in project jcabi-github by jcabi.

the class RtGistCommentsTest method iterateComments.

/**
 * RtGistComments can iterate comments.
 * @throws Exception if there is any error
 */
@Test
public void iterateComments() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, Json.createArrayBuilder().add(comment("comment 1")).add(comment("comment 2")).build().toString())).start(this.resource.port());
    final Gist gist = Mockito.mock(Gist.class);
    Mockito.doReturn("2").when(gist).identifier();
    final RtGistComments comments = new RtGistComments(new JdkRequest(container.home()), gist);
    MatcherAssert.assertThat(comments.iterate(), Matchers.<GistComment>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)

Example 12 with JdkRequest

use of com.jcabi.http.request.JdkRequest in project jcabi-github by jcabi.

the class RtGistCommentsTest method getComment.

/**
 * RtGistComments can get a single comment.
 * @throws Exception if some problem inside
 */
@Test
public void getComment() throws Exception {
    final String body = "Just commenting";
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, comment(body).toString())).start(this.resource.port());
    final Gist gist = Mockito.mock(Gist.class);
    Mockito.doReturn("1").when(gist).identifier();
    final RtGistComments comments = new RtGistComments(new JdkRequest(container.home()), gist);
    final GistComment comment = comments.get(1);
    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) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 13 with JdkRequest

use of com.jcabi.http.request.JdkRequest 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)

Example 14 with JdkRequest

use of com.jcabi.http.request.JdkRequest in project jcabi-github by jcabi.

the class RtHooksTest method canFetchEmptyListOfHooks.

/**
 * RtHooks can fetch empty list of hooks.
 * @throws Exception if some problem inside
 */
@Test
public void canFetchEmptyListOfHooks() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "[]")).start();
    final Hooks hooks = new RtHooks(new JdkRequest(container.home()), RtHooksTest.repo());
    try {
        MatcherAssert.assertThat(hooks.iterate(), Matchers.emptyIterable());
    } finally {
        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)

Example 15 with JdkRequest

use of com.jcabi.http.request.JdkRequest in project jcabi-github by jcabi.

the class RtIssuesTest method iterateIssues.

/**
 * RtIssues can iterate issues.
 * @throws Exception if there is any error
 */
@Test
public void iterateIssues() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, Json.createArrayBuilder().add(issue("new issue")).add(issue("code issue")).build().toString())).start(this.resource.port());
    final RtIssues issues = new RtIssues(new JdkRequest(container.home()), repo());
    MatcherAssert.assertThat(issues.iterate(new ArrayMap<String, String>()), Matchers.<Issue>iterableWithSize(2));
    container.stop();
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) JdkRequest(com.jcabi.http.request.JdkRequest) ArrayMap(com.jcabi.immutable.ArrayMap) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Aggregations

JdkRequest (com.jcabi.http.request.JdkRequest)32 Test (org.junit.Test)32 MkContainer (com.jcabi.http.mock.MkContainer)31 MkGrizzlyContainer (com.jcabi.http.mock.MkGrizzlyContainer)31 MkAnswer (com.jcabi.http.mock.MkAnswer)8 MkQuery (com.jcabi.http.mock.MkQuery)4 MkGithub (com.jcabi.github.mock.MkGithub)2 RestResponse (com.jcabi.http.response.RestResponse)2 XmlResponse (com.jcabi.http.response.XmlResponse)1 ArrayMap (com.jcabi.immutable.ArrayMap)1 FkBase (io.wring.fake.FkBase)1 EnumMap (java.util.EnumMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Take (org.takes.Take)1 FtRemote (org.takes.http.FtRemote)1