Package com.github.kevinsawicki.http

Examples of com.github.kevinsawicki.http.HttpRequest.body()


    @Test
    public void should_post_B() throws Exception {
        HttpRequest httpRequest = server.client().authenticatedAs("admin").POST(
                "/api/polymorphic").send("{\"@class\":\".PolymorphicResource$B\",\"a\":\"a3\",\"b\":\"b\"}");
        assertThat(httpRequest.code()).isEqualTo(200);
        assertThat(httpRequest.body().trim()).isEqualTo("{\n" +
                "  \"@class\" : \".PolymorphicResource$B\",\n" +
                "  \"a\" : \"a3\",\n" +
                "  \"b\" : \"b\"\n" +
                "}");
    }
View Full Code Here


    @Test
    public void should_access_secured_resource() throws Exception {
        HttpRequest httpRequest = server.client().authenticatedAs("admin").GET("/api/security/user");
        assertThat(httpRequest.code()).isEqualTo(200);
        assertThat(httpRequest.body().trim()).isEqualTo("admin");
    }

    @Test
    public void should_access_secured_resource_with_su() throws Exception {
        HttpRequest httpRequest = server.client().authenticatedAs("admin").GET("/api/security/user")
View Full Code Here

    @Test
    public void should_access_secured_resource_with_su() throws Exception {
        HttpRequest httpRequest = server.client().authenticatedAs("admin").GET("/api/security/user")
                .header("RestxSu", "{ \"principal\": \"user1\" }");
        assertThat(httpRequest.code()).isEqualTo(200);
        assertThat(httpRequest.body().trim()).isEqualTo("user1");
    }

    @Test
    public void should_access_secured_resource_with_http_basic() throws Exception {
        HttpTestClient client = server.client();
View Full Code Here

        HttpTestClient client = server.client();
        HttpRequest httpRequest = client.GET("/api/security/user")
                .basic("admin", Hashing.md5().hashString("juma", Charsets.UTF_8).toString());
        assertThat(httpRequest.code()).isEqualTo(200);
        assertThat(httpRequest.headers("Set-Cookie")[1]).contains("\"principal\":\"admin\"");
        assertThat(httpRequest.body().trim()).isEqualTo("admin");
    }

    @Test
    public void should_not_access_secured_resource_with_http_basic_when_deactivated() throws Exception {
        threadLocal().set(activationKey(HttpAuthenticationFilter.class, "HttpAuthenticationFilter"), "false");
View Full Code Here

    @Test
    public void should_share_threadlocal_components_with_server() throws Exception {
        // first we try the default implementation of the ClientAffinityResource
        HttpRequest httpRequest = server.client().GET("/api/clientAffinity");
        assertThat(httpRequest.code()).isEqualTo(200);
        assertThat(httpRequest.body().trim()).isEqualTo("NONE");

        // now we provide a component in thread local, which should be used on the server for this test
        overrideComponents().set(ClientAffinityResource.COMPONENT_NAME, "myvalue");
        httpRequest = server.client().GET("/api/clientAffinity");
        assertThat(httpRequest.code()).isEqualTo(200);
View Full Code Here

        // now we provide a component in thread local, which should be used on the server for this test
        overrideComponents().set(ClientAffinityResource.COMPONENT_NAME, "myvalue");
        httpRequest = server.client().GET("/api/clientAffinity");
        assertThat(httpRequest.code()).isEqualTo(200);
        assertThat(httpRequest.body().trim()).isEqualTo("myvalue");
    }
}
View Full Code Here

        HttpTestClient client = server.client();
        HttpRequest httpRequest = client.GET("/api/security/user")
                .basic("admin", Hashing.md5().hashString("juma", Charsets.UTF_8).toString());
        assertThat(httpRequest.code()).isEqualTo(200);
        assertThat(httpRequest.header("Set-Cookie")).isNull();
        assertThat(httpRequest.body().trim()).isEqualTo("admin");

        httpRequest = client.GET("/api/security/user");
        assertThat(httpRequest.code()).isEqualTo(401);
    }
}
View Full Code Here

    @Test
    public void should_return_hello() throws Exception {
        HttpRequest httpRequest = server.client().authenticatedAs("admin").GET(
                "/api/core/hello?who=restx");
        assertThat(httpRequest.code()).isEqualTo(200);
        assertThat(httpRequest.body().trim()).isEqualTo("hello restx");
    }

    @Test
    public void should_return_hello_msg() throws Exception {
        HttpRequest httpRequest = server.client().authenticatedAs("admin").GET(
View Full Code Here

    @Test
    public void should_return_hello_msg() throws Exception {
        HttpRequest httpRequest = server.client().authenticatedAs("admin").GET(
                "/api/core/hellomsg?who=restx");
        assertThat(httpRequest.code()).isEqualTo(200);
        assertThat(httpRequest.body().trim()).isEqualTo("{\n  \"msg\" : \"hello restx\"\n}");
    }

    @Test
    public void should_post_hello() throws Exception {
        HttpRequest httpRequest = server.client().authenticatedAs("admin").POST(
View Full Code Here

    @Test
    public void should_post_hello() throws Exception {
        HttpRequest httpRequest = server.client().authenticatedAs("admin").POST(
                "/api/core/hellomsg").send("{\"msg\": \"restx\"}");
        assertThat(httpRequest.code()).isEqualTo(200);
        assertThat(httpRequest.body().trim()).isEqualTo("{\n  \"msg\" : \"hello restx\"\n}");
    }

    @Test
    public void should_lifecycle_hello() throws Exception {
        LifecycleListenerFilter filter = new LifecycleListenerFilter();
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.