Search in sources :

Example 46 with MkContainer

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

the class RtContentsTest method canUpdateFilesInRepository.

/**
 * RtContents can update files into the repository.
 * @throws Exception If any problems during test execution occurs.
 */
@Test
public void canUpdateFilesInRepository() throws Exception {
    final String sha = "2f97253a513bbe26658881c29e27910082fef900";
    final JsonObject resp = Json.createObjectBuilder().add("sha", sha).build();
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, Json.createObjectBuilder().add("commit", resp).build().toString())).next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, resp.toString())).start(this.resource.port());
    try {
        final RtContents contents = new RtContents(new ApacheRequest(container.home()), repo());
        final String path = "test.txt";
        final JsonObject json = Json.createObjectBuilder().add("message", "let's change it.").add("content", "bmV3IHRlc3Q=").add("sha", "90b67dda6d5944ad167e20ec52bfed8fd56986c8").build();
        MatcherAssert.assertThat(new RepoCommit.Smart(contents.update(path, json)).sha(), Matchers.is(sha));
        final MkQuery query = container.take();
        MatcherAssert.assertThat(query.method(), Matchers.equalTo(Request.PUT));
        MatcherAssert.assertThat(query.uri().getPath(), Matchers.endsWith(path));
        MatcherAssert.assertThat(query.body(), Matchers.equalTo(json.toString()));
    } finally {
        container.stop();
    }
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) MkAnswer(com.jcabi.http.mock.MkAnswer) MkQuery(com.jcabi.http.mock.MkQuery) JsonObject(javax.json.JsonObject) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 47 with MkContainer

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

the class RtContentsTest method canFetchFilesFromRepository.

/**
 * RtContents can fetch files from the repository.
 *
 * @throws Exception if some problem inside.
 * @checkstyle MultipleStringLiteralsCheck (50 lines)
 */
@Test
public void canFetchFilesFromRepository() throws Exception {
    final String path = "test/file";
    final String name = "file";
    final JsonObject body = Json.createObjectBuilder().add("path", path).add("name", name).build();
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, Json.createObjectBuilder().add("path", path).add("name", name).build().toString())).next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, body.toString())).start(this.resource.port());
    final RtContents contents = new RtContents(new ApacheRequest(container.home()), repo());
    try {
        final Content.Smart smart = new Content.Smart(contents.get(path, "branch1"));
        final MkQuery query = container.take();
        MatcherAssert.assertThat(query.uri().toString(), Matchers.endsWith("/repos/test/contents/contents/test/file?ref=branch1"));
        MatcherAssert.assertThat(smart.path(), Matchers.is(path));
        MatcherAssert.assertThat(smart.name(), Matchers.is(name));
        MatcherAssert.assertThat(query.method(), Matchers.equalTo(Request.GET));
        MatcherAssert.assertThat(container.take().uri().toString(), Matchers.endsWith("/repos/test/contents/contents/test/file?ref=branch1"));
    } finally {
        container.stop();
    }
}
Also used : MkQuery(com.jcabi.http.mock.MkQuery) JsonObject(javax.json.JsonObject) MkContainer(com.jcabi.http.mock.MkContainer) MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) MkAnswer(com.jcabi.http.mock.MkAnswer) Test(org.junit.Test)

Example 48 with MkContainer

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

the class RtContentsTest method canFetchReadmeFileFromSpecifiedBranch.

/**
 * RtContents can fetch the readme file from the specified branch.
 *
 * @throws Exception if a problem occurs.
 */
@Test
public void canFetchReadmeFileFromSpecifiedBranch() throws Exception {
    final String path = "README.md";
    final JsonObject body = Json.createObjectBuilder().add("path", path).build();
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, body.toString())).start(this.resource.port());
    final RtContents contents = new RtContents(new ApacheRequest(container.home()), repo());
    try {
        MatcherAssert.assertThat(contents.readme("test-branch").path(), Matchers.is(path));
        final MkQuery query = container.take();
        MatcherAssert.assertThat(query.uri().toString(), Matchers.endsWith("/repos/test/contents/readme"));
        MatcherAssert.assertThat(query.body(), Matchers.is("{\"ref\":\"test-branch\"}"));
    } 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 49 with MkContainer

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

the class RtGistCommentsTest method iterateComments.

/**
 * RtGistComments can iterate comments.
 * @throws Exception if there is any error
 */
@Test
public void iterateComments() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, Json.createArrayBuilder().add(comment("comment 1")).add(comment("comment 2")).build().toString())).start(this.resource.port());
    final Gist gist = Mockito.mock(Gist.class);
    Mockito.doReturn("2").when(gist).identifier();
    final RtGistComments comments = new RtGistComments(new JdkRequest(container.home()), gist);
    MatcherAssert.assertThat(comments.iterate(), Matchers.<GistComment>iterableWithSize(2));
    container.stop();
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) JdkRequest(com.jcabi.http.request.JdkRequest) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 50 with MkContainer

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

the class RtGistCommentsTest method getComment.

/**
 * RtGistComments can get a single comment.
 * @throws Exception if some problem inside
 */
@Test
public void getComment() throws Exception {
    final String body = "Just commenting";
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, comment(body).toString())).start(this.resource.port());
    final Gist gist = Mockito.mock(Gist.class);
    Mockito.doReturn("1").when(gist).identifier();
    final RtGistComments comments = new RtGistComments(new JdkRequest(container.home()), gist);
    final GistComment comment = comments.get(1);
    MatcherAssert.assertThat(new GistComment.Smart(comment).body(), Matchers.equalTo(body));
    container.stop();
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) JdkRequest(com.jcabi.http.request.JdkRequest) 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