Package com.github.kevinsawicki.http

Examples of com.github.kevinsawicki.http.HttpRequest


        return new HttpTestClient(baseUrl, principal,
                ImmutableMap.<String,String>builder().putAll(cookies).put(cookieName, cookieValue).build());
    }

    public HttpRequest http(String method, String url) {
        HttpRequest httpRequest = new HttpRequest(baseUrl + root(url), method)
                .header("RestxThreadLocal", Factory.LocalMachines.threadLocal().getId())
                .header("RestxBlade", Blade.current())
                ;

        if (!cookies.isEmpty()) {
            StringBuilder sb = new StringBuilder();
            for (Map.Entry<String, String> entry : cookies.entrySet()) {
                sb.append(entry.getKey()).append("=\"").append(entry.getValue().replace("\"", "\\\"")).append("\"; ");
            }
            sb.setLength(sb.length() - 2);
            httpRequest.header("Cookie", sb.toString());
        }

        return httpRequest;
    }
View Full Code Here


        Files.delete(dir);
    }

    @Test
    public void should_record_with_uuids() throws Exception {
        HttpRequest httpRequest = server.client().authenticatedAs("admin")
                .GET("/api/uuids/random")
                .header("RestxMode", RestxContext.Modes.RECORDING)
                .header("RestxRecordPath", dir.getAbsolutePath())
                ;

        assertThat(httpRequest.code()).isEqualTo(200);
        assertThat(httpRequest.body()).isNotEmpty();

        File record = new File(dir, "001_GET_uuids_random.spec.yaml");
        waitForFileExists(record);

View Full Code Here

    @Test
    public void should_use_spec() throws Exception {
        WebServer server = SpecsServer.getServer(WebServers.findAvailablePort(), "/api", ".");
        server.start();
        try {
            HttpRequest httpRequest = HttpRequest.get(server.baseUrl() + "/api/message?who=xavier");

            assertThat(httpRequest.code()).isEqualTo(200);
            assertThat(httpRequest.body().trim()).isEqualTo("{\"message\":\"hello xavier, it's 14:33:18\"}");
        } finally {
            server.stop();
        }

    }
View Full Code Here

    @ClassRule
    public static RestxServerRule server = new RestxServerRule();

    @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" +
                "  \"a\" : \"a2\",\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

        threadLocal().clear();
    }

    @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");
    }
View Full Code Here

        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")
                .header("RestxSu", "{ \"principal\": \"user1\" }");
        assertThat(httpRequest.code()).isEqualTo(200);
        assertThat(httpRequest.body().trim()).isEqualTo("user1");
    }
View Full Code Here

TOP

Related Classes of com.github.kevinsawicki.http.HttpRequest

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.