use of io.vertx.ext.web.api.RequestParameter in project vertx-web by vert-x3.
the class OpenAPI3ParametersUnitTest method testPathMatrixExplodeObject.
/**
* Test: path_matrix_explode_object
* Expected parameters sent:
* color: ;R=100;G=200;B=150
* Expected response: {"color":{"R":"100","G":"200","B":"150"}}
* @throws Exception
*/
@Test
public void testPathMatrixExplodeObject() throws Exception {
routerFactory.addHandlerByOperationId("path_matrix_explode_object", routingContext -> {
RequestParameters params = routingContext.get("parsedParameters");
JsonObject res = new JsonObject();
RequestParameter color_path = params.pathParameter("color");
assertNotNull(color_path);
assertTrue(color_path.isObject());
Map<String, String> map = new HashMap<>();
for (String key : color_path.getObjectKeys()) map.put(key, color_path.getObjectValue(key).getString());
res.put("color", map);
routingContext.response().setStatusCode(200).setStatusMessage("OK").putHeader("content-type", "application/json; charset=utf-8").end(res.encode());
});
CountDownLatch latch = new CountDownLatch(1);
Map<String, Object> color_path;
color_path = new HashMap<>();
color_path.put("R", "100");
color_path.put("G", "200");
color_path.put("B", "150");
startServer();
apiClient.pathMatrixExplodeObject(color_path, (AsyncResult<HttpResponse> ar) -> {
if (ar.succeeded()) {
assertEquals(200, ar.result().statusCode());
assertTrue("Expected: " + new JsonObject("{\"color\":{\"R\":\"100\",\"G\":\"200\",\"B\":\"150\"}}").encode() + " Actual: " + ar.result().bodyAsJsonObject().encode(), new JsonObject("{\"color\":{\"R\":\"100\",\"G\":\"200\",\"B\":\"150\"}}").equals(ar.result().bodyAsJsonObject()));
} else {
assertTrue(ar.cause().getMessage(), false);
}
latch.countDown();
});
awaitLatch(latch);
}
use of io.vertx.ext.web.api.RequestParameter in project vertx-web by vert-x3.
the class OpenAPI3ParametersUnitTest method testCookieFormNoexplodeString.
/**
* Test: cookie_form_noexplode_string
* Expected parameters sent:
* color: color=blue
* Expected response: {"color":"blue"}
* @throws Exception
*/
@Test
public void testCookieFormNoexplodeString() throws Exception {
routerFactory.addHandlerByOperationId("cookie_form_noexplode_string", routingContext -> {
RequestParameters params = routingContext.get("parsedParameters");
JsonObject res = new JsonObject();
RequestParameter color_cookie = params.cookieParameter("color");
assertNotNull(color_cookie);
assertTrue(color_cookie.isString());
assertEquals(color_cookie.getString(), "blue");
res.put("color", color_cookie.getString());
routingContext.response().setStatusCode(200).setStatusMessage("OK").putHeader("content-type", "application/json; charset=utf-8").end(res.encode());
});
CountDownLatch latch = new CountDownLatch(1);
String color_cookie;
color_cookie = "blue";
startServer();
apiClient.cookieFormNoexplodeString(color_cookie, (AsyncResult<HttpResponse> ar) -> {
if (ar.succeeded()) {
assertEquals(200, ar.result().statusCode());
assertTrue("Expected: " + new JsonObject("{\"color\":\"blue\"}").encode() + " Actual: " + ar.result().bodyAsJsonObject().encode(), new JsonObject("{\"color\":\"blue\"}").equals(ar.result().bodyAsJsonObject()));
} else {
assertTrue(ar.cause().getMessage(), false);
}
latch.countDown();
});
awaitLatch(latch);
}
use of io.vertx.ext.web.api.RequestParameter in project vertx-web by vert-x3.
the class OpenAPI3ParametersUnitTest method testPathLabelExplodeObject.
/**
* Test: path_label_explode_object
* Expected parameters sent:
* color: .R=100.G=200.B=150
* Expected response: {"color":{"R":"100","G":"200","B":"150"}}
* @throws Exception
*/
@Test
public void testPathLabelExplodeObject() throws Exception {
routerFactory.addHandlerByOperationId("path_label_explode_object", routingContext -> {
RequestParameters params = routingContext.get("parsedParameters");
JsonObject res = new JsonObject();
RequestParameter color_path = params.pathParameter("color");
assertNotNull(color_path);
assertTrue(color_path.isObject());
Map<String, String> map = new HashMap<>();
for (String key : color_path.getObjectKeys()) map.put(key, color_path.getObjectValue(key).getString());
res.put("color", map);
routingContext.response().setStatusCode(200).setStatusMessage("OK").putHeader("content-type", "application/json; charset=utf-8").end(res.encode());
});
CountDownLatch latch = new CountDownLatch(1);
Map<String, Object> color_path;
color_path = new HashMap<>();
color_path.put("R", "100");
color_path.put("G", "200");
color_path.put("B", "150");
startServer();
apiClient.pathLabelExplodeObject(color_path, (AsyncResult<HttpResponse> ar) -> {
if (ar.succeeded()) {
assertEquals(200, ar.result().statusCode());
assertTrue("Expected: " + new JsonObject("{\"color\":{\"R\":\"100\",\"G\":\"200\",\"B\":\"150\"}}").encode() + " Actual: " + ar.result().bodyAsJsonObject().encode(), new JsonObject("{\"color\":{\"R\":\"100\",\"G\":\"200\",\"B\":\"150\"}}").equals(ar.result().bodyAsJsonObject()));
} else {
assertTrue(ar.cause().getMessage(), false);
}
latch.countDown();
});
awaitLatch(latch);
}
use of io.vertx.ext.web.api.RequestParameter in project vertx-web by vert-x3.
the class OpenAPI3ParametersUnitTest method testQueryFormNoexplodeObject.
/**
* Test: query_form_noexplode_object
* Expected parameters sent:
* color: color=R,100,G,200,B,150
* Expected response: {"color":{"R":"100","G":"200","B":"150"}}
* @throws Exception
*/
@Test
public void testQueryFormNoexplodeObject() throws Exception {
routerFactory.addHandlerByOperationId("query_form_noexplode_object", routingContext -> {
RequestParameters params = routingContext.get("parsedParameters");
JsonObject res = new JsonObject();
RequestParameter color_query = params.queryParameter("color");
assertNotNull(color_query);
assertTrue(color_query.isObject());
Map<String, String> map = new HashMap<>();
for (String key : color_query.getObjectKeys()) map.put(key, color_query.getObjectValue(key).getString());
res.put("color", map);
routingContext.response().setStatusCode(200).setStatusMessage("OK").putHeader("content-type", "application/json; charset=utf-8").end(res.encode());
});
CountDownLatch latch = new CountDownLatch(1);
Map<String, Object> color_query;
color_query = new HashMap<>();
color_query.put("R", "100");
color_query.put("G", "200");
color_query.put("B", "150");
startServer();
apiClient.queryFormNoexplodeObject(color_query, (AsyncResult<HttpResponse> ar) -> {
if (ar.succeeded()) {
assertEquals(200, ar.result().statusCode());
assertTrue("Expected: " + new JsonObject("{\"color\":{\"R\":\"100\",\"G\":\"200\",\"B\":\"150\"}}").encode() + " Actual: " + ar.result().bodyAsJsonObject().encode(), new JsonObject("{\"color\":{\"R\":\"100\",\"G\":\"200\",\"B\":\"150\"}}").equals(ar.result().bodyAsJsonObject()));
} else {
assertTrue(ar.cause().getMessage(), false);
}
latch.countDown();
});
awaitLatch(latch);
}
use of io.vertx.ext.web.api.RequestParameter in project vertx-web by vert-x3.
the class OpenAPI3ParametersUnitTest method testQueryFormExplodeObject.
/**
* Test: query_form_explode_object
* Expected parameters sent:
* color: R=100&G=200&B=150
* Expected response: {"color":{"R":"100","G":"200","B":"150"}}
* @throws Exception
*/
@Test
public void testQueryFormExplodeObject() throws Exception {
routerFactory.addHandlerByOperationId("query_form_explode_object", routingContext -> {
RequestParameters params = routingContext.get("parsedParameters");
JsonObject res = new JsonObject();
RequestParameter color_query = params.queryParameter("color");
assertNotNull(color_query);
assertTrue(color_query.isObject());
Map<String, String> map = new HashMap<>();
for (String key : color_query.getObjectKeys()) map.put(key, color_query.getObjectValue(key).getString());
res.put("color", map);
routingContext.response().setStatusCode(200).setStatusMessage("OK").putHeader("content-type", "application/json; charset=utf-8").end(res.encode());
});
CountDownLatch latch = new CountDownLatch(1);
Map<String, Object> color_query;
color_query = new HashMap<>();
color_query.put("R", "100");
color_query.put("G", "200");
color_query.put("B", "150");
startServer();
apiClient.queryFormExplodeObject(color_query, (AsyncResult<HttpResponse> ar) -> {
if (ar.succeeded()) {
assertEquals(200, ar.result().statusCode());
assertTrue("Expected: " + new JsonObject("{\"color\":{\"R\":\"100\",\"G\":\"200\",\"B\":\"150\"}}").encode() + " Actual: " + ar.result().bodyAsJsonObject().encode(), new JsonObject("{\"color\":{\"R\":\"100\",\"G\":\"200\",\"B\":\"150\"}}").equals(ar.result().bodyAsJsonObject()));
} else {
assertTrue(ar.cause().getMessage(), false);
}
latch.countDown();
});
awaitLatch(latch);
}
Aggregations