Search in sources :

Example 66 with JsonObject

use of io.vertx.core.json.JsonObject in project vert.x by eclipse.

the class JsonObjectTest method testCreateFromMapNestedJsonArray.

@Test
public void testCreateFromMapNestedJsonArray() {
    Map<String, Object> map = new HashMap<>();
    JsonArray nestedArr = new JsonArray().add("foo");
    map.put("nested", nestedArr);
    JsonObject obj = new JsonObject(map);
    JsonArray nestedRetrieved = obj.getJsonArray("nested");
    assertEquals("foo", nestedRetrieved.getString(0));
}
Also used : JsonArray(io.vertx.core.json.JsonArray) JsonObject(io.vertx.core.json.JsonObject) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Example 67 with JsonObject

use of io.vertx.core.json.JsonObject in project vert.x by eclipse.

the class JsonObjectTest method assertNumberNotEquals.

private void assertNumberNotEquals(Number value1, Number value2) {
    JsonObject o1 = new JsonObject().put("key", value1);
    JsonObject o2 = new JsonObject().put("key", value2);
    if (o1.equals(o2)) {
        fail("Was expecting " + value1.getClass().getSimpleName() + ":" + value1 + " != " + value2.getClass().getSimpleName() + ":" + value2);
    }
}
Also used : JsonObject(io.vertx.core.json.JsonObject)

Example 68 with JsonObject

use of io.vertx.core.json.JsonObject in project vert.x by eclipse.

the class JsonObjectTest method testCommentsInJson.

// Strict JSON doesn't allow comments but we do so users can add comments to config files etc
@Test
public void testCommentsInJson() {
    String jsonWithComments = "// single line comment\n" + "/*\n" + "  This is a multi \n" + "  line comment\n" + "*/\n" + "{\n" + "// another single line comment this time inside the JSON object itself\n" + "  \"foo\": \"bar\" // and a single line comment at end of line \n" + "/*\n" + "  This is a another multi \n" + "  line comment this time inside the JSON object itself\n" + "*/\n" + "}";
    JsonObject json = new JsonObject(jsonWithComments);
    assertEquals("{\"foo\":\"bar\"}", json.encode());
}
Also used : JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Example 69 with JsonObject

use of io.vertx.core.json.JsonObject in project vert.x by eclipse.

the class JsonObjectTest method testMergeIn1.

@Test
public void testMergeIn1() {
    JsonObject obj1 = new JsonObject().put("foo", "bar");
    JsonObject obj2 = new JsonObject().put("eek", "flurb");
    obj1.mergeIn(obj2);
    assertEquals(2, obj1.size());
    assertEquals("bar", obj1.getString("foo"));
    assertEquals("flurb", obj1.getString("eek"));
    assertEquals(1, obj2.size());
    assertEquals("flurb", obj2.getString("eek"));
}
Also used : JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Example 70 with JsonObject

use of io.vertx.core.json.JsonObject in project vert.x by eclipse.

the class JsonObjectTest method testStream.

@Test
public void testStream() {
    jsonObject.put("foo", "bar");
    jsonObject.put("quux", 123);
    JsonObject obj = createJsonObject();
    jsonObject.put("wibble", obj);
    List<Map.Entry<String, Object>> list = jsonObject.stream().collect(Collectors.toList());
    Iterator<Map.Entry<String, Object>> iter = list.iterator();
    assertTrue(iter.hasNext());
    Map.Entry<String, Object> entry = iter.next();
    assertEquals("foo", entry.getKey());
    assertEquals("bar", entry.getValue());
    assertTrue(iter.hasNext());
    entry = iter.next();
    assertEquals("quux", entry.getKey());
    assertEquals(123, entry.getValue());
    assertTrue(iter.hasNext());
    entry = iter.next();
    assertEquals("wibble", entry.getKey());
    assertEquals(obj, entry.getValue());
    assertFalse(iter.hasNext());
}
Also used : JsonObject(io.vertx.core.json.JsonObject) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Aggregations

JsonObject (io.vertx.core.json.JsonObject)383 Test (org.junit.Test)210 JsonArray (io.vertx.core.json.JsonArray)89 HttpURLConnection (java.net.HttpURLConnection)68 Future (io.vertx.core.Future)55 Handler (io.vertx.core.Handler)51 Async (io.vertx.ext.unit.Async)50 Vertx (io.vertx.core.Vertx)48 TestContext (io.vertx.ext.unit.TestContext)48 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)47 RunWith (org.junit.runner.RunWith)47 Timeout (org.junit.rules.Timeout)43 Before (org.junit.Before)41 Rule (org.junit.Rule)33 EventBusMessage (org.eclipse.hono.util.EventBusMessage)27 AsyncResult (io.vertx.core.AsyncResult)26 Buffer (io.vertx.core.buffer.Buffer)26 Constants (org.eclipse.hono.util.Constants)25 Mockito (org.mockito.Mockito)25 Objects (java.util.Objects)23