use of io.vertx.ext.web.validation.RequestParameter in project vertx-web by vert-x3.
the class OpenAPI3ParametersUnitTest method testPathSimpleExplodeArray.
/**
* Test: path_simple_explode_array
* Expected parameters sent:
* color: blue,black,brown
* Expected response: {"color":["blue","black","brown"]}
*/
@Test
public void testPathSimpleExplodeArray(Vertx vertx, VertxTestContext testContext) {
loadBuilderAndStartServer(vertx, SPEC_URL, testContext, routerBuilder -> {
routerBuilder.setOptions(new RouterBuilderOptions().setMountNotImplementedHandler(false));
routerBuilder.operation("path_simple_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.pathSimpleExplodeArray(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.RequestParameter in project vertx-web by vert-x3.
the class OpenAPI3ParametersUnitTest method testPathMultiSimpleMatrix.
/**
* Test: path_multi_simple_matrix
* Expected parameters sent:
* color_simple: blue
* color_matrix: ;color=blue,black,brown
* Expected response: {"color_simple":"blue","color_matrix":["blue","black","brown"]}
*/
@Test
public void testPathMultiSimpleMatrix(Vertx vertx, VertxTestContext testContext) {
loadBuilderAndStartServer(vertx, SPEC_URL, testContext, routerBuilder -> {
routerBuilder.setOptions(new RouterBuilderOptions().setMountNotImplementedHandler(false));
routerBuilder.operation("path_multi_simple_matrix").handler(routingContext -> {
RequestParameters params = routingContext.get("parsedParameters");
JsonObject res = new JsonObject();
testContext.verify(() -> {
RequestParameter colorSimple_path = params.pathParameter("color_simple");
assertThat(colorSimple_path).isNotNull();
assertThat(colorSimple_path.isString()).isTrue();
assertThat(colorSimple_path.getString()).isEqualTo("blue");
res.put("color_simple", colorSimple_path.getString());
RequestParameter colorMatrix_path = params.pathParameter("color_matrix");
assertThat(colorMatrix_path).isNotNull();
assertThat(colorMatrix_path.isJsonArray()).isTrue();
res.put("color_matrix", colorMatrix_path.getJsonArray());
});
routingContext.response().setStatusCode(200).setStatusMessage("OK").putHeader("content-type", "application/json; charset=utf-8").end(res.encode());
});
}).onComplete(h -> {
String colorSimple_path;
colorSimple_path = "blue";
List<Object> colorMatrix_path;
colorMatrix_path = new ArrayList<>();
colorMatrix_path.add("blue");
colorMatrix_path.add("black");
colorMatrix_path.add("brown");
apiClient.pathMultiSimpleMatrix(colorSimple_path, colorMatrix_path, (AsyncResult<HttpResponse> ar) -> {
if (ar.succeeded()) {
testContext.verify(() -> {
assertThat(ar.result().bodyAsJsonObject()).isEqualTo(new JsonObject("{\"color_simple\":\"blue\",\"color_matrix\":[\"blue\",\"black\",\"brown\"]}"));
});
testContext.completeNow();
} else {
testContext.failNow(ar.cause());
}
});
});
}
use of io.vertx.ext.web.validation.RequestParameter in project vertx-web by vert-x3.
the class OpenAPI3ParametersUnitTest method testQueryFormExplodeEmpty.
/**
* Test: query_form_explode_empty
* Expected parameters sent:
* color: color=
* Expected response: {"color":null}
*/
@Test
public void testQueryFormExplodeEmpty(Vertx vertx, VertxTestContext testContext) {
loadBuilderAndStartServer(vertx, SPEC_URL, testContext, routerBuilder -> {
routerBuilder.setOptions(new RouterBuilderOptions().setMountNotImplementedHandler(false));
routerBuilder.operation("query_form_explode_empty").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.isEmpty()).isTrue();
res.putNull("color");
});
routingContext.response().setStatusCode(200).setStatusMessage("OK").putHeader("content-type", "application/json; charset=utf-8").end(res.encode());
});
}).onComplete(h -> {
String color_query;
color_query = "";
apiClient.queryFormExplodeEmpty(color_query, (AsyncResult<HttpResponse> ar) -> {
if (ar.succeeded()) {
testContext.verify(() -> {
assertThat(ar.result().bodyAsJsonObject()).isEqualTo(new JsonObject("{\"color\":null}"));
});
testContext.completeNow();
} else {
testContext.failNow(ar.cause());
}
});
});
}
use of io.vertx.ext.web.validation.RequestParameter in project vertx-web by vert-x3.
the class OpenAPI3ParametersUnitTest method testHeaderSimpleNoexplodeString.
/**
* Test: header_simple_noexplode_string
* Expected parameters sent:
* color: blue
* Expected response: {"color":"blue"}
*/
@Test
public void testHeaderSimpleNoexplodeString(Vertx vertx, VertxTestContext testContext) {
loadBuilderAndStartServer(vertx, SPEC_URL, testContext, routerBuilder -> {
routerBuilder.setOptions(new RouterBuilderOptions().setMountNotImplementedHandler(false));
routerBuilder.operation("header_simple_noexplode_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.headerSimpleNoexplodeString(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.RequestParameter in project vertx-web by vert-x3.
the class OpenAPI3ParametersUnitTest method testPathMatrixExplodeString.
/**
* Test: path_matrix_explode_string
* Expected parameters sent:
* color: ;color=blue
* Expected response: {"color":"blue"}
*/
@Test
public void testPathMatrixExplodeString(Vertx vertx, VertxTestContext testContext) {
loadBuilderAndStartServer(vertx, SPEC_URL, testContext, routerBuilder -> {
routerBuilder.setOptions(new RouterBuilderOptions().setMountNotImplementedHandler(false));
routerBuilder.operation("path_matrix_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.pathMatrixExplodeString(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