Package com.jcabi.http.mock

Examples of com.jcabi.http.mock.MkContainer


     * This tests that the remove() method is working fine.
     * @throws Exception - in case something goes wrong.
     */
    @Test
    public void removesComment() throws Exception {
        final MkContainer container = new MkGrizzlyContainer().next(
            new MkAnswer.Simple(HttpURLConnection.HTTP_NO_CONTENT, "")
        ).start();
        final Repo repo = repo();
        final Issue issue = repo.issues().create("testing3", "issue3");
        final RtComment comment = new RtComment(
            new ApacheRequest(container.home()), issue, 10
        );
        try {
            comment.remove();
            final MkQuery query = container.take();
            MatcherAssert.assertThat(
                query.method(),
                Matchers.equalTo(Request.DELETE)
            );
        } finally {
            container.stop();
        }
    }
View Full Code Here


     * @throws Exception - if something goes wrong.
     */
    @Test
    public void returnsItsJSon() throws Exception {
        final String body = "{\"body\":\"test5\"}";
        final MkContainer container = new MkGrizzlyContainer().next(
            new MkAnswer.Simple(HttpURLConnection.HTTP_OK, body)
        ).start();
        final Repo repo = repo();
        final Issue issue = repo.issues().create("testing4", "issue4");
        final RtComment comment = new RtComment(
            new ApacheRequest(container.home()), issue, 10
        );
        try {
            final JsonObject json = comment.json();
            MatcherAssert.assertThat(
                json.getString("body"),
                Matchers.is("test5")
            );
        } finally {
            container.stop();
        }
    }
View Full Code Here

     * RtComment can patch a comment.
     * @throws Exception - if anything goes wrong.
     */
    @Test
    public void patchesComment() throws Exception {
        final MkContainer container = new MkGrizzlyContainer().next(
            new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "")
        ).start();
        final Repo repo = repo();
        final Issue issue = repo.issues().create("testing5", "issue5");
        final RtComment comment = new RtComment(
            new ApacheRequest(container.home()), issue, 10
        );
        final JsonObject jsonPatch = Json.createObjectBuilder()
            .add("title", "test comment").build();
        try {
            comment.patch(jsonPatch);
            final MkQuery query = container.take();
            MatcherAssert.assertThat(
                query.method(), Matchers.equalTo(Request.PATCH)
            );
        } finally {
            container.stop();
        }
    }
View Full Code Here

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

     * @throws Exception If a problem occurs
     * @checkstyle MagicNumberCheck (25 lines)
     */
    @Test
    public void retrievesOrganizations() throws Exception {
        final MkContainer container = new MkGrizzlyContainer().next(
            new MkAnswer.Simple(
                HttpURLConnection.HTTP_OK,
                Json.createArrayBuilder()
                    .add(org(1, "org1"))
                    .add(org(2, "org2"))
                    .add(org(3, "org3"))
                    .build().toString()
            )
        ).start();
        try {
            final Organizations orgs = new RtOrganizations(
                new MkGithub(),
                new ApacheRequest(container.home()),
                Mockito.mock(User.class)
            );
            MatcherAssert.assertThat(
                orgs.iterate(),
                Matchers.<Organization>iterableWithSize(3)
            );
            MatcherAssert.assertThat(
                container.take().uri().toString(),
                Matchers.endsWith("/user/orgs")
            );
        } finally {
            container.stop();
        }
    }
View Full Code Here

     *
     * @throws Exception If a problem occurs
     */
    @Test
    public void canIterateOrganizationsForUnauthUser() throws Exception {
        final MkContainer container = new MkGrizzlyContainer().next(
            new MkAnswer.Simple(
                HttpURLConnection.HTTP_OK,
                Json.createArrayBuilder()
                    .add(org(Tv.THREE, "org11"))
                    .add(org(Tv.FOUR, "org12"))
                    .add(org(Tv.FIVE, "org13"))
                    .build().toString()
            )
        ).start();
        try {
            final Organizations orgs = new RtOrganizations(
                new MkGithub(),
                new ApacheRequest(container.home()),
                Mockito.mock(User.class)
            );
            final String username = "octopus";
            MatcherAssert.assertThat(
                orgs.iterate(username),
                Matchers.<Organization>iterableWithSize(Tv.THREE)
            );
            MatcherAssert.assertThat(
                container.take().uri().toString(),
                Matchers.endsWith(String.format("/users/%s/orgs", username))
            );
        } finally {
            container.stop();
        }
    }
View Full Code Here

     *
     * @throws Exception if a problem occurs
     */
    @Test
    public void fetchesSingleOrganization() throws Exception {
        final MkContainer container = new MkGrizzlyContainer().next(
            new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "")
        ).start();
        try {
            final Organizations orgs = new RtOrganizations(
                new MkGithub(),
                new ApacheRequest(container.home()),
                Mockito.mock(User.class)
            );
            MatcherAssert.assertThat(
                orgs.get("org"),
                Matchers.notNullValue()
            );
        } finally {
            container.stop();
        }
    }
View Full Code Here

     * RtAssignees can iterate over assignees.
     * @throws Exception Exception If some problem inside
     */
    @Test
    public void iteratesAssignees() throws Exception {
        final MkContainer container = new MkGrizzlyContainer().next(
            new MkAnswer.Simple(
                HttpURLConnection.HTTP_OK,
                Json.createArrayBuilder()
                    .add(RtAssigneesTest.json("octocat"))
                    .add(RtAssigneesTest.json("dummy"))
                    .build().toString()
            )
        ).start();
        final Assignees users = new RtAssignees(
            new JdkRequest(container.home()),
            this.repo()
        );
        MatcherAssert.assertThat(
            users.iterate(),
            Matchers.<User>iterableWithSize(2)
        );
        container.stop();
    }
View Full Code Here

     * RtAssignees can check if user is assignee for this repo.
     * @throws Exception Exception If some problem inside
     */
    @Test
    public void checkUserIsAssigneeForRepo() throws Exception {
        final MkContainer container = new MkGrizzlyContainer().next(
            new MkAnswer.Simple(
                HttpURLConnection.HTTP_NO_CONTENT,
                Json.createArrayBuilder()
                    .add(RtAssigneesTest.json("octocat2"))
                    .add(RtAssigneesTest.json("dummy"))
                    .build().toString()
            )
        ).start();
        final Assignees users = new RtAssignees(
            new JdkRequest(container.home()),
            this.repo()
        );
        MatcherAssert.assertThat(
            users.check("octocat2"),
            Matchers.equalTo(true)
        );
        container.stop();
    }
View Full Code Here

     * RtAssignees can check if user is NOT assignee for this repo.
     * @throws Exception Exception If some problem inside
     */
    @Test
    public void checkUserIsNotAssigneeForRepo() throws Exception {
        final MkContainer container = new MkGrizzlyContainer().next(
            new MkAnswer.Simple(
                HttpURLConnection.HTTP_NOT_FOUND,
                Json.createArrayBuilder()
                    .add(RtAssigneesTest.json("octocat3"))
                    .add(RtAssigneesTest.json("dummy"))
                    .build().toString()
            )
        ).start();
        final Assignees users = new RtAssignees(
            new JdkRequest(container.home()),
            this.repo()
        );
        MatcherAssert.assertThat(
            users.check("octocat33"),
            Matchers.equalTo(false)
        );
        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.