use of io.vertx.ext.web.validation.RequestParameters in project vertx-web by vert-x3.
the class OpenAPI3ParametersUnitTest method testPathSimpleNoexplodeObject.
/**
* Test: path_simple_noexplode_object
* Expected parameters sent:
* color: R,100,G,200,B,150
* Expected response: {"color":{"R":"100","G":"200","B":"150"}}
*/
@Test
public void testPathSimpleNoexplodeObject(Vertx vertx, VertxTestContext testContext) {
loadBuilderAndStartServer(vertx, SPEC_URL, testContext, routerBuilder -> {
routerBuilder.setOptions(new RouterBuilderOptions().setMountNotImplementedHandler(false));
routerBuilder.operation("path_simple_noexplode_object").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.isJsonObject()).isTrue();
res.put("color", color_path.getJsonObject());
});
routingContext.response().setStatusCode(200).setStatusMessage("OK").putHeader("content-type", "application/json; charset=utf-8").end(res.encode());
});
}).onComplete(h -> {
Map<String, Object> color_path;
color_path = new HashMap<>();
color_path.put("R", "100");
color_path.put("G", "200");
color_path.put("B", "150");
apiClient.pathSimpleNoexplodeObject(color_path, (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 testCookieFormNoexplodeEmpty.
/**
* Test: cookie_form_noexplode_empty
* Expected parameters sent:
* color: color=
* Expected response: {"color":null}
*/
@Test
public void testCookieFormNoexplodeEmpty(Vertx vertx, VertxTestContext testContext) {
loadBuilderAndStartServer(vertx, SPEC_URL, testContext, routerBuilder -> {
routerBuilder.setOptions(new RouterBuilderOptions().setMountNotImplementedHandler(false));
routerBuilder.operation("cookie_form_noexplode_empty").handler(routingContext -> {
RequestParameters params = routingContext.get("parsedParameters");
JsonObject res = new JsonObject();
testContext.verify(() -> {
RequestParameter color_cookie = params.cookieParameter("color");
assertThat(color_cookie).isNotNull();
assertThat(color_cookie.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_cookie;
color_cookie = "";
apiClient.cookieFormNoexplodeEmpty(color_cookie, (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.RequestParameters in project vertx-web by vert-x3.
the class OpenAPI3ParametersUnitTest method testPathLabelNoexplodeObject.
/**
* Test: path_label_noexplode_object
* Expected parameters sent:
* color: .R.100.G.200.B.150
* Expected response: {"color":{"R":"100","G":"200","B":"150"}}
*/
@Test
public void testPathLabelNoexplodeObject(Vertx vertx, VertxTestContext testContext) {
loadBuilderAndStartServer(vertx, SPEC_URL, testContext, routerBuilder -> {
routerBuilder.setOptions(new RouterBuilderOptions().setMountNotImplementedHandler(false));
routerBuilder.operation("path_label_noexplode_object").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.isJsonObject()).isTrue();
res.put("color", color_path.getJsonObject());
});
routingContext.response().setStatusCode(200).setStatusMessage("OK").putHeader("content-type", "application/json; charset=utf-8").end(res.encode());
});
}).onComplete(h -> {
Map<String, Object> color_path;
color_path = new HashMap<>();
color_path.put("R", "100");
color_path.put("G", "200");
color_path.put("B", "150");
apiClient.pathLabelNoexplodeObject(color_path, (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 testQueryFormExplodeArray.
/**
* Test: query_form_explode_array
* Expected parameters sent:
* color: color=blue&color=black&color=brown
* Expected response: {"color":["blue","black","brown"]}
*/
@Test
public void testQueryFormExplodeArray(Vertx vertx, VertxTestContext testContext) {
loadBuilderAndStartServer(vertx, SPEC_URL, testContext, routerBuilder -> {
routerBuilder.setOptions(new RouterBuilderOptions().setMountNotImplementedHandler(false));
routerBuilder.operation("query_form_explode_array").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.isJsonArray()).isTrue();
res.put("color", color_query.getJsonArray());
});
routingContext.response().setStatusCode(200).setStatusMessage("OK").putHeader("content-type", "application/json; charset=utf-8").end(res.encode());
});
}).onComplete(h -> {
List<Object> color_query;
color_query = new ArrayList<>();
color_query.add("blue");
color_query.add("black");
color_query.add("brown");
apiClient.queryFormExplodeArray(color_query, (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 OpenAPI3ParametersUnitTest method testPathMultiLabelMatrix.
/**
* Test: path_multi_label_matrix
* Expected parameters sent:
* color_label: .blue.black.brown
* color_matrix: ;R=100;G=200;B=150
* Expected response: {"color_label":["blue","black","brown"],"color_matrix":{"R":"100","G":"200","B":"150"}}
*/
@Test
public void testPathMultiLabelMatrix(Vertx vertx, VertxTestContext testContext) {
loadBuilderAndStartServer(vertx, SPEC_URL, testContext, routerBuilder -> {
routerBuilder.setOptions(new RouterBuilderOptions().setMountNotImplementedHandler(false));
routerBuilder.operation("path_multi_label_matrix").handler(routingContext -> {
RequestParameters params = routingContext.get("parsedParameters");
JsonObject res = new JsonObject();
testContext.verify(() -> {
RequestParameter colorLabel_path = params.pathParameter("color_label");
assertThat(colorLabel_path).isNotNull();
assertThat(colorLabel_path.isJsonArray()).isTrue();
res.put("color_label", colorLabel_path.getJsonArray());
RequestParameter colorMatrix_path = params.pathParameter("color_matrix");
assertThat(colorMatrix_path).isNotNull();
assertThat(colorMatrix_path.isJsonObject()).isTrue();
res.put("color_matrix", colorMatrix_path.getJsonObject());
});
routingContext.response().setStatusCode(200).setStatusMessage("OK").putHeader("content-type", "application/json; charset=utf-8").end(res.encode());
});
}).onComplete(h -> {
List<Object> colorLabel_path;
colorLabel_path = new ArrayList<>();
colorLabel_path.add("blue");
colorLabel_path.add("black");
colorLabel_path.add("brown");
Map<String, Object> colorMatrix_path;
colorMatrix_path = new HashMap<>();
colorMatrix_path.put("R", "100");
colorMatrix_path.put("G", "200");
colorMatrix_path.put("B", "150");
apiClient.pathMultiLabelMatrix(colorLabel_path, colorMatrix_path, (AsyncResult<HttpResponse> ar) -> {
if (ar.succeeded()) {
testContext.verify(() -> {
assertThat(ar.result().bodyAsJsonObject()).isEqualTo(new JsonObject("{\"color_label\":[\"blue\",\"black\",\"brown\"],\"color_matrix\":{\"R\":\"100\",\"G\":\"200\",\"B\":\"150\"}}"));
});
testContext.completeNow();
} else {
testContext.failNow(ar.cause());
}
});
});
}
Aggregations