use of com.jcabi.http.mock.MkQuery in project jcabi-github by jcabi.
the class RtContentTest method patchWithJson.
/**
* RtContent should be able to perform a patch request.
*
* @throws Exception if a problem occurs.
*/
@Test
public void patchWithJson() throws Exception {
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "response")).start(this.resource.port());
final RtContent content = new RtContent(new ApacheRequest(container.home()), this.repo(), "path");
content.patch(Json.createObjectBuilder().add("patch", "test").build());
final MkQuery query = container.take();
try {
MatcherAssert.assertThat(query.method(), Matchers.equalTo(Request.PATCH));
MatcherAssert.assertThat(query.body(), Matchers.equalTo("{\"patch\":\"test\"}"));
} finally {
container.stop();
}
}
use of com.jcabi.http.mock.MkQuery 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.mock.MkQuery 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.mock.MkQuery in project jcabi-github by jcabi.
the class RtDeployKeyTest method canDeleteDeployKey.
/**
* RtDeployKey can delete a deploy key.
*
* @throws Exception If some problem inside.
*/
@Test
public void canDeleteDeployKey() throws Exception {
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_NO_CONTENT, "")).start(this.resource.port());
final DeployKey key = new RtDeployKey(new ApacheRequest(container.home()), 3, RtDeployKeyTest.repo());
key.remove();
final MkQuery query = container.take();
MatcherAssert.assertThat(query.method(), Matchers.equalTo(Request.DELETE));
container.stop();
}
use of com.jcabi.http.mock.MkQuery in project jcabi-github by jcabi.
the class RtLabelsTest method deleteLabel.
/**
* RtLabels can delete a label.
* @throws Exception if some problem inside
*/
@Test
public void deleteLabel() throws Exception {
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_NO_CONTENT, "")).start();
final RtLabels issues = new RtLabels(new JdkRequest(container.home()), repo());
issues.delete("issue");
final MkQuery query = container.take();
MatcherAssert.assertThat(query.method(), Matchers.equalTo(Request.DELETE));
MatcherAssert.assertThat(query.body(), Matchers.isEmptyOrNullString());
container.stop();
}
Aggregations