Search in sources :

Example 26 with MkGrizzlyContainer

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

the class RtReferencesTest method iteratesTags.

/**
 * RtReferences should be able to iterate over tags.
 * @throws Exception - If something goes wrong.
 */
@Test
public void iteratesTags() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "[{\"ref\":\"refs/tags/feature-b\"}]")).start();
    final References refs = new RtReferences(new ApacheRequest(container.home()), new MkGithub().randomRepo());
    try {
        MatcherAssert.assertThat(refs.tags(), Matchers.<Reference>iterableWithSize(1));
        MatcherAssert.assertThat(container.take().uri().toString(), Matchers.endsWith("/git/refs/tags"));
    } 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 27 with MkGrizzlyContainer

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

the class RtReferencesTest method iteratesHeads.

/**
 * RtReferences should be able to iterate over heads.
 * @throws Exception - If something goes wrong.
 */
@Test
public void iteratesHeads() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "[{\"ref\":\"refs/heads/feature-c\"}]")).start();
    final References refs = new RtReferences(new ApacheRequest(container.home()), new MkGithub().randomRepo());
    try {
        MatcherAssert.assertThat(refs.heads(), Matchers.<Reference>iterableWithSize(1));
        MatcherAssert.assertThat(container.take().uri().toString(), Matchers.endsWith("/git/refs/heads"));
    } 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 28 with MkGrizzlyContainer

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

the class RtStarsTest method checkIfRepoStarred.

/**
 * RtStars can check if repo is starred.
 *
 * @throws Exception If something goes wrong.
 */
@Test
public void checkIfRepoStarred() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_NO_CONTENT)).next(new MkAnswer.Simple(HttpURLConnection.HTTP_NOT_FOUND)).start();
    try {
        final Stars starred = new RtStars(new ApacheRequest(container.home()), RtStarsTest.repo("someuser", "starredrepo"));
        MatcherAssert.assertThat(starred.starred(), Matchers.is(true));
        final Stars unstarred = new RtStars(new ApacheRequest(container.home()), RtStarsTest.repo("otheruser", "notstarredrepo"));
        MatcherAssert.assertThat(unstarred.starred(), Matchers.is(false));
    } finally {
        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 29 with MkGrizzlyContainer

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

the class RtStarsTest method unstarRepository.

/**
 * RtStars can unstar repository.
 *
 * @throws Exception If something goes wrong.
 */
@Test
public void unstarRepository() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_NO_CONTENT)).start();
    final String user = "unstaruser";
    final String repo = "unstarrepo";
    final Stars stars = new RtStars(new ApacheRequest(container.home()), RtStarsTest.repo(user, repo));
    try {
        stars.unstar();
        final MkQuery query = container.take();
        MatcherAssert.assertThat(query.method(), Matchers.equalTo(Request.DELETE));
        MatcherAssert.assertThat(query.uri().getPath(), Matchers.containsString(UriBuilder.fromPath(user).path(repo).build().getPath()));
    } 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 30 with MkGrizzlyContainer

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

the class RtTagsTest method createsTag.

/**
 * RtTags can create a tag.
 * @throws Exception - If something goes wrong.
 * @checkstyle IndentationCheck (20 lines)
 */
@Test
public void createsTag() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_CREATED, "{\"sha\":\"0abcd89jcabitest\",\"tag\":\"v.0.1\"}")).next(new MkAnswer.Simple(HttpURLConnection.HTTP_CREATED, "{\"ref\":\"refs/heads/feature-a\"}")).start();
    final Tags tags = new RtTags(new ApacheRequest(container.home()), new MkGithub().randomRepo());
    final JsonObject tagger = Json.createObjectBuilder().add("name", "Scott").add("email", "scott@gmail.com").add("date", "2011-06-17T14:53:35-07:00").build();
    final JsonObject input = Json.createObjectBuilder().add("tag", "v.0.1").add("message", "initial version").add("object", "07cd4r45Test444").add("type", "commit").add("tagger", tagger).build();
    try {
        MatcherAssert.assertThat(tags.create(input), Matchers.instanceOf(Tag.class));
        MatcherAssert.assertThat(container.take().method(), Matchers.equalTo(Request.POST));
        MatcherAssert.assertThat(container.take().method(), Matchers.equalTo(Request.POST));
    } 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) 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