Search in sources :

Example 76 with ApacheRequest

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

the class RtPullTest method fetchesCommits.

/**
 * RtPull should be able to retrieve commits.
 *
 * @throws Exception when a problem occurs.
 */
@Test
public void fetchesCommits() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "[{\"commits\":\"test\"}]")).start();
    final RtPull pull = new RtPull(new ApacheRequest(container.home()), this.repo(), 1);
    try {
        MatcherAssert.assertThat(pull.commits(), 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)

Example 77 with ApacheRequest

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

the class RtPullTest method fetchesHead.

/**
 * RtPull can fetch its head ref.
 * @throws IOException If some I/O problem occurs
 */
@Test
public void fetchesHead() throws IOException {
    final String ref = "neat-other-branch";
    final String sha = "9c717b4716e4fc4d917f546e8e6b562e810e3922";
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, Json.createObjectBuilder().add("head", Json.createObjectBuilder().add(RtPullTest.REF_PROP, ref).add(RtPullTest.SHA_PROP, sha).build()).build().toString())).start();
    final RtPull pull = new RtPull(new ApacheRequest(container.home()), this.repo(), 1);
    try {
        final PullRef head = pull.head();
        MatcherAssert.assertThat(head, Matchers.notNullValue());
        MatcherAssert.assertThat(head.ref(), Matchers.equalTo(ref));
        MatcherAssert.assertThat(head.sha(), Matchers.equalTo(sha));
    } 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 78 with ApacheRequest

use of com.jcabi.http.request.ApacheRequest 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 79 with ApacheRequest

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

the class RtPullTest method fetchesBase.

/**
 * RtPull can fetch its base ref.
 * @throws IOException If some I/O problem occurs
 */
@Test
public void fetchesBase() throws IOException {
    final String ref = "sweet-feature-branch";
    final String sha = "e93c6a2216c69daa574abc16e7c14767fce44ad6";
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, Json.createObjectBuilder().add("base", Json.createObjectBuilder().add(RtPullTest.REF_PROP, ref).add(RtPullTest.SHA_PROP, sha).build()).build().toString())).start();
    final RtPull pull = new RtPull(new ApacheRequest(container.home()), this.repo(), 1);
    try {
        final PullRef base = pull.base();
        MatcherAssert.assertThat(base, Matchers.notNullValue());
        MatcherAssert.assertThat(base.ref(), Matchers.equalTo(ref));
        MatcherAssert.assertThat(base.sha(), Matchers.equalTo(sha));
    } 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 80 with ApacheRequest

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

the class RtReferenceTest method fetchesContent.

/**
 * RtReference should be able to fetch its json.
 * @throws Exception - if something goes wrong.
 */
@Test
public void fetchesContent() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "{\"ref\":\"refs/heads/featureB\"}")).start();
    final Reference reference = new RtReference(new ApacheRequest(container.home()), new MkGithub().randomRepo(), "refs/heads/featureB");
    try {
        MatcherAssert.assertThat(reference.json().getString("ref"), Matchers.is("refs/heads/featureB"));
    } 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