Package com.github.kevinsawicki.http

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


    @Test
    public void should_lifecycle_post_hello_msg() throws Exception {
        LifecycleListenerFilter filter = new LifecycleListenerFilter();
        Factory.LocalMachines.overrideComponents().set("LifecycleListenerFilter", filter);
        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}");

        assertLifecycleMethods(filter, "[Optional.of(Message{msg='restx'})]", "[Optional.of(Message{msg='hello restx'})]");
    }
View Full Code Here


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

    @Test
    public void should_provide_etag() throws Exception {
        HttpRequest request = client().GET("/api/etag/test1");
        assertHttpResponse(request, 200, "{\n  \"name\" : \"test1\"\n}");
        assertThat(request.header("ETag")).isEqualTo("5a105e8b9d40e1329780d62ea2265d8a");
    }
View Full Code Here

        assertThat(request.header("ETag")).isEqualTo("5a105e8b9d40e1329780d62ea2265d8a");
    }

    @Test
    public void should_304_on_provided_etag() throws Exception {
        HttpRequest request = client().GET("/api/etag/test1").header("If-None-Match", "5a105e8b9d40e1329780d62ea2265d8a");
        assertThat(request.code()).isEqualTo(304);
    }
View Full Code Here

        assertThat(request.code()).isEqualTo(304);
    }

    @Test
    public void should_reply_on_bad_provided_etag() throws Exception {
        HttpRequest request = client().GET("/api/etag/test1").header("If-None-Match", "123456");
        assertHttpResponse(request, 200, "{\n  \"name\" : \"test1\"\n}");
    }
View Full Code Here

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

    @Test
    public void should_get_labels_json() throws Exception {
        HttpRequest request = server.client().GET("/api/i18n/labels.json");

        assertThat(request.code()).isEqualTo(200);
        assertThat(request.body()).isEqualTo("{\n" +
                "  \"key1\" : \"value1\",\n" +
                "  \"key2\" : \"hello {{test}}\"\n" +
                "}\n");
    }
View Full Code Here

                "}\n");
    }

    @Test
    public void should_get_labels_js() throws Exception {
        HttpRequest request = server.client().GET("/api/i18n/labels.js");

        assertThat(request.code()).isEqualTo(200);
        assertThat(request.body()).isEqualTo(
                "// RESTX Labels - customize this with restx.i18n.labelsJsTemplate named String\n" +
                "window.labels = {\n" +
                "  \"key1\" : \"value1\",\n" +
                "  \"key2\" : \"hello {{test}}\"\n" +
                "};\n");
View Full Code Here

                        .build())
                .build())
                .setRouterPath("/api").setPort(WebServers.findAvailablePort()).build();
        server.start();
        try {
            HttpRequest httpRequest = HttpRequest.get(server.baseUrl() + "/api/route1/xavier");
            assertThat(httpRequest.code()).isEqualTo(200);
            assertThat(httpRequest.body().trim()).isEqualTo("{\"id\":\"xavier\"}");

            httpRequest = HttpRequest.put(server.baseUrl() + "/api/route4").send("{\"test\":\"val1\"}");
            assertThat(httpRequest.code()).isEqualTo(200);
            assertThat(httpRequest.body().trim()).isEqualTo("{\"test\":\"val1\",\"size\":1}");
        } finally {
            server.stop();
        }
    }
View Full Code Here

                .addRouter(FSRouter.mount("src/test/resources").readonly().on("/test"))
                .build())
                .setRouterPath("/api").setPort(WebServers.findAvailablePort()).build();
        server.start();
        try {
            HttpRequest httpRequest = HttpRequest.get(server.baseUrl() + "/api/test/test.txt");
            assertThat(httpRequest.code()).isEqualTo(200);
            assertThat(httpRequest.contentType()).isEqualTo("text/plain; charset=UTF-8");
            assertThat(httpRequest.body().trim()).isEqualTo("hello");

            httpRequest = HttpRequest.put(server.baseUrl() + "/api/test/test.txt").send("bonjour");
            assertThat(httpRequest.code()).isEqualTo(HttpStatus.NOT_FOUND.getCode());
        } finally {
            server.stop();
        }
    }
View Full Code Here

                        .allowDirectoryListing().readonly().on("/test"))
                .build())
                .setRouterPath("/api").setPort(WebServers.findAvailablePort()).build();
        server.start();
        try {
            HttpRequest httpRequest = HttpRequest.get(server.baseUrl() + "/api/test/");
            assertThat(httpRequest.code()).isEqualTo(200);
            assertThat(httpRequest.body().trim()).isEqualTo("[\n" +
                    "\"test.txt\"\n" +
                    "]");
        } finally {
            server.stop();
        }
View Full Code Here

                        .allowDirectoryListing().on("/test"))
                .build())
                .setRouterPath("/api").setPort(WebServers.findAvailablePort()).build();
        server.start();
        try {
            HttpRequest httpRequest = HttpRequest.get(server.baseUrl() + "/api/test/");
            assertThat(httpRequest.code()).isEqualTo(200);
            assertThat(httpRequest.body().trim()).isEqualTo("[\n]");

            httpRequest = HttpRequest.put(server.baseUrl() + "/api/test/test.txt").send("bonjour");
            assertThat(httpRequest.code()).isEqualTo(HttpStatus.CREATED.getCode());

            httpRequest = HttpRequest.get(server.baseUrl() + "/api/test/test.txt");
            assertThat(httpRequest.code()).isEqualTo(200);
            assertThat(httpRequest.body().trim()).isEqualTo("bonjour");

            httpRequest = HttpRequest.get(server.baseUrl() + "/api/test/");
            assertThat(httpRequest.code()).isEqualTo(200);
            assertThat(httpRequest.body().trim()).isEqualTo("[\n" +
                    "\"test.txt\"\n" +
                    "]");

            httpRequest = HttpRequest.put(server.baseUrl() + "/api/test/test.txt").send("hello");
            assertThat(httpRequest.code()).isEqualTo(HttpStatus.ACCEPTED.getCode());

            httpRequest = HttpRequest.get(server.baseUrl() + "/api/test/test.txt");
            assertThat(httpRequest.code()).isEqualTo(200);
            assertThat(httpRequest.body().trim()).isEqualTo("hello");

            httpRequest = HttpRequest.put(server.baseUrl() + "/api/test/test2.txt").send("bonjour");
            assertThat(httpRequest.code()).isEqualTo(HttpStatus.CREATED.getCode());

            httpRequest = HttpRequest.get(server.baseUrl() + "/api/test/");
            assertThat(httpRequest.code()).isEqualTo(200);
            assertThat(httpRequest.body().trim()).isIn("[\n" +
                    "\"test.txt\",\n" +
                    "\"test2.txt\"\n" +
                    "]", "[\n" +
                    "\"test2.txt\",\n" +
                    "\"test.txt\"\n" +
                    "]");

            httpRequest = HttpRequest.delete(server.baseUrl() + "/api/test/test.txt");
            assertThat(httpRequest.code()).isEqualTo(HttpStatus.NO_CONTENT.getCode());
            httpRequest = HttpRequest.delete(server.baseUrl() + "/api/test/test2.txt");
            assertThat(httpRequest.code()).isEqualTo(HttpStatus.NO_CONTENT.getCode());

            httpRequest = HttpRequest.get(server.baseUrl() + "/api/test/");
            assertThat(httpRequest.code()).isEqualTo(200);
            assertThat(httpRequest.body().trim()).isEqualTo("[\n]");

            httpRequest = HttpRequest.put(server.baseUrl() + "/api/test/dir/").send("[]");
            assertThat(httpRequest.code()).isEqualTo(HttpStatus.CREATED.getCode());

            httpRequest = HttpRequest.get(server.baseUrl() + "/api/test/");
            assertThat(httpRequest.code()).isEqualTo(200);
            assertThat(httpRequest.body().trim()).isEqualTo("[\n" +
                    "\"dir/\"\n" +
                    "]");

            httpRequest = HttpRequest.get(server.baseUrl() + "/api/test/dir/");
            assertThat(httpRequest.code()).isEqualTo(200);
            assertThat(httpRequest.body().trim()).isEqualTo("[\n]");

            httpRequest = HttpRequest.delete(server.baseUrl() + "/api/test/dir/");
            assertThat(httpRequest.code()).isEqualTo(HttpStatus.NO_CONTENT.getCode());

            httpRequest = HttpRequest.get(server.baseUrl() + "/api/test/");
            assertThat(httpRequest.code()).isEqualTo(200);
            assertThat(httpRequest.body().trim()).isEqualTo("[\n]");

            httpRequest = HttpRequest.put(server.baseUrl() + "/api/test/dir/test.txt").send("bonjour");
            assertThat(httpRequest.code()).isEqualTo(HttpStatus.CREATED.getCode());

            httpRequest = HttpRequest.get(server.baseUrl() + "/api/test/dir/test.txt");
            assertThat(httpRequest.code()).isEqualTo(200);
            assertThat(httpRequest.body().trim()).isEqualTo("bonjour");
        } finally {
            server.stop();
        }
    }
View Full Code Here

TOP

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

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.