use of io.vertx.ext.web.api.RequestParameters in project vertx-web by vert-x3.
the class OpenAPI3ParametersUnitTest method testPathMatrixNoexplodeObject.
/**
* Test: path_matrix_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 testPathMatrixNoexplodeObject() throws Exception {
routerFactory.addHandlerByOperationId("path_matrix_noexplode_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.pathMatrixNoexplodeObject(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.RequestParameters in project vertx-web by vert-x3.
the class OpenAPI3ParametersUnitTest method testPathLabelNoexplodeArray.
/**
* Test: path_label_noexplode_array
* Expected parameters sent:
* color: .blue.black.brown
* Expected response: {"color":["blue","black","brown"]}
* @throws Exception
*/
@Test
public void testPathLabelNoexplodeArray() throws Exception {
routerFactory.addHandlerByOperationId("path_label_noexplode_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.pathLabelNoexplodeArray(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.ext.web.api.RequestParameters in project vertx-web by vert-x3.
the class OpenAPI3ParametersUnitTest method testPathLabelExplodeString.
/**
* Test: path_label_explode_string
* Expected parameters sent:
* color: .blue
* Expected response: {"color":"blue"}
* @throws Exception
*/
@Test
public void testPathLabelExplodeString() throws Exception {
routerFactory.addHandlerByOperationId("path_label_explode_string", routingContext -> {
RequestParameters params = routingContext.get("parsedParameters");
JsonObject res = new JsonObject();
RequestParameter color_path = params.pathParameter("color");
assertNotNull(color_path);
assertTrue(color_path.isString());
assertEquals(color_path.getString(), "blue");
res.put("color", color_path.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_path;
color_path = "blue";
startServer();
apiClient.pathLabelExplodeString(color_path, (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.RequestParameters in project vertx-web by vert-x3.
the class OpenAPI3ParametersUnitTest method testPathSimpleExplodeObject.
/**
* Test: path_simple_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 testPathSimpleExplodeObject() throws Exception {
routerFactory.addHandlerByOperationId("path_simple_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.pathSimpleExplodeObject(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.RequestParameters in project vertx-web by vert-x3.
the class OpenAPI3ParametersUnitTest method testHeaderSimpleExplodeObject.
/**
* Test: header_simple_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 testHeaderSimpleExplodeObject() throws Exception {
routerFactory.addHandlerByOperationId("header_simple_explode_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.headerSimpleExplodeObject(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