GUI Topo -- added NodeBadge field to NodeHighlight.
- updated TopoJson to include device badge in JSON output. Change-Id: I7fc0ec226c378a0395cd1eec765cb7bc867f9100
Showing
4 changed files
with
81 additions
and
6 deletions
| ... | @@ -17,16 +17,16 @@ | ... | @@ -17,16 +17,16 @@ |
| 17 | package org.onosproject.ui.topo; | 17 | package org.onosproject.ui.topo; |
| 18 | 18 | ||
| 19 | /** | 19 | /** |
| 20 | - * Denotes the highlighting to apply to a device. | 20 | + * Denotes the highlighting to be applied to a device. |
| 21 | */ | 21 | */ |
| 22 | public class DeviceHighlight extends NodeHighlight { | 22 | public class DeviceHighlight extends NodeHighlight { |
| 23 | 23 | ||
| 24 | + /** | ||
| 25 | + * Constructs a device highlight entity. | ||
| 26 | + * | ||
| 27 | + * @param deviceId the device identifier | ||
| 28 | + */ | ||
| 24 | public DeviceHighlight(String deviceId) { | 29 | public DeviceHighlight(String deviceId) { |
| 25 | super(TopoElementType.DEVICE, deviceId); | 30 | super(TopoElementType.DEVICE, deviceId); |
| 26 | } | 31 | } |
| 27 | - | ||
| 28 | - // TODO: implement device highlighting: | ||
| 29 | - // - visual highlight | ||
| 30 | - // - badging | ||
| 31 | - | ||
| 32 | } | 32 | } | ... | ... |
| ... | @@ -20,7 +20,34 @@ package org.onosproject.ui.topo; | ... | @@ -20,7 +20,34 @@ package org.onosproject.ui.topo; |
| 20 | * Parent class of {@link DeviceHighlight} and {@link HostHighlight}. | 20 | * Parent class of {@link DeviceHighlight} and {@link HostHighlight}. |
| 21 | */ | 21 | */ |
| 22 | public abstract class NodeHighlight extends AbstractHighlight { | 22 | public abstract class NodeHighlight extends AbstractHighlight { |
| 23 | + | ||
| 24 | + private NodeBadge badge; | ||
| 25 | + | ||
| 26 | + /** | ||
| 27 | + * Constructs a node highlight entity. | ||
| 28 | + * | ||
| 29 | + * @param type element type | ||
| 30 | + * @param elementId element identifier | ||
| 31 | + */ | ||
| 23 | public NodeHighlight(TopoElementType type, String elementId) { | 32 | public NodeHighlight(TopoElementType type, String elementId) { |
| 24 | super(type, elementId); | 33 | super(type, elementId); |
| 25 | } | 34 | } |
| 35 | + | ||
| 36 | + /** | ||
| 37 | + * Sets the badge for this node. | ||
| 38 | + * | ||
| 39 | + * @param badge badge to apply | ||
| 40 | + */ | ||
| 41 | + public void setBadge(NodeBadge badge) { | ||
| 42 | + this.badge = badge; | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + /** | ||
| 46 | + * Returns the badge for this node, if any. | ||
| 47 | + * | ||
| 48 | + * @return badge, or null | ||
| 49 | + */ | ||
| 50 | + public NodeBadge badge() { | ||
| 51 | + return badge; | ||
| 52 | + } | ||
| 26 | } | 53 | } | ... | ... |
| ... | @@ -37,6 +37,8 @@ public final class TopoJson { | ... | @@ -37,6 +37,8 @@ public final class TopoJson { |
| 37 | static final String ID = "id"; | 37 | static final String ID = "id"; |
| 38 | static final String LABEL = "label"; | 38 | static final String LABEL = "label"; |
| 39 | static final String CSS = "css"; | 39 | static final String CSS = "css"; |
| 40 | + static final String BADGE = "badge"; | ||
| 41 | + static final String MSG = "msg"; | ||
| 40 | 42 | ||
| 41 | static final String TITLE = "title"; | 43 | static final String TITLE = "title"; |
| 42 | static final String TYPE = "type"; | 44 | static final String TYPE = "type"; |
| ... | @@ -103,6 +105,13 @@ public final class TopoJson { | ... | @@ -103,6 +105,13 @@ public final class TopoJson { |
| 103 | if (dh.subdued()) { | 105 | if (dh.subdued()) { |
| 104 | n.put(SUBDUE, true); | 106 | n.put(SUBDUE, true); |
| 105 | } | 107 | } |
| 108 | + NodeBadge badge = dh.badge(); | ||
| 109 | + if (badge != null) { | ||
| 110 | + ObjectNode b = objectNode() | ||
| 111 | + .put(TYPE, badge.type().code()) | ||
| 112 | + .put(MSG, badge.message()); | ||
| 113 | + n.set(BADGE, b); | ||
| 114 | + } | ||
| 106 | return n; | 115 | return n; |
| 107 | } | 116 | } |
| 108 | 117 | ... | ... |
| ... | @@ -23,12 +23,17 @@ import org.onosproject.ui.JsonUtils; | ... | @@ -23,12 +23,17 @@ import org.onosproject.ui.JsonUtils; |
| 23 | import org.onosproject.ui.topo.Highlights.Amount; | 23 | import org.onosproject.ui.topo.Highlights.Amount; |
| 24 | 24 | ||
| 25 | import static org.junit.Assert.assertEquals; | 25 | import static org.junit.Assert.assertEquals; |
| 26 | +import static org.junit.Assert.assertNotNull; | ||
| 26 | 27 | ||
| 27 | /** | 28 | /** |
| 28 | * Unit tests for {@link TopoJson}. | 29 | * Unit tests for {@link TopoJson}. |
| 29 | */ | 30 | */ |
| 30 | public class TopoJsonTest { | 31 | public class TopoJsonTest { |
| 31 | 32 | ||
| 33 | + private static final String DEV1 = "device-1"; | ||
| 34 | + private static final String DEV2 = "device-2"; | ||
| 35 | + private static final String BADGE_MSG = "Hello there"; | ||
| 36 | + | ||
| 32 | private ObjectNode payload; | 37 | private ObjectNode payload; |
| 33 | 38 | ||
| 34 | private void checkArrayLength(String key, int expLen) { | 39 | private void checkArrayLength(String key, int expLen) { |
| ... | @@ -68,4 +73,38 @@ public class TopoJsonTest { | ... | @@ -68,4 +73,38 @@ public class TopoJsonTest { |
| 68 | String subdue = JsonUtils.string(payload, TopoJson.SUBDUE); | 73 | String subdue = JsonUtils.string(payload, TopoJson.SUBDUE); |
| 69 | assertEquals("not max", "max", subdue); | 74 | assertEquals("not max", "max", subdue); |
| 70 | } | 75 | } |
| 76 | + | ||
| 77 | + @Test | ||
| 78 | + public void badgedDevice() { | ||
| 79 | + Highlights h = new Highlights(); | ||
| 80 | + DeviceHighlight dh = new DeviceHighlight(DEV1); | ||
| 81 | + dh.setBadge(NodeBadge.info(BADGE_MSG)); | ||
| 82 | + h.add(dh); | ||
| 83 | + | ||
| 84 | + dh = new DeviceHighlight(DEV2); | ||
| 85 | + dh.setBadge(NodeBadge.number(7)); | ||
| 86 | + h.add(dh); | ||
| 87 | + | ||
| 88 | + payload = TopoJson.json(h); | ||
| 89 | + System.out.println(payload); | ||
| 90 | + | ||
| 91 | + // dig into the payload, and verify the badges are set on the devices | ||
| 92 | + ArrayNode a = (ArrayNode) payload.get(TopoJson.DEVICES); | ||
| 93 | + | ||
| 94 | + ObjectNode d = (ObjectNode) a.get(0); | ||
| 95 | + assertEquals("wrong device id", DEV1, d.get(TopoJson.ID).asText()); | ||
| 96 | + | ||
| 97 | + ObjectNode b = (ObjectNode) d.get(TopoJson.BADGE); | ||
| 98 | + assertNotNull("missing badge", b); | ||
| 99 | + assertEquals("wrong type code", "i", b.get(TopoJson.TYPE).asText()); | ||
| 100 | + assertEquals("wrong message", BADGE_MSG, b.get(TopoJson.MSG).asText()); | ||
| 101 | + | ||
| 102 | + d = (ObjectNode) a.get(1); | ||
| 103 | + assertEquals("wrong device id", DEV2, d.get(TopoJson.ID).asText()); | ||
| 104 | + | ||
| 105 | + b = (ObjectNode) d.get(TopoJson.BADGE); | ||
| 106 | + assertNotNull("missing badge", b); | ||
| 107 | + assertEquals("wrong type code", "n", b.get(TopoJson.TYPE).asText()); | ||
| 108 | + assertEquals("wrong message", "7", b.get(TopoJson.MSG).asText()); | ||
| 109 | + } | ||
| 71 | } | 110 | } | ... | ... |
-
Please register or login to post a comment