use of com.jcabi.http.mock.MkGrizzlyContainer 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.mock.MkGrizzlyContainer in project jcabi-github by jcabi.
the class RtGistsTest method canCreateFiles.
/**
* RtGists can create new files.
*
* @throws Exception if a problem occurs.
*/
@Test
public void canCreateFiles() throws Exception {
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_CREATED, "{\"id\":\"1\"}")).start(this.resource.port());
final Gists gists = new RtGists(new MkGithub(), new ApacheRequest(container.home()));
try {
MatcherAssert.assertThat(gists.create(Collections.singletonMap("test", ""), false), Matchers.notNullValue());
MatcherAssert.assertThat(container.take().body(), Matchers.startsWith("{\"files\":{\"test\":{\"content\":"));
} finally {
container.stop();
}
}
use of com.jcabi.http.mock.MkGrizzlyContainer in project jcabi-github by jcabi.
the class RtGistsTest method canIterateThrouRtGists.
/**
* RtGists can iterate through its contents.
*
* @throws Exception if a problem occurs.
*/
@Test
public void canIterateThrouRtGists() throws Exception {
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "[{\"id\":\"hello\"}]")).start(this.resource.port());
final Gists gists = new RtGists(new MkGithub(), new ApacheRequest(container.home()));
try {
MatcherAssert.assertThat(gists.iterate().iterator().next(), Matchers.notNullValue());
} finally {
container.stop();
}
}
use of com.jcabi.http.mock.MkGrizzlyContainer in project jcabi-github by jcabi.
the class RtGistsTest method canRetrieveSpecificGist.
/**
* RtGists can retrieve a specific Gist.
*
* @throws Exception if a problem occurs.
*/
@Test
public void canRetrieveSpecificGist() throws Exception {
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "testing")).start(this.resource.port());
final Gists gists = new RtGists(new MkGithub(), new ApacheRequest(container.home()));
try {
MatcherAssert.assertThat(gists.get("gist"), Matchers.notNullValue());
} finally {
container.stop();
}
}
use of com.jcabi.http.mock.MkGrizzlyContainer 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();
}
Aggregations