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();
}
}
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();
}
}
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();
}
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();
}
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();
}
Aggregations