Search in sources :

Example 11 with MkContainer

use of com.jcabi.http.mock.MkContainer in project jcabi-github by jcabi.

the class RtPullsTest method getSinglePull.

/**
 * RtPulls can get a single pull request.
 * @throws Exception if some problem inside
 */
@Test
public void getSinglePull() throws Exception {
    final String title = "new-feature";
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, pull(title).toString())).start();
    final RtPulls pulls = new RtPulls(new ApacheRequest(container.home()), repo());
    final Pull pull = pulls.get(Tv.BILLION);
    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) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 12 with MkContainer

use of com.jcabi.http.mock.MkContainer 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 13 with MkContainer

use of com.jcabi.http.mock.MkContainer 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 14 with MkContainer

use of com.jcabi.http.mock.MkContainer 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 15 with MkContainer

use of com.jcabi.http.mock.MkContainer 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)

Aggregations

MkContainer (com.jcabi.http.mock.MkContainer)136 MkGrizzlyContainer (com.jcabi.http.mock.MkGrizzlyContainer)136 Test (org.junit.Test)136 ApacheRequest (com.jcabi.http.request.ApacheRequest)105 MkGithub (com.jcabi.github.mock.MkGithub)40 MkQuery (com.jcabi.http.mock.MkQuery)34 MkAnswer (com.jcabi.http.mock.MkAnswer)32 JdkRequest (com.jcabi.http.request.JdkRequest)31 JsonObject (javax.json.JsonObject)19 Request (com.jcabi.http.Request)5 JsonArray (javax.json.JsonArray)3 FakeRequest (com.jcabi.http.request.FakeRequest)2 ArrayMap (com.jcabi.immutable.ArrayMap)2 InputStream (java.io.InputStream)2 RestResponse (com.jcabi.http.response.RestResponse)1 StringReader (java.io.StringReader)1 EnumMap (java.util.EnumMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1