@Test public void badgedDevice() { Highlights h = new Highlights(); DeviceHighlight dh = new DeviceHighlight(DEV1); dh.setBadge(NodeBadge.number(7)); h.add(dh); dh = new DeviceHighlight(DEV2); dh.setBadge(NodeBadge.glyph(Status.WARN, GID, SOME_MSG)); h.add(dh); payload = TopoJson.json(h); ArrayNode a = (ArrayNode) payload.get(TopoJson.DEVICES); ObjectNode d = (ObjectNode) a.get(0); assertEquals("wrong device id", DEV1, d.get(TopoJson.ID).asText()); ObjectNode b = (ObjectNode) d.get(TopoJson.BADGE); assertNotNull("missing badge", b); assertEquals("wrong status code", "i", b.get(TopoJson.STATUS).asText()); assertEquals("wrong text", "7", b.get(TopoJson.TXT).asText()); assertNull("glyph?", b.get(TopoJson.GID)); assertNull("msg?", b.get(TopoJson.MSG)); d = (ObjectNode) a.get(1); assertEquals("wrong device id", DEV2, d.get(TopoJson.ID).asText()); b = (ObjectNode) d.get(TopoJson.BADGE); assertNotNull("missing badge", b); assertEquals("wrong status code", "w", b.get(TopoJson.STATUS).asText()); assertNull("text?", b.get(TopoJson.TXT)); assertEquals("wrong text", GID, b.get(TopoJson.GID).asText()); assertEquals("wrong message", SOME_MSG, b.get(TopoJson.MSG).asText()); }
public static ObjectNode json(Highlights highlights) { ObjectNode payload = objectNode(); ArrayNode devices = arrayNode(); ArrayNode hosts = arrayNode(); ArrayNode links = arrayNode(); payload.set(DEVICES, devices); payload.set(HOSTS, hosts); payload.set(LINKS, links); highlights.devices().forEach(dh -> devices.add(json(dh))); highlights.hosts().forEach(hh -> hosts.add(json(hh))); highlights.links().forEach(lh -> links.add(json(lh))); Highlights.Amount toSubdue = highlights.subdueLevel(); if (!toSubdue.equals(Highlights.Amount.ZERO)) { payload.put(SUBDUE, toSubdue.toString()); } int delay = highlights.delayMs(); if (delay > 0) { payload.put(DELAY, delay); } return payload; }
TopoJson { public static ObjectNode json(Highlights highlights) { ObjectNode payload = objectNode(); ArrayNode devices = arrayNode(); ArrayNode hosts = arrayNode(); ArrayNode links = arrayNode(); payload.set(DEVICES, devices); payload.set(HOSTS, hosts); payload.set(LINKS, links); highlights.devices().forEach(dh -> devices.add(json(dh))); highlights.hosts().forEach(hh -> hosts.add(json(hh))); highlights.links().forEach(lh -> links.add(json(lh))); Highlights.Amount toSubdue = highlights.subdueLevel(); if (!toSubdue.equals(Highlights.Amount.ZERO)) { payload.put(SUBDUE, toSubdue.toString()); } int delay = highlights.delayMs(); if (delay > 0) { payload.put(DELAY, delay); } return payload; } }
TopoJson { public static ObjectNode json(Highlights highlights) { ObjectNode payload = objectNode(); ArrayNode devices = arrayNode(); ArrayNode hosts = arrayNode(); ArrayNode links = arrayNode(); payload.set(DEVICES, devices); payload.set(HOSTS, hosts); payload.set(LINKS, links); highlights.devices().forEach(dh -> devices.add(json(dh))); highlights.hosts().forEach(hh -> hosts.add(json(hh))); highlights.links().forEach(lh -> links.add(json(lh))); Highlights.Amount toSubdue = highlights.subdueLevel(); if (!toSubdue.equals(Highlights.Amount.ZERO)) { payload.put(SUBDUE, toSubdue.toString()); } int delay = highlights.delayMs(); if (delay > 0) { payload.put(DELAY, delay); } return payload; } private  TopoJson(); }
TopoJson { public static ObjectNode json(Highlights highlights) { ObjectNode payload = objectNode(); ArrayNode devices = arrayNode(); ArrayNode hosts = arrayNode(); ArrayNode links = arrayNode(); payload.set(DEVICES, devices); payload.set(HOSTS, hosts); payload.set(LINKS, links); highlights.devices().forEach(dh -> devices.add(json(dh))); highlights.hosts().forEach(hh -> hosts.add(json(hh))); highlights.links().forEach(lh -> links.add(json(lh))); Highlights.Amount toSubdue = highlights.subdueLevel(); if (!toSubdue.equals(Highlights.Amount.ZERO)) { payload.put(SUBDUE, toSubdue.toString()); } int delay = highlights.delayMs(); if (delay > 0) { payload.put(DELAY, delay); } return payload; } private  TopoJson(); static ObjectNode highlightsMessage(Highlights highlights); static ObjectNode json(Highlights highlights); static ObjectNode json(PropertyPanel pp); }
TopoJson { public static ObjectNode json(Highlights highlights) { ObjectNode payload = objectNode(); ArrayNode devices = arrayNode(); ArrayNode hosts = arrayNode(); ArrayNode links = arrayNode(); payload.set(DEVICES, devices); payload.set(HOSTS, hosts); payload.set(LINKS, links); highlights.devices().forEach(dh -> devices.add(json(dh))); highlights.hosts().forEach(hh -> hosts.add(json(hh))); highlights.links().forEach(lh -> links.add(json(lh))); Highlights.Amount toSubdue = highlights.subdueLevel(); if (!toSubdue.equals(Highlights.Amount.ZERO)) { payload.put(SUBDUE, toSubdue.toString()); } int delay = highlights.delayMs(); if (delay > 0) { payload.put(DELAY, delay); } return payload; } private  TopoJson(); static ObjectNode highlightsMessage(Highlights highlights); static ObjectNode json(Highlights highlights); static ObjectNode json(PropertyPanel pp);  }