Package com.jcabi.http.mock

Examples of com.jcabi.http.mock.MkContainer


     * RtHooks can fetch non empty list of hooks.
     * @throws Exception if some problem inside
     */
    @Test
    public void canFetchNonEmptyListOfHooks() throws Exception {
        final MkContainer container = new MkGrizzlyContainer().next(
            new MkAnswer.Simple(
                HttpURLConnection.HTTP_OK,
                Json.createArrayBuilder()
                    .add(hook("hook 1", Collections.<String, String>emptyMap()))
                    .add(hook("hook 2", Collections.<String, String>emptyMap()))
                    .build().toString()
            )
        ).start();
        final RtHooks hooks = new RtHooks(
            new JdkRequest(container.home()),
            RtHooksTest.repo()
        );
        MatcherAssert.assertThat(
            hooks.iterate(),
            Matchers.<Hook>iterableWithSize(2)
        );
        container.stop();
    }
View Full Code Here


     * @throws Exception if some problem inside
     */
    @Test
    public void canFetchSingleHook() throws Exception {
        final String name = "hook name";
        final MkContainer container = new MkGrizzlyContainer().next(
            new MkAnswer.Simple(
                HttpURLConnection.HTTP_OK,
                RtHooksTest.hook(
                    name,
                    Collections.<String, String>emptyMap()
                ).toString()
            )
        ).start();
        final Hooks hooks = new RtHooks(
            new JdkRequest(container.home()),
            RtHooksTest.repo()
        );
        final Hook hook = hooks.get(1);
        MatcherAssert.assertThat(
            new Hook.Smart(hook).name(),
            Matchers.equalTo(name)
        );
        container.stop();
    }
View Full Code Here

        final ConcurrentHashMap<String, String> config =
            new ConcurrentHashMap<String, String>(2);
        config.put("url", "http://example.com");
        config.put("content_type", "json");
        final String body = RtHooksTest.hook(name, config).toString();
        final MkContainer container = new MkGrizzlyContainer().next(
            new MkAnswer.Simple(HttpURLConnection.HTTP_CREATED, body)
        ).next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK, body)).start();
        final Hooks hooks = new RtHooks(
            new JdkRequest(container.home()),
            RtHooksTest.repo()
        );
        try {
            final Hook hook = hooks.create(name, config);
            MatcherAssert.assertThat(
                container.take().method(),
                Matchers.equalTo(Request.POST)
            );
            MatcherAssert.assertThat(
                new Hook.Smart(hook).name(),
                Matchers.equalTo(name)
            );
        } finally {
            container.stop();
        }
    }
View Full Code Here

     *
     * @throws Exception if something goes wrong.
     */
    @Test
    public void canDeleteHook() throws Exception {
        final MkContainer container = new MkGrizzlyContainer().next(
            new MkAnswer.Simple(HttpURLConnection.HTTP_NO_CONTENT, "")
        ).start();
        final Hooks hooks = new RtHooks(
            new JdkRequest(container.home()),
            RtHooksTest.repo()
        );
        hooks.remove(1);
        try {
            final MkQuery query = container.take();
            MatcherAssert.assertThat(
                query.method(),
                Matchers.equalTo(Request.DELETE)
            );
            MatcherAssert.assertThat(
                query.body(),
                Matchers.isEmptyString()
            );
        } finally {
            container.stop();
        }
    }
View Full Code Here

     * @throws Exception if there is any error
     */
    @Test
    public void iterateUsers() throws Exception {
        final String identifier = "1";
        final MkContainer container = new MkGrizzlyContainer().next(
            new MkAnswer.Simple(
                HttpURLConnection.HTTP_OK,
                Json.createArrayBuilder()
                    .add(RtUsersTest.json("octocat", identifier))
                    .add(RtUsersTest.json("dummy", "2"))
                    .build().toString()
            )
        ).start();
        final Users users = new RtUsers(
            Mockito.mock(Github.class),
            new ApacheRequest(container.home())
        );
        MatcherAssert.assertThat(
            users.iterate(identifier),
            Matchers.<User>iterableWithSize(2)
        );
        container.stop();
    }
View Full Code Here

     * @throws Exception  if there is any error
     */
    @Test
    public void getSingleUser() throws Exception {
        final String login = "mark";
        final MkContainer container = new MkGrizzlyContainer().next(
            new MkAnswer.Simple(
                HttpURLConnection.HTTP_OK,
                RtUsersTest.json(login, "3").toString()
            )
        ).start();
        final Users users = new RtUsers(
            Mockito.mock(Github.class),
            new ApacheRequest(container.home())
        );
        MatcherAssert.assertThat(
            users.get(login).login(),
            Matchers.equalTo(login)
        );
        container.stop();
    }
View Full Code Here

     * @throws Exception  if there is any error
     */
    @Test
    public void getCurrentUser() throws Exception {
        final String login = "kendy";
        final MkContainer container = new MkGrizzlyContainer().next(
            new MkAnswer.Simple(
                HttpURLConnection.HTTP_OK,
                RtUsersTest.json(login, "4").toString()
            )
        ).start();
        final Users users = new RtUsers(
            Mockito.mock(Github.class),
            new ApacheRequest(container.home())
        );
        MatcherAssert.assertThat(
            users.self().login(),
            Matchers.equalTo(login)
        );
        container.stop();
    }
View Full Code Here

     * RtReferences should create and return a Reference.
     * @throws Exception - if something goes wrong.
     */
    @Test
    public void createsReference() throws Exception {
        final MkContainer container = new MkGrizzlyContainer().next(
            new MkAnswer.Simple(
                HttpURLConnection.HTTP_CREATED,
                "{\"ref\":\"refs/heads/feature-a\"}"
            )
        ).start();
        final References refs = new RtReferences(
            new ApacheRequest(container.home()),
            repo()
        );
        try {
            MatcherAssert.assertThat(
                refs.create("abceefgh3456", "refs/heads/feature-a"),
                Matchers.instanceOf(Reference.class)
            );
            MatcherAssert.assertThat(
                container.take().method(),
                Matchers.equalTo(Request.POST)
            );
        } finally {
            container.stop();
        }
    }
View Full Code Here

     * RtReferences should be able to iterate over References.
     * @throws Exception - If something goes wrong.
     */
    @Test
    public void iteratesReferences() throws Exception {
        final MkContainer container = new MkGrizzlyContainer().next(
            new MkAnswer.Simple(
                HttpURLConnection.HTTP_OK,
                "{\"ref\":\"refs/heads/feature-a\"}"
            )
        ).start();
        final References refs = new RtReferences(
            new ApacheRequest(container.home()),
            repo()
        );
        try {
            MatcherAssert.assertThat(
                refs.iterate(),
                Matchers.notNullValue()
            );
        } finally {
            container.stop();
        }
    }
View Full Code Here

     * RtReferences should be able to remove a Reference.
     * @throws Exception - If somethins goes wrong.
     */
    @Test
    public void removesReference() throws Exception {
        final MkContainer container = new MkGrizzlyContainer().next(
            new MkAnswer.Simple(HttpURLConnection.HTTP_NO_CONTENT, "")
        ).start();
        final References refs = new RtReferences(
            new ApacheRequest(container.home()),
            repo()
        );
        refs.remove("heads/feature-a");
        try {
            MatcherAssert.assertThat(
                container.take().method(),
                Matchers.equalTo(Request.DELETE)
            );
        } 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.