Examples of MkContainer


Examples of com.jcabi.http.mock.MkContainer

     *
     * @throws Exception if there is any problem
     */
    @Test
    public void sendHttpRequestAndWriteResponseAsJson() throws Exception {
        final MkContainer container = new MkGrizzlyContainer().next(
            new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "{\"msg\": \"hi\"}")
        ).start();
        final RtLabel label = new RtLabel(
            new ApacheRequest(container.home()),
            RtLabelTest.repo(),
            "bug"
        );
        MatcherAssert.assertThat(
            label.json().getString("msg"),
            Matchers.equalTo("hi")
        );
        container.stop();
    }
View Full Code Here

Examples of com.jcabi.http.mock.MkContainer

     *
     * @throws Exception if there is any problem
     */
    @Test
    public void executePatchRequest() throws Exception {
        final MkContainer container = new MkGrizzlyContainer().next(
            new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "{\"msg\":\"hi\"}")
        ).start();
        final RtLabel label = new RtLabel(
            new ApacheRequest(container.home()),
            RtLabelTest.repo(),
            "enhance"
        );
        label.patch(
            Json.createObjectBuilder()
                .add("content", "hi you!")
                .build()
        );
        MatcherAssert.assertThat(
            container.take().method(),
            Matchers.equalTo(Request.PATCH)
        );
        container.stop();
    }
View Full Code Here

Examples of com.jcabi.http.mock.MkContainer

     */
    @Test
    public void canCreateBlob() throws Exception {
        final String content = "Content of the blob";
        final String body = blob().toString();
        final MkContainer container = new MkGrizzlyContainer().next(
            new MkAnswer.Simple(HttpURLConnection.HTTP_CREATED, body)
        ).next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, body)).start();
        final RtBlobs blobs = new RtBlobs(
            new ApacheRequest(container.home()),
            repo()
        );
        try {
            final Blob blob = blobs.create(content, "utf-8");
            MatcherAssert.assertThat(
                container.take().method(),
                Matchers.equalTo(Request.POST)
            );
            MatcherAssert.assertThat(
                new Blob.Smart(blob).url(),
                Matchers.equalTo("http://localhost/1")
            );
        } finally {
            container.stop();
        }
    }
View Full Code Here

Examples of com.jcabi.http.mock.MkContainer

            Json.createObjectBuilder()
                .add(bodyString, body)
                .add(idString, identifier)
                .build().toString()
        );
        final MkContainer container =
            new MkGrizzlyContainer().next(first).next(second).next(third)
                .start();
        final MkContainer gistContainer = new MkGrizzlyContainer().start();
        final RtGist gist =
            new RtGist(
                new MkGithub(),
                new ApacheRequest(gistContainer.home()), "someName"
            );
        final RtGistComment comment = new RtGistComment(
            new ApacheRequest(container.home()), gist, identifier
        );
        comment.patch(Json.createObjectBuilder()
            .add(bodyString, patchedBody)
            .add(idString, identifier)
            .build()
        );
        MatcherAssert.assertThat(
            comment.json().getString(bodyString),
            Matchers.equalTo(patchedBody)
        );
        container.stop();
        gistContainer.stop();
    }
View Full Code Here

Examples of com.jcabi.http.mock.MkContainer

     * @throws IOException if has some problems with json parsing.
     */
    @Test
    public final void removeGistComment() throws IOException {
        final int identifier = 1;
        final MkContainer container = new MkGrizzlyContainer().next(
            new MkAnswer.Simple(HttpURLConnection.HTTP_NO_CONTENT, "")
        ).start();
        final RtGist gist = new RtGist(
            new MkGithub(),
            new FakeRequest().withStatus(HttpURLConnection.HTTP_NO_CONTENT),
            "gistName"
        );
        final RtGistComment comment = new RtGistComment(
            new ApacheRequest(container.home()), gist, identifier
        );
        comment.remove();
        MatcherAssert.assertThat(
            container.take().method(),
            Matchers.equalTo(Request.DELETE)
        );
        container.stop();
    }
View Full Code Here

Examples of com.jcabi.http.mock.MkContainer

     * @throws Exception if there is a problem.
     * @checkstyle MultipleStringLiteralsCheck (20 lines)
     */
    @Test
    public void readsFileWithContents() throws Exception {
        final MkContainer container = new MkGrizzlyContainer().next(
            new MkAnswer.Simple(
                HttpURLConnection.HTTP_OK,
                "{\"files\":{\"hello\":{\"raw_url\":\"world\"}}}"
            )
        ).next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "success!"))
            .start();
        final RtGist gist = new RtGist(
            new MkGithub(),
            new ApacheRequest(container.home()),
            "test"
        );
        try {
            MatcherAssert.assertThat(
                gist.read("hello"),
                Matchers.equalTo("success!")
            );
        } finally {
            container.stop();
        }
    }
View Full Code Here

Examples of com.jcabi.http.mock.MkContainer

     * RtGist should be able to do writes.
     * @throws Exception if there is a problem.
     */
    @Test
    public void writesFileContents() throws Exception {
        final MkContainer container = new MkGrizzlyContainer().next(
            new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "testFileWrite")
        ).start();
        final RtGist gist = new RtGist(
            new MkGithub(),
            new ApacheRequest(container.home()),
            "testWrite"
        );
        gist.write("testFile", "testContent");
        try {
            MatcherAssert.assertThat(
                container.take().body(),
                Matchers.containsString(
                    "\"testFile\":{\"content\":\"testContent\"}"
                )
            );
        } finally {
            container.stop();
        }
    }
View Full Code Here

Examples of com.jcabi.http.mock.MkContainer

     * @throws IOException If there is a problem.
     */
    @Test
    public void fork() throws IOException {
        final String fileContent = "success";
        final MkContainer container = new MkGrizzlyContainer();
        container.next(
            new MkAnswer.Simple(
                HttpURLConnection.HTTP_OK,
                "{\"files\":{\"hello\":{\"raw_url\":\"world\"}}}"
            )
        );
        container.next(
            new MkAnswer.Simple(HttpURLConnection.HTTP_OK, fileContent)
        );
        container.next(
            new MkAnswer.Simple(
                HttpURLConnection.HTTP_CREATED,
                "{\"id\": \"forked\"}"
            )
        );
        container.next(
            new MkAnswer.Simple(
                HttpURLConnection.HTTP_OK,
                "{\"files\":{\"hello\":{\"raw_url\":\"world\"}}}"
            )
        );
        container.next(
            new MkAnswer.Simple(HttpURLConnection.HTTP_OK, fileContent)
        );
        container.start();
        final Gist gist = new RtGist(
            new MkGithub(),
            new ApacheRequest(container.home()),
            "test"
        );
        final String content = gist.read("hello");
        final Gist forkedGist = gist.fork();
        try {
            MatcherAssert.assertThat(
                forkedGist.read("hello"),
                Matchers.equalTo(content)
            );
        } finally {
            container.stop();
        }
    }
View Full Code Here

Examples of com.jcabi.http.mock.MkContainer

     *
     * @throws Exception if something goes wrong.
     */
    @Test
    public void canIterateFiles() throws Exception {
        final MkContainer container = new MkGrizzlyContainer().next(
            new MkAnswer.Simple(
                HttpURLConnection.HTTP_OK,
                "{\"files\":{\"something\":{\"filename\":\"not null\"}}}"
            )
        ).start();
        final Gist.Smart smart = new Gist.Smart(
            new RtGist(
                new MkGithub(),
                new ApacheRequest(container.home()),
                "testGetFiles"
            )
        );
        try {
            MatcherAssert.assertThat(
                smart.files(),
                Matchers.notNullValue()
            );
            MatcherAssert.assertThat(
                container.take().uri().toString(),
                Matchers.endsWith("/gists/testGetFiles")
            );
        } finally {
            container.stop();
        }
    }
View Full Code Here

Examples of com.jcabi.http.mock.MkContainer

     *
     * @throws Exception If something goes wrong.
     */
    @Test
    public void canRepresentAsString() throws Exception {
        final MkContainer container = new MkGrizzlyContainer().start();
        final RtGist gist = new RtGist(
            new MkGithub(),
            new ApacheRequest(container.home()),
            "testToString"
        );
        try {
            MatcherAssert.assertThat(
                gist.toString(),
                Matchers.endsWith("/gists/testToString")
            );
        } finally {
            container.stop();
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.