use of com.jcabi.http.mock.MkQuery 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.MkQuery 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.MkQuery 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.MkQuery in project jcabi-github by jcabi.
the class RtGistTest method canUnstarAGist.
/**
* RtGist can unstar a starred Gist.
* @throws Exception If something goes wrong.
*/
@Test
public void canUnstarAGist() throws Exception {
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_NO_CONTENT, "")).start();
final RtGist gist = new RtGist(new MkGithub(), new ApacheRequest(container.home()), "unstar");
gist.unstar();
final MkQuery query = container.take();
MatcherAssert.assertThat(query.method(), Matchers.equalTo(Request.DELETE));
MatcherAssert.assertThat(query.body(), Matchers.isEmptyOrNullString());
container.stop();
}
use of com.jcabi.http.mock.MkQuery in project jcabi-github by jcabi.
the class RtGistsTest method removesGistByName.
/**
* RtGists can remove a gist by name.
* @throws Exception - if something goes wrong.
*/
@Test
public void removesGistByName() throws Exception {
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_NO_CONTENT, "")).start(this.resource.port());
final Gists gists = new RtGists(new MkGithub(), new ApacheRequest(container.home()));
try {
gists.remove("12234");
final MkQuery query = container.take();
MatcherAssert.assertThat(query.method(), Matchers.equalTo(Request.DELETE));
} finally {
container.stop();
}
}
Aggregations