Search in sources :

Example 36 with MkGrizzlyContainer

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

the class RtMarkdownTest method returnsJsonOutput.

/**
 * RtMarkdown should be able to return JSON output.
 *
 * @throws Exception If a problem occurs.
 */
@Test
public void returnsJsonOutput() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "{\"a\":\"b\"}").withHeader(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_HTML)).start(this.resource.port());
    final RtMarkdown markdown = new RtMarkdown(new MkGithub(), new ApacheRequest(container.home()));
    try {
        MatcherAssert.assertThat(markdown.render(Json.createObjectBuilder().add("hello", "world").build()), Matchers.equalTo("{\"a\":\"b\"}"));
        MatcherAssert.assertThat(container.take().body(), Matchers.equalTo("{\"hello\":\"world\"}"));
    } 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 37 with MkGrizzlyContainer

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

the class RtMarkdownTest method returnsRawOutput.

/**
 * RtMarkdown should be able to return raw output.
 *
 * @throws Exception If a problem occurs.
 */
@Test
public void returnsRawOutput() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "Test Output").withHeader(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_HTML)).start(this.resource.port());
    final RtMarkdown markdown = new RtMarkdown(new MkGithub(), new ApacheRequest(container.home()));
    try {
        MatcherAssert.assertThat(markdown.raw("Hello World!"), Matchers.equalTo("Test Output"));
        MatcherAssert.assertThat(container.take().body(), Matchers.equalTo("Hello World!"));
    } 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 38 with MkGrizzlyContainer

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

the class RtIssuesTest method searchIssues.

/**
 * RtIssues can search issues within a repository.
 * @throws Exception if there is any error
 */
@Test
public void searchIssues() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, Json.createArrayBuilder().add(issue("some issue")).add(issue("some other issue")).build().toString())).start(this.resource.port());
    final RtIssues issues = new RtIssues(new JdkRequest(container.home()), repo());
    MatcherAssert.assertThat(issues.search(Issues.Sort.UPDATED, Search.Order.ASC, new EnumMap<Issues.Qualifier, String>(Issues.Qualifier.class)), Matchers.<Issue>iterableWithSize(2));
    container.stop();
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) JdkRequest(com.jcabi.http.request.JdkRequest) MkContainer(com.jcabi.http.mock.MkContainer) EnumMap(java.util.EnumMap) Test(org.junit.Test)

Example 39 with MkGrizzlyContainer

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

the class RtIssuesTest method createIssue.

/**
 * RtIssues can create an issue.
 *
 * @throws Exception if some problem inside
 */
@Test
public void createIssue() throws Exception {
    final String title = "Found a bug";
    final String body = issue(title).toString();
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_CREATED, body)).next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, body)).start(this.resource.port());
    final RtIssues issues = new RtIssues(new JdkRequest(container.home()), repo());
    final Issue issue = issues.create(title, "having a problem with it.");
    MatcherAssert.assertThat(container.take().method(), Matchers.equalTo(Request.POST));
    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) MkAnswer(com.jcabi.http.mock.MkAnswer) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 40 with MkGrizzlyContainer

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

the class RtLabelTest method executePatchRequest.

/**
 * GhLabel can execute PATCH request.
 *
 * @throws Exception if there is any problem
 */
@Test
public void executePatchRequest() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "{\"msg\":\"hi\"}")).start();
    final RtLabel label = new RtLabel(new ApacheRequest(container.home()), RtLabelTest.repo(), "enhance");
    label.patch(Json.createObjectBuilder().add("content", "hi you!").build());
    MatcherAssert.assertThat(container.take().method(), Matchers.equalTo(Request.PATCH));
    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)

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