Search in sources :

Example 36 with AsyncResult

use of io.vertx.core.AsyncResult in project vertx-web by vert-x3.

the class OpenAPI3ParametersUnitTest method testPathSimpleNoexplodeObject.

/**
 * Test: path_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 testPathSimpleNoexplodeObject() throws Exception {
    routerFactory.addHandlerByOperationId("path_simple_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.pathSimpleNoexplodeObject(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);
}
Also used : HashMap(java.util.HashMap) RequestParameter(io.vertx.ext.web.api.RequestParameter) JsonObject(io.vertx.core.json.JsonObject) JsonObject(io.vertx.core.json.JsonObject) CountDownLatch(java.util.concurrent.CountDownLatch) AsyncResult(io.vertx.core.AsyncResult) RequestParameters(io.vertx.ext.web.api.RequestParameters) Test(org.junit.Test)

Example 37 with AsyncResult

use of io.vertx.core.AsyncResult 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"}
 * @throws Exception
 */
@Test
public void testPathMatrixNoexplodeString() throws Exception {
    routerFactory.addHandlerByOperationId("path_matrix_noexplode_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.pathMatrixNoexplodeString(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);
}
Also used : RequestParameter(io.vertx.ext.web.api.RequestParameter) JsonObject(io.vertx.core.json.JsonObject) CountDownLatch(java.util.concurrent.CountDownLatch) AsyncResult(io.vertx.core.AsyncResult) RequestParameters(io.vertx.ext.web.api.RequestParameters) Test(org.junit.Test)

Example 38 with AsyncResult

use of io.vertx.core.AsyncResult in project vertx-web by vert-x3.

the class OpenAPI3ParametersUnitTest method testQuerySpaceDelimitedNoexplodeObject.

/**
 * Test: query_spaceDelimited_noexplode_object
 * Expected parameters sent:
 * color: R%20100%20G%20200%20B%20150
 * Expected response: {"color":{"R":"100","G":"200","B":"150"}}
 * @throws Exception
 */
@Test
public void testQuerySpaceDelimitedNoexplodeObject() throws Exception {
    routerFactory.addHandlerByOperationId("query_spaceDelimited_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.querySpaceDelimitedNoexplodeObject(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);
}
Also used : HashMap(java.util.HashMap) RequestParameter(io.vertx.ext.web.api.RequestParameter) JsonObject(io.vertx.core.json.JsonObject) JsonObject(io.vertx.core.json.JsonObject) CountDownLatch(java.util.concurrent.CountDownLatch) AsyncResult(io.vertx.core.AsyncResult) RequestParameters(io.vertx.ext.web.api.RequestParameters) Test(org.junit.Test)

Example 39 with AsyncResult

use of io.vertx.core.AsyncResult in project vertx-web by vert-x3.

the class OpenAPI3ParametersUnitTest method testCookieFormExplodeEmpty.

/**
 * Test: cookie_form_explode_empty
 * Expected parameters sent:
 * color: color=
 * Expected response: {"color":null}
 * @throws Exception
 */
@Test
public void testCookieFormExplodeEmpty() throws Exception {
    routerFactory.addHandlerByOperationId("cookie_form_explode_empty", routingContext -> {
        RequestParameters params = routingContext.get("parsedParameters");
        JsonObject res = new JsonObject();
        RequestParameter color_cookie = params.cookieParameter("color");
        assertNotNull(color_cookie.getString());
        assertTrue(color_cookie.getString().isEmpty());
        res.putNull("color");
        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 = "";
    startServer();
    apiClient.cookieFormExplodeEmpty(color_cookie, (AsyncResult<HttpResponse> ar) -> {
        if (ar.succeeded()) {
            assertEquals(200, ar.result().statusCode());
            assertTrue("Expected: " + new JsonObject("{\"color\":null}").encode() + " Actual: " + ar.result().bodyAsJsonObject().encode(), new JsonObject("{\"color\":null}").equals(ar.result().bodyAsJsonObject()));
        } else {
            assertTrue(ar.cause().getMessage(), false);
        }
        latch.countDown();
    });
    awaitLatch(latch);
}
Also used : RequestParameter(io.vertx.ext.web.api.RequestParameter) JsonObject(io.vertx.core.json.JsonObject) CountDownLatch(java.util.concurrent.CountDownLatch) AsyncResult(io.vertx.core.AsyncResult) RequestParameters(io.vertx.ext.web.api.RequestParameters) Test(org.junit.Test)

Example 40 with AsyncResult

use of io.vertx.core.AsyncResult in project vertx-web by vert-x3.

the class OpenAPI3ParametersUnitTest method testPathMatrixExplodeString.

/**
 * Test: path_matrix_explode_string
 * Expected parameters sent:
 * color: ;color=blue
 * Expected response: {"color":"blue"}
 * @throws Exception
 */
@Test
public void testPathMatrixExplodeString() throws Exception {
    routerFactory.addHandlerByOperationId("path_matrix_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.pathMatrixExplodeString(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);
}
Also used : RequestParameter(io.vertx.ext.web.api.RequestParameter) JsonObject(io.vertx.core.json.JsonObject) CountDownLatch(java.util.concurrent.CountDownLatch) AsyncResult(io.vertx.core.AsyncResult) RequestParameters(io.vertx.ext.web.api.RequestParameters) Test(org.junit.Test)

Aggregations

AsyncResult (io.vertx.core.AsyncResult)210 Handler (io.vertx.core.Handler)148 Future (io.vertx.core.Future)102 JsonObject (io.vertx.core.json.JsonObject)81 Test (org.junit.Test)71 Map (java.util.Map)63 CountDownLatch (java.util.concurrent.CountDownLatch)63 List (java.util.List)62 Vertx (io.vertx.core.Vertx)61 HashMap (java.util.HashMap)58 RequestParameter (io.vertx.ext.web.api.RequestParameter)48 RequestParameters (io.vertx.ext.web.api.RequestParameters)48 IOException (java.io.IOException)48 ArrayList (java.util.ArrayList)47 Promise (io.vertx.core.Promise)45 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)40 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)40 Context (io.vertx.core.Context)37 Buffer (io.vertx.core.buffer.Buffer)37 Collectors (java.util.stream.Collectors)36