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));
}
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();
}
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);
}
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,{"name":"joe"}, 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();
});
}
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());
});
}
Aggregations