Search in sources :

Example 36 with ApacheRequest

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

the class RtContentsTest method canCreateFileInRepository.

/**
 * RtContents can create a file in the repository.
 * @throws Exception If a problem occurs.
 */
@Test
public void canCreateFileInRepository() throws Exception {
    final String path = "test/thefile";
    final String name = "thefile";
    final JsonObject body = Json.createObjectBuilder().add("path", path).add("name", name).build();
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_CREATED, Json.createObjectBuilder().add("content", body).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());
    final JsonObject content = Json.createObjectBuilder().add("path", path).add("message", "theMessage").add("content", "blah").build();
    try {
        final Content.Smart smart = new Content.Smart(contents.create(content));
        MatcherAssert.assertThat(container.take().uri().toString(), Matchers.endsWith(path));
        MatcherAssert.assertThat(smart.path(), Matchers.is(path));
        MatcherAssert.assertThat(smart.name(), Matchers.is(name));
        MatcherAssert.assertThat(container.take().uri().toString(), Matchers.endsWith("/repos/test/contents/contents/test/thefile"));
    } 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 37 with ApacheRequest

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

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

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

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

the class RtGistTest method canUnstarAGist.

/**
 * RtGist can unstar a starred Gist.
 * @throws Exception If something goes wrong.
 */
@Test
public void canUnstarAGist() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_NO_CONTENT, "")).start();
    final RtGist gist = new RtGist(new MkGithub(), new ApacheRequest(container.home()), "unstar");
    gist.unstar();
    final MkQuery query = container.take();
    MatcherAssert.assertThat(query.method(), Matchers.equalTo(Request.DELETE));
    MatcherAssert.assertThat(query.body(), Matchers.isEmptyOrNullString());
    container.stop();
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) MkQuery(com.jcabi.http.mock.MkQuery) MkGithub(com.jcabi.github.mock.MkGithub) 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