Refine search
/** * Create a delivery options from JSON * * @param json the JSON */ public DeliveryOptions(JsonObject json) { this.timeout = json.getLong("timeout", DEFAULT_TIMEOUT); this.codecName = json.getString("codecName", null); JsonObject hdrs = json.getJsonObject("headers", null); if (hdrs != null) { headers = new CaseInsensitiveHeaders(); for (Map.Entry<String, Object> entry: hdrs) { if (!(entry.getValue() instanceof String)) { throw new IllegalStateException("Invalid type for message header value " + entry.getValue().getClass()); } headers.set(entry.getKey(), (String)entry.getValue()); } } this.localOnly = json.getBoolean("localOnly", DEFAULT_LOCAL_ONLY); }
public CustomMetricsOptions(JsonObject json) { value = json.getString("customProperty"); JsonObject nestedOptionsJson = json.getJsonObject("nestedOptions"); this.nestedOptions = nestedOptionsJson == null ? null : new NestedMetricsOptions(nestedOptionsJson); }
@Test public void testCreateFromMapNestedMap() { Map<String, Object> map = new HashMap<>(); Map<String, Object> nestedMap = new HashMap<>(); nestedMap.put("foo", "bar"); map.put("nested", nestedMap); JsonObject obj = new JsonObject(map); JsonObject nestedRetrieved = obj.getJsonObject("nested"); assertEquals("bar", nestedRetrieved.getString("foo")); }
@Test public void testCreateFromMapNestedJsonObject() { Map<String, Object> map = new HashMap<>(); JsonObject nestedObj = new JsonObject().put("foo", "bar"); map.put("nested", nestedObj); JsonObject obj = new JsonObject(map); JsonObject nestedRetrieved = obj.getJsonObject("nested"); assertEquals("bar", nestedRetrieved.getString("foo")); }
final String verticleName = failedVerticle.getString("verticle_name"); final CountDownLatch latch = new CountDownLatch(1); final AtomicReference<Throwable> err = new AtomicReference<>(); JsonObject options = failedVerticle.getJsonObject("options"); try { doDeployVerticle(verticleName, new DeploymentOptions(options), result -> {
@Test public void testMergeInDepth2() { JsonObject obj1 = new JsonObject("{ \"foo\": \"bar\", \"flurb\": { \"eek\": \"foo\", \"bar\": \"flurb\"}}"); JsonObject obj2 = new JsonObject("{ \"flurb\": { \"bar\": \"flurb1\" }}"); obj1.mergeIn(obj2, 2); assertEquals(2, obj1.size()); assertEquals(2, obj1.getJsonObject("flurb").size()); assertEquals("foo", obj1.getJsonObject("flurb").getString("eek")); assertEquals("flurb1", obj1.getJsonObject("flurb").getString("bar")); }
@Test public void testMergeInDepth0() { JsonObject obj1 = new JsonObject("{ \"foo\": { \"bar\": \"flurb\" }}"); JsonObject obj2 = new JsonObject("{ \"foo\": { \"bar\": \"eek\" }}"); obj1.mergeIn(obj2, 0); assertEquals(1, obj1.size()); assertEquals(1, obj1.getJsonObject("foo").size()); assertEquals("flurb", obj1.getJsonObject("foo").getString("bar")); }
@Test public void testMergeInDepth1() { JsonObject obj1 = new JsonObject("{ \"foo\": \"bar\", \"flurb\": { \"eek\": \"foo\", \"bar\": \"flurb\"}}"); JsonObject obj2 = new JsonObject("{ \"flurb\": { \"bar\": \"flurb1\" }}"); obj1.mergeIn(obj2, 1); assertEquals(2, obj1.size()); assertEquals(1, obj1.getJsonObject("flurb").size()); assertEquals("flurb1", obj1.getJsonObject("flurb").getString("bar")); }
@Test public void testMergeInFlat() { JsonObject obj1 = new JsonObject("{ \"foo\": { \"bar\": \"flurb\", \"eek\": 32 }}"); JsonObject obj2 = new JsonObject("{ \"foo\": { \"bar\": \"eek\" }}"); obj1.mergeIn(obj2, false); assertEquals(1, obj1.size()); assertEquals(1, obj1.getJsonObject("foo").size()); assertEquals("eek", obj1.getJsonObject("foo").getString("bar")); }
@Override public void start() throws Exception { // A simple backend vertx.eventBus().<JsonObject>consumer("backend", msg -> { JsonObject json = msg.body(); switch (json.getString("op", "")) { case "get": { String productID = json.getString("id"); msg.reply(products.get(productID)); break; } case "add": { String productID = json.getString("id"); JsonObject product = json.getJsonObject("product"); product.put("id", productID); msg.reply(addProduct(product)); break; } case "list": { JsonArray arr = new JsonArray(); products.forEach((k, v) -> arr.add(v)); msg.reply(arr); break; } default: { msg.fail(0, "operation not permitted"); } } }); }
/** * Initialise the fields of this instance from the specified JSON * * @param json the JSON */ public void fromJson(JsonObject json) { this.config = json.getJsonObject("config"); this.worker = json.getBoolean("worker", DEFAULT_WORKER); this.isolationGroup = json.getString("isolationGroup", DEFAULT_ISOLATION_GROUP); this.ha = json.getBoolean("ha", DEFAULT_HA); JsonArray arr = json.getJsonArray("extraClasspath", null); if (arr != null) { this.extraClasspath = arr.getList(); } this.instances = json.getInteger("instances", DEFAULT_INSTANCES); JsonArray arrIsolated = json.getJsonArray("isolatedClasses", null); if (arrIsolated != null) { this.isolatedClasses = arrIsolated.getList(); } }
@Test public void testStartingApplicationInRedeployModeWithFileConf2() throws IOException { cli.dispatch(new Launcher(), new String[]{"run", HttpTestVerticle.class.getName(), "--redeploy=**" + File.separator + "*.txt", "--launcher-class=" + Launcher.class.getName(), "--conf=" + new File("src/test/resources/conf.json").getAbsolutePath() }); assertWaitUntil(() -> { try { return RunCommandTest.getHttpCode() == 200; } catch (IOException e) { return false; } }); JsonObject conf = RunCommandTest.getContent().getJsonObject("conf"); assertThat(conf).isNotNull().isNotEmpty(); assertThat(conf.getString("name")).isEqualTo("vertx"); }
@Test public void testStartingApplicationInRedeployModeWithFileConf() throws IOException { cli.dispatch(new Launcher(), new String[]{"run", HttpTestVerticle.class.getName(), "--redeploy=**" + File.separator + "*.txt", "--launcher-class=" + Launcher.class.getName(), "--conf", new File("src/test/resources/conf.json").getAbsolutePath() }); assertWaitUntil(() -> { try { return RunCommandTest.getHttpCode() == 200; } catch (IOException e) { return false; } }); JsonObject conf = RunCommandTest.getContent().getJsonObject("conf"); assertThat(conf).isNotNull().isNotEmpty(); assertThat(conf.getString("name")).isEqualTo("vertx"); }
@Test public void testToJsonObject() { Map<String, Object> map = new HashMap<>(); map.put("string", "the_string"); map.put("integer", 4); map.put("boolean", true); map.put("charsequence", new AsciiString("the_charsequence")); map.put("biginteger", new BigInteger("1234567")); map.put("binary", Buffer.buffer("hello")); map.put("object", Collections.singletonMap("nested", 4)); map.put("array", Arrays.asList(1, 2, 3)); JsonObject json = (JsonObject) ConversionHelper.toObject(map); assertEquals(8, json.size()); assertEquals("the_string", json.getString("string")); assertEquals(4, (int)json.getInteger("integer")); assertEquals(true, json.getBoolean("boolean")); assertEquals("the_charsequence", json.getString("charsequence")); assertEquals(1234567, (int)json.getInteger("biginteger")); assertEquals("hello", new String(json.getBinary("binary"))); assertEquals(new JsonObject().put("nested", 4), json.getJsonObject("object")); assertEquals(new JsonArray().add(1).add(2).add(3), json.getJsonArray("array")); }
@Test public void testWithConfProvidedAsFile() throws IOException { setManifest("MANIFEST-Launcher-Http-Verticle.MF"); cli.dispatch(new Launcher(), new String[] {"--conf", "target/test-classes/conf.json"}); assertWaitUntil(() -> { try { return getHttpCode() == 200; } catch (IOException e) { return false; } }); assertThat(getContent().getJsonObject("conf").getString("name")).isEqualToIgnoringCase("vertx"); }
jsonObject.put("obj", (Object)obj); jsonObject.put("arr", (Object)arr); assertEquals("bar", jsonObject.getString("str")); assertEquals(Integer.valueOf(123), jsonObject.getInteger("int")); assertEquals(Long.valueOf(123l), jsonObject.getLong("long")); assertEquals(now, jsonObject.getInstant("instant")); assertEquals(now.toString(), jsonObject.getValue("instant")); assertEquals(obj, jsonObject.getJsonObject("obj")); assertEquals(arr, jsonObject.getJsonArray("arr")); try {
@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 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")); assertArrayEquals(bytes, obj.getBinary("mybinary")); assertEquals(Base64.getEncoder().encodeToString(bytes), obj.getValue("mybinary")); assertEquals(now, obj.getInstant("myinstant")); assertEquals(now.toString(), obj.getValue("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))); }
/** * Create a delivery options from JSON * * @param json the JSON */ public DeliveryOptions(JsonObject json) { this.timeout = json.getLong("timeout", DEFAULT_TIMEOUT); this.codecName = json.getString("codecName", null); JsonObject hdrs = json.getJsonObject("headers", null); if (hdrs != null) { headers = new CaseInsensitiveHeaders(); for (Map.Entry<String, Object> entry: hdrs) { if (!(entry.getValue() instanceof String)) { throw new IllegalStateException("Invalid type for message header value " + entry.getValue().getClass()); } headers.set(entry.getKey(), (String)entry.getValue()); } } this.localOnly = json.getBoolean("localOnly", DEFAULT_LOCAL_ONLY); }
public CustomMetricsOptions(JsonObject json) { value = json.getString("customProperty"); JsonObject nestedOptionsJson = json.getJsonObject("nestedOptions"); this.nestedOptions = nestedOptionsJson == null ? null : new NestedMetricsOptions(nestedOptionsJson); }