Search in sources :

Example 21 with MkContainer

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

the class RtOrganizationTest method canRepresentAsString.

/**
 * RtOrganization can return a String representation correctly reflecting
 * its URI.
 *
 * @throws Exception if something goes wrong.
 */
@Test
public void canRepresentAsString() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "blah")).start();
    final RtOrganization org = new RtOrganization(new MkGithub(), new ApacheRequest(container.home()), "testToString");
    try {
        MatcherAssert.assertThat(org.toString(), Matchers.endsWith("/orgs/testToString"));
    } 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 22 with MkContainer

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

the class RtPullCommentTest method canDescribeAsJson.

/**
 * RtPullComment can return its JSON description.
 * @throws Exception If a problem occurs.
 */
@Test
public void canDescribeAsJson() throws Exception {
    final String body = "{\"body\":\"test\"}";
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, body)).start();
    final Pull pull = Mockito.mock(Pull.class);
    Mockito.doReturn(repo()).when(pull).repo();
    final RtPullComment comment = new RtPullComment(new ApacheRequest(container.home()), pull, 1);
    try {
        final JsonObject json = comment.json();
        MatcherAssert.assertThat(json.getString("body"), Matchers.is("test"));
        MatcherAssert.assertThat(container.take().uri().toString(), Matchers.endsWith("/repos/joe/blueharvest/pulls/comments/1"));
    } finally {
        container.stop();
    }
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) JsonObject(javax.json.JsonObject) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 23 with MkContainer

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

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

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

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