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));
}
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);
});
}
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);
});
}
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));
}
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);
});
}
Aggregations