use of io.vertx.core.json.JsonObject in project vert.x by eclipse.
the class JsonObjectTest method testGetMap.
@Test
public void testGetMap() {
jsonObject.put("foo", "bar");
jsonObject.put("quux", 123);
JsonObject obj = createJsonObject();
jsonObject.put("wibble", obj);
Map<String, Object> map = jsonObject.getMap();
map.remove("foo");
assertFalse(jsonObject.containsKey("foo"));
map.put("bleep", "flarp");
assertTrue(jsonObject.containsKey("bleep"));
jsonObject.remove("quux");
assertFalse(map.containsKey("quux"));
jsonObject.put("wooble", "plink");
assertTrue(map.containsKey("wooble"));
assertSame(obj, map.get("wibble"));
}
use of io.vertx.core.json.JsonObject in project vert.x by eclipse.
the class JsonObjectTest method testPutJsonObject.
@Test
public void testPutJsonObject() {
JsonObject obj1 = new JsonObject().put("blah", "wibble");
JsonObject obj2 = new JsonObject().put("eeek", "flibb");
JsonObject obj3 = new JsonObject().put("floob", "plarp");
assertSame(jsonObject, jsonObject.put("foo", obj1));
assertEquals(obj1, jsonObject.getJsonObject("foo"));
jsonObject.put("quux", obj2);
assertEquals(obj2, jsonObject.getJsonObject("quux"));
assertEquals(obj1, jsonObject.getJsonObject("foo"));
jsonObject.put("foo", obj3);
assertEquals(obj3, jsonObject.getJsonObject("foo"));
jsonObject.put("foo", (JsonObject) null);
assertTrue(jsonObject.containsKey("foo"));
try {
jsonObject.put(null, new JsonObject());
fail();
} catch (NullPointerException e) {
// OK
}
}
use of io.vertx.core.json.JsonObject in project vert.x by eclipse.
the class KeyStoreTest method testDefaultTrustOptionsJson.
@Test
public void testDefaultTrustOptionsJson() {
PemTrustOptions def = new PemTrustOptions();
PemTrustOptions json = new PemTrustOptions(new JsonObject());
assertEquals(def.getCertPaths(), json.getCertPaths());
assertEquals(def.getCertValues(), json.getCertValues());
}
use of io.vertx.core.json.JsonObject in project vert.x by eclipse.
the class JsonObjectTest method testGetJsonObject.
@Test
public void testGetJsonObject() {
JsonObject obj = new JsonObject().put("blah", "wibble");
jsonObject.put("foo", obj);
assertEquals(obj, jsonObject.getJsonObject("foo"));
jsonObject.put("foo", "hello");
try {
jsonObject.getJsonObject("foo");
fail();
} catch (ClassCastException e) {
// Ok
}
jsonObject.putNull("foo");
assertNull(jsonObject.getJsonObject("foo"));
assertNull(jsonObject.getJsonObject("absent"));
try {
jsonObject.getJsonObject(null);
fail();
} catch (NullPointerException e) {
// OK
}
}
use of io.vertx.core.json.JsonObject in project vert.x by eclipse.
the class JsonObjectTest method testDecode.
@Test
public void testDecode() throws Exception {
byte[] bytes = TestUtils.randomByteArray(10);
String strBytes = Base64.getEncoder().encodeToString(bytes);
Instant now = Instant.now();
String strInstant = ISO_INSTANT.format(now);
String json = "{\"mystr\":\"foo\",\"myint\":123,\"mylong\":1234,\"myfloat\":1.23,\"mydouble\":2.34,\"" + "myboolean\":true,\"mybinary\":\"" + strBytes + "\",\"myinstant\":\"" + strInstant + "\",\"mynull\":null,\"myobj\":{\"foo\":\"bar\"},\"myarr\":[\"foo\",123]}";
JsonObject obj = new JsonObject(json);
assertEquals(json, obj.encode());
assertEquals("foo", obj.getString("mystr"));
assertEquals(Integer.valueOf(123), obj.getInteger("myint"));
assertEquals(Long.valueOf(1234), obj.getLong("mylong"));
assertEquals(Float.valueOf(1.23f), obj.getFloat("myfloat"));
assertEquals(Double.valueOf(2.34d), obj.getDouble("mydouble"));
assertTrue(obj.getBoolean("myboolean"));
assertTrue(TestUtils.byteArraysEqual(bytes, obj.getBinary("mybinary")));
assertEquals(now, obj.getInstant("myinstant"));
assertTrue(obj.containsKey("mynull"));
JsonObject nestedObj = obj.getJsonObject("myobj");
assertEquals("bar", nestedObj.getString("foo"));
JsonArray nestedArr = obj.getJsonArray("myarr");
assertEquals("foo", nestedArr.getString(0));
assertEquals(Integer.valueOf(123), Integer.valueOf(nestedArr.getInteger(1)));
}
Aggregations