use of io.vertx.core.AsyncResult in project vertx-web by vert-x3.
the class OpenAPI3ParametersUnitTest method testQueryPipeDelimitedNoexplodeArray.
/**
* Test: query_pipeDelimited_noexplode_array
* Expected parameters sent:
* color: blue|black|brown
* Expected response: {"color":["blue","black","brown"]}
* @throws Exception
*/
@Test
public void testQueryPipeDelimitedNoexplodeArray() throws Exception {
routerFactory.addHandlerByOperationId("query_pipeDelimited_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.queryPipeDelimitedNoexplodeArray(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 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"]}
* @throws Exception
*/
@Test
public void testPathMultiSimpleMatrix() throws Exception {
routerFactory.addHandlerByOperationId("path_multi_simple_matrix", routingContext -> {
RequestParameters params = routingContext.get("parsedParameters");
JsonObject res = new JsonObject();
RequestParameter colorSimple_path = params.pathParameter("color_simple");
assertNotNull(colorSimple_path);
assertTrue(colorSimple_path.isString());
assertEquals(colorSimple_path.getString(), "blue");
res.put("color_simple", colorSimple_path.getString());
RequestParameter colorMatrix_path = params.pathParameter("color_matrix");
assertNotNull(colorMatrix_path);
assertTrue(colorMatrix_path.isArray());
res.put("color_matrix", new JsonArray(colorMatrix_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);
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");
startServer();
apiClient.pathMultiSimpleMatrix(colorSimple_path, colorMatrix_path, (AsyncResult<HttpResponse> ar) -> {
if (ar.succeeded()) {
assertEquals(200, ar.result().statusCode());
assertTrue("Expected: " + new JsonObject("{\"color_simple\":\"blue\",\"color_matrix\":[\"blue\",\"black\",\"brown\"]}").encode() + " Actual: " + ar.result().bodyAsJsonObject().encode(), new JsonObject("{\"color_simple\":\"blue\",\"color_matrix\":[\"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 testQueryDeepObjectExplodeObject.
/**
* Test: query_deepObject_explode_object
* Expected parameters sent:
* color: color[R]=100&color[G]=200&color[B]=150
* Expected response: {"color":{"R":"100","G":"200","B":"150"}}
* @throws Exception
*/
@Test
public void testQueryDeepObjectExplodeObject() throws Exception {
routerFactory.addHandlerByOperationId("query_deepObject_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.queryDeepObjectExplodeObject(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.core.AsyncResult in project vertx-web by vert-x3.
the class OpenAPI3ParametersUnitTest method testQueryFormNoexplodeString.
/**
* Test: query_form_noexplode_string
* Expected parameters sent:
* color: color=blue
* Expected response: {"color":"blue"}
* @throws Exception
*/
@Test
public void testQueryFormNoexplodeString() throws Exception {
routerFactory.addHandlerByOperationId("query_form_noexplode_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.queryFormNoexplodeString(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);
}
use of io.vertx.core.AsyncResult in project vertx-web by vert-x3.
the class OpenAPI3ParametersUnitTest method testHeaderSimpleNoexplodeObject.
/**
* Test: header_simple_noexplode_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 testHeaderSimpleNoexplodeObject() throws Exception {
routerFactory.addHandlerByOperationId("header_simple_noexplode_object", routingContext -> {
RequestParameters params = routingContext.get("parsedParameters");
JsonObject res = new JsonObject();
RequestParameter color_header = params.headerParameter("color");
assertNotNull(color_header);
assertTrue(color_header.isObject());
Map<String, String> map = new HashMap<>();
for (String key : color_header.getObjectKeys()) map.put(key, color_header.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_header;
color_header = new HashMap<>();
color_header.put("R", "100");
color_header.put("G", "200");
color_header.put("B", "150");
startServer();
apiClient.headerSimpleNoexplodeObject(color_header, (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