Search in sources :

Example 16 with JdkRequest

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

the class RtBranchesTest method iteratesOverBranches.

/**
 * RtBranches can iterate over all branches.
 * @throws Exception if there is any error
 */
@Test
public void iteratesOverBranches() throws Exception {
    final String firstname = "first";
    final String firstsha = "a971b1aca044105897297b87b0b0983a54dd5817";
    final String secondname = "second";
    final String secondsha = "5d8dc2acf9c95d0d4e8881eebe04c2f0cbb249ff";
    final MkAnswer answer = new MkAnswer.Simple(HttpURLConnection.HTTP_OK, Json.createArrayBuilder().add(branch(firstname, firstsha)).add(branch(secondname, secondsha)).build().toString());
    final MkContainer container = new MkGrizzlyContainer().next(answer).next(answer).start(this.resource.port());
    final RtBranches branches = new RtBranches(new JdkRequest(container.home()), new MkGithub().randomRepo());
    MatcherAssert.assertThat(branches.iterate(), Matchers.<Branch>iterableWithSize(2));
    final Iterator<Branch> iter = branches.iterate().iterator();
    final Branch first = iter.next();
    MatcherAssert.assertThat(first.name(), Matchers.equalTo(firstname));
    MatcherAssert.assertThat(first.commit().sha(), Matchers.equalTo(firstsha));
    final Branch second = iter.next();
    MatcherAssert.assertThat(second.name(), Matchers.equalTo(secondname));
    MatcherAssert.assertThat(second.commit().sha(), Matchers.equalTo(secondsha));
    container.stop();
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) JdkRequest(com.jcabi.http.request.JdkRequest) 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 JdkRequest

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

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

Example 19 with JdkRequest

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

the class RtHooksTest method canFetchSingleHook.

/**
 * RtHooks can fetch single hook.
 * @throws Exception if some problem inside
 */
@Test
public void canFetchSingleHook() throws Exception {
    final String name = "hook name";
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, RtHooksTest.hook(name, Collections.<String, String>emptyMap()).toString())).start();
    final Hooks hooks = new RtHooks(new JdkRequest(container.home()), RtHooksTest.repo());
    final Hook hook = hooks.get(1);
    MatcherAssert.assertThat(new Hook.Smart(hook).name(), Matchers.equalTo(name));
    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 20 with JdkRequest

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

the class RtHooksTest method canCreateHook.

/**
 * RtHooks can create a hook.
 *
 * @throws Exception if something goes wrong.
 */
@Test
public void canCreateHook() throws Exception {
    final String name = "hook name";
    final ConcurrentHashMap<String, String> config = new ConcurrentHashMap<String, String>(2);
    config.put("url", "http://example.com");
    config.put("content_type", "json");
    final String body = RtHooksTest.hook(name, config).toString();
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_CREATED, body)).next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, body)).start();
    final Hooks hooks = new RtHooks(new JdkRequest(container.home()), RtHooksTest.repo());
    try {
        final Hook hook = hooks.create(name, config, true);
        MatcherAssert.assertThat(container.take().method(), Matchers.equalTo(Request.POST));
        MatcherAssert.assertThat(new Hook.Smart(hook).name(), Matchers.equalTo(name));
    } finally {
        container.stop();
    }
}
Also used : JdkRequest(com.jcabi.http.request.JdkRequest) MkContainer(com.jcabi.http.mock.MkContainer) MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) MkAnswer(com.jcabi.http.mock.MkAnswer) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) 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