use of com.jcabi.http.mock.MkContainer 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();
}
}
use of com.jcabi.http.mock.MkContainer 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.MkContainer in project jcabi-github by jcabi.
the class RtEventTest method retrieveEventAsJson.
/**
* RtEvent can be retrieved in JSON form.
*
* @throws Exception If a problem occurs.
*/
@Test
public void retrieveEventAsJson() throws Exception {
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "{\"test\":\"events\"}")).start(this.resource.port());
final RtEvent event = new RtEvent(new ApacheRequest(container.home()), this.repo(), 3);
try {
MatcherAssert.assertThat(event.json().getString("test"), Matchers.equalTo("events"));
} finally {
container.stop();
}
}
use of com.jcabi.http.mock.MkContainer in project jcabi-github by jcabi.
the class RtDeployKeysTest method canCreateDeployKey.
/**
* RtDeployKeys can create a key.
* @throws IOException If some problem inside.
*/
@Test
public void canCreateDeployKey() throws IOException {
final int number = 2;
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_CREATED, String.format("{\"id\":%d}", number)));
container.start(this.resource.port());
try {
final DeployKeys keys = new RtDeployKeys(new ApacheRequest(container.home()), RtDeployKeysTest.repo());
MatcherAssert.assertThat(keys.create("Title", "Key").number(), Matchers.equalTo(number));
} finally {
container.stop();
}
}
use of com.jcabi.http.mock.MkContainer in project jcabi-github by jcabi.
the class RtForkTest method patchAndCheckJsonFork.
/**
* RtFork can patch comment and return new json.
* @throws IOException if has some problems with json parsing.
*/
@Test
public void patchAndCheckJsonFork() throws IOException {
final String original = "some organization";
final String patched = "some patched organization";
final MkContainer container = new MkGrizzlyContainer().next(this.answer(original)).next(this.answer(patched)).next(this.answer(original)).start(this.resource.port());
final MkContainer forksContainer = new MkGrizzlyContainer().start(this.resource.port());
final RtRepo repo = new RtRepo(new MkGithub(), new ApacheRequest(forksContainer.home()), new Coordinates.Simple("test_user", "test_repo"));
final RtFork fork = new RtFork(new ApacheRequest(container.home()), repo, 1);
fork.patch(RtForkTest.fork(patched));
MatcherAssert.assertThat(new Fork.Smart(fork).organization(), Matchers.equalTo(patched));
MatcherAssert.assertThat(new Fork.Smart(fork).name(), Matchers.notNullValue());
container.stop();
forksContainer.stop();
}
Aggregations