Search in sources :

Example 76 with MkContainer

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

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

Example 78 with MkContainer

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

the class RtIssueTest method patchWithJson.

/**
 * RtIssue should be able to perform a patch request.
 *
 * @throws Exception if a problem occurs.
 */
@Test
public void patchWithJson() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "response")).start(this.resource.port());
    final RtIssue issue = new RtIssue(new ApacheRequest(container.home()), this.repo(), 1);
    issue.patch(Json.createObjectBuilder().add("patch", "test").build());
    final MkQuery query = container.take();
    try {
        MatcherAssert.assertThat(query.method(), Matchers.equalTo(Request.PATCH));
        MatcherAssert.assertThat(query.body(), Matchers.equalTo("{\"patch\":\"test\"}"));
    } finally {
        container.stop();
    }
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) MkQuery(com.jcabi.http.mock.MkQuery) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 79 with MkContainer

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

the class RtIssuesTest method getSingleIssue.

/**
 * RtIssues can get a single issue.
 * @throws Exception if some problem inside
 */
@Test
public void getSingleIssue() throws Exception {
    final String title = "Unit test";
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, issue(title).toString())).start(this.resource.port());
    final RtIssues issues = new RtIssues(new JdkRequest(container.home()), repo());
    final Issue issue = issues.get(1);
    MatcherAssert.assertThat(new Issue.Smart(issue).title(), Matchers.equalTo(title));
    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 80 with MkContainer

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

the class RtCollaboratorsTest method canIterate.

/**
 * RtCollaborators can iterate over a list of collaborators.
 * @throws Exception if any error occurs.
 */
@Test
public void canIterate() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, Json.createArrayBuilder().add(RtCollaboratorsTest.json("octocat")).add(RtCollaboratorsTest.json("dummy")).build().toString())).start(this.resource.port());
    final Collaborators users = new RtCollaborators(new JdkRequest(container.home()), this.repo());
    MatcherAssert.assertThat(users.iterate(), Matchers.<User>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