Add error logging to PathCalcRuntime

- error logging to PathCalcRuntime
- add IntentOperationListTest
- register Intent class in KryoFactory

Change-Id: Ie3e0302fc8e433aac932cfb7da91ee1111c00212
diff --git a/src/main/java/net/onrc/onos/intent/runtime/PathCalcRuntime.java b/src/main/java/net/onrc/onos/intent/runtime/PathCalcRuntime.java
index 95c63c8..5600e0c 100644
--- a/src/main/java/net/onrc/onos/intent/runtime/PathCalcRuntime.java
+++ b/src/main/java/net/onrc/onos/intent/runtime/PathCalcRuntime.java
@@ -16,11 +16,15 @@
 import net.onrc.onos.ofcontroller.networkgraph.Path;
 import net.onrc.onos.ofcontroller.networkgraph.Switch;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 /**
  * @author Toshio Koide (t-koide@onlab.us)
  */
 public class PathCalcRuntime implements IFloodlightService {
 	private NetworkGraph graph;
+	private final static Logger log = LoggerFactory.getLogger(PathCalcRuntime.class);
 	public PathCalcRuntime(NetworkGraph g) {
 		this.graph = g;
 	}
@@ -39,7 +43,7 @@
 			switch (intentOp.operator) {
 			case ADD:
 				if (!(intentOp.intent instanceof ShortestPathIntent)) {
-					// unsupported intent type.
+					log.error("unsupported intent type: {}", intentOp.intent.getClass().getName());
 					// TODO should push back the intent to caller
 					continue;
 				}
@@ -48,7 +52,9 @@
 				Switch srcSwitch = graph.getSwitch(spIntent.getSrcSwitchDpid());
 				Switch dstSwitch = graph.getSwitch(spIntent.getDstSwitchDpid());
 				if (srcSwitch == null || dstSwitch == null) {
-					// incomplete intent.
+					log.error("Switch not found: {}, {}",
+							spIntent.getSrcSwitchDpid(),
+							spIntent.getDstSwitchDpid());
 					// TODO should push back the intent to caller
 					continue;
 				}
@@ -68,7 +74,7 @@
 				}
 				Path path = tree.getPath(dstSwitch);
 				if (path == null) {
-					// path not found.
+					log.error("Path not found: {}", intentOp.intent.toString());
 					// TODO should push back the intent to caller
 					continue;
 				}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/util/serializers/KryoFactory.java b/src/main/java/net/onrc/onos/ofcontroller/util/serializers/KryoFactory.java
index 7ddf5d8..f65a830 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/util/serializers/KryoFactory.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/util/serializers/KryoFactory.java
@@ -178,6 +178,7 @@
 	kryo.register(IntentOperationList.class);
 	kryo.register(IntentOperation.class);
 	kryo.register(PathIntent.class);
+	kryo.register(Intent.class);
 	kryo.register(ShortestPathIntent.class);
 	kryo.register(ConstrainedShortestPathIntent.class);
 	kryo.register(Intent.IntentState.class);
diff --git a/src/test/java/net/onrc/onos/intent/IntentOperationListTest.java b/src/test/java/net/onrc/onos/intent/IntentOperationListTest.java
new file mode 100644
index 0000000..ad5315b
--- /dev/null
+++ b/src/test/java/net/onrc/onos/intent/IntentOperationListTest.java
@@ -0,0 +1,67 @@
+package net.onrc.onos.intent;
+
+import static org.junit.Assert.assertEquals;
+import net.onrc.onos.ofcontroller.networkgraph.LinkEvent;
+import net.onrc.onos.ofcontroller.networkgraph.Path;
+import net.onrc.onos.ofcontroller.util.serializers.KryoFactory;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.esotericsoftware.kryo.Kryo;
+import com.esotericsoftware.kryo.io.Input;
+import com.esotericsoftware.kryo.io.Output;
+
+public class IntentOperationListTest {
+
+	@Before
+	public void setUp() throws Exception {
+	}
+
+	@After
+	public void tearDown() throws Exception {
+	}
+
+	@Test
+	public void test() {
+		IntentOperationList opList = new IntentOperationList();
+
+		ConstrainedShortestPathIntent cspIntent1 =
+				new ConstrainedShortestPathIntent("1", 2L, 3L, 4L, 5L, 6L, 7L, 1000.0);
+
+		Path path = new Path();
+		path.add(new LinkEvent(1L, 2L, 3L, 4L));
+		path.add(new LinkEvent(5L, 6L, 7L, 8L));
+		path.add(new LinkEvent(9L, 0L, 1L, 2L));
+
+		PathIntent pathIntent1 = new PathIntent("11", path, 123.45, cspIntent1);
+		opList.add(IntentOperation.Operator.ADD, pathIntent1);
+		opList.add(IntentOperation.Operator.REMOVE, new Intent("22"));
+
+		KryoFactory factory = new KryoFactory();
+		Kryo kryo = factory.newKryo();
+		Output output = new Output(1024);
+		kryo.writeObject(output, opList);
+		output.close();
+
+		byte[] bytes = output.toBytes();
+
+		Input input = new Input(bytes);
+		IntentOperationList rcvOpList = kryo.readObject(input, IntentOperationList.class);
+
+		assertEquals(2, rcvOpList.size());
+
+		IntentOperation op1 = rcvOpList.get(0);
+		IntentOperation op2 = rcvOpList.get(1);
+
+		assertEquals(IntentOperation.Operator.ADD, op1.operator);
+		PathIntent intent1 = (PathIntent) op1.intent;
+		assertEquals("11", intent1.getId());
+		assertEquals(3, intent1.getPath().size());
+
+		assertEquals(IntentOperation.Operator.REMOVE, op2.operator);
+		Intent intent2 = op2.intent;
+		assertEquals("22", intent2.getId());
+	}
+}