use of io.vertx.ext.web.validation.RequestParameter in project vertx-web by vert-x3.
the class OpenAPI3ParametersUnitTest method testCookieFormNoexplodeArray.
/**
* Test: cookie_form_noexplode_array
* Expected parameters sent:
* color: color=blue,black,brown
* Expected response: {"color":["blue","black","brown"]}
*/
@Test
public void testCookieFormNoexplodeArray(Vertx vertx, VertxTestContext testContext) {
loadBuilderAndStartServer(vertx, SPEC_URL, testContext, routerBuilder -> {
routerBuilder.setOptions(new RouterBuilderOptions().setMountNotImplementedHandler(false));
routerBuilder.operation("cookie_form_noexplode_array").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.isJsonArray()).isTrue();
res.put("color", color_cookie.getJsonArray());
});
routingContext.response().setStatusCode(200).setStatusMessage("OK").putHeader("content-type", "application/json; charset=utf-8").end(res.encode());
});
}).onComplete(h -> {
List<Object> color_cookie;
color_cookie = new ArrayList<>();
color_cookie.add("blue");
color_cookie.add("black");
color_cookie.add("brown");
apiClient.cookieFormNoexplodeArray(color_cookie, (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 testPathMatrixNoexplodeString.
/**
* Test: path_matrix_noexplode_string
* Expected parameters sent:
* color: ;color=blue
* Expected response: {"color":"blue"}
*/
@Test
public void testPathMatrixNoexplodeString(Vertx vertx, VertxTestContext testContext) {
loadBuilderAndStartServer(vertx, SPEC_URL, testContext, routerBuilder -> {
routerBuilder.setOptions(new RouterBuilderOptions().setMountNotImplementedHandler(false));
routerBuilder.operation("path_matrix_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.pathMatrixNoexplodeString(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.RequestParameter in project vertx-web by vert-x3.
the class OpenAPI3ParametersUnitTest method testCookieFormExplodeArray.
/**
* Test: cookie_form_explode_array
* Expected parameters sent:
* color: color=blue&color=black&color=brown
* Expected response: {"color":["blue","black","brown"]}
*/
@Test
public void testCookieFormExplodeArray(Vertx vertx, VertxTestContext testContext) {
loadBuilderAndStartServer(vertx, SPEC_URL, testContext, routerBuilder -> {
routerBuilder.setOptions(new RouterBuilderOptions().setMountNotImplementedHandler(false));
routerBuilder.operation("cookie_form_explode_array").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.isJsonArray()).isTrue();
res.put("color", color_cookie.getJsonArray());
});
routingContext.response().setStatusCode(200).setStatusMessage("OK").putHeader("content-type", "application/json; charset=utf-8").end(res.encode());
});
}).onComplete(h -> {
List<Object> color_cookie;
color_cookie = new ArrayList<>();
color_cookie.add("blue");
color_cookie.add("black");
color_cookie.add("brown");
apiClient.cookieFormExplodeArray(color_cookie, (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 testCookieFormExplodeObject.
/**
* Test: cookie_form_explode_object
* Expected parameters sent:
* color: R=100&G=200&B=150
* Expected response: {"color":{"R":"100","G":"200","B":"150"}}
*/
@Test
public void testCookieFormExplodeObject(Vertx vertx, VertxTestContext testContext) {
loadBuilderAndStartServer(vertx, SPEC_URL, testContext, routerBuilder -> {
routerBuilder.setOptions(new RouterBuilderOptions().setMountNotImplementedHandler(false));
routerBuilder.operation("cookie_form_explode_object").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.isJsonObject()).isTrue();
res.put("color", color_cookie.getJsonObject());
});
routingContext.response().setStatusCode(200).setStatusMessage("OK").putHeader("content-type", "application/json; charset=utf-8").end(res.encode());
});
}).onComplete(h -> {
Map<String, Object> color_cookie;
color_cookie = new HashMap<>();
color_cookie.put("R", "100");
color_cookie.put("G", "200");
color_cookie.put("B", "150");
apiClient.cookieFormExplodeObject(color_cookie, (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.RequestParameter in project vertx-web by vert-x3.
the class OpenAPI3ParametersUnitTest method testPathSimpleNoexplodeArray.
/**
* Test: path_simple_noexplode_array
* Expected parameters sent:
* color: blue,black,brown
* Expected response: {"color":["blue","black","brown"]}
*/
@Test
public void testPathSimpleNoexplodeArray(Vertx vertx, VertxTestContext testContext) {
loadBuilderAndStartServer(vertx, SPEC_URL, testContext, routerBuilder -> {
routerBuilder.setOptions(new RouterBuilderOptions().setMountNotImplementedHandler(false));
routerBuilder.operation("path_simple_noexplode_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.pathSimpleNoexplodeArray(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());
}
});
});
}
Aggregations