Search in sources :

Example 31 with RequestParameter

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

the class OpenAPI3ParametersUnitTest method testPathLabelNoexplodeString.

/**
 * Test: path_label_noexplode_string
 * Expected parameters sent:
 * color: .blue
 * Expected response: {"color":"blue"}
 */
@Test
public void testPathLabelNoexplodeString(Vertx vertx, VertxTestContext testContext) {
    loadBuilderAndStartServer(vertx, SPEC_URL, testContext, routerBuilder -> {
        routerBuilder.setOptions(new RouterBuilderOptions().setMountNotImplementedHandler(false));
        routerBuilder.operation("path_label_noexplode_string").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.isString()).isTrue();
                assertThat(color_path.getString()).isEqualTo("blue");
                res.put("color", color_path.getString());
            });
            routingContext.response().setStatusCode(200).setStatusMessage("OK").putHeader("content-type", "application/json; charset=utf-8").end(res.encode());
        });
    }).onComplete(h -> {
        String color_path;
        color_path = "blue";
        apiClient.pathLabelNoexplodeString(color_path, (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)

Example 32 with RequestParameter

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

the class OpenAPI3ParametersUnitTest method testQueryFormExplodeString.

/**
 * Test: query_form_explode_string
 * Expected parameters sent:
 * color: color=blue
 * Expected response: {"color":"blue"}
 */
@Test
public void testQueryFormExplodeString(Vertx vertx, VertxTestContext testContext) {
    loadBuilderAndStartServer(vertx, SPEC_URL, testContext, routerBuilder -> {
        routerBuilder.setOptions(new RouterBuilderOptions().setMountNotImplementedHandler(false));
        routerBuilder.operation("query_form_explode_string").handler(routingContext -> {
            RequestParameters params = routingContext.get("parsedParameters");
            JsonObject res = new JsonObject();
            testContext.verify(() -> {
                RequestParameter color_query = params.queryParameter("color");
                assertThat(color_query).isNotNull();
                assertThat(color_query.isString()).isTrue();
                assertThat(color_query.getString()).isEqualTo("blue");
                res.put("color", color_query.getString());
            });
            routingContext.response().setStatusCode(200).setStatusMessage("OK").putHeader("content-type", "application/json; charset=utf-8").end(res.encode());
        });
    }).onComplete(h -> {
        String color_query;
        color_query = "blue";
        apiClient.queryFormExplodeString(color_query, (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)

Example 33 with RequestParameter

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

the class OpenAPI3ParametersUnitTest method testQueryFormExplodeObject.

/**
 * Test: query_form_explode_object
 * Expected parameters sent:
 * color: R=100&G=200&B=150
 * Expected response: {"color":{"R":"100","G":"200","B":"150"}}
 */
@Test
public void testQueryFormExplodeObject(Vertx vertx, VertxTestContext testContext) {
    loadBuilderAndStartServer(vertx, SPEC_URL, testContext, routerBuilder -> {
        routerBuilder.setOptions(new RouterBuilderOptions().setMountNotImplementedHandler(false));
        routerBuilder.operation("query_form_explode_object").handler(routingContext -> {
            RequestParameters params = routingContext.get("parsedParameters");
            JsonObject res = new JsonObject();
            testContext.verify(() -> {
                RequestParameter color_query = params.queryParameter("color");
                assertThat(color_query).isNotNull();
                assertThat(color_query.isJsonObject()).isTrue();
                res.put("color", color_query.getJsonObject());
            });
            routingContext.response().setStatusCode(200).setStatusMessage("OK").putHeader("content-type", "application/json; charset=utf-8").end(res.encode());
        });
    }).onComplete(h -> {
        Map<String, Object> color_query;
        color_query = new HashMap<>();
        color_query.put("R", "100");
        color_query.put("G", "200");
        color_query.put("B", "150");
        apiClient.queryFormExplodeObject(color_query, (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 34 with RequestParameter

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

the class OpenAPI3ParametersUnitTest method testQueryPipeDelimitedNoexplodeObject.

/**
 * Test: query_pipeDelimited_noexplode_object
 * Expected parameters sent:
 * color: R|100|G|200|B|150
 * Expected response: {"color":{"R":"100","G":"200","B":"150"}}
 */
@Test
public void testQueryPipeDelimitedNoexplodeObject(Vertx vertx, VertxTestContext testContext) {
    loadBuilderAndStartServer(vertx, SPEC_URL, testContext, routerBuilder -> {
        routerBuilder.setOptions(new RouterBuilderOptions().setMountNotImplementedHandler(false));
        routerBuilder.operation("query_pipeDelimited_noexplode_object").handler(routingContext -> {
            RequestParameters params = routingContext.get("parsedParameters");
            JsonObject res = new JsonObject();
            testContext.verify(() -> {
                RequestParameter color_query = params.queryParameter("color");
                assertThat(color_query).isNotNull();
                assertThat(color_query.isJsonObject()).isTrue();
                res.put("color", color_query.getJsonObject());
            });
            routingContext.response().setStatusCode(200).setStatusMessage("OK").putHeader("content-type", "application/json; charset=utf-8").end(res.encode());
        });
    }).onComplete(h -> {
        Map<String, Object> color_query;
        color_query = new HashMap<>();
        color_query.put("R", "100");
        color_query.put("G", "200");
        color_query.put("B", "150");
        apiClient.queryPipeDelimitedNoexplodeObject(color_query, (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 35 with RequestParameter

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

the class OpenAPI3ParametersUnitTest method testPathLabelExplodeString.

/**
 * Test: path_label_explode_string
 * Expected parameters sent:
 * color: .blue
 * Expected response: {"color":"blue"}
 */
@Test
public void testPathLabelExplodeString(Vertx vertx, VertxTestContext testContext) {
    loadBuilderAndStartServer(vertx, SPEC_URL, testContext, routerBuilder -> {
        routerBuilder.setOptions(new RouterBuilderOptions().setMountNotImplementedHandler(false));
        routerBuilder.operation("path_label_explode_string").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.isString()).isTrue();
                assertThat(color_path.getString()).isEqualTo("blue");
                res.put("color", color_path.getString());
            });
            routingContext.response().setStatusCode(200).setStatusMessage("OK").putHeader("content-type", "application/json; charset=utf-8").end(res.encode());
        });
    }).onComplete(h -> {
        String color_path;
        color_path = "blue";
        apiClient.pathLabelExplodeString(color_path, (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)49 JsonObject (io.vertx.core.json.JsonObject)49 RequestParameter (io.vertx.ext.web.validation.RequestParameter)49 RequestParameters (io.vertx.ext.web.validation.RequestParameters)49 VertxExtension (io.vertx.junit5.VertxExtension)49 VertxTestContext (io.vertx.junit5.VertxTestContext)49 ArrayList (java.util.ArrayList)49 List (java.util.List)49 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)49 Test (org.junit.jupiter.api.Test)49 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)49 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)1 QueryStringEncoder (io.netty.handler.codec.http.QueryStringEncoder)1 Future (io.vertx.core.Future)1 Handler (io.vertx.core.Handler)1