use of io.vertx.ext.web.validation.RequestParameters in project vertx-web by vert-x3.
the class OpenAPI3ParametersUnitTest method testQuerySpaceDelimitedNoexplodeObject.
/**
* Test: query_spaceDelimited_noexplode_object
* Expected parameters sent:
* color: R%20100%20G%20200%20B%20150
* Expected response: {"color":{"R":"100","G":"200","B":"150"}}
*/
@Test
public void testQuerySpaceDelimitedNoexplodeObject(Vertx vertx, VertxTestContext testContext) {
loadBuilderAndStartServer(vertx, SPEC_URL, testContext, routerBuilder -> {
routerBuilder.setOptions(new RouterBuilderOptions().setMountNotImplementedHandler(false));
routerBuilder.operation("query_spaceDelimited_noexplode_object").handler(routingContext -> {
RequestParameters params = routingContext.get("parsedParameters");
JsonObject res = new JsonObject();
testContext.verify(() -> {
RequestParameter color_query = params.queryParameter("color");
assertThat(color_query).isNotNull();
assertThat(color_query.isJsonObject()).isTrue();
res.put("color", color_query.getJsonObject());
});
routingContext.response().setStatusCode(200).setStatusMessage("OK").putHeader("content-type", "application/json; charset=utf-8").end(res.encode());
});
}).onComplete(h -> {
Map<String, Object> color_query;
color_query = new HashMap<>();
color_query.put("R", "100");
color_query.put("G", "200");
color_query.put("B", "150");
apiClient.querySpaceDelimitedNoexplodeObject(color_query, (AsyncResult<HttpResponse> ar) -> {
if (ar.succeeded()) {
testContext.verify(() -> {
assertThat(ar.result().bodyAsJsonObject()).isEqualTo(new JsonObject("{\"color\":{\"R\":\"100\",\"G\":\"200\",\"B\":\"150\"}}"));
});
testContext.completeNow();
} else {
testContext.failNow(ar.cause());
}
});
});
}
use of io.vertx.ext.web.validation.RequestParameters in project vertx-web by vert-x3.
the class OpenAPI3ParametersUnitTest method testHeaderSimpleExplodeString.
/**
* Test: header_simple_explode_string
* Expected parameters sent:
* color: blue
* Expected response: {"color":"blue"}
*/
@Test
public void testHeaderSimpleExplodeString(Vertx vertx, VertxTestContext testContext) {
loadBuilderAndStartServer(vertx, SPEC_URL, testContext, routerBuilder -> {
routerBuilder.setOptions(new RouterBuilderOptions().setMountNotImplementedHandler(false));
routerBuilder.operation("header_simple_explode_string").handler(routingContext -> {
RequestParameters params = routingContext.get("parsedParameters");
JsonObject res = new JsonObject();
testContext.verify(() -> {
RequestParameter color_header = params.headerParameter("color");
assertThat(color_header).isNotNull();
assertThat(color_header.isString()).isTrue();
assertThat(color_header.getString()).isEqualTo("blue");
res.put("color", color_header.getString());
});
routingContext.response().setStatusCode(200).setStatusMessage("OK").putHeader("content-type", "application/json; charset=utf-8").end(res.encode());
});
}).onComplete(h -> {
String color_header;
color_header = "blue";
apiClient.headerSimpleExplodeString(color_header, (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 OpenAPI3ParametersUnitTest method testPathLabelExplodeArray.
/**
* Test: path_label_explode_array
* Expected parameters sent:
* color: .blue.black.brown
* Expected response: {"color":["blue","black","brown"]}
*/
@Test
public void testPathLabelExplodeArray(Vertx vertx, VertxTestContext testContext) {
loadBuilderAndStartServer(vertx, SPEC_URL, testContext, routerBuilder -> {
routerBuilder.setOptions(new RouterBuilderOptions().setMountNotImplementedHandler(false));
routerBuilder.operation("path_label_explode_array").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.isJsonArray()).isTrue();
res.put("color", color_path.getJsonArray());
});
routingContext.response().setStatusCode(200).setStatusMessage("OK").putHeader("content-type", "application/json; charset=utf-8").end(res.encode());
});
}).onComplete(h -> {
List<Object> color_path;
color_path = new ArrayList<>();
color_path.add("blue");
color_path.add("black");
color_path.add("brown");
apiClient.pathLabelExplodeArray(color_path, (AsyncResult<HttpResponse> ar) -> {
if (ar.succeeded()) {
testContext.verify(() -> {
assertThat(ar.result().bodyAsJsonObject()).isEqualTo(new JsonObject("{\"color\":[\"blue\",\"black\",\"brown\"]}"));
});
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 testPathParameter.
@Test
public void testPathParameter(Vertx vertx, VertxTestContext testContext) {
Checkpoint checkpoint = testContext.checkpoint(2);
loadBuilderAndStartServer(vertx, VALIDATION_SPEC, testContext, routerBuilder -> {
routerBuilder.operation("showPetById").handler(routingContext -> {
RequestParameters params = routingContext.get("parsedParameters");
routingContext.response().setStatusMessage(params.pathParameter("petId").toString()).end();
});
}).onComplete(h -> {
testRequest(client, HttpMethod.GET, "/pets/3").expect(statusCode(200), statusMessage("3")).send(testContext, checkpoint);
testRequest(client, HttpMethod.GET, "/pets/three").expect(statusCode(400)).expect(badParameterResponse(ParameterProcessorException.ParameterProcessorErrorType.PARSING_ERROR, "petId", ParameterLocation.PATH)).send(testContext, checkpoint);
});
}
use of io.vertx.ext.web.validation.RequestParameters in project vertx-web by vert-x3.
the class RouterBuilderIntegrationTest method testOctetStreamBody.
/**
* Test: binary_test
*/
@Test
public void testOctetStreamBody(Vertx vertx, VertxTestContext testContext) {
Buffer body = Buffer.buffer("Hello World!");
loadBuilderAndStartServer(vertx, VALIDATION_SPEC, testContext, routerBuilder -> {
routerBuilder.operation("binary_test").handler(routingContext -> {
RequestParameters params = routingContext.get("parsedParameters");
routingContext.response().setStatusCode(200).setStatusMessage("OK").putHeader("content-type", "application/octet-stream").end(params.body().getBuffer());
});
}).onComplete(h -> {
testRequest(client, HttpMethod.POST, "/binaryTest").expect(statusCode(200)).expect(bodyResponse(body, "application/octet-stream")).with(requestHeader("content-type", "application/octet-stream")).sendBuffer(body, testContext);
});
}
Aggregations