Search in sources :

Example 1 with TestRequest

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);
    });
}
Also used : VertxTestContext(io.vertx.junit5.VertxTestContext) Vertx(io.vertx.core.Vertx) ServiceBinder(io.vertx.serviceproxy.ServiceBinder) TestRequest(io.vertx.ext.web.validation.testutils.TestRequest) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) io.vertx.ext.web.openapi.service(io.vertx.ext.web.openapi.service) AfterEach(org.junit.jupiter.api.AfterEach) List(java.util.List) HttpMethod(io.vertx.core.http.HttpMethod) JsonObject(io.vertx.core.json.JsonObject) Checkpoint(io.vertx.junit5.Checkpoint) MessageConsumer(io.vertx.core.eventbus.MessageConsumer) Checkpoint(io.vertx.junit5.Checkpoint) ServiceBinder(io.vertx.serviceproxy.ServiceBinder) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.jupiter.api.Test)

Example 2 with TestRequest

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);
    });
}
Also used : VertxTestContext(io.vertx.junit5.VertxTestContext) Vertx(io.vertx.core.Vertx) ServiceBinder(io.vertx.serviceproxy.ServiceBinder) TestRequest(io.vertx.ext.web.validation.testutils.TestRequest) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) io.vertx.ext.web.openapi.service(io.vertx.ext.web.openapi.service) AfterEach(org.junit.jupiter.api.AfterEach) List(java.util.List) HttpMethod(io.vertx.core.http.HttpMethod) JsonObject(io.vertx.core.json.JsonObject) Checkpoint(io.vertx.junit5.Checkpoint) MessageConsumer(io.vertx.core.eventbus.MessageConsumer) Checkpoint(io.vertx.junit5.Checkpoint) ServiceBinder(io.vertx.serviceproxy.ServiceBinder) Test(org.junit.jupiter.api.Test)

Example 3 with TestRequest

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);
    });
}
Also used : VertxTestContext(io.vertx.junit5.VertxTestContext) Vertx(io.vertx.core.Vertx) ServiceBinder(io.vertx.serviceproxy.ServiceBinder) TestRequest(io.vertx.ext.web.validation.testutils.TestRequest) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) io.vertx.ext.web.openapi.service(io.vertx.ext.web.openapi.service) AfterEach(org.junit.jupiter.api.AfterEach) List(java.util.List) HttpMethod(io.vertx.core.http.HttpMethod) JsonObject(io.vertx.core.json.JsonObject) Checkpoint(io.vertx.junit5.Checkpoint) MessageConsumer(io.vertx.core.eventbus.MessageConsumer) Checkpoint(io.vertx.junit5.Checkpoint) ServiceBinder(io.vertx.serviceproxy.ServiceBinder) Test(org.junit.jupiter.api.Test)

Example 4 with TestRequest

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);
    });
}
Also used : VertxTestContext(io.vertx.junit5.VertxTestContext) Arrays(java.util.Arrays) RequestParameters(io.vertx.ext.web.validation.RequestParameters) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) MultiMap(io.vertx.core.MultiMap) Router(io.vertx.ext.web.Router) RoutingContext(io.vertx.ext.web.RoutingContext) BodyHandler(io.vertx.ext.web.handler.BodyHandler) BodyProcessorException(io.vertx.ext.web.validation.BodyProcessorException) Timeout(io.vertx.junit5.Timeout) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) MultipartForm(io.vertx.ext.web.multipart.MultipartForm) ParameterLocation(io.vertx.ext.web.validation.impl.ParameterLocation) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) JsonObject(io.vertx.core.json.JsonObject) RequestParameter(io.vertx.ext.web.validation.RequestParameter) Route(io.vertx.ext.web.Route) QueryStringEncoder(io.netty.handler.codec.http.QueryStringEncoder) StaticHandler(io.vertx.ext.web.handler.StaticHandler) Vertx(io.vertx.core.Vertx) TestRequest(io.vertx.ext.web.validation.testutils.TestRequest) HttpHeaders(io.vertx.core.http.HttpHeaders) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) VertxExtension(io.vertx.junit5.VertxExtension) Future(io.vertx.core.Future) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) JsonArray(io.vertx.core.json.JsonArray) List(java.util.List) Stream(java.util.stream.Stream) ValidationTestUtils(io.vertx.ext.web.validation.testutils.ValidationTestUtils) Buffer(io.vertx.core.buffer.Buffer) HttpMethod(io.vertx.core.http.HttpMethod) ParameterProcessorException(io.vertx.ext.web.validation.ParameterProcessorException) Condition(org.assertj.core.api.Condition) Checkpoint(io.vertx.junit5.Checkpoint) Pattern(java.util.regex.Pattern) Handler(io.vertx.core.Handler) Checkpoint(io.vertx.junit5.Checkpoint) JsonObject(io.vertx.core.json.JsonObject) RequestParameters(io.vertx.ext.web.validation.RequestParameters) Test(org.junit.jupiter.api.Test)

Example 5 with TestRequest

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);
    });
}
Also used : VertxTestContext(io.vertx.junit5.VertxTestContext) Arrays(java.util.Arrays) RequestParameters(io.vertx.ext.web.validation.RequestParameters) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) MultiMap(io.vertx.core.MultiMap) Router(io.vertx.ext.web.Router) RoutingContext(io.vertx.ext.web.RoutingContext) BodyHandler(io.vertx.ext.web.handler.BodyHandler) BodyProcessorException(io.vertx.ext.web.validation.BodyProcessorException) Timeout(io.vertx.junit5.Timeout) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) MultipartForm(io.vertx.ext.web.multipart.MultipartForm) ParameterLocation(io.vertx.ext.web.validation.impl.ParameterLocation) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) JsonObject(io.vertx.core.json.JsonObject) RequestParameter(io.vertx.ext.web.validation.RequestParameter) Route(io.vertx.ext.web.Route) QueryStringEncoder(io.netty.handler.codec.http.QueryStringEncoder) StaticHandler(io.vertx.ext.web.handler.StaticHandler) Vertx(io.vertx.core.Vertx) TestRequest(io.vertx.ext.web.validation.testutils.TestRequest) HttpHeaders(io.vertx.core.http.HttpHeaders) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) VertxExtension(io.vertx.junit5.VertxExtension) Future(io.vertx.core.Future) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) JsonArray(io.vertx.core.json.JsonArray) List(java.util.List) Stream(java.util.stream.Stream) ValidationTestUtils(io.vertx.ext.web.validation.testutils.ValidationTestUtils) Buffer(io.vertx.core.buffer.Buffer) HttpMethod(io.vertx.core.http.HttpMethod) ParameterProcessorException(io.vertx.ext.web.validation.ParameterProcessorException) Condition(org.assertj.core.api.Condition) Checkpoint(io.vertx.junit5.Checkpoint) Pattern(java.util.regex.Pattern) Handler(io.vertx.core.Handler) Checkpoint(io.vertx.junit5.Checkpoint) RequestParameters(io.vertx.ext.web.validation.RequestParameters) Test(org.junit.jupiter.api.Test)

Aggregations

Vertx (io.vertx.core.Vertx)56 HttpMethod (io.vertx.core.http.HttpMethod)56 TestRequest (io.vertx.ext.web.validation.testutils.TestRequest)56 Checkpoint (io.vertx.junit5.Checkpoint)56 VertxTestContext (io.vertx.junit5.VertxTestContext)56 Test (org.junit.jupiter.api.Test)56 JsonObject (io.vertx.core.json.JsonObject)55 VertxExtension (io.vertx.junit5.VertxExtension)50 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)50 Future (io.vertx.core.Future)47 Timeout (io.vertx.junit5.Timeout)47 Handler (io.vertx.core.Handler)46 Route (io.vertx.ext.web.Route)46 Router (io.vertx.ext.web.Router)46 RoutingContext (io.vertx.ext.web.RoutingContext)46 Arrays (java.util.Arrays)46 Collectors (java.util.stream.Collectors)46 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)46 Condition (org.assertj.core.api.Condition)46 ArrayList (java.util.ArrayList)36