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