use of io.vertx.ext.web.validation.testutils.TestRequest in project vertx-web by vert-x3.
the class RouterBuilderIntegrationTest method testFormArrayParameter.
@Test
public void testFormArrayParameter(Vertx vertx, VertxTestContext testContext) {
Checkpoint checkpoint = testContext.checkpoint(2);
loadBuilderAndStartServer(vertx, VALIDATION_SPEC, testContext, routerBuilder -> {
routerBuilder.setOptions(HANDLERS_TESTS_OPTIONS);
routerBuilder.operation("formArrayTest").handler(routingContext -> {
RequestParameters params = routingContext.get("parsedParameters");
String serialized = params.body().getJsonObject().getJsonArray("values").stream().map(Object::toString).collect(Collectors.joining(","));
routingContext.response().setStatusMessage(params.body().getJsonObject().getString("id") + serialized).end();
});
}).onComplete(h -> {
testRequest(client, HttpMethod.POST, "/formTests/arraytest").expect(statusCode(200), statusMessage("a+b+c" + "10,8,4")).sendURLEncodedForm(MultiMap.caseInsensitiveMultiMap().add("id", "a+b+c").add("values", (Iterable<String>) Arrays.asList("10", "8", "4")), testContext, checkpoint);
testRequest(client, HttpMethod.POST, "/formTests/arraytest").expect(statusCode(400)).expect(badBodyResponse(BodyProcessorException.BodyProcessorErrorType.PARSING_ERROR)).sendURLEncodedForm(MultiMap.caseInsensitiveMultiMap().add("id", "id").add("values", (Iterable<String>) Arrays.asList("10", "bla", "4")), testContext, checkpoint);
});
}
use of io.vertx.ext.web.validation.testutils.TestRequest 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.testutils.TestRequest in project vertx-web by vert-x3.
the class RouterBuilderIntegrationTest method mountFailureHandlerTest.
@Test
public void mountFailureHandlerTest(Vertx vertx, VertxTestContext testContext) {
Checkpoint checkpoint = testContext.checkpoint();
loadBuilderAndStartServer(vertx, "src/test/resources/specs/router_builder_test.yaml", testContext, routerBuilder -> {
routerBuilder.setOptions(HANDLERS_TESTS_OPTIONS);
routerBuilder.operation("listPets").handler(routingContext -> routingContext.fail(null)).failureHandler(routingContext -> routingContext.response().setStatusCode(500).setStatusMessage("ERROR").end());
}).onComplete(h -> testRequest(client, HttpMethod.GET, "/pets").expect(statusCode(500), statusMessage("ERROR")).send(testContext, checkpoint));
}
use of io.vertx.ext.web.validation.testutils.TestRequest in project vertx-web by vert-x3.
the class RouterBuilderIntegrationTest method testIssue1876.
@Timeout(10000)
@Test
public void testIssue1876(Vertx vertx, VertxTestContext testContext) {
Checkpoint checkpoint = testContext.checkpoint(2);
loadBuilderAndStartServer(vertx, "specs/repro_1876.yaml", testContext, routerBuilder -> {
routerBuilder.setOptions(new RouterBuilderOptions().setRequireSecurityHandlers(false).setMountNotImplementedHandler(true));
routerBuilder.operation("createAccount").handler(routingContext -> routingContext.response().setStatusCode(200).end());
routerBuilder.operation("createAccountMember").handler(routingContext -> routingContext.response().setStatusCode(200).end());
}).onComplete(h -> {
testRequest(client, HttpMethod.POST, "/accounts").expect(statusCode(200), emptyResponse()).sendJson(new JsonObject().put("data", new JsonObject().put("id", 123).put("type", "account-registration").put("attributes", new JsonObject().put("ownerEmail", "test@gmail.com"))), testContext, checkpoint);
testRequest(client, HttpMethod.POST, "/members").expect(statusCode(200), emptyResponse()).sendJson(new JsonObject().put("data", new JsonObject().put("type", "account-member-registration").put("attributes", new JsonObject().put("email", "test@gmail.com"))), testContext, checkpoint);
});
}
use of io.vertx.ext.web.validation.testutils.TestRequest in project vertx-web by vert-x3.
the class RouterBuilderIntegrationTest method mountHandlerTest.
@Test
public void mountHandlerTest(Vertx vertx, VertxTestContext testContext) {
Checkpoint checkpoint = testContext.checkpoint();
loadBuilderAndStartServer(vertx, "src/test/resources/specs/router_builder_test.yaml", testContext, routerBuilder -> {
routerBuilder.setOptions(HANDLERS_TESTS_OPTIONS);
routerBuilder.operation("listPets").handler(routingContext -> routingContext.response().setStatusCode(200).end());
}).onComplete(h -> testRequest(client, HttpMethod.GET, "/pets").expect(statusCode(200)).send(testContext, checkpoint));
}
Aggregations