use of io.vertx.ext.web.validation.RequestParameters in project vertx-web by vert-x3.
the class RouterBuilderIntegrationTest method wildcardMultipartEncoding.
@Test
public void wildcardMultipartEncoding(Vertx vertx, VertxTestContext testContext) {
Checkpoint checkpoint = testContext.checkpoint(3);
loadBuilderAndStartServer(vertx, "src/test/resources/specs/multipart.yaml", testContext, routerBuilder -> {
routerBuilder.setOptions(new RouterBuilderOptions().setRequireSecurityHandlers(false));
routerBuilder.operation("testMultipartWildcard").handler(routingContext -> {
RequestParameters params = routingContext.get("parsedParameters");
routingContext.response().setStatusCode(200).setStatusMessage(params.body().getJsonObject().getString("type")).end();
});
}).onComplete(h -> {
MultipartForm form1 = MultipartForm.create().binaryFileUpload("file1", "random.txt", "src/test/resources/random.txt", "text/plain").attribute("type", "text/plain");
testRequest(client, HttpMethod.POST, "/testMultipartWildcard").expect(statusCode(200), statusMessage("text/plain")).sendMultipartForm(form1, testContext, checkpoint);
MultipartForm form2 = MultipartForm.create().binaryFileUpload("file1", "random.csv", "src/test/resources/random.csv", "text/csv").attribute("type", "text/csv");
testRequest(client, HttpMethod.POST, "/testMultipartWildcard").expect(statusCode(200), statusMessage("text/csv")).sendMultipartForm(form2, testContext, checkpoint);
MultipartForm form3 = MultipartForm.create().binaryFileUpload("file1", "random.txt", "src/test/resources/random.txt", "application/json").attribute("type", "application/json");
testRequest(client, HttpMethod.POST, "/testMultipartWildcard").expect(statusCode(400)).sendMultipartForm(form3, testContext, checkpoint);
});
}
use of io.vertx.ext.web.validation.RequestParameters in project vertx-web by vert-x3.
the class RouterBuilderIntegrationTest method testAllOfQueryParam.
@Test
public void testAllOfQueryParam(Vertx vertx, VertxTestContext testContext) {
Checkpoint checkpoint = testContext.checkpoint(4);
loadBuilderAndStartServer(vertx, VALIDATION_SPEC, testContext, routerBuilder -> {
routerBuilder.setOptions(HANDLERS_TESTS_OPTIONS);
routerBuilder.operation("alloftest").handler(routingContext -> {
RequestParameters params = routingContext.get("parsedParameters");
routingContext.response().setStatusMessage("" + params.queryParameter("parameter").getJsonObject().getInteger("a") + params.queryParameter("parameter").getJsonObject().getBoolean("b")).end();
});
}).onComplete(h -> {
testRequest(client, HttpMethod.GET, "/queryTests/allOfTest?parameter=a,5,b,true").expect(statusCode(200), statusMessage("5true")).send(testContext, checkpoint);
testRequest(client, HttpMethod.GET, "/queryTests/allOfTest?parameter=a,5,b,").expect(statusCode(400)).expect(badParameterResponse(ParameterProcessorException.ParameterProcessorErrorType.VALIDATION_ERROR, "parameter", ParameterLocation.QUERY)).send(testContext, checkpoint);
testRequest(client, HttpMethod.GET, "/queryTests/allOfTest?parameter=a,5").expect(statusCode(200), statusMessage("5false")).send(testContext, checkpoint);
testRequest(client, HttpMethod.GET, "/queryTests/allOfTest?parameter=a,5,b,bla").expect(statusCode(400)).expect(badParameterResponse(ParameterProcessorException.ParameterProcessorErrorType.PARSING_ERROR, "parameter", ParameterLocation.QUERY)).send(testContext, checkpoint);
});
}
use of io.vertx.ext.web.validation.RequestParameters in project vertx-web by vert-x3.
the class RouterBuilderIntegrationTest method testQueryOptionalFormExplodeObject.
/**
* Test: query_optional_form_explode_object
*/
@Test
public void testQueryOptionalFormExplodeObject(Vertx vertx, VertxTestContext testContext) {
Checkpoint checkpoint = testContext.checkpoint(2);
loadBuilderAndStartServer(vertx, VALIDATION_SPEC, testContext, routerBuilder -> {
routerBuilder.operation("query_form_explode_object").handler(routingContext -> {
RequestParameters params = routingContext.get("parsedParameters");
routingContext.response().setStatusCode(200).setStatusMessage("OK").putHeader("content-type", "application/json").end(params.queryParameter("color").getJsonObject().encode());
});
}).onComplete(h -> {
testRequest(client, HttpMethod.GET, "/query/form/explode/object?R=100&G=200&B=150&alpha=50").expect(statusCode(200)).expect(jsonBodyResponse(new JsonObject("{\"R\":\"100\",\"G\":\"200\",\"B\":\"150\",\"alpha\":50}"))).send(testContext, checkpoint);
testRequest(client, HttpMethod.GET, "/query/form/explode/object?R=100&G=200&B=150&alpha=aaa").expect(statusCode(400)).expect(badParameterResponse(ParameterProcessorException.ParameterProcessorErrorType.PARSING_ERROR, "color", ParameterLocation.QUERY)).send(testContext, checkpoint);
});
}
use of io.vertx.ext.web.validation.RequestParameters in project vertx-web by vert-x3.
the class RouterBuilderIntegrationTest method testAllowEmptyValueBooleanQueryParameter.
@Test
public void testAllowEmptyValueBooleanQueryParameter(Vertx vertx, VertxTestContext testContext) {
Checkpoint checkpoint = testContext.checkpoint(3);
loadBuilderAndStartServer(vertx, VALIDATION_SPEC, testContext, routerBuilder -> {
routerBuilder.operation("testDefaultBoolean").handler(routingContext -> routingContext.response().setStatusMessage("" + ((RequestParameters) routingContext.get("parsedParameters")).queryParameter("parameter").toString()).end());
}).onComplete(h -> {
testRequest(client, HttpMethod.GET, "/queryTests/defaultBoolean?parameter").expect(statusCode(200), statusMessage("false")).send(testContext, checkpoint);
testRequest(client, HttpMethod.GET, "/queryTests/defaultBoolean").expect(statusCode(200), statusMessage("false")).send(testContext, checkpoint);
testRequest(client, HttpMethod.GET, "/queryTests/defaultBoolean?parameter=true").expect(statusCode(200), statusMessage("true")).send(testContext, checkpoint);
});
}
use of io.vertx.ext.web.validation.RequestParameters in project vertx-web by vert-x3.
the class RouterBuilderIntegrationTest method consumesTest.
@Test
public void consumesTest(Vertx vertx, VertxTestContext testContext) {
Checkpoint checkpoint = testContext.checkpoint(4);
loadBuilderAndStartServer(vertx, "src/test/resources/specs/produces_consumes_test.yaml", testContext, routerBuilder -> {
routerBuilder.setOptions(new RouterBuilderOptions().setMountNotImplementedHandler(false));
routerBuilder.operation("consumesTest").handler(routingContext -> {
RequestParameters params = routingContext.get("parsedParameters");
if (params.body() != null && params.body().isJsonObject()) {
routingContext.response().setStatusCode(200).putHeader("Content-Type", "application/json").end(params.body().getJsonObject().encode());
} else {
routingContext.response().setStatusCode(200).end();
}
});
}).onComplete(h -> {
JsonObject obj = new JsonObject().put("name", "francesco");
testRequest(client, HttpMethod.POST, "/consumesTest").expect(statusCode(200)).expect(jsonBodyResponse(obj)).sendJson(obj, testContext, checkpoint);
MultiMap form = MultiMap.caseInsensitiveMultiMap();
form.add("name", "francesco");
testRequest(client, HttpMethod.POST, "/consumesTest").expect(statusCode(200)).expect(jsonBodyResponse(obj)).sendURLEncodedForm(form, testContext, checkpoint);
MultipartForm multipartForm = MultipartForm.create();
form.add("name", "francesco");
testRequest(client, HttpMethod.POST, "/consumesTest").expect(statusCode(400)).expect(badBodyResponse(BodyProcessorException.BodyProcessorErrorType.MISSING_MATCHING_BODY_PROCESSOR)).sendMultipartForm(multipartForm, testContext, checkpoint);
testRequest(client, HttpMethod.POST, "/consumesTest").expect(statusCode(400)).expect(failurePredicateResponse()).send(testContext, checkpoint);
});
}
Aggregations