Package com.jcabi.http.mock

Examples of com.jcabi.http.mock.MkContainer


     *
     * @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();
        final Commits commits = new RtCommits(
            new ApacheRequest(container.home()),
            repo()
        );
        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();
        }
    }
View Full Code Here


     * @throws Exception - If something goes wrong.
     * @checkstyle IndentationCheck (20 lines)
     */
    @Test
    public void createsTag() throws Exception {
        final MkContainer container = new MkGrizzlyContainer().next(
            new MkAnswer.Simple(
                HttpURLConnection.HTTP_CREATED,
                "{\"sha\":\"0abcd89jcabitest\",\"tag\":\"v.0.1\"}"
            )
        ).next(
            new MkAnswer.Simple(
                HttpURLConnection.HTTP_CREATED,
                "{\"ref\":\"refs/heads/feature-a\"}"
            )
        ).start();
        final Tags tags = new RtTags(
            new ApacheRequest(container.home()),
            repo()
        );
        final JsonObject tagger = 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("tag", "v.0.1").add("message", "initial version")
            .add("object", "07cd4r45Test444").add("type", "commit")
            .add("tagger", tagger).build();
        try {
            MatcherAssert.assertThat(
                tags.create(input),
                Matchers.instanceOf(Tag.class)
            );
            MatcherAssert.assertThat(
                container.take().method(),
                Matchers.equalTo(Request.POST)
            );
            MatcherAssert.assertThat(
                container.take().method(),
                Matchers.equalTo(Request.POST)
            );
        } finally {
            container.stop();
        }
    }
View Full Code Here

     *
     * @throws Exception If a problem occurs.
     */
    @Test
    public void performsValidRequest() throws Exception {
        final MkContainer container = new MkGrizzlyContainer().next(
            new MkAnswer.Simple(
                HttpURLConnection.HTTP_OK,
                "{\"test\":\"hook\"}"
            )
        ).start();
        try {
            final Hook hook = new RtHook(
                new ApacheRequest(container.home()),
                repo(),
                1
            );
            MatcherAssert.assertThat(
                hook.json(),
                Matchers.notNullValue()
            );
            MatcherAssert.assertThat(
                container.take().uri().toString(),
                Matchers.endsWith("/repos/test/repo/hooks/1")
            );
        } finally {
            container.stop();
        }
    }
View Full Code Here

            "src/attributes/classes.js",
            "classes.js",
            // @checkstyle LineLength (1 line)
            "https://api.github.com/repos/user/repo/contents/src/attributes/classes.js?ref=f3b89ba0820882bd4ce4404b7e7c819e7b506de5"
        ).build();
        final MkContainer container = new MkGrizzlyContainer().next(
            new MkAnswer.Simple(RtSearchTest.search(first, second).toString())
        ).next(new MkAnswer.Simple(first.toString()))
            .next(new MkAnswer.Simple(second.toString()))
            .start();
        try {
            final Search search = new RtGithub(
                new ApacheRequest(container.home())
            ).search();
            MatcherAssert.assertThat(
                search.codes("test4", "joined", Search.Order.DESC),
                Matchers.<Content>iterableWithSize(2)
            );
        } finally {
            container.stop();
        }
    }
View Full Code Here

    public void canUpdateFilesInRepository() throws Exception {
        final String sha = "2f97253a513bbe26658881c29e27910082fef900";
        final JsonObject resp = Json.createObjectBuilder()
            // @checkstyle MultipleStringLiterals (1 line)
            .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();
        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();
        }
    }
View Full Code Here

        ).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();
        final RtContents contents = new RtContents(
            new ApacheRequest(container.home()),
            repo()
        );
        try {
            MatcherAssert.assertThat(
                contents.iterate("dir", "branch2"),
                Matchers.<Content>iterableWithSize(2)
            );
        } finally {
            container.stop();
        }
    }
View Full Code Here

     * 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();
    }
View Full Code Here

     * RtCollaborators can iterate over a list of collaborators.
     * @throws Exception if any error occurs.
     */
    @Test
    public void canIterate() throws Exception {
        final MkContainer container = new MkGrizzlyContainer().next(
            new MkAnswer.Simple(
                HttpURLConnection.HTTP_OK,
                Json.createArrayBuilder()
                    .add(RtCollaboratorsTest.json("octocat"))
                    .add(RtCollaboratorsTest.json("dummy"))
                    .build().toString()
            )
        ).start();
        final Collaborators users = new RtCollaborators(
            new JdkRequest(container.home()),
            this.repo()
        );
        MatcherAssert.assertThat(
            users.iterate(),
            Matchers.<User>iterableWithSize(2)
        );
        container.stop();
    }
View Full Code Here

     * 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();
        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();
        }
    }
View Full Code Here

     * 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();
        final Collaborators users = new RtCollaborators(
            new JdkRequest(container.home()),
            this.repo()
        );
        try {
            MatcherAssert.assertThat(
                users.isCollaborator("octocat2"),
                Matchers.equalTo(true)
            );
        } finally {
            container.stop();
        }
    }
View Full Code Here

TOP

Related Classes of com.jcabi.http.mock.MkContainer

Copyright © 2018 www.massapicom. 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.