use of io.vertx.core.AsyncResult in project vertx-web by vert-x3.
the class OpenAPI3ParametersUnitTest method testQueryFormNoexplodeArray.
/**
* Test: query_form_noexplode_array
* Expected parameters sent:
* color: color=blue,black,brown
* Expected response: {"color":["blue","black","brown"]}
* @throws Exception
*/
@Test
public void testQueryFormNoexplodeArray() throws Exception {
routerFactory.addHandlerByOperationId("query_form_noexplode_array", routingContext -> {
RequestParameters params = routingContext.get("parsedParameters");
JsonObject res = new JsonObject();
RequestParameter color_query = params.queryParameter("color");
assertNotNull(color_query);
assertTrue(color_query.isArray());
res.put("color", new JsonArray(color_query.getArray().stream().map(param -> param.getString()).collect(Collectors.toList())));
routingContext.response().setStatusCode(200).setStatusMessage("OK").putHeader("content-type", "application/json; charset=utf-8").end(res.encode());
});
CountDownLatch latch = new CountDownLatch(1);
List<Object> color_query;
color_query = new ArrayList<>();
color_query.add("blue");
color_query.add("black");
color_query.add("brown");
startServer();
apiClient.queryFormNoexplodeArray(color_query, (AsyncResult<HttpResponse> ar) -> {
if (ar.succeeded()) {
assertEquals(200, ar.result().statusCode());
assertTrue("Expected: " + new JsonObject("{\"color\":[\"blue\",\"black\",\"brown\"]}").encode() + " Actual: " + ar.result().bodyAsJsonObject().encode(), new JsonObject("{\"color\":[\"blue\",\"black\",\"brown\"]}").equals(ar.result().bodyAsJsonObject()));
} else {
assertTrue(ar.cause().getMessage(), false);
}
latch.countDown();
});
awaitLatch(latch);
}
use of io.vertx.core.AsyncResult 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"]}
* @throws Exception
*/
@Test
public void testPathSimpleExplodeArray() throws Exception {
routerFactory.addHandlerByOperationId("path_simple_explode_array", routingContext -> {
RequestParameters params = routingContext.get("parsedParameters");
JsonObject res = new JsonObject();
RequestParameter color_path = params.pathParameter("color");
assertNotNull(color_path);
assertTrue(color_path.isArray());
res.put("color", new JsonArray(color_path.getArray().stream().map(param -> param.getString()).collect(Collectors.toList())));
routingContext.response().setStatusCode(200).setStatusMessage("OK").putHeader("content-type", "application/json; charset=utf-8").end(res.encode());
});
CountDownLatch latch = new CountDownLatch(1);
List<Object> color_path;
color_path = new ArrayList<>();
color_path.add("blue");
color_path.add("black");
color_path.add("brown");
startServer();
apiClient.pathSimpleExplodeArray(color_path, (AsyncResult<HttpResponse> ar) -> {
if (ar.succeeded()) {
assertEquals(200, ar.result().statusCode());
assertTrue("Expected: " + new JsonObject("{\"color\":[\"blue\",\"black\",\"brown\"]}").encode() + " Actual: " + ar.result().bodyAsJsonObject().encode(), new JsonObject("{\"color\":[\"blue\",\"black\",\"brown\"]}").equals(ar.result().bodyAsJsonObject()));
} else {
assertTrue(ar.cause().getMessage(), false);
}
latch.countDown();
});
awaitLatch(latch);
}
use of io.vertx.core.AsyncResult 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"}}
* @throws Exception
*/
@Test
public void testCookieFormExplodeObject() throws Exception {
routerFactory.addHandlerByOperationId("cookie_form_explode_object", routingContext -> {
RequestParameters params = routingContext.get("parsedParameters");
JsonObject res = new JsonObject();
RequestParameter color_cookie = params.cookieParameter("color");
assertNotNull(color_cookie);
assertTrue(color_cookie.isObject());
Map<String, String> map = new HashMap<>();
for (String key : color_cookie.getObjectKeys()) map.put(key, color_cookie.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_cookie;
color_cookie = new HashMap<>();
color_cookie.put("R", "100");
color_cookie.put("G", "200");
color_cookie.put("B", "150");
startServer();
apiClient.cookieFormExplodeObject(color_cookie, (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.core.AsyncResult in project vertx-web by vert-x3.
the class OpenAPI3ParametersUnitTest method testPathMatrixExplodeArray.
/**
* Test: path_matrix_explode_array
* Expected parameters sent:
* color: ;color=blue;color=black;color=brown
* Expected response: {"color":["blue","black","brown"]}
* @throws Exception
*/
@Test
public void testPathMatrixExplodeArray() throws Exception {
routerFactory.addHandlerByOperationId("path_matrix_explode_array", routingContext -> {
RequestParameters params = routingContext.get("parsedParameters");
JsonObject res = new JsonObject();
RequestParameter color_path = params.pathParameter("color");
assertNotNull(color_path);
assertTrue(color_path.isArray());
res.put("color", new JsonArray(color_path.getArray().stream().map(param -> param.getString()).collect(Collectors.toList())));
routingContext.response().setStatusCode(200).setStatusMessage("OK").putHeader("content-type", "application/json; charset=utf-8").end(res.encode());
});
CountDownLatch latch = new CountDownLatch(1);
List<Object> color_path;
color_path = new ArrayList<>();
color_path.add("blue");
color_path.add("black");
color_path.add("brown");
startServer();
apiClient.pathMatrixExplodeArray(color_path, (AsyncResult<HttpResponse> ar) -> {
if (ar.succeeded()) {
assertEquals(200, ar.result().statusCode());
assertTrue("Expected: " + new JsonObject("{\"color\":[\"blue\",\"black\",\"brown\"]}").encode() + " Actual: " + ar.result().bodyAsJsonObject().encode(), new JsonObject("{\"color\":[\"blue\",\"black\",\"brown\"]}").equals(ar.result().bodyAsJsonObject()));
} else {
assertTrue(ar.cause().getMessage(), false);
}
latch.countDown();
});
awaitLatch(latch);
}
use of io.vertx.core.AsyncResult in project vertx-web by vert-x3.
the class OpenAPI3ParametersUnitTest method testQueryFormExplodeString.
/**
* Test: query_form_explode_string
* Expected parameters sent:
* color: color=blue
* Expected response: {"color":"blue"}
* @throws Exception
*/
@Test
public void testQueryFormExplodeString() throws Exception {
routerFactory.addHandlerByOperationId("query_form_explode_string", routingContext -> {
RequestParameters params = routingContext.get("parsedParameters");
JsonObject res = new JsonObject();
RequestParameter color_query = params.queryParameter("color");
assertNotNull(color_query);
assertTrue(color_query.isString());
assertEquals(color_query.getString(), "blue");
res.put("color", color_query.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_query;
color_query = "blue";
startServer();
apiClient.queryFormExplodeString(color_query, (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);
}
Aggregations