@Test public void testRemoveMethodReturnedObject() { JsonObject obj = new JsonObject(); obj.put("simple", "bar") .put("object", new JsonObject().put("name", "vert.x").put("count", 2)) .put("array", new JsonArray().add(1.0).add(2.0)); Object removed = obj.remove("missing"); assertNull(removed); removed = obj.remove("simple"); assertTrue(removed instanceof String); removed = obj.remove("object"); assertTrue(removed instanceof JsonObject); assertEquals(((JsonObject) removed).getString("name"), "vert.x"); removed = obj.remove("array"); assertTrue(removed instanceof JsonArray); assertEquals(((JsonArray) removed).getDouble(0), 1.0, 0.0); }
@Test public void testFieldNames() { jsonObject.put("foo", "bar"); jsonObject.put("eek", 123); jsonObject.put("flib", new JsonObject()); Set<String> fieldNames = jsonObject.fieldNames(); assertEquals(3, fieldNames.size()); assertTrue(fieldNames.contains("foo")); assertTrue(fieldNames.contains("eek")); assertTrue(fieldNames.contains("flib")); jsonObject.remove("foo"); assertEquals(2, fieldNames.size()); assertFalse(fieldNames.contains("foo")); }
@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")); }
@Test public void testRemove() { jsonObject.put("mystr", "bar"); jsonObject.put("myint", 123); assertEquals("bar", jsonObject.remove("mystr")); assertNull(jsonObject.getValue("mystr")); assertEquals(123, jsonObject.remove("myint")); assertNull(jsonObject.getValue("myint")); assertTrue(jsonObject.isEmpty()); }
@Test public void testGetList() { JsonObject obj = new JsonObject().put("quux", "wibble"); jsonArray.add("foo").add(123).add(obj); List<Object> list = jsonArray.getList(); list.remove("foo"); assertFalse(jsonArray.contains("foo")); list.add("floob"); assertTrue(jsonArray.contains("floob")); assertSame(obj, list.get(1)); obj.remove("quux"); }
@Test public void testCopy() { jsonObject.put("foo", "bar"); jsonObject.put("quux", 123); JsonObject obj = createJsonObject(); jsonObject.put("wibble", obj); jsonObject.put("eek", new StringBuilder("blah")); // CharSequence JsonObject copy = jsonObject.copy(); assertNotSame(jsonObject, copy); assertEquals(jsonObject, copy); copy.put("blah", "flib"); assertFalse(jsonObject.containsKey("blah")); copy.remove("foo"); assertFalse(copy.containsKey("foo")); assertTrue(jsonObject.containsKey("foo")); jsonObject.put("oob", "flarb"); assertFalse(copy.containsKey("oob")); jsonObject.remove("quux"); assertFalse(jsonObject.containsKey("quux")); assertTrue(copy.containsKey("quux")); JsonObject nested = jsonObject.getJsonObject("wibble"); JsonObject nestedCopied = copy.getJsonObject("wibble"); assertNotSame(nested, nestedCopied); assertEquals(nested, nestedCopied); assertEquals("blah", copy.getString("eek")); }
@Test public void testSize() { assertEquals(0, jsonObject.size()); jsonObject.put("foo", "bar"); assertEquals(1, jsonObject.size()); jsonObject.put("bar", 123); assertEquals(2, jsonObject.size()); jsonObject.putNull("wibble"); assertEquals(3, jsonObject.size()); jsonObject.remove("wibble"); assertEquals(2, jsonObject.size()); jsonObject.clear(); assertEquals(0, jsonObject.size()); }
json.remove("keyStoreOptions"); json.remove("trustStoreOptions"); json.put("pfxKeyCertOptions", new JsonObject().put("password", ksPassword)) .put("pfxTrustOptions", new JsonObject().put("password", tsPassword)); assertTrue(options.getKeyCertOptions() instanceof PfxOptions); json.remove("pfxKeyCertOptions"); json.remove("pfxTrustOptions"); json.put("pemKeyCertOptions", new JsonObject()) .put("pemTrustOptions", new JsonObject());
json.remove("keyStoreOptions"); json.remove("trustStoreOptions"); json.put("pfxKeyCertOptions", new JsonObject().put("password", ksPassword)) .put("pfxTrustOptions", new JsonObject().put("password", tsPassword)); assertTrue(options.getKeyCertOptions() instanceof PfxOptions); json.remove("pfxKeyCertOptions"); json.remove("pfxTrustOptions"); json.put("pemKeyCertOptions", new JsonObject()) .put("pemTrustOptions", new JsonObject());
json.remove("keyStoreOptions"); json.remove("trustStoreOptions"); json.put("pfxKeyCertOptions", new JsonObject().put("password", ksPassword)) .put("pfxTrustOptions", new JsonObject().put("password", tsPassword)); assertTrue(options.getKeyCertOptions() instanceof PfxOptions); json.remove("pfxKeyCertOptions"); json.remove("pfxTrustOptions"); json.put("pemKeyCertOptions", new JsonObject()) .put("pemTrustOptions", new JsonObject());
json.remove("keyStoreOptions"); json.remove("trustStoreOptions"); json.put("pfxKeyCertOptions", new JsonObject().put("password", ksPassword)) .put("pfxTrustOptions", new JsonObject().put("password", tsPassword)); assertTrue(options.getKeyCertOptions() instanceof PfxOptions); json.remove("pfxKeyCertOptions"); json.remove("pfxTrustOptions"); json.put("pemKeyCertOptions", new JsonObject()) .put("pemTrustOptions", new JsonObject());
@Test public void testSendPermittedStructureMatch() throws Exception { JsonObject match = new JsonObject().put("fib", "wib").put("oop", 12); sockJSHandler.bridge(defaultOptions.addInboundPermitted(new PermittedOptions().setMatch(match))); testSend(addr, match); JsonObject json1 = match.copy(); json1.put("blah", "foob"); testSend(addr, json1); json1.remove("fib"); testError(new JsonObject().put("type", "send").put("address", addr).put("body", json1), "access_denied"); }
@Test public void testRemove() { jsonObject.put("mystr", "bar"); jsonObject.put("myint", 123); assertEquals("bar", jsonObject.remove("mystr")); assertNull(jsonObject.getValue("mystr")); assertEquals(123, jsonObject.remove("myint")); assertNull(jsonObject.getValue("myint")); assertTrue(jsonObject.isEmpty()); }
@Test public void testHookPublishMissingAddress() throws Exception { sockJSHandler.bridge(allAccessOptions, be -> { if (be.type() == BridgeEventType.PUBLISH) { be.getRawMessage().remove("address"); testComplete(); } be.complete(true); }); testError(new JsonObject().put("type", "publish").put("address", addr).put("body", "foobar"), "missing_address"); await(); }
@Test public void testHookUnregisterMissingAddress() throws Exception { sockJSHandler.bridge(allAccessOptions, be -> { if (be.type() == BridgeEventType.UNREGISTER) { be.getRawMessage().remove("address"); testComplete(); } be.complete(true); }); testError(new JsonObject().put("type", "unregister").put("address", addr).put("body", "foobar"), "missing_address"); await(); }
@Test public void testHookRegisterMissingAddress() throws Exception { sockJSHandler.bridge(allAccessOptions, be -> { if (be.type() == BridgeEventType.REGISTER) { be.getRawMessage().remove("address"); testComplete(); } be.complete(true); }); testError(new JsonObject().put("type", "register").put("address", addr).put("body", "foobar"), "missing_address"); await(); }
@Test public void testGetList() { JsonObject obj = new JsonObject().put("quux", "wibble"); jsonArray.add("foo").add(123).add(obj); List<Object> list = jsonArray.getList(); list.remove("foo"); assertFalse(jsonArray.contains("foo")); list.add("floob"); assertTrue(jsonArray.contains("floob")); assertSame(obj, list.get(1)); obj.remove("quux"); }
@Test public void testHookSendMissingAddress() throws Exception { sockJSHandler.bridge(allAccessOptions, be -> { if (be.type() == BridgeEventType.SEND) { be.getRawMessage().remove("address"); testComplete(); } be.complete(true); }); testError(new JsonObject().put("type", "send").put("address", addr).put("body", "foobar"), "missing_address"); await(); }
@Test public void testRegisterPermittedStructureMatch() throws Exception { JsonObject match = new JsonObject().put("fib", "wib").put("oop", 12); sockJSHandler.bridge(defaultOptions.addOutboundPermitted(new PermittedOptions().setMatch(match))); testReceive(addr, match); JsonObject json1 = match.copy(); json1.put("blah", "foob"); testReceive(addr, json1); JsonObject json2 = json1.copy(); json2.remove("fib"); testReceiveFail(addr, json2); }
@Test public void testRegisterPermittedStructureMatchWithAddress() throws Exception { JsonObject match = new JsonObject().put("fib", "wib").put("oop", 12); sockJSHandler.bridge(defaultOptions.addOutboundPermitted(new PermittedOptions().setMatch(match).setAddress(addr))); testReceive(addr, match); JsonObject json1 = match.copy(); json1.put("blah", "foob"); testReceive(addr, json1); JsonObject json2 = json1.copy(); json2.remove("fib"); testReceiveFail(addr, json2); }