use of io.vertx.ext.web.validation.RequestParameter in project vertx-web by vert-x3.
the class OpenAPI3ParametersUnitTest method testHeaderSimpleExplodeArray.
/**
* Test: header_simple_explode_array
* Expected parameters sent:
* color: blue,black,brown
* Expected response: {"color":["blue","black","brown"]}
*/
@Test
public void testHeaderSimpleExplodeArray(Vertx vertx, VertxTestContext testContext) {
loadBuilderAndStartServer(vertx, SPEC_URL, testContext, routerBuilder -> {
routerBuilder.setOptions(new RouterBuilderOptions().setMountNotImplementedHandler(false));
routerBuilder.operation("header_simple_explode_array").handler(routingContext -> {
RequestParameters params = routingContext.get("parsedParameters");
JsonObject res = new JsonObject();
testContext.verify(() -> {
RequestParameter color_header = params.headerParameter("color");
assertThat(color_header).isNotNull();
assertThat(color_header.isJsonArray()).isTrue();
res.put("color", color_header.getJsonArray());
});
routingContext.response().setStatusCode(200).setStatusMessage("OK").putHeader("content-type", "application/json; charset=utf-8").end(res.encode());
});
}).onComplete(h -> {
List<Object> color_header;
color_header = new ArrayList<>();
color_header.add("blue");
color_header.add("black");
color_header.add("brown");
apiClient.headerSimpleExplodeArray(color_header, (AsyncResult<HttpResponse> ar) -> {
if (ar.succeeded()) {
testContext.verify(() -> {
assertThat(ar.result().bodyAsJsonObject()).isEqualTo(new JsonObject("{\"color\":[\"blue\",\"black\",\"brown\"]}"));
});
testContext.completeNow();
} else {
testContext.failNow(ar.cause());
}
});
});
}
use of io.vertx.ext.web.validation.RequestParameter in project vertx-web by vert-x3.
the class OpenAPI3ParametersUnitTest method testQueryFormNoexplodeString.
/**
* Test: query_form_noexplode_string
* Expected parameters sent:
* color: color=blue
* Expected response: {"color":"blue"}
*/
@Test
public void testQueryFormNoexplodeString(Vertx vertx, VertxTestContext testContext) {
loadBuilderAndStartServer(vertx, SPEC_URL, testContext, routerBuilder -> {
routerBuilder.setOptions(new RouterBuilderOptions().setMountNotImplementedHandler(false));
routerBuilder.operation("query_form_noexplode_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.queryFormNoexplodeString(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());
}
});
});
}
use of io.vertx.ext.web.validation.RequestParameter in project vertx-web by vert-x3.
the class OpenAPI3ParametersUnitTest method testQueryDeepObjectExplodeObject.
/**
* Test: query_deepObject_explode_object
* Expected parameters sent:
* color: color[R]=100&color[G]=200&color[B]=150
* Expected response: {"color":{"R":"100","G":"200","B":"150"}}
*/
@Test
public void testQueryDeepObjectExplodeObject(Vertx vertx, VertxTestContext testContext) {
loadBuilderAndStartServer(vertx, SPEC_URL, testContext, routerBuilder -> {
routerBuilder.setOptions(new RouterBuilderOptions().setMountNotImplementedHandler(false));
routerBuilder.operation("query_deepObject_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.queryDeepObjectExplodeObject(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());
}
});
});
}
use of io.vertx.ext.web.validation.RequestParameter in project vertx-web by vert-x3.
the class OpenAPI3ParametersUnitTest method testPathMatrixNoexplodeArray.
/**
* Test: path_matrix_noexplode_array
* Expected parameters sent:
* color: ;color=blue,black,brown
* Expected response: {"color":["blue","black","brown"]}
*/
@Test
public void testPathMatrixNoexplodeArray(Vertx vertx, VertxTestContext testContext) {
loadBuilderAndStartServer(vertx, SPEC_URL, testContext, routerBuilder -> {
routerBuilder.setOptions(new RouterBuilderOptions().setMountNotImplementedHandler(false));
routerBuilder.operation("path_matrix_noexplode_array").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.isJsonArray()).isTrue();
res.put("color", color_path.getJsonArray());
});
routingContext.response().setStatusCode(200).setStatusMessage("OK").putHeader("content-type", "application/json; charset=utf-8").end(res.encode());
});
}).onComplete(h -> {
List<Object> color_path;
color_path = new ArrayList<>();
color_path.add("blue");
color_path.add("black");
color_path.add("brown");
apiClient.pathMatrixNoexplodeArray(color_path, (AsyncResult<HttpResponse> ar) -> {
if (ar.succeeded()) {
testContext.verify(() -> {
assertThat(ar.result().bodyAsJsonObject()).isEqualTo(new JsonObject("{\"color\":[\"blue\",\"black\",\"brown\"]}"));
});
testContext.completeNow();
} else {
testContext.failNow(ar.cause());
}
});
});
}
use of io.vertx.ext.web.validation.RequestParameter in project vertx-web by vert-x3.
the class OpenAPI3ParametersUnitTest method testHeaderSimpleNoexplodeObject.
/**
* Test: header_simple_noexplode_object
* Expected parameters sent:
* color: R,100,G,200,B,150
* Expected response: {"color":{"R":"100","G":"200","B":"150"}}
*/
@Test
public void testHeaderSimpleNoexplodeObject(Vertx vertx, VertxTestContext testContext) {
loadBuilderAndStartServer(vertx, SPEC_URL, testContext, routerBuilder -> {
routerBuilder.setOptions(new RouterBuilderOptions().setMountNotImplementedHandler(false));
routerBuilder.operation("header_simple_noexplode_object").handler(routingContext -> {
RequestParameters params = routingContext.get("parsedParameters");
JsonObject res = new JsonObject();
testContext.verify(() -> {
RequestParameter color_header = params.headerParameter("color");
assertThat(color_header).isNotNull();
assertThat(color_header.isJsonObject()).isTrue();
res.put("color", color_header.getJsonObject());
});
routingContext.response().setStatusCode(200).setStatusMessage("OK").putHeader("content-type", "application/json; charset=utf-8").end(res.encode());
});
}).onComplete(h -> {
Map<String, Object> color_header;
color_header = new HashMap<>();
color_header.put("R", "100");
color_header.put("G", "200");
color_header.put("B", "150");
apiClient.headerSimpleNoexplodeObject(color_header, (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());
}
});
});
}
Aggregations