Make test intent types serializable by Kryo

- Move test intent types from inner class to onos.core.newintent package
- Register test intent types to Kryo

Change-Id: I908e7224e50da293e8fb0ac7b4910b9de778d610
diff --git a/src/main/java/net/onrc/onos/core/newintent/TestIntent.java b/src/main/java/net/onrc/onos/core/newintent/TestIntent.java
new file mode 100644
index 0000000..f401759
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/newintent/TestIntent.java
@@ -0,0 +1,30 @@
+package net.onrc.onos.core.newintent;
+
+import net.onrc.onos.api.newintent.AbstractIntent;
+import net.onrc.onos.api.newintent.InstallableIntent;
+import net.onrc.onos.api.newintent.IntentId;
+
+/**
+ * A intent used in the unit test.
+ *
+ * FIXME: we don't want to expose this class publicly, but the current Kryo
+ * serialization mechanism does not allow this class to be private and placed
+ * on testing directory.
+ */
+public class TestIntent extends AbstractIntent implements InstallableIntent {
+    /**
+     * Constructs an instance with the specified intent ID.
+     *
+     * @param id intent ID
+     */
+    public TestIntent(IntentId id) {
+        super(id);
+    }
+
+    /**
+     * Constructor for serializer.
+     */
+    protected TestIntent() {
+        super();
+    }
+}
diff --git a/src/main/java/net/onrc/onos/core/newintent/TestSubclassIntent.java b/src/main/java/net/onrc/onos/core/newintent/TestSubclassIntent.java
new file mode 100644
index 0000000..815d317
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/newintent/TestSubclassIntent.java
@@ -0,0 +1,28 @@
+package net.onrc.onos.core.newintent;
+
+import net.onrc.onos.api.newintent.IntentId;
+
+/**
+ * A intent used in the unit test.
+ *
+ * FIXME: we don't want to expose this class publicly, but the current Kryo
+ * serialization mechanism does not allow this class to be private and placed
+ * on testing directory.
+ */
+public class TestSubclassIntent extends TestIntent {
+    /**
+     * Constructs an instance with the specified intent ID.
+     *
+     * @param id intent ID
+     */
+    public TestSubclassIntent(IntentId id) {
+        super(id);
+    }
+
+    /**
+     * Constructor for serializer.
+     */
+    protected TestSubclassIntent() {
+        super();
+    }
+}
diff --git a/src/main/java/net/onrc/onos/core/util/serializers/KryoFactory.java b/src/main/java/net/onrc/onos/core/util/serializers/KryoFactory.java
index dde06f6..69c0b1a 100644
--- a/src/main/java/net/onrc/onos/core/util/serializers/KryoFactory.java
+++ b/src/main/java/net/onrc/onos/core/util/serializers/KryoFactory.java
@@ -38,6 +38,8 @@
 import net.onrc.onos.core.newintent.PathFlowIntent;
 import net.onrc.onos.core.newintent.SingleDstTreeFlowIntent;
 import net.onrc.onos.core.newintent.SingleSrcTreeFlowIntent;
+import net.onrc.onos.core.newintent.TestIntent;
+import net.onrc.onos.core.newintent.TestSubclassIntent;
 import net.onrc.onos.core.packetservice.BroadcastPacketOutNotification;
 import net.onrc.onos.core.packetservice.PacketOutNotification;
 import net.onrc.onos.core.packetservice.SinglePacketOutNotification;
@@ -224,6 +226,12 @@
         kryo.register(SingleDstTreeFlowIntent.class);
         kryo.register(PacketConnectivityIntent.class);
         kryo.register(OpticalConnectivityIntent.class);
+        // FIXME: due to lack of functionality to register a serializer
+        // in API user side, we added the following two classes.
+        // Theoretically the classes are only for test. we should create
+        // a way to register serializer without editing source code
+        kryo.register(TestIntent.class);
+        kryo.register(TestSubclassIntent.class);
 
         // Host-related classes
         kryo.register(HashSet.class);
diff --git a/src/test/java/net/onrc/onos/api/newintent/IntentServiceTest.java b/src/test/java/net/onrc/onos/api/newintent/IntentServiceTest.java
index 5fce2b6..852ef68 100644
--- a/src/test/java/net/onrc/onos/api/newintent/IntentServiceTest.java
+++ b/src/test/java/net/onrc/onos/api/newintent/IntentServiceTest.java
@@ -1,5 +1,7 @@
 package net.onrc.onos.api.newintent;
 
+import net.onrc.onos.core.newintent.TestIntent;
+import net.onrc.onos.core.newintent.TestSubclassIntent;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -256,18 +258,6 @@
         }
     }
 
-    private class TestIntent extends AbstractIntent implements InstallableIntent {
-        TestIntent(IntentId id) {
-            super(id);
-        }
-    }
-
-    private class TestSubclassIntent extends TestIntent {
-        TestSubclassIntent(IntentId id) {
-            super(id);
-        }
-    }
-
     // Controllable compiler
     private class TestCompiler implements IntentCompiler<TestIntent> {
         private final boolean fail;