Search in sources :

Example 26 with MkQuery

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();
    }
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) MkQuery(com.jcabi.http.mock.MkQuery) MkGithub(com.jcabi.github.mock.MkGithub) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 27 with MkQuery

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();
    }
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) MkQuery(com.jcabi.http.mock.MkQuery) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 28 with MkQuery

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();
    }
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) MkAnswer(com.jcabi.http.mock.MkAnswer) MkQuery(com.jcabi.http.mock.MkQuery) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 29 with MkQuery

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();
    }
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) MkAnswer(com.jcabi.http.mock.MkAnswer) MkQuery(com.jcabi.http.mock.MkQuery) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 30 with MkQuery

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();
    }
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) MkQuery(com.jcabi.http.mock.MkQuery) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Aggregations

MkQuery (com.jcabi.http.mock.MkQuery)35 Test (org.junit.Test)35 MkContainer (com.jcabi.http.mock.MkContainer)34 MkGrizzlyContainer (com.jcabi.http.mock.MkGrizzlyContainer)34 ApacheRequest (com.jcabi.http.request.ApacheRequest)30 JsonObject (javax.json.JsonObject)9 MkGithub (com.jcabi.github.mock.MkGithub)6 MkAnswer (com.jcabi.http.mock.MkAnswer)6 JdkRequest (com.jcabi.http.request.JdkRequest)4 Request (com.jcabi.http.Request)1 FakeRequest (com.jcabi.http.request.FakeRequest)1 InputStream (java.io.InputStream)1 StringReader (java.io.StringReader)1