Package com.github.kevinsawicki.http

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


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


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

    @Test
    public void should_return_B_list() throws Exception {
        HttpRequest httpRequest = server.client().authenticatedAs("admin").GET(
                "/api/polymorphic/list/B");
        assertThat(httpRequest.code()).isEqualTo(200);
        assertThat(httpRequest.body().trim()).isEqualTo("[ {\n" +
                "  \"@class\" : \".PolymorphicResource$A\",\n" +
                "  \"a\" : \"a1\"\n" +
                "}, {\n" +
                "  \"@class\" : \".PolymorphicResource$B\",\n" +
View Full Code Here

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

    @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 {
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 {
View Full Code Here

    @Test
    public void should_access_secured_resource_with_http_basic() throws Exception {
        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
View Full Code Here

    @Test
    public void should_not_access_secured_resource_with_http_basic_when_deactivated() throws Exception {
        threadLocal().set(activationKey(HttpAuthenticationFilter.class, "HttpAuthenticationFilter"), "false");
        HttpRequest httpRequest = server.client().GET("/api/security/user")
                .basic("admin", Hashing.md5().hashString("juma", Charsets.UTF_8).toString());
        assertThat(httpRequest.code()).isEqualTo(401);
    }

    @Test
    public void should_access_secured_resource_with_http_basic_no_session() throws Exception {
        threadLocal()
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");
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.