use of io.vertx.ext.web.validation.testutils.TestRequest in project vertx-web by vert-x3.
the class RouterBuilderApiServiceIntegrationTest method operationExtension.
@Test
public void operationExtension(Vertx vertx, VertxTestContext testContext) {
Checkpoint checkpoint = testContext.checkpoint(4);
TestService service = new TestServiceImpl(vertx);
final ServiceBinder serviceBinder = new ServiceBinder(vertx).setAddress("address");
consumers.add(serviceBinder.register(TestService.class, service));
AnotherTestService anotherService = AnotherTestService.create(vertx);
final ServiceBinder anotherServiceBinder = new ServiceBinder(vertx).setAddress("anotherAddress");
consumers.add(anotherServiceBinder.register(AnotherTestService.class, anotherService));
loadBuilderAndStartServer(vertx, "src/test/resources/specs/extension_test.yaml", testContext, routerBuilder -> {
routerBuilder.setOptions(HANDLERS_TESTS_OPTIONS);
routerBuilder.mountServicesFromExtensions();
}).onComplete(h -> {
testRequest(client, HttpMethod.POST, "/testA").expect(jsonBodyResponse(new JsonObject().put("result", "Ciao Francesco!")), statusCode(200)).sendJson(new JsonObject().put("hello", "Ciao").put("name", "Francesco"), testContext, checkpoint);
testRequest(client, HttpMethod.POST, "/testB").expect(jsonBodyResponse(new JsonObject().put("result", "Ciao Francesco?")), statusCode(200)).sendJson(new JsonObject().put("hello", "Ciao").put("name", "Francesco"), testContext, checkpoint);
testRequest(client, HttpMethod.POST, "/testC").expect(jsonBodyResponse(new JsonObject().put("content-type", "application/json").put("anotherResult", "Francesco Ciao?")), statusCode(200)).sendJson(new JsonObject().put("hello", "Ciao").put("name", "Francesco"), testContext, checkpoint);
testRequest(client, HttpMethod.POST, "/testD").expect(jsonBodyResponse(new JsonObject().put("content-type", "application/json").put("anotherResult", "Francesco Ciao?")), statusCode(200)).sendJson(new JsonObject().put("hello", "Ciao").put("name", "Francesco"), testContext, checkpoint);
});
}
use of io.vertx.ext.web.validation.testutils.TestRequest in project vertx-web by vert-x3.
the class RouterBuilderApiServiceIntegrationTest method pathAndOperationExtensionMerge.
@Test
public void pathAndOperationExtensionMerge(Vertx vertx, VertxTestContext testContext) {
Checkpoint checkpoint = testContext.checkpoint(2);
PathExtensionTestService service = new PathExtensionTestServiceImpl();
final ServiceBinder serviceBinder = new ServiceBinder(vertx).setAddress("address");
consumers.add(serviceBinder.register(PathExtensionTestService.class, service));
loadBuilderAndStartServer(vertx, "src/test/resources/specs/extension_test.yaml", testContext, routerBuilder -> {
routerBuilder.setOptions(HANDLERS_TESTS_OPTIONS);
routerBuilder.mountServicesFromExtensions();
}).onComplete(h -> {
testRequest(client, HttpMethod.GET, "/testMerge").expect(statusCode(200), statusMessage("getPathLevel")).send(testContext, checkpoint);
testRequest(client, HttpMethod.POST, "/testMerge").expect(statusCode(200), statusMessage("postPathLevel")).send(testContext, checkpoint);
});
}
use of io.vertx.ext.web.validation.testutils.TestRequest in project vertx-web by vert-x3.
the class RouterBuilderApiServiceIntegrationTest method pathAndOperationExtensionMapsMerge.
@Test
public void pathAndOperationExtensionMapsMerge(Vertx vertx, VertxTestContext testContext) {
Checkpoint checkpoint = testContext.checkpoint(2);
PathExtensionTestService service = new PathExtensionTestServiceImpl();
final ServiceBinder serviceBinder = new ServiceBinder(vertx).setAddress("address");
consumers.add(serviceBinder.register(PathExtensionTestService.class, service));
loadBuilderAndStartServer(vertx, "src/test/resources/specs/extension_test.yaml", testContext, routerBuilder -> {
routerBuilder.setOptions(HANDLERS_TESTS_OPTIONS);
routerBuilder.mountServicesFromExtensions();
}).onComplete(h -> {
testRequest(client, HttpMethod.GET, "/testMerge2").expect(statusCode(200), statusMessage("getPathLevel")).send(testContext, checkpoint);
testRequest(client, HttpMethod.POST, "/testMerge2").expect(statusCode(200), statusMessage("postPathLevel")).send(testContext, checkpoint);
});
}
use of io.vertx.ext.web.validation.testutils.TestRequest in project vertx-web by vert-x3.
the class RouterBuilderIntegrationTest method testQueryParameterArrayDefaultStyle.
@Test
public void testQueryParameterArrayDefaultStyle(Vertx vertx, VertxTestContext testContext) {
Checkpoint checkpoint = testContext.checkpoint(2);
loadBuilderAndStartServer(vertx, VALIDATION_SPEC, testContext, routerBuilder -> {
routerBuilder.setOptions(HANDLERS_TESTS_OPTIONS);
routerBuilder.operation("arrayTest").handler(routingContext -> {
RequestParameters params = routingContext.get("parsedParameters");
String serialized = params.queryParameter("parameter").getJsonArray().stream().map(Object::toString).collect(Collectors.joining(","));
routingContext.response().setStatusMessage(serialized).end();
});
}).onComplete(h -> {
String serialized = String.join(",", "4", "2", "26");
testRequest(client, HttpMethod.GET, "/queryTests/arrayTests/default?parameter=" + serialized).expect(statusCode(200), statusMessage(serialized)).send(testContext, checkpoint);
testRequest(client, HttpMethod.GET, "/queryTests/arrayTests/default?parameter=" + String.join(",", "4", "1", "26")).expect(statusCode(400)).expect(badParameterResponse(ParameterProcessorException.ParameterProcessorErrorType.VALIDATION_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 mountHandlersOrderTest.
@Test
public void mountHandlersOrderTest(Vertx vertx, VertxTestContext testContext) {
Checkpoint checkpoint = testContext.checkpoint(2);
loadBuilderAndStartServer(vertx, "src/test/resources/specs/test_order_spec.yaml", testContext, routerBuilder -> {
routerBuilder.setOptions(new RouterBuilderOptions().setMountNotImplementedHandler(false));
routerBuilder.operation("showSpecialProduct").handler(routingContext -> routingContext.response().setStatusMessage("special").end());
routerBuilder.operation("showProductById").handler(routingContext -> {
RequestParameters params = routingContext.get("parsedParameters");
routingContext.response().setStatusMessage(params.pathParameter("id").getInteger().toString()).end();
});
testContext.completeNow();
}).onComplete(h -> {
testRequest(client, HttpMethod.GET, "/product/special").expect(statusCode(200), statusMessage("special")).send(testContext, checkpoint);
testRequest(client, HttpMethod.GET, "/product/123").expect(statusCode(200), statusMessage("123")).send(testContext, checkpoint);
});
}
Aggregations