use of com.jcabi.http.mock.MkContainer in project jcabi-github by jcabi.
the class RtContentsTest method canUpdateFilesInRepository.
/**
* RtContents can update files into the repository.
* @throws Exception If any problems during test execution occurs.
*/
@Test
public void canUpdateFilesInRepository() throws Exception {
final String sha = "2f97253a513bbe26658881c29e27910082fef900";
final JsonObject resp = Json.createObjectBuilder().add("sha", sha).build();
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, Json.createObjectBuilder().add("commit", resp).build().toString())).next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, resp.toString())).start(this.resource.port());
try {
final RtContents contents = new RtContents(new ApacheRequest(container.home()), repo());
final String path = "test.txt";
final JsonObject json = Json.createObjectBuilder().add("message", "let's change it.").add("content", "bmV3IHRlc3Q=").add("sha", "90b67dda6d5944ad167e20ec52bfed8fd56986c8").build();
MatcherAssert.assertThat(new RepoCommit.Smart(contents.update(path, json)).sha(), Matchers.is(sha));
final MkQuery query = container.take();
MatcherAssert.assertThat(query.method(), Matchers.equalTo(Request.PUT));
MatcherAssert.assertThat(query.uri().getPath(), Matchers.endsWith(path));
MatcherAssert.assertThat(query.body(), Matchers.equalTo(json.toString()));
} finally {
container.stop();
}
}
use of com.jcabi.http.mock.MkContainer in project jcabi-github by jcabi.
the class RtContentsTest method canFetchFilesFromRepository.
/**
* RtContents can fetch files from the repository.
*
* @throws Exception if some problem inside.
* @checkstyle MultipleStringLiteralsCheck (50 lines)
*/
@Test
public void canFetchFilesFromRepository() throws Exception {
final String path = "test/file";
final String name = "file";
final JsonObject body = Json.createObjectBuilder().add("path", path).add("name", name).build();
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, Json.createObjectBuilder().add("path", path).add("name", name).build().toString())).next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, body.toString())).start(this.resource.port());
final RtContents contents = new RtContents(new ApacheRequest(container.home()), repo());
try {
final Content.Smart smart = new Content.Smart(contents.get(path, "branch1"));
final MkQuery query = container.take();
MatcherAssert.assertThat(query.uri().toString(), Matchers.endsWith("/repos/test/contents/contents/test/file?ref=branch1"));
MatcherAssert.assertThat(smart.path(), Matchers.is(path));
MatcherAssert.assertThat(smart.name(), Matchers.is(name));
MatcherAssert.assertThat(query.method(), Matchers.equalTo(Request.GET));
MatcherAssert.assertThat(container.take().uri().toString(), Matchers.endsWith("/repos/test/contents/contents/test/file?ref=branch1"));
} finally {
container.stop();
}
}
use of com.jcabi.http.mock.MkContainer in project jcabi-github by jcabi.
the class RtContentsTest method canFetchReadmeFileFromSpecifiedBranch.
/**
* RtContents can fetch the readme file from the specified branch.
*
* @throws Exception if a problem occurs.
*/
@Test
public void canFetchReadmeFileFromSpecifiedBranch() throws Exception {
final String path = "README.md";
final JsonObject body = Json.createObjectBuilder().add("path", path).build();
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, body.toString())).start(this.resource.port());
final RtContents contents = new RtContents(new ApacheRequest(container.home()), repo());
try {
MatcherAssert.assertThat(contents.readme("test-branch").path(), Matchers.is(path));
final MkQuery query = container.take();
MatcherAssert.assertThat(query.uri().toString(), Matchers.endsWith("/repos/test/contents/readme"));
MatcherAssert.assertThat(query.body(), Matchers.is("{\"ref\":\"test-branch\"}"));
} finally {
container.stop();
}
}
use of com.jcabi.http.mock.MkContainer in project jcabi-github by jcabi.
the class RtGistCommentsTest method iterateComments.
/**
* RtGistComments can iterate comments.
* @throws Exception if there is any error
*/
@Test
public void iterateComments() throws Exception {
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, Json.createArrayBuilder().add(comment("comment 1")).add(comment("comment 2")).build().toString())).start(this.resource.port());
final Gist gist = Mockito.mock(Gist.class);
Mockito.doReturn("2").when(gist).identifier();
final RtGistComments comments = new RtGistComments(new JdkRequest(container.home()), gist);
MatcherAssert.assertThat(comments.iterate(), Matchers.<GistComment>iterableWithSize(2));
container.stop();
}
use of com.jcabi.http.mock.MkContainer in project jcabi-github by jcabi.
the class RtGistCommentsTest method getComment.
/**
* RtGistComments can get a single comment.
* @throws Exception if some problem inside
*/
@Test
public void getComment() throws Exception {
final String body = "Just commenting";
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, comment(body).toString())).start(this.resource.port());
final Gist gist = Mockito.mock(Gist.class);
Mockito.doReturn("1").when(gist).identifier();
final RtGistComments comments = new RtGistComments(new JdkRequest(container.home()), gist);
final GistComment comment = comments.get(1);
MatcherAssert.assertThat(new GistComment.Smart(comment).body(), Matchers.equalTo(body));
container.stop();
}
Aggregations