use of io.vertx.ext.web.api.RequestParameters in project vertx-web by vert-x3.
the class OpenAPI3ValidationTest method testNullJson.
@Test
public void testNullJson() throws Exception {
Operation op = testSpec.getPaths().get("/pets").getPost();
OpenAPI3RequestValidationHandler validationHandler = new OpenAPI3RequestValidationHandlerImpl(op, op.getParameters(), testSpec);
loadHandlers("/pets", HttpMethod.POST, true, validationHandler, (routingContext) -> {
RequestParameters params = routingContext.get("parsedParameters");
routingContext.response().setStatusCode(200).setStatusMessage("OK").putHeader("Content-Type", "application/json").end(params.body().getJsonObject().encode());
});
// An empty body should be a non parsable json, not an empty object invalid
testRequestWithJSON(HttpMethod.POST, "/pets", null, 400, errorMessage(ValidationException.ErrorType.JSON_INVALID));
// An empty json object should be invalid, because some fields are required
testRequestWithJSON(HttpMethod.POST, "/pets", new JsonObject(), 400, errorMessage(ValidationException.ErrorType.JSON_INVALID));
}
use of io.vertx.ext.web.api.RequestParameters in project vertx-web by vert-x3.
the class OpenAPI3ValidationTest method testAllOfQueryParamWithDefault.
@Test
public void testAllOfQueryParamWithDefault() throws Exception {
Operation op = testSpec.getPaths().get("/queryTests/allOfTest").getGet();
OpenAPI3RequestValidationHandler validationHandler = new OpenAPI3RequestValidationHandlerImpl(op, op.getParameters(), testSpec);
loadHandlers("/queryTests/allOfTest", HttpMethod.GET, false, validationHandler, (routingContext) -> {
RequestParameters params = routingContext.get("parsedParameters");
routingContext.response().setStatusMessage(params.queryParameter("parameter").getObjectValue("a").getInteger().toString() + params.queryParameter("parameter").getObjectValue("b").getBoolean().toString()).end();
});
String a = "5";
String b = "";
String parameter = "parameter=a," + a + ",b," + b;
testRequest(HttpMethod.GET, "/queryTests/allOfTest?" + parameter, 200, a + "false");
}
use of io.vertx.ext.web.api.RequestParameters in project vertx-web by vert-x3.
the class OpenAPI3ValidationTest method testQueryParameterByteFormat.
@Test
public void testQueryParameterByteFormat() throws Exception {
Operation op = testSpec.getPaths().get("/queryTests/byteFormat").getGet();
OpenAPI3RequestValidationHandler validationHandler = new OpenAPI3RequestValidationHandlerImpl(op, op.getParameters(), testSpec);
loadHandlers("/queryTests/byteFormat", HttpMethod.GET, false, validationHandler, (routingContext) -> {
RequestParameters params = routingContext.get("parsedParameters");
routingContext.response().setStatusMessage(params.queryParameter("parameter").getString()).end();
});
testRequest(HttpMethod.GET, "/queryTests/byteFormat?parameter=Zm9vYmFyCg==", 200, "Zm9vYmFyCg==");
}
use of io.vertx.ext.web.api.RequestParameters in project vertx-web by vert-x3.
the class HTTPRequestValidationTest method testFormMultipartParamWithIncludedTypes.
@Test
public void testFormMultipartParamWithIncludedTypes() throws Exception {
HTTPRequestValidationHandler validationHandler = HTTPRequestValidationHandler.create().addFormParam("parameter", ParameterType.INT, true);
router.route().handler(BodyHandler.create());
router.post("/testFormParam").handler(validationHandler);
router.post("/testFormParam").handler(routingContext -> {
RequestParameters params = routingContext.get("parsedParameters");
routingContext.response().setStatusMessage(params.formParameter("parameter").getInteger().toString()).end();
}).failureHandler(generateFailureHandler(false));
String formParam = getSuccessSample(ParameterType.INT).getInteger().toString();
MultiMap form = MultiMap.caseInsensitiveMultiMap();
form.add("parameter", formParam);
testRequestWithForm(HttpMethod.POST, "/testFormParam", FormType.MULTIPART, form, 200, formParam);
}
use of io.vertx.ext.web.api.RequestParameters in project vertx-web by vert-x3.
the class HTTPRequestValidationTest method testQueryParamsFailureWithIncludedTypes.
@Test
public void testQueryParamsFailureWithIncludedTypes() throws Exception {
HTTPRequestValidationHandler validationHandler = HTTPRequestValidationHandler.create().addQueryParam("param1", ParameterType.BOOL, true).addQueryParam("param2", ParameterType.INT, true);
router.get("/testQueryParams").handler(validationHandler);
router.get("/testQueryParams").handler(routingContext -> {
RequestParameters params = routingContext.get("parsedParameters");
routingContext.response().setStatusMessage(params.queryParameter("param1").getBoolean().toString() + params.queryParameter("param2").getInteger().toString());
}).failureHandler(generateFailureHandler(true));
QueryStringEncoder encoder = new QueryStringEncoder("/testQueryParams");
encoder.addParam("param1", getFailureSample(ParameterType.BOOL));
encoder.addParam("param2", getFailureSample(ParameterType.INT));
testRequest(HttpMethod.GET, encoder.toString(), 400, "failure:NO_MATCH");
}
Aggregations