use of com.jcabi.http.mock.MkQuery in project jcabi-github by jcabi.
the class RtOrganizationTest method patchWithJson.
/**
* RtOrganization 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();
final RtOrganization org = new RtOrganization(new MkGithub(), new ApacheRequest(container.home()), "testPatch");
org.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 RtPullTest method executeMerge.
/**
* RtPull should be able to perform a merge.
*
* @throws Exception when a problem occurs.
*/
@Test
public void executeMerge() throws Exception {
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "testMerge")).start();
final RtPull pull = new RtPull(new ApacheRequest(container.home()), this.repo(), 3);
pull.merge("Test commit.");
try {
final MkQuery query = container.take();
MatcherAssert.assertThat(query.method(), Matchers.equalTo(Request.PUT));
MatcherAssert.assertThat(query.body(), Matchers.equalTo("{\"commit_message\":\"Test commit.\"}"));
} finally {
container.stop();
}
}
use of com.jcabi.http.mock.MkQuery in project jcabi-github by jcabi.
the class RtPublicMembersTest method publicizesMembers.
/**
* RtPublicMembers can publicize the membership of
* a user in the organization.
* @throws IOException If there is an I/O problem
*/
@Test
public void publicizesMembers() throws IOException {
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_NO_CONTENT)).next(new MkAnswer.Simple(HttpURLConnection.HTTP_INTERNAL_ERROR)).start();
try {
final RtPublicMembers members = new RtPublicMembers(new ApacheRequest(container.home()), organization());
members.publicize(user());
final MkQuery req = container.take();
MatcherAssert.assertThat(req.method(), Matchers.equalTo(Request.PUT));
MatcherAssert.assertThat(req.uri().toString(), Matchers.endsWith(MEMBER_URL));
this.thrown.expect(AssertionError.class);
members.publicize(user());
} finally {
container.stop();
}
}
use of com.jcabi.http.mock.MkQuery in project jcabi-github by jcabi.
the class RtPublicMembersTest method checkPublicMembership.
/**
* RtPublicMembers can check whether a user
* is a public member of the organization.
* @throws IOException If there is an I/O problem
*/
@Test
public void checkPublicMembership() throws IOException {
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_NOT_FOUND)).next(new MkAnswer.Simple(HttpURLConnection.HTTP_NOT_FOUND)).next(new MkAnswer.Simple(HttpURLConnection.HTTP_NO_CONTENT)).next(new MkAnswer.Simple(HttpURLConnection.HTTP_INTERNAL_ERROR)).start();
try {
final RtPublicMembers members = new RtPublicMembers(new ApacheRequest(container.home()), organization());
members.contains(user());
final MkQuery req = container.take();
MatcherAssert.assertThat(req.method(), Matchers.equalTo(Request.GET));
MatcherAssert.assertThat(req.uri().toString(), Matchers.endsWith(MEMBER_URL));
MatcherAssert.assertThat("404 is interpreted as the user not being a public member", !members.contains(user()));
MatcherAssert.assertThat("204 is interpreted as the user being a public member", members.contains(user()));
this.thrown.expect(AssertionError.class);
members.contains(user());
} finally {
container.stop();
}
}
use of com.jcabi.http.mock.MkQuery in project jcabi-github by jcabi.
the class RtPullCommentsTest method removesPullComment.
/**
* RtPullComments can remove a pull comment.
*
* @throws Exception If something goes wrong.
*/
@Test
public void removesPullComment() throws Exception {
final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_NO_CONTENT, "")).start(this.resource.port());
final Pull pull = Mockito.mock(Pull.class);
final Repo repository = repo();
Mockito.doReturn(repository).when(pull).repo();
final RtPullComments comments = new RtPullComments(new ApacheRequest(container.home()), pull);
try {
comments.remove(2);
final MkQuery query = container.take();
MatcherAssert.assertThat(query.method(), Matchers.equalTo(Request.DELETE));
MatcherAssert.assertThat(query.uri().toString(), Matchers.endsWith(String.format("/repos/johnny/%s/pulls/0/comments/2", repository.coordinates().repo())));
} finally {
container.stop();
}
}
Aggregations