use of io.vertx.ext.web.validation.testutils.TestRequest in project vertx-web by vert-x3.
the class RouterBuilderIntegrationTest method multipleWildcardMultipartEncoding.
@Test
public void multipleWildcardMultipartEncoding(Vertx vertx, VertxTestContext testContext) {
Checkpoint checkpoint = testContext.checkpoint(6);
loadBuilderAndStartServer(vertx, "src/test/resources/specs/multipart.yaml", testContext, routerBuilder -> {
routerBuilder.setOptions(new RouterBuilderOptions().setRequireSecurityHandlers(false));
routerBuilder.operation("testMultipartMultipleWildcard").handler(routingContext -> {
routingContext.response().setStatusCode(200).end();
});
}).onComplete(h -> {
testRequest(client, HttpMethod.POST, "/testMultipartMultipleWildcard").expect(statusCode(200)).sendMultipartForm(MultipartForm.create().binaryFileUpload("file1", "random.txt", "src/test/resources/random.txt", "text/plain").binaryFileUpload("file2", "random.txt", "src/test/resources/random.txt", "text/json"), testContext, checkpoint);
testRequest(client, HttpMethod.POST, "/testMultipartMultipleWildcard").expect(statusCode(200)).sendMultipartForm(MultipartForm.create().binaryFileUpload("file1", "random.txt", "src/test/resources/random.txt", "application/json").binaryFileUpload("file2", "random.txt", "src/test/resources/random.txt", "text/json"), testContext, checkpoint);
testRequest(client, HttpMethod.POST, "/testMultipartMultipleWildcard").expect(statusCode(400)).sendMultipartForm(MultipartForm.create().binaryFileUpload("file1", "random.txt", "src/test/resources/random.txt", "text/json").binaryFileUpload("file2", "random.txt", "src/test/resources/random.txt", "text/json"), testContext, checkpoint);
testRequest(client, HttpMethod.POST, "/testMultipartMultipleWildcard").expect(statusCode(200)).sendMultipartForm(MultipartForm.create().binaryFileUpload("file1", "random.txt", "src/test/resources/random.txt", "text/plain").binaryFileUpload("file2", "random.txt", "src/test/resources/random.txt", "text/json"), testContext, checkpoint);
testRequest(client, HttpMethod.POST, "/testMultipartMultipleWildcard").expect(statusCode(200)).sendMultipartForm(MultipartForm.create().binaryFileUpload("file1", "random.txt", "src/test/resources/random.txt", "text/plain").binaryFileUpload("file2", "random.txt", "src/test/resources/random.txt", "application/json"), testContext, checkpoint);
testRequest(client, HttpMethod.POST, "/testMultipartMultipleWildcard").expect(statusCode(400)).sendMultipartForm(MultipartForm.create().binaryFileUpload("file1", "random.txt", "src/test/resources/random.txt", "text/plain").binaryFileUpload("file2", "random.txt", "src/test/resources/random.txt", "bla/json"), testContext, checkpoint);
});
}
use of io.vertx.ext.web.validation.testutils.TestRequest in project vertx-web by vert-x3.
the class RouterBuilderIntegrationTest method testQueryParameterAnyOf.
@Test
public void testQueryParameterAnyOf(Vertx vertx, VertxTestContext testContext) {
Checkpoint checkpoint = testContext.checkpoint(5);
loadBuilderAndStartServer(vertx, VALIDATION_SPEC, testContext, routerBuilder -> {
routerBuilder.operation("anyOfTest").handler(routingContext -> routingContext.response().setStatusMessage(((RequestParameters) routingContext.get("parsedParameters")).queryParameter("parameter").toString()).end());
}).onComplete(h -> {
testRequest(client, HttpMethod.GET, "/queryTests/anyOfTest?parameter=true").expect(statusCode(200), statusMessage("true")).send(testContext, checkpoint);
testRequest(client, HttpMethod.GET, "/queryTests/anyOfTest?parameter=5").expect(statusCode(200), statusMessage("5")).send(testContext, checkpoint);
testRequest(client, HttpMethod.GET, "/queryTests/anyOfTest?parameter=5,4").expect(statusCode(200), statusMessage(new JsonArray().add(5).add(4).encode())).send(testContext, checkpoint);
testRequest(client, HttpMethod.GET, "/queryTests/anyOfTest?parameter=a,5").expect(statusCode(200), statusMessage(new JsonObject().put("a", 5).encode())).send(testContext, checkpoint);
testRequest(client, HttpMethod.GET, "/queryTests/anyOfTest?parameter=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 producesTest.
@Test
public void producesTest(Vertx vertx, VertxTestContext testContext) {
Checkpoint checkpoint = testContext.checkpoint(2);
loadBuilderAndStartServer(vertx, "src/test/resources/specs/produces_consumes_test.yaml", testContext, routerBuilder -> {
routerBuilder.setOptions(new RouterBuilderOptions().setMountNotImplementedHandler(false));
routerBuilder.operation("producesTest").handler(routingContext -> {
if (((RequestParameters) routingContext.get("parsedParameters")).queryParameter("fail").getBoolean())
routingContext.response().putHeader("content-type", "text/plain").setStatusCode(500).end("Hate it");
else
// ResponseContentTypeHandler does the job for me
routingContext.response().setStatusCode(200).end("{}");
});
}).onComplete(h -> {
String acceptableContentTypes = String.join(", ", "application/json", "text/plain");
testRequest(client, HttpMethod.GET, "/producesTest").with(requestHeader("Accept", acceptableContentTypes)).expect(statusCode(200), responseHeader("Content-type", "application/json")).send(testContext, checkpoint);
testRequest(client, HttpMethod.GET, "/producesTest?fail=true").with(requestHeader("Accept", acceptableContentTypes)).expect(statusCode(500), responseHeader("Content-type", "text/plain")).send(testContext, checkpoint);
});
}
use of io.vertx.ext.web.validation.testutils.TestRequest in project vertx-web by vert-x3.
the class RouterBuilderSecurityWithFactoryTest method mountSingle.
@Test
public void mountSingle(Vertx vertx, VertxTestContext testContext) {
Checkpoint checkpoint = testContext.checkpoint();
loadBuilderAndStartServer(vertx, SECURITY_TESTS, testContext, routerBuilder -> {
routerBuilder.setOptions(FACTORY_OPTIONS).securityHandler("api_key").bindBlocking(config -> mockSuccessfulAuthHandler(routingContext -> routingContext.put("api_key", "1"))).operation("listPetsSingleSecurity").handler(routingContext -> {
routingContext.response().setStatusCode(200).setStatusMessage(concatenateRoutingContextEntries(routingContext, "api_key")).end();
});
}).onComplete(h -> testRequest(client, HttpMethod.GET, "/pets_single_security").expect(statusCode(200), statusMessage("1")).send(testContext, checkpoint));
}
use of io.vertx.ext.web.validation.testutils.TestRequest in project vertx-web by vert-x3.
the class RouterBuilderSecurityWithFactoryTest method mountOrAndMixed.
@Test
public void mountOrAndMixed(Vertx vertx, VertxTestContext testContext) {
Checkpoint checkpoint = testContext.checkpoint();
loadBuilderAndStartServer(vertx, SECURITY_TESTS, testContext, routerBuilder -> {
routerBuilder.setOptions(FACTORY_OPTIONS);
routerBuilder.operation("listPetsOrAndSecurity").handler(routingContext -> routingContext.response().setStatusCode(200).setStatusMessage(concatenateRoutingContextEntries(routingContext, "api_key", "second_api_key", "sibling_second_api_key", "third_api_key")).end());
routerBuilder.securityHandler("api_key", mockFailingAuthHandler(routingContext -> routingContext.put("api_key", "1")));
routerBuilder.securityHandler("second_api_key", mockSuccessfulAuthHandler(routingContext -> routingContext.put("second_api_key", "2")));
routerBuilder.securityHandler("sibling_second_api_key", mockSuccessfulAuthHandler(routingContext -> routingContext.put("sibling_second_api_key", "3")));
routerBuilder.securityHandler("third_api_key", mockFailingAuthHandler(routingContext -> routingContext.put("third_api_key", "4")));
}).onComplete(h -> testRequest(client, HttpMethod.GET, "/pets_or_and_security").expect(statusCode(200), statusMessage("1-2-3-null")).send(testContext, checkpoint));
}
Aggregations