Topology REST API modifications and unit tests
- added a Serializer for Topology operations
- added a REST test harness class for Topology tests
- added REST API tests for topology get of all
topology, links, switches, and devices.
Change-Id: I13e3654aad7c0f5af41f07be66da82330933d3a3
diff --git a/src/main/java/net/onrc/onos/core/topology/serializers/TopologySerializer.java b/src/main/java/net/onrc/onos/core/topology/serializers/TopologySerializer.java
new file mode 100644
index 0000000..1bc4ff2
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/topology/serializers/TopologySerializer.java
@@ -0,0 +1,68 @@
+package net.onrc.onos.core.topology.serializers;
+
+import net.onrc.onos.core.topology.Device;
+import net.onrc.onos.core.topology.Link;
+import net.onrc.onos.core.topology.Switch;
+import net.onrc.onos.core.topology.Topology;
+import org.codehaus.jackson.JsonGenerator;
+import org.codehaus.jackson.map.SerializerProvider;
+import org.codehaus.jackson.map.ser.std.SerializerBase;
+
+import java.io.IOException;
+
+/**
+ * JSON serializer for Topology objects. Used by REST implementation of the
+ * topology APIs.
+ */
+public class TopologySerializer extends SerializerBase<Topology> {
+
+ /**
+ * Default constructor. Performs basic initialization of the JSON
+ * serializer.
+ */
+ public TopologySerializer() {
+ super(Topology.class);
+ }
+
+ /**
+ * Serialize a Topology object in JSON. The resulting JSON contains the
+ * switches, links and ports provided by the Topology object.
+ *
+ * @param topology the Topology that is being converted to JSON
+ * @param jsonGenerator generator to place the serialized JSON into
+ * @param serializerProvider unused but required for method override
+ * @throws IOException if the JSON serialization process fails
+ */
+ @Override
+ public void serialize(Topology topology,
+ JsonGenerator jsonGenerator,
+ SerializerProvider serializerProvider)
+ throws IOException {
+ // Start the object
+ jsonGenerator.writeStartObject();
+
+ // Output the switches array
+ jsonGenerator.writeArrayFieldStart("switches");
+ for (final Switch swtch : topology.getSwitches()) {
+ jsonGenerator.writeObject(swtch);
+ }
+ jsonGenerator.writeEndArray();
+
+ // Output the links array
+ jsonGenerator.writeArrayFieldStart("links");
+ for (final Link link : topology.getLinks()) {
+ jsonGenerator.writeObject(link);
+ }
+ jsonGenerator.writeEndArray();
+
+ // Output the devices array
+ jsonGenerator.writeArrayFieldStart("devices");
+ for (final Device device : topology.getDevices()) {
+ jsonGenerator.writeObject(device);
+ }
+ jsonGenerator.writeEndArray();
+
+ // All done
+ jsonGenerator.writeEndObject();
+ }
+}