Search in sources :

Example 66 with RequestParameters

use of io.vertx.ext.web.validation.RequestParameters in project vertx-web by vert-x3.

the class OpenAPI3ParametersUnitTest method testCookieFormNoexplodeObject.

/**
 * Test: cookie_form_noexplode_object
 * Expected parameters sent:
 * color: color=R,100,G,200,B,150
 * Expected response: {"color":{"R":"100","G":"200","B":"150"}}
 */
@Test
public void testCookieFormNoexplodeObject(Vertx vertx, VertxTestContext testContext) {
    loadBuilderAndStartServer(vertx, SPEC_URL, testContext, routerBuilder -> {
        routerBuilder.setOptions(new RouterBuilderOptions().setMountNotImplementedHandler(false));
        routerBuilder.operation("cookie_form_noexplode_object").handler(routingContext -> {
            RequestParameters params = routingContext.get("parsedParameters");
            JsonObject res = new JsonObject();
            testContext.verify(() -> {
                RequestParameter color_cookie = params.cookieParameter("color");
                assertThat(color_cookie).isNotNull();
                assertThat(color_cookie.isJsonObject()).isTrue();
                res.put("color", color_cookie.getJsonObject());
            });
            routingContext.response().setStatusCode(200).setStatusMessage("OK").putHeader("content-type", "application/json; charset=utf-8").end(res.encode());
        });
    }).onComplete(h -> {
        Map<String, Object> color_cookie;
        color_cookie = new HashMap<>();
        color_cookie.put("R", "100");
        color_cookie.put("G", "200");
        color_cookie.put("B", "150");
        apiClient.cookieFormNoexplodeObject(color_cookie, (AsyncResult<HttpResponse> ar) -> {
            if (ar.succeeded()) {
                testContext.verify(() -> {
                    assertThat(ar.result().bodyAsJsonObject()).isEqualTo(new JsonObject("{\"color\":{\"R\":\"100\",\"G\":\"200\",\"B\":\"150\"}}"));
                });
                testContext.completeNow();
            } else {
                testContext.failNow(ar.cause());
            }
        });
    });
}
Also used : VertxTestContext(io.vertx.junit5.VertxTestContext) BeforeEach(org.junit.jupiter.api.BeforeEach) HttpResponse(io.vertx.ext.web.client.HttpResponse) RequestParameters(io.vertx.ext.web.validation.RequestParameters) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Vertx(io.vertx.core.Vertx) HashMap(java.util.HashMap) VertxExtension(io.vertx.junit5.VertxExtension) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) List(java.util.List) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Map(java.util.Map) JsonObject(io.vertx.core.json.JsonObject) RequestParameter(io.vertx.ext.web.validation.RequestParameter) AsyncResult(io.vertx.core.AsyncResult) RequestParameter(io.vertx.ext.web.validation.RequestParameter) JsonObject(io.vertx.core.json.JsonObject) JsonObject(io.vertx.core.json.JsonObject) AsyncResult(io.vertx.core.AsyncResult) RequestParameters(io.vertx.ext.web.validation.RequestParameters) Test(org.junit.jupiter.api.Test)

Example 67 with RequestParameters

use of io.vertx.ext.web.validation.RequestParameters in project vertx-web by vert-x3.

the class OpenAPI3ParametersUnitTest method testPathMatrixNoexplodeObject.

/**
 * Test: path_matrix_noexplode_object
 * Expected parameters sent:
 * color: ;color=R,100,G,200,B,150
 * Expected response: {"color":{"R":"100","G":"200","B":"150"}}
 */
@Test
public void testPathMatrixNoexplodeObject(Vertx vertx, VertxTestContext testContext) {
    loadBuilderAndStartServer(vertx, SPEC_URL, testContext, routerBuilder -> {
        routerBuilder.setOptions(new RouterBuilderOptions().setMountNotImplementedHandler(false));
        routerBuilder.operation("path_matrix_noexplode_object").handler(routingContext -> {
            RequestParameters params = routingContext.get("parsedParameters");
            JsonObject res = new JsonObject();
            testContext.verify(() -> {
                RequestParameter color_path = params.pathParameter("color");
                assertThat(color_path).isNotNull();
                assertThat(color_path.isJsonObject()).isTrue();
                res.put("color", color_path.getJsonObject());
            });
            routingContext.response().setStatusCode(200).setStatusMessage("OK").putHeader("content-type", "application/json; charset=utf-8").end(res.encode());
        });
    }).onComplete(h -> {
        Map<String, Object> color_path;
        color_path = new HashMap<>();
        color_path.put("R", "100");
        color_path.put("G", "200");
        color_path.put("B", "150");
        apiClient.pathMatrixNoexplodeObject(color_path, (AsyncResult<HttpResponse> ar) -> {
            if (ar.succeeded()) {
                testContext.verify(() -> {
                    assertThat(ar.result().bodyAsJsonObject()).isEqualTo(new JsonObject("{\"color\":{\"R\":\"100\",\"G\":\"200\",\"B\":\"150\"}}"));
                });
                testContext.completeNow();
            } else {
                testContext.failNow(ar.cause());
            }
        });
    });
}
Also used : VertxTestContext(io.vertx.junit5.VertxTestContext) BeforeEach(org.junit.jupiter.api.BeforeEach) HttpResponse(io.vertx.ext.web.client.HttpResponse) RequestParameters(io.vertx.ext.web.validation.RequestParameters) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Vertx(io.vertx.core.Vertx) HashMap(java.util.HashMap) VertxExtension(io.vertx.junit5.VertxExtension) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) List(java.util.List) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Map(java.util.Map) JsonObject(io.vertx.core.json.JsonObject) RequestParameter(io.vertx.ext.web.validation.RequestParameter) AsyncResult(io.vertx.core.AsyncResult) RequestParameter(io.vertx.ext.web.validation.RequestParameter) JsonObject(io.vertx.core.json.JsonObject) JsonObject(io.vertx.core.json.JsonObject) AsyncResult(io.vertx.core.AsyncResult) RequestParameters(io.vertx.ext.web.validation.RequestParameters) Test(org.junit.jupiter.api.Test)

Example 68 with RequestParameters

use of io.vertx.ext.web.validation.RequestParameters in project vertx-web by vert-x3.

the class OpenAPI3ParametersUnitTest method testCookieFormNoexplodeString.

/**
 * Test: cookie_form_noexplode_string
 * Expected parameters sent:
 * color: color=blue
 * Expected response: {"color":"blue"}
 */
@Test
public void testCookieFormNoexplodeString(Vertx vertx, VertxTestContext testContext) {
    loadBuilderAndStartServer(vertx, SPEC_URL, testContext, routerBuilder -> {
        routerBuilder.setOptions(new RouterBuilderOptions().setMountNotImplementedHandler(false));
        routerBuilder.operation("cookie_form_noexplode_string").handler(routingContext -> {
            RequestParameters params = routingContext.get("parsedParameters");
            JsonObject res = new JsonObject();
            testContext.verify(() -> {
                RequestParameter color_cookie = params.cookieParameter("color");
                assertThat(color_cookie).isNotNull();
                assertThat(color_cookie.isString()).isTrue();
                assertThat(color_cookie.getString()).isEqualTo("blue");
                res.put("color", color_cookie.getString());
            });
            routingContext.response().setStatusCode(200).setStatusMessage("OK").putHeader("content-type", "application/json; charset=utf-8").end(res.encode());
        });
    }).onComplete(h -> {
        String color_cookie;
        color_cookie = "blue";
        apiClient.cookieFormNoexplodeString(color_cookie, (AsyncResult<HttpResponse> ar) -> {
            if (ar.succeeded()) {
                testContext.verify(() -> {
                    assertThat(ar.result().bodyAsJsonObject()).isEqualTo(new JsonObject("{\"color\":\"blue\"}"));
                });
                testContext.completeNow();
            } else {
                testContext.failNow(ar.cause());
            }
        });
    });
}
Also used : VertxTestContext(io.vertx.junit5.VertxTestContext) BeforeEach(org.junit.jupiter.api.BeforeEach) HttpResponse(io.vertx.ext.web.client.HttpResponse) RequestParameters(io.vertx.ext.web.validation.RequestParameters) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Vertx(io.vertx.core.Vertx) HashMap(java.util.HashMap) VertxExtension(io.vertx.junit5.VertxExtension) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) List(java.util.List) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Map(java.util.Map) JsonObject(io.vertx.core.json.JsonObject) RequestParameter(io.vertx.ext.web.validation.RequestParameter) AsyncResult(io.vertx.core.AsyncResult) RequestParameter(io.vertx.ext.web.validation.RequestParameter) JsonObject(io.vertx.core.json.JsonObject) AsyncResult(io.vertx.core.AsyncResult) RequestParameters(io.vertx.ext.web.validation.RequestParameters) Test(org.junit.jupiter.api.Test)

Aggregations

Vertx (io.vertx.core.Vertx)68 JsonObject (io.vertx.core.json.JsonObject)68 RequestParameter (io.vertx.ext.web.validation.RequestParameter)68 RequestParameters (io.vertx.ext.web.validation.RequestParameters)68 VertxExtension (io.vertx.junit5.VertxExtension)68 VertxTestContext (io.vertx.junit5.VertxTestContext)68 ArrayList (java.util.ArrayList)68 List (java.util.List)68 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)68 Test (org.junit.jupiter.api.Test)68 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)68 AsyncResult (io.vertx.core.AsyncResult)48 HttpResponse (io.vertx.ext.web.client.HttpResponse)48 HashMap (java.util.HashMap)48 Map (java.util.Map)48 BeforeEach (org.junit.jupiter.api.BeforeEach)48 HttpResponseStatus (io.netty.handler.codec.http.HttpResponseStatus)20 QueryStringEncoder (io.netty.handler.codec.http.QueryStringEncoder)20 Future (io.vertx.core.Future)20 Handler (io.vertx.core.Handler)20