Package com.github.kevinsawicki.http

Examples of com.github.kevinsawicki.http.HttpRequest$ConnectionFactory


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

    @Test
    public void should_access_base_uri() throws Exception {
        HttpRequest httpRequest = server.client().GET(
                "/api/contextParams/baseUri");
        assertThat(httpRequest.code()).isEqualTo(200);
        assertThat(httpRequest.body().trim()).isEqualTo(server.getServer().baseUrl() + "/api");
    }
View Full Code Here


            SimpleWebServer server = SimpleWebServer.builder()
                    .setRouterPath("/api").setPort(WebServers.findAvailablePort()).build();
            server.start();
            try {
                HttpTestClient client = HttpTestClient.withBaseUrl(server.baseUrl());
                HttpRequest httpRequest = client.GET("/api/autostartable/test");
                assertThat(httpRequest.code()).isEqualTo(200);
                assertThat(httpRequest.body().trim()).isEqualTo(
                        "called: 1 - autostartable: called: 1 started: 1 closed: 0 instanciated: 1" +
                                " serverId: "+server.getServerId()+" baseUrl: "+server.baseUrl()+" routerPresent: true");

                httpRequest = client.GET("/api/autostartable/test");
                assertThat(httpRequest.code()).isEqualTo(200);
                // called should be only one in test mode, components are dropped at each request
                // but autostartable should be reused
                assertThat(httpRequest.body().trim()).isEqualTo(
                        "called: 1 - autostartable: called: 2 started: 1 closed: 0 instanciated: 1" +
                                " serverId: "+server.getServerId()+" baseUrl: "+server.baseUrl()+" routerPresent: true");
            } finally {
                server.stop();
            }
View Full Code Here

        assertThat(httpRequest.body().trim()).isEqualTo(server.getServer().baseUrl() + "/api");
    }

    @Test
    public void should_use_proxy_headers_for_base_uri() throws Exception {
        HttpRequest httpRequest = server.client().GET(
                "/api/contextParams/baseUri")
                .header("Via", "HTTPS/1.1 proxy")
                .header("X-Forwarded-Host", "www.example.com");
        assertThat(httpRequest.code()).isEqualTo(200);
        assertThat(httpRequest.body().trim()).isEqualTo("https://www.example.com/api");
    }
View Full Code Here

        assertThat(httpRequest.body().trim()).isEqualTo("https://www.example.com/api");
    }

    @Test
    public void should_use_proxy_headers_proto_for_base_uri() throws Exception {
        HttpRequest httpRequest = server.client().GET(
                "/api/contextParams/baseUri")
                .header("X-Forwarded-Proto", "https")
                .header("X-Forwarded-Host", "www.example.com");
        assertThat(httpRequest.code()).isEqualTo(200);
        assertThat(httpRequest.body().trim()).isEqualTo("https://www.example.com/api");
    }
View Full Code Here

        assertThat(httpRequest.body().trim()).isEqualTo("https://www.example.com/api");
    }

    @Test
    public void should_access_client_address() throws Exception {
        HttpRequest httpRequest = server.client().GET(
                "/api/contextParams/clientAddress");
        assertThat(httpRequest.code()).isEqualTo(200);
        assertThat(httpRequest.body().trim()).contains("127.0.0.1");
    }
View Full Code Here

        assertThat(httpRequest.body().trim()).contains("127.0.0.1");
    }

    @Test
    public void should_use_x_forwarded_for_client_address() throws Exception {
        HttpRequest httpRequest = server.client().GET(
                "/api/contextParams/clientAddress").header("X-Forwarded-For", "10.0.10.1");
        assertThat(httpRequest.code()).isEqualTo(200);
        assertThat(httpRequest.body().trim()).contains("10.0.10.1");
    }
View Full Code Here

        assertThat(httpRequest.body().trim()).contains("10.0.10.1");
    }

    @Test
    public void should_access_request() throws Exception {
        HttpRequest httpRequest = server.client().GET(
                "/api/contextParams/request");
        assertThat(httpRequest.code()).isEqualTo(200);
        assertThat(httpRequest.body().trim()).isEqualTo("[RESTX REQUEST] GET /contextParams/request");
    }
View Full Code Here

        assertThat(httpRequest.body().trim()).isEqualTo("[RESTX REQUEST] GET /contextParams/request");
    }

    @Test
    public void should_access_locale() throws Exception {
        HttpRequest httpRequest = server.client().GET(
                "/api/contextParams/locale").header("Accept-Language", "fr-FR");
        assertThat(httpRequest.code()).isEqualTo(200);
        assertThat(httpRequest.body().trim()).isEqualTo("fr-FR");
    }
View Full Code Here

        assertThat(httpRequest.body().trim()).isEqualTo("fr-FR");
    }

    @Test
    public void should_access_locales() throws Exception {
        HttpRequest httpRequest = server.client().GET(
                "/api/contextParams/locales").header("Accept-Language", "fr-FR, en-US");
        assertThat(httpRequest.code()).isEqualTo(200);
        assertThat(httpRequest.body().trim()).isEqualTo("[fr_FR, en_US]");
    }
View Full Code Here

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

    @Test
    public void should_access_resource_relying_on_module_declaring_exceptions() throws Exception {
        HttpRequest httpRequest = server.client().authenticatedAs("admin")
                .GET("/api/providesWithExceptions");
        assertThat(httpRequest.code()).isEqualTo(200);
        assertThat(httpRequest.body().trim()).isEqualTo("noproblem");
    }
View Full Code Here

TOP

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

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.