Unit tests for Instruction and Ethernet codecs
Added tests for codecs for Ethernet and Instruction classes
Also fixed some bugs uncovered by the tests
Change-Id: I29f82d169e81b3fca417f88fab992148bf36dc71
diff --git a/web/api/src/main/java/org/onosproject/codec/impl/EthernetCodec.java b/web/api/src/main/java/org/onosproject/codec/impl/EthernetCodec.java
index 1bacec2..c426a46 100644
--- a/web/api/src/main/java/org/onosproject/codec/impl/EthernetCodec.java
+++ b/web/api/src/main/java/org/onosproject/codec/impl/EthernetCodec.java
@@ -36,13 +36,23 @@
public ObjectNode encode(Ethernet ethernet, CodecContext context) {
checkNotNull(ethernet, "Ethernet cannot be null");
- return context.mapper().createObjectNode()
- .put("destinationMacAddress", ethernet.getDestinationMAC().toString())
- .put("sourceMacAddress", ethernet.getSourceMAC().toString())
- .put("priorityCode", ethernet.getPriorityCode())
+ final ObjectNode result = context.mapper().createObjectNode()
.put("vlanId", ethernet.getVlanID())
.put("etherType", ethernet.getEtherType())
+ .put("priorityCode", ethernet.getPriorityCode())
.put("pad", ethernet.isPad());
+
+ if (ethernet.getDestinationMAC() != null) {
+ result.put("destMac",
+ ethernet.getDestinationMAC().toString());
+ }
+
+ if (ethernet.getSourceMAC() != null) {
+ result.put("srcMac",
+ ethernet.getSourceMAC().toString());
+ }
+
+ return result;
}
}