Search in sources :

Example 46 with TestRequest

use of io.vertx.ext.web.validation.testutils.TestRequest in project vertx-web by vert-x3.

the class RouterBuilderApiServiceIntegrationTest method serviceProxyManualTest.

@Test
public void serviceProxyManualTest(Vertx vertx, VertxTestContext testContext) {
    TestService service = new TestServiceImpl(vertx);
    final ServiceBinder serviceBinder = new ServiceBinder(vertx).setAddress("someAddress");
    consumers.add(serviceBinder.register(TestService.class, service));
    loadBuilderAndStartServer(vertx, "src/test/resources/specs/service_proxy_test.yaml", testContext, routerBuilder -> {
        routerBuilder.setOptions(HANDLERS_TESTS_OPTIONS);
        routerBuilder.operation("testA").routeToEventBus("someAddress");
    }).onComplete(h -> testRequest(client, HttpMethod.POST, "/testA").expect(statusCode(200)).expect(jsonBodyResponse(new JsonObject().put("result", "Ciao Francesco!"))).sendJson(new JsonObject().put("hello", "Ciao").put("name", "Francesco"), testContext));
}
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) ServiceBinder(io.vertx.serviceproxy.ServiceBinder) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.jupiter.api.Test)

Example 47 with TestRequest

use of io.vertx.ext.web.validation.testutils.TestRequest in project vertx-web by vert-x3.

the class RouterBuilderApiServiceIntegrationTest method serviceProxyWithReflectionsTest.

@Test
public void serviceProxyWithReflectionsTest(Vertx vertx, VertxTestContext testContext) {
    Checkpoint checkpoint = testContext.checkpoint(2);
    TestService service = new TestServiceImpl(vertx);
    final ServiceBinder serviceBinder = new ServiceBinder(vertx).setAddress("someAddress");
    consumers.add(serviceBinder.register(TestService.class, service));
    loadBuilderAndStartServer(vertx, "src/test/resources/specs/service_proxy_test.yaml", testContext, routerBuilder -> {
        routerBuilder.setOptions(HANDLERS_TESTS_OPTIONS);
        routerBuilder.mountServiceInterface(service.getClass(), "someAddress");
    }).onComplete(h -> {
        testRequest(client, HttpMethod.POST, "/testA").expect(statusCode(200)).expect(jsonBodyResponse(new JsonObject().put("result", "Ciao Francesco!"))).sendJson(new JsonObject().put("hello", "Ciao").put("name", "Francesco"), testContext, checkpoint);
        testRequest(client, HttpMethod.POST, "/testB").expect(statusCode(200)).expect(jsonBodyResponse(new JsonObject().put("result", "Ciao Francesco?"))).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 48 with TestRequest

use of io.vertx.ext.web.validation.testutils.TestRequest in project vertx-web by vert-x3.

the class RouterBuilderApiServiceIntegrationTest method pathExtension.

@Test
public void pathExtension(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, "/testPathLevel").expect(statusCode(200), statusMessage("pathLevelGet")).send(testContext, checkpoint);
        testRequest(client, HttpMethod.POST, "/testPathLevel").expect(statusCode(200), statusMessage("pathLevelPost")).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 49 with TestRequest

use of io.vertx.ext.web.validation.testutils.TestRequest in project vertx-web by vert-x3.

the class RouterBuilderIntegrationTest method mountHandlerEncodedTest.

@Test
public void mountHandlerEncodedTest(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("encodedParamTest").handler(routingContext -> {
            RequestParameters params = routingContext.get("parsedParameters");
            assertThat(params.pathParameter("p1").toString()).isEqualTo("a:b");
            assertThat(params.queryParameter("p2").toString()).isEqualTo("a:b");
            routingContext.response().setStatusCode(200).setStatusMessage(params.pathParameter("p1").toString()).end();
        });
        testContext.completeNow();
    }).onComplete(h -> testRequest(client, HttpMethod.GET, "/foo/a%3Ab?p2=a%3Ab").expect(statusCode(200), statusMessage("a:b")).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)

Example 50 with TestRequest

use of io.vertx.ext.web.validation.testutils.TestRequest in project vertx-web by vert-x3.

the class RouterBuilderIntegrationTest method mountContractEndpoint.

@Test
public void mountContractEndpoint(Vertx vertx, VertxTestContext testContext) {
    Checkpoint checkpoint = testContext.checkpoint(5);
    loadBuilderAndStartServer(vertx, "src/test/resources/specs/router_builder_test.yaml", testContext, routerBuilder -> {
        routerBuilder.setOptions(new RouterBuilderOptions().setMountNotImplementedHandler(true).setRequireSecurityHandlers(false).setContractEndpoint(RouterBuilderOptions.STANDARD_CONTRACT_ENDPOINT));
    }).onComplete(h -> {
        testRequest(client, HttpMethod.GET, "/openapi").expect(statusCode(200), responseHeader(HttpHeaders.CONTENT_TYPE.toString(), "text/yaml"), stringBody(body -> assertThat(body).containsIgnoringCase("openapi"))).send(testContext, checkpoint);
        testRequest(client, HttpMethod.GET, "/openapi").with(requestHeader("Accept", "application/json")).expect(statusCode(200), responseHeader(HttpHeaders.CONTENT_TYPE.toString(), "application/json"), stringBody(body -> assertThat(body).containsIgnoringCase("openapi"))).send(testContext, checkpoint);
        testRequest(client, HttpMethod.GET, "/openapi").with(queryParam("format", "yaml")).expect(statusCode(200), responseHeader(HttpHeaders.CONTENT_TYPE.toString(), "text/yaml"), stringBody(body -> assertThat(body).containsIgnoringCase("openapi"))).send(testContext, checkpoint);
        testRequest(client, HttpMethod.GET, "/openapi").with(queryParam("format", "json")).expect(statusCode(200), responseHeader(HttpHeaders.CONTENT_TYPE.toString(), "application/json"), stringBody(body -> assertThat(body).containsIgnoringCase("openapi"))).send(testContext, checkpoint);
        testRequest(client, HttpMethod.GET, "/openapi").with(queryParam("format", "JSON")).expect(statusCode(200), responseHeader(HttpHeaders.CONTENT_TYPE.toString(), "application/json"), stringBody(body -> assertThat(body).containsIgnoringCase("openapi"))).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) 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