Search in sources :

Example 96 with ApacheRequest

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

the class RtPullsTest method iteratePulls.

/**
 * RtPulls can iterate pulls.
 * @throws Exception if there is any error
 */
@Test
public void iteratePulls() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, Json.createArrayBuilder().add(pull("new-topic")).add(pull("Amazing new feature")).build().toString())).start();
    final RtPulls pulls = new RtPulls(new ApacheRequest(container.home()), repo());
    MatcherAssert.assertThat(pulls.iterate(new ArrayMap<String, String>()), Matchers.<Pull>iterableWithSize(2));
    container.stop();
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) ArrayMap(com.jcabi.immutable.ArrayMap) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 97 with ApacheRequest

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

the class RtReleaseAssetTest method rawAsset.

/**
 * RtReleaseAsset can stream raw content.
 * @throws Exception If a problem occurs.
 */
@Test
public void rawAsset() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "")).start();
    final RtReleaseAsset asset = new RtReleaseAsset(new ApacheRequest(container.home()), release(), 4);
    try {
        final InputStream stream = asset.raw();
        final MkQuery query = container.take();
        MatcherAssert.assertThat(query.method(), Matchers.equalTo(Request.GET));
        MatcherAssert.assertThat(IOUtils.toString(stream, StandardCharsets.UTF_8), Matchers.notNullValue());
    } finally {
        container.stop();
    }
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) InputStream(java.io.InputStream) ApacheRequest(com.jcabi.http.request.ApacheRequest) MkQuery(com.jcabi.http.mock.MkQuery) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 98 with ApacheRequest

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

the class RtReleaseTest method release.

/**
 * Create a test release.
 * @param uri REST API entry point.
 * @return A test release.
 */
private static RtRelease release(final URI uri) {
    final Repo repo = Mockito.mock(Repo.class);
    final Coordinates coords = Mockito.mock(Coordinates.class);
    Mockito.doReturn(coords).when(repo).coordinates();
    Mockito.doReturn("tstuser").when(coords).user();
    Mockito.doReturn("tstbranch").when(coords).repo();
    return new RtRelease(new ApacheRequest(uri), repo, 2);
}
Also used : ApacheRequest(com.jcabi.http.request.ApacheRequest)

Example 99 with ApacheRequest

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

the class RtReleasesTest method canDeleteRelease.

/**
 * RtReleases can delete a release.
 * @throws Exception If some problem inside
 */
@Test
public void canDeleteRelease() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_NO_CONTENT, "")).start();
    final Releases releases = new RtReleases(new ApacheRequest(container.home()), RtReleasesTest.repo());
    try {
        releases.remove(1);
        final MkQuery query = container.take();
        MatcherAssert.assertThat(query.uri().toString(), Matchers.endsWith("/releases/1"));
        MatcherAssert.assertThat(query.method(), Matchers.equalTo(Request.DELETE));
    } 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 100 with ApacheRequest

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

the class RtRepoTest method fetchLanguages.

/**
 * RtRepo can fetch languages.
 * @throws Exception if a problem occurs.
 */
@Test
public void fetchLanguages() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, Json.createObjectBuilder().add("Ruby", 1).build().toString())).start();
    try {
        final Repo repo = RtRepoTest.repo(new ApacheRequest(container.home()));
        MatcherAssert.assertThat(repo.languages(), Matchers.notNullValue());
    } 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)

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