Search in sources :

Example 16 with MkGrizzlyContainer

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

the class RtReleasesTest method canCreateRelease.

/**
 * RtReleases can create a release.
 * @throws Exception If some problem inside
 */
@Test
public void canCreateRelease() throws Exception {
    final String tag = "v1.0.0";
    final String rel = release(tag).toString();
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_CREATED, rel)).next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, rel)).start();
    final RtReleases releases = new RtReleases(new JdkRequest(container.home()), repo());
    final Release release = releases.create(tag);
    MatcherAssert.assertThat(container.take().method(), Matchers.equalTo(Request.POST));
    MatcherAssert.assertThat(release.json().getString("tag_name"), Matchers.equalTo(tag));
    container.stop();
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) JdkRequest(com.jcabi.http.request.JdkRequest) MkAnswer(com.jcabi.http.mock.MkAnswer) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 17 with MkGrizzlyContainer

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

Example 18 with MkGrizzlyContainer

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

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

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

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