use of io.vertx.ext.web.validation.testutils.TestRequest 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.testutils.TestRequest 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.testutils.TestRequest 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.testutils.TestRequest in project vertx-web by vert-x3.
the class RouterBuilderIntegrationTest method mountNotAllowedHandler.
@Test
public void mountNotAllowedHandler(Vertx vertx, VertxTestContext testContext) {
Checkpoint checkpoint = testContext.checkpoint();
loadBuilderAndStartServer(vertx, "src/test/resources/specs/router_builder_test.yaml", testContext, routerBuilder -> {
routerBuilder.setOptions(new RouterBuilderOptions().setRequireSecurityHandlers(false).setMountNotImplementedHandler(true));
routerBuilder.operation("deletePets").handler(RoutingContext::next);
routerBuilder.operation("createPets").handler(RoutingContext::next);
}).onComplete(rc -> testRequest(client, HttpMethod.GET, "/pets").expect(statusCode(405), statusMessage("Method Not Allowed")).expect(resp -> assertThat(new HashSet<>(Arrays.asList(resp.getHeader("Allow").split(Pattern.quote(", "))))).isEqualTo(Stream.of("DELETE", "POST").collect(Collectors.toSet()))).send(testContext, checkpoint));
}
use of io.vertx.ext.web.validation.testutils.TestRequest 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