use of com.jcabi.http.request.ApacheRequest in project jcabi-github by jcabi.
the class RtContentsTest method canDeleteFilesFromRepository.
/**
* RtContents can delete files from the repository.
*
* @throws Exception if a problem occurs.
* @checkstyle MultipleStringLiteralsCheck (50 lines)
*/
@Test
public void canDeleteFilesFromRepository() throws Exception {
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, Json.createObjectBuilder().add("commit", Json.createObjectBuilder().add("sha", "commitSha").build()).build().toString())).start(this.resource.port());
final RtContents contents = new RtContents(new ApacheRequest(container.home()), repo());
try {
final RepoCommit commit = contents.remove(Json.createObjectBuilder().add("path", "to/remove").add("message", "Delete me").add("sha", "fileSha").build());
MatcherAssert.assertThat(commit.sha(), Matchers.is("commitSha"));
final MkQuery query = container.take();
MatcherAssert.assertThat(query.body(), Matchers.allOf(Matchers.containsString("\"message\":\"Delete me\""), Matchers.containsString("\"sha\":\"fileSha\"")));
MatcherAssert.assertThat(query.uri().toString(), Matchers.endsWith("/repos/test/contents/contents/to/remove"));
} finally {
container.stop();
}
}
use of com.jcabi.http.request.ApacheRequest in project jcabi-github by jcabi.
the class RtContentsTest method canFetchReadmeFile.
/**
* RtContents can fetch the default branch readme file.
*
* @throws Exception if some problem inside.
*/
@Test
public void canFetchReadmeFile() 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().path(), Matchers.is(path));
final MkQuery query = container.take();
MatcherAssert.assertThat(query.uri().toString(), Matchers.endsWith("/repos/test/contents/readme"));
MatcherAssert.assertThat(query.body().length(), Matchers.is(0));
} finally {
container.stop();
}
}
use of com.jcabi.http.request.ApacheRequest in project jcabi-github by jcabi.
the class RtContentsTest method canIterateDirectoryContents.
/**
* RtContents can iterate through a directory's contents.
* @throws Exception If something goes wrong.
*/
@Test
public void canIterateDirectoryContents() throws Exception {
final JsonArray body = Json.createArrayBuilder().add(Json.createObjectBuilder().add("path", "README.md").build()).add(Json.createObjectBuilder().add("path", ".gitignore").build()).build();
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, body.toString())).next(new MkAnswer.Simple("{\"path\":\"README.md\"}")).next(new MkAnswer.Simple("{\"path\":\".gitignore\"}")).start(this.resource.port());
final RtContents contents = new RtContents(new ApacheRequest(container.home()), repo());
try {
MatcherAssert.assertThat(contents.iterate("dir", "branch2"), Matchers.<Content>iterableWithSize(2));
} finally {
container.stop();
}
}
use of com.jcabi.http.request.ApacheRequest in project jcabi-github by jcabi.
the class RtCommentTest method givesToString.
/**
* This tests that the toString() method is working fine.
* @throws Exception - if anything goes wrong.
*/
@Test
public void givesToString() throws Exception {
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "")).start(this.resource.port());
final Repo repo = new MkGithub().randomRepo();
final Issue issue = repo.issues().create("testing6", "issue6");
final RtComment comment = new RtComment(new ApacheRequest(container.home()), issue, 10);
try {
final String stringComment = comment.toString();
MatcherAssert.assertThat(stringComment, Matchers.not(Matchers.isEmptyOrNullString()));
MatcherAssert.assertThat(stringComment, Matchers.endsWith("10"));
} finally {
container.stop();
}
}
use of com.jcabi.http.request.ApacheRequest in project jcabi-github by jcabi.
the class RtCommitsTest method createsCommit.
/**
* Tests creating a Commit.
*
* @throws Exception when an error occurs
*/
@Test
public final void createsCommit() throws Exception {
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_CREATED, "{\"sha\":\"0abcd89jcabitest\"}")).start(this.resource.port());
final Commits commits = new RtCommits(new ApacheRequest(container.home()), new MkGithub().randomRepo());
final JsonObject author = Json.createObjectBuilder().add("name", "Scott").add("email", "scott@gmail.com").add("date", "2011-06-17T14:53:35-07:00").build();
final JsonObject input = Json.createObjectBuilder().add("message", "initial version").add("author", author).build();
try {
final Commit newCommit = commits.create(input);
MatcherAssert.assertThat(newCommit, Matchers.instanceOf(Commit.class));
MatcherAssert.assertThat(container.take().method(), Matchers.equalTo(Request.POST));
MatcherAssert.assertThat(newCommit.sha(), Matchers.equalTo("0abcd89jcabitest"));
} finally {
container.stop();
}
}
Aggregations