use of com.jcabi.http.request.ApacheRequest in project jcabi-github by jcabi.
the class RtGistTest method fork.
/**
* RtGist can fork itself.
*
* @throws IOException If there is a problem.
*/
@Test
public void fork() throws IOException {
final String fileContent = "success";
final MkContainer container = new MkGrizzlyContainer();
container.next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "{\"files\":{\"hello\":{\"raw_url\":\"world\"}}}"));
container.next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, fileContent));
container.next(new MkAnswer.Simple(HttpURLConnection.HTTP_CREATED, "{\"id\": \"forked\"}"));
container.next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "{\"files\":{\"hello\":{\"raw_url\":\"world\"}}}"));
container.next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, fileContent));
container.start();
final Gist gist = new RtGist(new MkGithub(), new ApacheRequest(container.home()), "test");
final String content = gist.read("hello");
final Gist forkedGist = gist.fork();
try {
MatcherAssert.assertThat(forkedGist.read("hello"), Matchers.equalTo(content));
} finally {
container.stop();
}
}
use of com.jcabi.http.request.ApacheRequest 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();
}
}
use of com.jcabi.http.request.ApacheRequest in project jcabi-github by jcabi.
the class RtHookTest method performsValidRequest.
/**
* RtHook should perform a JSON request to "/repos/:owner/:repo/hooks/:id".
*
* @throws Exception If a problem occurs.
*/
@Test
public void performsValidRequest() throws Exception {
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "{\"test\":\"hook\"}")).start();
try {
final Hook hook = new RtHook(new ApacheRequest(container.home()), repo(), 1);
MatcherAssert.assertThat(hook.json(), Matchers.notNullValue());
MatcherAssert.assertThat(container.take().uri().toString(), Matchers.endsWith("/repos/test/repo/hooks/1"));
} finally {
container.stop();
}
}
use of com.jcabi.http.request.ApacheRequest in project jcabi-github by jcabi.
the class RtBlobsTest method canCreateBlob.
/**
* RtBlobs can create a blob.
*
* @throws Exception if some problem inside
*/
@Test
public void canCreateBlob() throws Exception {
final String content = "Content of the blob";
final String body = blob().toString();
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_CREATED, body)).next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, body)).start();
final RtBlobs blobs = new RtBlobs(new ApacheRequest(container.home()), repo());
try {
final Blob blob = blobs.create(content, "utf-8");
MatcherAssert.assertThat(container.take().method(), Matchers.equalTo(Request.POST));
MatcherAssert.assertThat(new Blob.Smart(blob).url(), Matchers.equalTo("http://localhost/1"));
} finally {
container.stop();
}
}
use of com.jcabi.http.request.ApacheRequest in project jcabi-github by jcabi.
the class RtCommentTest method patchesComment.
/**
* RtComment can patch a comment.
* @throws Exception - if anything goes wrong.
*/
@Test
public void patchesComment() 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("testing5", "issue5");
final RtComment comment = new RtComment(new ApacheRequest(container.home()), issue, 10);
final JsonObject jsonPatch = Json.createObjectBuilder().add("title", "test comment").build();
try {
comment.patch(jsonPatch);
final MkQuery query = container.take();
MatcherAssert.assertThat(query.method(), Matchers.equalTo(Request.PATCH));
} finally {
container.stop();
}
}
Aggregations