use of com.jcabi.http.mock.MkAnswer in project jcabi-github by jcabi.
the class RtBranchesTest method iteratesOverBranches.
/**
* RtBranches can iterate over all branches.
* @throws Exception if there is any error
*/
@Test
public void iteratesOverBranches() throws Exception {
final String firstname = "first";
final String firstsha = "a971b1aca044105897297b87b0b0983a54dd5817";
final String secondname = "second";
final String secondsha = "5d8dc2acf9c95d0d4e8881eebe04c2f0cbb249ff";
final MkAnswer answer = new MkAnswer.Simple(HttpURLConnection.HTTP_OK, Json.createArrayBuilder().add(branch(firstname, firstsha)).add(branch(secondname, secondsha)).build().toString());
final MkContainer container = new MkGrizzlyContainer().next(answer).next(answer).start(this.resource.port());
final RtBranches branches = new RtBranches(new JdkRequest(container.home()), new MkGithub().randomRepo());
MatcherAssert.assertThat(branches.iterate(), Matchers.<Branch>iterableWithSize(2));
final Iterator<Branch> iter = branches.iterate().iterator();
final Branch first = iter.next();
MatcherAssert.assertThat(first.name(), Matchers.equalTo(firstname));
MatcherAssert.assertThat(first.commit().sha(), Matchers.equalTo(firstsha));
final Branch second = iter.next();
MatcherAssert.assertThat(second.name(), Matchers.equalTo(secondname));
MatcherAssert.assertThat(second.commit().sha(), Matchers.equalTo(secondsha));
container.stop();
}
use of com.jcabi.http.mock.MkAnswer in project jcabi-github by jcabi.
the class RtGistCommentTest method patchAndCheckJsonGistComment.
/**
* RtGistComment can patch comment and return new json.
* @throws IOException if has some problems with json parsing.
*/
@Test
public final void patchAndCheckJsonGistComment() throws IOException {
final int identifier = 1;
final String idString = "id";
final String bodyString = "body";
final String body = "somebody";
final String patchedBody = "some patchedbody";
final MkAnswer first = new MkAnswer.Simple(HttpURLConnection.HTTP_OK, Json.createObjectBuilder().add(bodyString, body).add(idString, identifier).build().toString());
final MkAnswer second = new MkAnswer.Simple(HttpURLConnection.HTTP_OK, Json.createObjectBuilder().add(bodyString, patchedBody).add(idString, identifier).build().toString());
final MkAnswer third = new MkAnswer.Simple(HttpURLConnection.HTTP_OK, Json.createObjectBuilder().add(bodyString, body).add(idString, identifier).build().toString());
final MkContainer container = new MkGrizzlyContainer().next(first).next(second).next(third).start(this.resource.port());
final MkContainer gistContainer = new MkGrizzlyContainer().start(this.resource.port());
final RtGist gist = new RtGist(new MkGithub(), new ApacheRequest(gistContainer.home()), "someName");
final RtGistComment comment = new RtGistComment(new ApacheRequest(container.home()), gist, identifier);
comment.patch(Json.createObjectBuilder().add(bodyString, patchedBody).add(idString, identifier).build());
MatcherAssert.assertThat(comment.json().getString(bodyString), Matchers.equalTo(patchedBody));
container.stop();
gistContainer.stop();
}
use of com.jcabi.http.mock.MkAnswer in project jcabi-github by jcabi.
the class RtGistCommentsTest method postComment.
/**
* RtGistComments can create a comment.
* @throws Exception if there is any error
*/
@Test
public void postComment() throws Exception {
final String body = "new commenting";
final MkAnswer answer = new MkAnswer.Simple(HttpURLConnection.HTTP_OK, comment(body).toString());
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_CREATED, comment(body).toString())).next(answer).start(this.resource.port());
final Gist gist = Mockito.mock(Gist.class);
Mockito.doReturn("3").when(gist).identifier();
final RtGistComments comments = new RtGistComments(new JdkRequest(container.home()), gist);
final GistComment comment = comments.post(body);
MatcherAssert.assertThat(container.take().method(), Matchers.equalTo(Request.POST));
MatcherAssert.assertThat(new GistComment.Smart(comment).body(), Matchers.equalTo(body));
container.stop();
}
use of com.jcabi.http.mock.MkAnswer in project jcabi-github by jcabi.
the class RtForksTest method createsFork.
/**
* RtForks should be able to create a new fork.
*
* @throws Exception if a problem occurs.
*/
@Test
public void createsFork() throws Exception {
final String organization = RandomStringUtils.randomAlphanumeric(10);
final MkAnswer answer = new MkAnswer.Simple(HttpURLConnection.HTTP_OK, fork(organization).toString());
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_ACCEPTED, fork(organization).toString())).next(answer).start(this.resource.port());
final Repo owner = Mockito.mock(Repo.class);
final Coordinates coordinates = new Coordinates.Simple("test_user", "test_repo");
Mockito.doReturn(coordinates).when(owner).coordinates();
final RtForks forks = new RtForks(new JdkRequest(container.home()), owner);
final Fork fork = forks.create(organization);
MatcherAssert.assertThat(container.take().method(), Matchers.equalTo(Request.POST));
MatcherAssert.assertThat(fork.json().getString(ORGANIZATION), Matchers.equalTo(organization));
container.stop();
}
Aggregations