use of com.jcabi.http.mock.MkGrizzlyContainer in project jcabi-github by jcabi.
the class RtGistTest method writesFileContents.
/**
* RtGist should be able to do writes.
* @throws Exception if there is a problem.
*/
@Test
public void writesFileContents() throws Exception {
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "testFileWrite")).start();
final RtGist gist = new RtGist(new MkGithub(), new ApacheRequest(container.home()), "testWrite");
gist.write("testFile", "testContent");
try {
MatcherAssert.assertThat(container.take().body(), Matchers.containsString("\"testFile\":{\"content\":\"testContent\"}"));
} finally {
container.stop();
}
}
use of com.jcabi.http.mock.MkGrizzlyContainer 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.mock.MkGrizzlyContainer 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.mock.MkGrizzlyContainer 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.mock.MkGrizzlyContainer in project jcabi-github by jcabi.
the class RtHooksTest method canDeleteHook.
/**
* RtHooks can delete a hook.
*
* @throws Exception if something goes wrong.
*/
@Test
public void canDeleteHook() throws Exception {
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_NO_CONTENT, "")).start();
final Hooks hooks = new RtHooks(new JdkRequest(container.home()), RtHooksTest.repo());
hooks.remove(1);
try {
final MkQuery query = container.take();
MatcherAssert.assertThat(query.method(), Matchers.equalTo(Request.DELETE));
MatcherAssert.assertThat(query.body(), Matchers.isEmptyString());
} finally {
container.stop();
}
}
Aggregations