Search in sources :

Example 96 with JsonArray

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

the class EventbusBridgeTest method testReceiveJsonArrayAllAccess.

@Test
public void testReceiveJsonArrayAllAccess() throws Exception {
    sockJSHandler.bridge(allAccessOptions);
    testReceive(new JsonArray().add("foo").add(1456));
}
Also used : JsonArray(io.vertx.core.json.JsonArray) Test(org.junit.Test)

Example 97 with JsonArray

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

the class StaticHandlerTest method testDirectoryListingJson.

@Test
public void testDirectoryListingJson() throws Exception {
    stat.setDirectoryListing(true);
    Set<String> expected = new HashSet<>(Arrays.asList(".hidden.html", "foo.json", "index.html", "otherpage.html", "a", "somedir", "somedir2", "somedir3", "file with spaces.html"));
    testRequest(HttpMethod.GET, "/", req -> {
        req.putHeader("accept", "application/json");
    }, resp -> {
        resp.bodyHandler(buff -> {
            assertEquals("application/json", resp.headers().get("content-type"));
            String sBuff = buff.toString();
            JsonArray arr = new JsonArray(sBuff);
            assertEquals(expected.size(), arr.size());
            for (Object elem : arr) {
                assertTrue(expected.contains(elem));
            }
            testComplete();
        });
    }, 200, "OK", null);
    await();
}
Also used : JsonArray(io.vertx.core.json.JsonArray) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 98 with JsonArray

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

the class RoutingContextImplTest method test_one_item_array_as_json_array_yields_one_item_json_array.

@Test
public void test_one_item_array_as_json_array_yields_one_item_json_array() throws Exception {
    router.route().handler(event -> {
        JsonArray array = new JsonArray(Collections.singletonList(new JsonObject(Collections.singletonMap("foo", "bar"))));
        assertEquals(array, event.getBodyAsJsonArray());
        event.response().end();
    });
    testRequest(HttpMethod.POST, "/", req -> {
        req.setChunked(true);
        req.write(Buffer.buffer("[ { \"foo\": \"bar\" } ]"));
    }, HttpResponseStatus.OK.code(), HttpResponseStatus.OK.reasonPhrase(), null);
}
Also used : JsonArray(io.vertx.core.json.JsonArray) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Example 99 with JsonArray

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

the class HandlebarsTemplateTest method testTemplateJsonArrayResolver.

@Test
public void testTemplateJsonArrayResolver() throws Exception {
    TemplateEngine engine = HandlebarsTemplateEngine.create();
    JsonArray jsonArray = new JsonArray();
    jsonArray.add("badger").add("fox").add(new JsonObject().put("name", "joe"));
    String expected = "Iterator: badger,fox,{&quot;name&quot;:&quot;joe&quot;}, Element by index:fox - joe - Out of bounds:  - Size:3";
    testTemplateHandlerWithContext(engine, "src/test/filesystemtemplates", "test-handlebars-template5.hbs", expected, context -> {
        context.put("foo", jsonArray);
        context.next();
    });
}
Also used : JsonArray(io.vertx.core.json.JsonArray) HandlebarsTemplateEngine(io.vertx.ext.web.templ.handlebars.HandlebarsTemplateEngine) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Example 100 with JsonArray

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

the class WebClientTest method testSendJsonArrayBody.

@Test
public void testSendJsonArrayBody() throws Exception {
    JsonArray body = new JsonArray().add(0).add(1).add(2);
    testSendBody(body, (contentType, buff) -> {
        assertEquals("application/json", contentType);
        assertEquals(body, buff.toJsonArray());
    });
}
Also used : JsonArray(io.vertx.core.json.JsonArray) Test(org.junit.Test)

Aggregations

JsonArray (io.vertx.core.json.JsonArray)535 JsonObject (io.vertx.core.json.JsonObject)379 Test (org.junit.Test)185 List (java.util.List)69 ArrayList (java.util.ArrayList)66 Map (java.util.Map)52 Handler (io.vertx.core.Handler)49 HashMap (java.util.HashMap)42 Collectors (java.util.stream.Collectors)42 Test (org.junit.jupiter.api.Test)41 Future (io.vertx.core.Future)37 IOException (java.io.IOException)35 AsyncResult (io.vertx.core.AsyncResult)34 Buffer (io.vertx.core.buffer.Buffer)33 HttpURLConnection (java.net.HttpURLConnection)30 StandardCharsets (java.nio.charset.StandardCharsets)29 RoutingContext (io.vertx.ext.web.RoutingContext)26 Objects (java.util.Objects)25 Instant (java.time.Instant)24 Rule (org.junit.Rule)22