Search in sources :

Example 61 with ApacheRequest

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

the class RtContentsTest method canDeleteFilesFromRepository.

/**
 * RtContents can delete files from the repository.
 *
 * @throws Exception if a problem occurs.
 * @checkstyle MultipleStringLiteralsCheck (50 lines)
 */
@Test
public void canDeleteFilesFromRepository() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, Json.createObjectBuilder().add("commit", Json.createObjectBuilder().add("sha", "commitSha").build()).build().toString())).start(this.resource.port());
    final RtContents contents = new RtContents(new ApacheRequest(container.home()), repo());
    try {
        final RepoCommit commit = contents.remove(Json.createObjectBuilder().add("path", "to/remove").add("message", "Delete me").add("sha", "fileSha").build());
        MatcherAssert.assertThat(commit.sha(), Matchers.is("commitSha"));
        final MkQuery query = container.take();
        MatcherAssert.assertThat(query.body(), Matchers.allOf(Matchers.containsString("\"message\":\"Delete me\""), Matchers.containsString("\"sha\":\"fileSha\"")));
        MatcherAssert.assertThat(query.uri().toString(), Matchers.endsWith("/repos/test/contents/contents/to/remove"));
    } 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 62 with ApacheRequest

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

the class RtContentsTest method canFetchReadmeFile.

/**
 * RtContents can fetch the default branch readme file.
 *
 * @throws Exception if some problem inside.
 */
@Test
public void canFetchReadmeFile() 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().path(), Matchers.is(path));
        final MkQuery query = container.take();
        MatcherAssert.assertThat(query.uri().toString(), Matchers.endsWith("/repos/test/contents/readme"));
        MatcherAssert.assertThat(query.body().length(), Matchers.is(0));
    } 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 63 with ApacheRequest

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

the class RtContentsTest method canIterateDirectoryContents.

/**
 * RtContents can iterate through a directory's contents.
 * @throws Exception If something goes wrong.
 */
@Test
public void canIterateDirectoryContents() throws Exception {
    final JsonArray body = Json.createArrayBuilder().add(Json.createObjectBuilder().add("path", "README.md").build()).add(Json.createObjectBuilder().add("path", ".gitignore").build()).build();
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, body.toString())).next(new MkAnswer.Simple("{\"path\":\"README.md\"}")).next(new MkAnswer.Simple("{\"path\":\".gitignore\"}")).start(this.resource.port());
    final RtContents contents = new RtContents(new ApacheRequest(container.home()), repo());
    try {
        MatcherAssert.assertThat(contents.iterate("dir", "branch2"), Matchers.<Content>iterableWithSize(2));
    } finally {
        container.stop();
    }
}
Also used : JsonArray(javax.json.JsonArray) 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 64 with ApacheRequest

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

the class RtCommentTest method givesToString.

/**
 * This tests that the toString() method is working fine.
 * @throws Exception - if anything goes wrong.
 */
@Test
public void givesToString() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "")).start(this.resource.port());
    final Repo repo = new MkGithub().randomRepo();
    final Issue issue = repo.issues().create("testing6", "issue6");
    final RtComment comment = new RtComment(new ApacheRequest(container.home()), issue, 10);
    try {
        final String stringComment = comment.toString();
        MatcherAssert.assertThat(stringComment, Matchers.not(Matchers.isEmptyOrNullString()));
        MatcherAssert.assertThat(stringComment, Matchers.endsWith("10"));
    } 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 65 with ApacheRequest

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

the class RtCommitsTest method createsCommit.

/**
 * Tests creating a Commit.
 *
 * @throws Exception when an error occurs
 */
@Test
public final void createsCommit() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_CREATED, "{\"sha\":\"0abcd89jcabitest\"}")).start(this.resource.port());
    final Commits commits = new RtCommits(new ApacheRequest(container.home()), new MkGithub().randomRepo());
    final JsonObject author = 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("message", "initial version").add("author", author).build();
    try {
        final Commit newCommit = commits.create(input);
        MatcherAssert.assertThat(newCommit, Matchers.instanceOf(Commit.class));
        MatcherAssert.assertThat(container.take().method(), Matchers.equalTo(Request.POST));
        MatcherAssert.assertThat(newCommit.sha(), Matchers.equalTo("0abcd89jcabitest"));
    } finally {
        container.stop();
    }
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) ApacheRequest(com.jcabi.http.request.ApacheRequest) JsonObject(javax.json.JsonObject) 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