use of io.vertx.ext.web.validation.testutils.TestRequest in project vertx-web by vert-x3.
the class RouterBuilderIntegrationTest method testJsonBodyWithDate.
@Test
public void testJsonBodyWithDate(Vertx vertx, VertxTestContext testContext) {
loadBuilderAndStartServer(vertx, VALIDATION_SPEC, testContext, routerBuilder -> {
routerBuilder.operation("jsonBodyWithDate").handler(routingContext -> {
RequestParameters params = routingContext.get("parsedParameters");
routingContext.response().setStatusCode(200).setStatusMessage("OK").putHeader("Content-Type", "application/json").end(params.body().getJsonObject().encode());
});
}).onComplete(h -> {
JsonObject obj = new JsonObject();
obj.put("date", "2018-02-18");
obj.put("dateTime1", "2018-01-01T10:00:00.0000000000000000000000Z");
obj.put("dateTime2", "2018-01-01T10:00:00+10:00");
obj.put("dateTime3", "2018-01-01T10:00:00-10:00");
testRequest(client, HttpMethod.POST, "/jsonBodyWithDate").expect(statusCode(200)).expect(jsonBodyResponse(obj)).sendJson(obj, testContext);
});
}
use of io.vertx.ext.web.validation.testutils.TestRequest in project vertx-web by vert-x3.
the class RouterBuilderIntegrationTest method mountNotImplementedHandler.
@Test
public void mountNotImplementedHandler(Vertx vertx, VertxTestContext testContext) {
Checkpoint checkpoint = testContext.checkpoint();
loadBuilderAndStartServer(vertx, "src/test/resources/specs/router_builder_test.yaml", testContext, routerBuilder -> {
routerBuilder.setOptions(new RouterBuilderOptions().setRequireSecurityHandlers(false).setMountNotImplementedHandler(true));
routerBuilder.operation("showPetById").handler(RoutingContext::next);
}).onComplete(h -> testRequest(client, HttpMethod.GET, "/pets").expect(statusCode(501), statusMessage("Not Implemented")).send(testContext, checkpoint));
}
use of io.vertx.ext.web.validation.testutils.TestRequest in project vertx-web by vert-x3.
the class RouterBuilderIntegrationTest method testQueryExpandedObjectTestOnlyAdditionalProperties.
@Test
public void testQueryExpandedObjectTestOnlyAdditionalProperties(Vertx vertx, VertxTestContext testContext) {
Checkpoint checkpoint = testContext.checkpoint(3);
loadBuilderAndStartServer(vertx, VALIDATION_SPEC, testContext, routerBuilder -> {
routerBuilder.setOptions(HANDLERS_TESTS_OPTIONS);
routerBuilder.operation("objectTestOnlyAdditionalProperties").handler(routingContext -> {
RequestParameters params = routingContext.get("parsedParameters");
testContext.verify(() -> {
assertThat(params.queryParameter("wellKnownParam").getString()).isEqualTo("hello");
JsonObject param = params.queryParameter("params").getJsonObject();
assertThat(param.containsKey("wellKnownParam")).isFalse();
assertThat(param.getInteger("param1")).isEqualTo(1);
assertThat(param.getInteger("param2")).isEqualTo(2);
});
routingContext.response().setStatusCode(200).end();
});
}).onComplete(h -> {
testRequest(client, HttpMethod.GET, "/queryTests/objectTests/onlyAdditionalProperties?param1=1¶m2=2&wellKnownParam=hello").expect(statusCode(200)).send(testContext, checkpoint);
testRequest(client, HttpMethod.GET, "/queryTests/objectTests/onlyAdditionalProperties?param1=1¶m2=a&wellKnownParam=hello").expect(statusCode(400)).expect(badParameterResponse(ParameterProcessorException.ParameterProcessorErrorType.PARSING_ERROR, "params", ParameterLocation.QUERY)).send(testContext, checkpoint);
testRequest(client, HttpMethod.GET, "/queryTests/objectTests/onlyAdditionalProperties?param1=1¶m2=2&wellKnownParam=a").expect(statusCode(400)).expect(badParameterResponse(ParameterProcessorException.ParameterProcessorErrorType.VALIDATION_ERROR, "wellKnownParam", ParameterLocation.QUERY)).send(testContext, checkpoint);
});
}
use of io.vertx.ext.web.validation.testutils.TestRequest in project vertx-web by vert-x3.
the class RouterBuilderSecurityWithFactoryTest method mountOrWithLastSuccessful.
@Test
public void mountOrWithLastSuccessful(Vertx vertx, VertxTestContext testContext) {
Checkpoint checkpoint = testContext.checkpoint();
loadBuilderAndStartServer(vertx, SECURITY_TESTS, testContext, routerBuilder -> {
routerBuilder.setOptions(FACTORY_OPTIONS);
routerBuilder.operation("listPetsOrSecurity").handler(routingContext -> routingContext.response().setStatusCode(200).setStatusMessage(concatenateRoutingContextEntries(routingContext, "api_key", "second_api_key", "third_api_key")).end());
routerBuilder.securityHandler("api_key", mockFailingAuthHandler(routingContext -> routingContext.put("api_key", "1")));
routerBuilder.securityHandler("second_api_key", mockFailingAuthHandler(routingContext -> routingContext.put("second_api_key", "2")));
routerBuilder.securityHandler("third_api_key", mockSuccessfulAuthHandler(routingContext -> routingContext.put("third_api_key", "3")));
}).onComplete(h -> testRequest(client, HttpMethod.GET, "/pets_or_security").expect(statusCode(200), statusMessage("1-2-3")).send(testContext, checkpoint));
}
use of io.vertx.ext.web.validation.testutils.TestRequest in project vertx-web by vert-x3.
the class RouterBuilderSecurityWithFactoryTest method mountOrWithAllFailing.
@Test
public void mountOrWithAllFailing(Vertx vertx, VertxTestContext testContext) {
Checkpoint checkpoint = testContext.checkpoint();
loadBuilderAndStartServer(vertx, SECURITY_TESTS, testContext, routerBuilder -> {
routerBuilder.setOptions(FACTORY_OPTIONS);
routerBuilder.operation("listPetsOrSecurity").handler(routingContext -> routingContext.response().setStatusCode(200).setStatusMessage(concatenateRoutingContextEntries(routingContext, "api_key", "second_api_key", "third_api_key")).end());
routerBuilder.securityHandler("api_key", mockFailingAuthHandler(routingContext -> routingContext.put("api_key", "1")));
routerBuilder.securityHandler("second_api_key", mockFailingAuthHandler(routingContext -> routingContext.put("second_api_key", "2")));
routerBuilder.securityHandler("third_api_key", mockFailingAuthHandler(routingContext -> routingContext.put("third_api_key", "3")));
}, new AbstractMap.SimpleImmutableEntry<>(401, routingContext -> routingContext.response().setStatusCode(401).setStatusMessage(concatenateRoutingContextEntries(routingContext, "api_key", "second_api_key", "third_api_key")).end())).onComplete(h -> testRequest(client, HttpMethod.GET, "/pets_or_security").expect(statusCode(401), statusMessage("1-2-3")).send(testContext, checkpoint));
}
Aggregations