Search in sources :

Example 11 with ApacheRequest

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

the class RtPullsTest method createPull.

/**
 * RtPulls can create a pull request.
 *
 * @throws Exception if some problem inside
 */
@Test
public void createPull() throws Exception {
    final String title = "new feature";
    final String body = pull(title).toString();
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_CREATED, body)).next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, body)).start();
    final RtPulls pulls = new RtPulls(new ApacheRequest(container.home()), repo());
    final Pull pull = pulls.create(title, "octocat", "master");
    MatcherAssert.assertThat(container.take().method(), Matchers.equalTo(Request.POST));
    MatcherAssert.assertThat(new Pull.Smart(pull).title(), Matchers.equalTo(title));
    container.stop();
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) MkAnswer(com.jcabi.http.mock.MkAnswer) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 12 with ApacheRequest

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

the class RtReferencesTest method iteratesReferences.

/**
 * RtReferences should be able to iterate over References.
 * @throws Exception - If something goes wrong.
 */
@Test
public void iteratesReferences() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "{\"ref\":\"refs/heads/feature-a\"}")).start();
    final References refs = new RtReferences(new ApacheRequest(container.home()), new MkGithub().randomRepo());
    try {
        MatcherAssert.assertThat(refs.iterate(), Matchers.notNullValue());
    } 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 13 with ApacheRequest

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

the class RtReleaseAssetTest method patchesAsset.

/**
 * RtReleaseAsset can create a patch request.
 * @throws Exception If a problem occurs.
 */
@Test
public void patchesAsset() 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(), 2);
    try {
        final JsonObject json = Json.createObjectBuilder().add("name", "hello").build();
        asset.patch(json);
        final MkQuery query = container.take();
        MatcherAssert.assertThat(query.method(), Matchers.equalTo(Request.PATCH));
        MatcherAssert.assertThat(query.body(), Matchers.containsString("{\"name\":\"hello\"}"));
        MatcherAssert.assertThat(query.uri().toString(), Matchers.endsWith("/repos/john/blueharvest/releases/assets/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 14 with ApacheRequest

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

the class RtReleaseAssetTest method removesAsset.

/**
 * RtReleaseAsset can remove itself.
 * @throws Exception If a problem occurs.
 */
@Test
public void removesAsset() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_NO_CONTENT, "")).start();
    final RtReleaseAsset asset = new RtReleaseAsset(new ApacheRequest(container.home()), release(), 3);
    try {
        asset.remove();
        final MkQuery query = container.take();
        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 15 with ApacheRequest

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

the class RtSearchTest method canSearchForContents.

/**
 * RtSearch can search for contents.
 *
 * @throws Exception if a problem occurs
 */
@Test
public void canSearchForContents() throws Exception {
    final JsonObject first = RtSearchTest.content("test/unit/attributes.js", "attributes.js", // @checkstyle LineLength (1 line)
    "https://api.github.com/repos/user/repo/contents/test/unit/attributes.js?ref=f3b89ba0820882bd4ce4404b7e7c819e7b506de5").build();
    final JsonObject second = RtSearchTest.content("src/attributes/classes.js", "classes.js", // @checkstyle LineLength (1 line)
    "https://api.github.com/repos/user/repo/contents/src/attributes/classes.js?ref=f3b89ba0820882bd4ce4404b7e7c819e7b506de5").build();
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(RtSearchTest.search(first, second).toString())).next(new MkAnswer.Simple(first.toString())).next(new MkAnswer.Simple(second.toString())).start();
    try {
        final Search search = new RtGithub(new ApacheRequest(container.home())).search();
        MatcherAssert.assertThat(search.codes("test4", "joined", Search.Order.DESC), Matchers.<Content>iterableWithSize(2));
    } finally {
        container.stop();
    }
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) MkAnswer(com.jcabi.http.mock.MkAnswer) JsonObject(javax.json.JsonObject) 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