use of io.vertx.ext.web.validation.RequestParameters in project vertx-web by vert-x3.
the class OpenAPI3ParametersUnitTest method testPathSimpleExplodeString.
/**
* Test: path_simple_explode_string
* Expected parameters sent:
* color: blue
* Expected response: {"color":"blue"}
*/
@Test
public void testPathSimpleExplodeString(Vertx vertx, VertxTestContext testContext) {
loadBuilderAndStartServer(vertx, SPEC_URL, testContext, routerBuilder -> {
routerBuilder.setOptions(new RouterBuilderOptions().setMountNotImplementedHandler(false));
routerBuilder.operation("path_simple_explode_string").handler(routingContext -> {
RequestParameters params = routingContext.get("parsedParameters");
JsonObject res = new JsonObject();
testContext.verify(() -> {
RequestParameter color_path = params.pathParameter("color");
assertThat(color_path).isNotNull();
assertThat(color_path.isString()).isTrue();
assertThat(color_path.getString()).isEqualTo("blue");
res.put("color", color_path.getString());
});
routingContext.response().setStatusCode(200).setStatusMessage("OK").putHeader("content-type", "application/json; charset=utf-8").end(res.encode());
});
}).onComplete(h -> {
String color_path;
color_path = "blue";
apiClient.pathSimpleExplodeString(color_path, (AsyncResult<HttpResponse> ar) -> {
if (ar.succeeded()) {
testContext.verify(() -> {
assertThat(ar.result().bodyAsJsonObject()).isEqualTo(new JsonObject("{\"color\":\"blue\"}"));
});
testContext.completeNow();
} else {
testContext.failNow(ar.cause());
}
});
});
}
use of io.vertx.ext.web.validation.RequestParameters 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.RequestParameters 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.RequestParameters 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.RequestParameters in project vertx-web by vert-x3.
the class OpenAPI3ParametersUnitTest method testPathLabelNoexplodeString.
/**
* Test: path_label_noexplode_string
* Expected parameters sent:
* color: .blue
* Expected response: {"color":"blue"}
*/
@Test
public void testPathLabelNoexplodeString(Vertx vertx, VertxTestContext testContext) {
loadBuilderAndStartServer(vertx, SPEC_URL, testContext, routerBuilder -> {
routerBuilder.setOptions(new RouterBuilderOptions().setMountNotImplementedHandler(false));
routerBuilder.operation("path_label_noexplode_string").handler(routingContext -> {
RequestParameters params = routingContext.get("parsedParameters");
JsonObject res = new JsonObject();
testContext.verify(() -> {
RequestParameter color_path = params.pathParameter("color");
assertThat(color_path).isNotNull();
assertThat(color_path.isString()).isTrue();
assertThat(color_path.getString()).isEqualTo("blue");
res.put("color", color_path.getString());
});
routingContext.response().setStatusCode(200).setStatusMessage("OK").putHeader("content-type", "application/json; charset=utf-8").end(res.encode());
});
}).onComplete(h -> {
String color_path;
color_path = "blue";
apiClient.pathLabelNoexplodeString(color_path, (AsyncResult<HttpResponse> ar) -> {
if (ar.succeeded()) {
testContext.verify(() -> {
assertThat(ar.result().bodyAsJsonObject()).isEqualTo(new JsonObject("{\"color\":\"blue\"}"));
});
testContext.completeNow();
} else {
testContext.failNow(ar.cause());
}
});
});
}
Aggregations