Search in sources :

Example 41 with MkGrizzlyContainer

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

the class RtGitignoresTest method iterateTemplateNames.

/**
 * RtGitignores can iterate template names.
 * @throws Exception if there is any error
 */
@Test
public void iterateTemplateNames() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, Json.createArrayBuilder().add("C").add("Java").build().toString())).start();
    final RtGitignores gitignores = new RtGitignores(new RtGithub(new JdkRequest(container.home())));
    MatcherAssert.assertThat(gitignores.iterate(), Matchers.<String>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 42 with MkGrizzlyContainer

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

the class RtCollaboratorsTest method userCanBeAddedAsCollaborator.

/**
 * User can be added to a repo as a collaborator.
 * @throws Exception if any error occurs.
 */
@Test
public void userCanBeAddedAsCollaborator() 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.add("dummy1");
        final MkQuery query = container.take();
        MatcherAssert.assertThat(query.method(), Matchers.equalTo(Request.PUT));
    } 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 43 with MkGrizzlyContainer

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

the class RtCommitTest method readsMessage.

/**
 * Commit.Smart can read message.
 * @throws Exception when an error occurs
 */
@Test
public final void readsMessage() throws Exception {
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "{\"sha\":\"a0b1c3\",\"commit\":{\"message\":\"hello\"}}")).start(this.resource.port());
    try {
        final Commit.Smart commit = new Commit.Smart(new RtCommit(new JdkRequest(container.home()), new MkGithub().randomRepo(), "sha"));
        MatcherAssert.assertThat(commit.message(), Matchers.equalTo("hello"));
    } finally {
        container.stop();
    }
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) JdkRequest(com.jcabi.http.request.JdkRequest) MkGithub(com.jcabi.github.mock.MkGithub) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 44 with MkGrizzlyContainer

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

the class RtContentTest method fetchesRawContent.

/**
 * RtContent should be able to fetch raw content.
 *
 * @throws Exception if a problem occurs.
 */
@Test
public void fetchesRawContent() throws Exception {
    final String raw = "the raw \u20ac";
    final MkContainer container = new MkGrizzlyContainer().next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, raw)).start(this.resource.port());
    final InputStream stream = new RtContent(new ApacheRequest(container.home()), this.repo(), "raw").raw();
    try {
        MatcherAssert.assertThat(IOUtils.toString(stream, StandardCharsets.UTF_8), Matchers.is(raw));
        MatcherAssert.assertThat(container.take().headers().get(HttpHeaders.ACCEPT).get(0), Matchers.is("application/vnd.github.v3.raw"));
    } finally {
        stream.close();
        container.stop();
    }
}
Also used : MkGrizzlyContainer(com.jcabi.http.mock.MkGrizzlyContainer) InputStream(java.io.InputStream) ApacheRequest(com.jcabi.http.request.ApacheRequest) MkContainer(com.jcabi.http.mock.MkContainer) Test(org.junit.Test)

Example 45 with MkGrizzlyContainer

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

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