Search in sources :

Example 21 with ApacheRequest

use of com.jcabi.http.request.ApacheRequest in project jcabi-github by jcabi.

the class RtPullCommentTest method patchesComment.

/**
 * RtPullComment can create a patch request.
 * @throws Exception If a problem occurs.
 */
@Test
public void patchesComment() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "")).start();
    final Pull pull = Mockito.mock(Pull.class);
    Mockito.doReturn(repo()).when(pull).repo();
    final RtPullComment comment = new RtPullComment(new ApacheRequest(container.home()), pull, 2);
    try {
        final JsonObject json = Json.createObjectBuilder().add("body", "test comment").build();
        comment.patch(json);
        final MkQuery query = container.take();
        MatcherAssert.assertThat(query.method(), Matchers.equalTo(Request.PATCH));
        MatcherAssert.assertThat(query.body(), Matchers.containsString("{\"body\":\"test comment\"}"));
        MatcherAssert.assertThat(query.uri().toString(), Matchers.endsWith("/repos/joe/blueharvest/pulls/comments/2"));
    } finally {
        container.stop();
    }
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) MkQuery(com.jcabi.http.mock.MkQuery) JsonObject(javax.json.JsonObject) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 22 with ApacheRequest

use of com.jcabi.http.request.ApacheRequest in project jcabi-github by jcabi.

the class RtPullTest method fetchesFiles.

/**
 * RtPull should be able to retrieve files.
 *
 * @throws Exception when a problem occurs.
 */
@Test
public void fetchesFiles() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "[{\"file1\":\"testFile\"}]")).start();
    final RtPull pull = new RtPull(new ApacheRequest(container.home()), this.repo(), 2);
    try {
        MatcherAssert.assertThat(pull.files().iterator().next().getString("file1"), Matchers.equalTo("testFile"));
    } finally {
        container.stop();
    }
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 23 with ApacheRequest

use of com.jcabi.http.request.ApacheRequest in project jcabi-github by jcabi.

the class RtReferenceTest method returnsRef.

/**
 * RtReference should be able to return its ref.
 * @throws Exception - If something goes wrong.
 */
@Test
public void returnsRef() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "{\"ref\":\"refs/heads/featureC\"}")).start();
    final Reference reference = new RtReference(new ApacheRequest(container.home()), new MkGithub().randomRepo(), "refs/heads/featureC");
    try {
        MatcherAssert.assertThat(reference.ref(), Matchers.is("refs/heads/featureC"));
    } finally {
        container.stop();
    }
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) MkGithub(com.jcabi.github.mock.MkGithub) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 24 with ApacheRequest

use of com.jcabi.http.request.ApacheRequest in project jcabi-github by jcabi.

the class RtReferencesTest method iteratesTags.

/**
 * RtReferences should be able to iterate over tags.
 * @throws Exception - If something goes wrong.
 */
@Test
public void iteratesTags() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "[{\"ref\":\"refs/tags/feature-b\"}]")).start();
    final References refs = new RtReferences(new ApacheRequest(container.home()), new MkGithub().randomRepo());
    try {
        MatcherAssert.assertThat(refs.tags(), Matchers.<Reference>iterableWithSize(1));
        MatcherAssert.assertThat(container.take().uri().toString(), Matchers.endsWith("/git/refs/tags"));
    } finally {
        container.stop();
    }
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) MkGithub(com.jcabi.github.mock.MkGithub) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 25 with ApacheRequest

use of com.jcabi.http.request.ApacheRequest in project jcabi-github by jcabi.

the class RtReferencesTest method iteratesHeads.

/**
 * RtReferences should be able to iterate over heads.
 * @throws Exception - If something goes wrong.
 */
@Test
public void iteratesHeads() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "[{\"ref\":\"refs/heads/feature-c\"}]")).start();
    final References refs = new RtReferences(new ApacheRequest(container.home()), new MkGithub().randomRepo());
    try {
        MatcherAssert.assertThat(refs.heads(), Matchers.<Reference>iterableWithSize(1));
        MatcherAssert.assertThat(container.take().uri().toString(), Matchers.endsWith("/git/refs/heads"));
    } finally {
        container.stop();
    }
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) MkGithub(com.jcabi.github.mock.MkGithub) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Aggregations

ApacheRequest (com.jcabi.http.request.ApacheRequest)106 MkContainer (com.jcabi.http.mock.MkContainer)105 MkGrizzlyContainer (com.jcabi.http.mock.MkGrizzlyContainer)105 Test (org.junit.Test)105 MkGithub (com.jcabi.github.mock.MkGithub)38 MkQuery (com.jcabi.http.mock.MkQuery)30 MkAnswer (com.jcabi.http.mock.MkAnswer)24 JsonObject (javax.json.JsonObject)19 Request (com.jcabi.http.Request)5 JsonArray (javax.json.JsonArray)3 FakeRequest (com.jcabi.http.request.FakeRequest)2 InputStream (java.io.InputStream)2 ArrayMap (com.jcabi.immutable.ArrayMap)1 StringReader (java.io.StringReader)1