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