Search in sources :

Example 16 with ApacheRequest

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

the class RtRepoTest method iteratesEvents.

/**
 * RtRepo can fetch events.
 *
 * @throws Exception If some problem inside
 */
@Test
public void iteratesEvents() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, Json.createArrayBuilder().add(event(Event.ASSIGNED)).add(event(Event.MENTIONED)).build().toString())).start();
    final Repo repo = RtRepoTest.repo(new ApacheRequest(container.home()));
    MatcherAssert.assertThat(repo.issueEvents().iterate(), Matchers.<Event>iterableWithSize(2));
    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 17 with ApacheRequest

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

the class RtRepoTest method iteratesLanguages.

/**
 * RtRepo can iterate languages.
 *
 * @throws Exception If some problem inside
 */
@Test
public void iteratesLanguages() throws Exception {
    final String lang = "C";
    final String other = "Java";
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, Json.createObjectBuilder().add(lang, 1).add(other, 2).build().toString())).start();
    final Repo repo = RtRepoTest.repo(new ApacheRequest(container.home()));
    try {
        final Iterator<Language> iter = repo.languages().iterator();
        MatcherAssert.assertThat(iter.hasNext(), Matchers.is(true));
        MatcherAssert.assertThat(iter.next().name(), Matchers.is(lang));
        MatcherAssert.assertThat(iter.hasNext(), Matchers.is(true));
        MatcherAssert.assertThat(iter.next().name(), Matchers.is(other));
        MatcherAssert.assertThat(iter.hasNext(), Matchers.is(false));
    } 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 18 with ApacheRequest

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

the class RtReposTest method removeRepo.

/**
 * RtRepos can remove a repo.
 * @throws Exception if some problem inside
 */
@Test
public void removeRepo() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_NO_CONTENT, "")).start();
    final Repos repos = new RtRepos(Mockito.mock(Github.class), new ApacheRequest(container.home()));
    repos.remove(new Coordinates.Simple("", ""));
    try {
        final MkQuery query = container.take();
        MatcherAssert.assertThat(query.method(), Matchers.equalTo(Request.DELETE));
        MatcherAssert.assertThat(query.body(), Matchers.isEmptyString());
    } 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 19 with ApacheRequest

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

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

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