Search in sources :

Example 81 with MkContainer

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

the class RtCollaboratorsTest method userCanBeRemoved.

/**
 * User can be removed from a list of collaborators.
 * @throws Exception if any error occurs.
 */
@Test
public void userCanBeRemoved() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_NO_CONTENT, Json.createArrayBuilder().add(RtCollaboratorsTest.json("octocat2")).add(RtCollaboratorsTest.json("dummy")).build().toString())).start(this.resource.port());
    final Collaborators users = new RtCollaborators(new JdkRequest(container.home()), this.repo());
    try {
        users.remove("dummy");
        final MkQuery query = container.take();
        MatcherAssert.assertThat(query.method(), Matchers.equalTo(Request.DELETE));
    } finally {
        container.stop();
    }
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) JdkRequest(com.jcabi.http.request.JdkRequest) MkQuery(com.jcabi.http.mock.MkQuery) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 82 with MkContainer

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

the class RtCollaboratorsTest method userCanBeTestForBeingCollaborator.

/**
 * User can be checked for being a collaborator.
 * @throws Exception if any error occurs.
 */
@Test
public void userCanBeTestForBeingCollaborator() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_NO_CONTENT, Json.createArrayBuilder().add(RtCollaboratorsTest.json("octocat2")).add(RtCollaboratorsTest.json("dummy")).build().toString())).start(this.resource.port());
    final Collaborators users = new RtCollaborators(new JdkRequest(container.home()), this.repo());
    try {
        MatcherAssert.assertThat(users.isCollaborator("octocat2"), Matchers.equalTo(true));
    } finally {
        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 83 with MkContainer

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

the class RtContentTest method patchWithJson.

/**
 * RtContent should be able to perform a patch request.
 *
 * @throws Exception if a problem occurs.
 */
@Test
public void patchWithJson() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "response")).start(this.resource.port());
    final RtContent content = new RtContent(new ApacheRequest(container.home()), this.repo(), "path");
    content.patch(Json.createObjectBuilder().add("patch", "test").build());
    final MkQuery query = container.take();
    try {
        MatcherAssert.assertThat(query.method(), Matchers.equalTo(Request.PATCH));
        MatcherAssert.assertThat(query.body(), Matchers.equalTo("{\"patch\":\"test\"}"));
    } 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 84 with MkContainer

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

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

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