Add unit test for InstallableIntents

The following classes are covered:

- PathFlowIntent
- SingleSrcTreeFlowIntent
- SingleDstTreeFlowIntent

Change-Id: I5af927e0ea1bfc5929cb6ea96176b9f9e1a3f72e
diff --git a/src/test/java/net/onrc/onos/core/newintent/PathFlowIntentTest.java b/src/test/java/net/onrc/onos/core/newintent/PathFlowIntentTest.java
new file mode 100644
index 0000000..6c83e86
--- /dev/null
+++ b/src/test/java/net/onrc/onos/core/newintent/PathFlowIntentTest.java
@@ -0,0 +1,53 @@
+package net.onrc.onos.core.newintent;
+
+import net.onrc.onos.api.flowmanager.FlowId;
+import net.onrc.onos.api.flowmanager.PacketPathFlow;
+import net.onrc.onos.api.flowmanager.Path;
+import net.onrc.onos.api.newintent.IntentId;
+import net.onrc.onos.api.newintent.IntentTest;
+import net.onrc.onos.core.matchaction.action.Action;
+import net.onrc.onos.core.matchaction.match.PacketMatch;
+import net.onrc.onos.core.matchaction.match.PacketMatchBuilder;
+import net.onrc.onos.core.util.PortNumber;
+
+import java.util.Collections;
+
+/**
+ * Suite of tests of {@link PathFlowIntent}.
+ */
+public class PathFlowIntentTest extends IntentTest {
+
+    private final IntentId intentId1 = new IntentId(123);
+    private final IntentId intentId2 = new IntentId(456);
+    private final FlowId flowId1 = new FlowId("path1");
+    private final PacketMatch match = new PacketMatchBuilder().build();
+    private final PortNumber port = new PortNumber((short) 1);
+
+    /**
+     * Creates a PathFlowIntent.
+     *
+     * @return PathFlowIntent
+     */
+    @Override
+    protected PathFlowIntent createOne() {
+        return new PathFlowIntent(
+                intentId1,
+                new PacketPathFlow(flowId1, match, port,
+                        new Path(), Collections.<Action>emptyList(), 0, 0)
+        );
+    }
+
+    /**
+     * Creates another PathFlowIntent, which is different from the intent created by {@link #createOne()}.
+     *
+     * @return another PathFlowIntent
+     */
+    @Override
+    protected PathFlowIntent createAnother() {
+        return new PathFlowIntent(
+                intentId2,
+                new PacketPathFlow(flowId1, match, port,
+                        new Path(), Collections.<Action>emptyList(), 0, 0)
+        );
+    }
+}
diff --git a/src/test/java/net/onrc/onos/core/newintent/SingleDstTreeFlowIntentTest.java b/src/test/java/net/onrc/onos/core/newintent/SingleDstTreeFlowIntentTest.java
new file mode 100644
index 0000000..4ad202e
--- /dev/null
+++ b/src/test/java/net/onrc/onos/core/newintent/SingleDstTreeFlowIntentTest.java
@@ -0,0 +1,61 @@
+package net.onrc.onos.core.newintent;
+
+import net.onrc.onos.api.flowmanager.FlowId;
+import net.onrc.onos.api.flowmanager.FlowLink;
+import net.onrc.onos.api.flowmanager.SingleDstTreeFlow;
+import net.onrc.onos.api.flowmanager.Tree;
+import net.onrc.onos.api.newintent.IntentId;
+import net.onrc.onos.api.newintent.IntentTest;
+import net.onrc.onos.core.matchaction.action.Action;
+import net.onrc.onos.core.matchaction.action.OutputAction;
+import net.onrc.onos.core.matchaction.match.PacketMatch;
+import net.onrc.onos.core.matchaction.match.PacketMatchBuilder;
+import net.onrc.onos.core.util.PortNumber;
+import net.onrc.onos.core.util.SwitchPort;
+
+import java.util.Arrays;
+
+/**
+ * Suites of test of {@link SingleDstTreeFlowIntent}.
+ */
+public class SingleDstTreeFlowIntentTest extends IntentTest {
+
+    private final IntentId intentId1 = new IntentId(1L);
+    private final IntentId intentId2 = new IntentId(2L);
+    private final FlowId flowId1 = new FlowId("intent1");
+    private final PacketMatch match = new PacketMatchBuilder().build();
+    private final short port1 = (short) 1;
+    private final short port2 = (short) 2;
+    private final short port3 = (short) 3;
+    private final SwitchPort switchPort1 = new SwitchPort(1, port1);
+    private final SwitchPort switchPort2 = new SwitchPort(2, port2);
+    private final SwitchPort switchPort3 = new SwitchPort(3, port3);
+
+    @Override
+    protected SingleDstTreeFlowIntent createOne() {
+        SingleDstTreeFlow treeFlow = new SingleDstTreeFlow(flowId1,
+                match,
+                Arrays.asList(switchPort1, switchPort2),
+                createTree(),
+                Arrays.asList((Action) new OutputAction(new PortNumber(port3))));
+        return new SingleDstTreeFlowIntent(intentId1, treeFlow);
+    }
+
+    @Override
+    protected SingleDstTreeFlowIntent createAnother() {
+        SingleDstTreeFlow treeFlow = new SingleDstTreeFlow(flowId1,
+                match,
+                Arrays.asList(switchPort1, switchPort3),
+                createTree(),
+                Arrays.asList((Action) new OutputAction(new PortNumber(port2))));
+        return new SingleDstTreeFlowIntent(intentId2, treeFlow);
+    }
+
+    private Tree createTree() {
+        Tree tree = new Tree();
+        tree.add(new FlowLink(switchPort1, switchPort2));
+        tree.add(new FlowLink(switchPort1, switchPort3));
+
+        return tree;
+    }
+}
diff --git a/src/test/java/net/onrc/onos/core/newintent/SingleSrcTreeFlowIntentTest.java b/src/test/java/net/onrc/onos/core/newintent/SingleSrcTreeFlowIntentTest.java
new file mode 100644
index 0000000..3330e47
--- /dev/null
+++ b/src/test/java/net/onrc/onos/core/newintent/SingleSrcTreeFlowIntentTest.java
@@ -0,0 +1,72 @@
+package net.onrc.onos.core.newintent;
+
+import net.onrc.onos.api.flowmanager.FlowId;
+import net.onrc.onos.api.flowmanager.FlowLink;
+import net.onrc.onos.api.flowmanager.SingleSrcTreeFlow;
+import net.onrc.onos.api.flowmanager.Tree;
+import net.onrc.onos.api.newintent.IntentId;
+import net.onrc.onos.api.newintent.IntentTest;
+import net.onrc.onos.core.matchaction.action.OutputAction;
+import net.onrc.onos.core.matchaction.match.PacketMatch;
+import net.onrc.onos.core.matchaction.match.PacketMatchBuilder;
+import net.onrc.onos.core.util.Dpid;
+import net.onrc.onos.core.util.Pair;
+import net.onrc.onos.core.util.PortNumber;
+import net.onrc.onos.core.util.SwitchPort;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * Suites of test of {@link SingleSrcTreeFlowIntent}.
+ */
+public class SingleSrcTreeFlowIntentTest extends IntentTest {
+
+    private final IntentId intentId1 = new IntentId(1L);
+    private final IntentId intentId2 = new IntentId(2L);
+    private final FlowId flowId1 = new FlowId("tree1");
+    private final FlowId flowId2 = new FlowId("tree2");
+    private final Dpid dpid1 = new Dpid(1);
+    private final Dpid dpid2 = new Dpid(2);
+    private final Dpid dpid3 = new Dpid(3);
+    private final PortNumber port1 = PortNumber.uint32(1);
+    private final PortNumber port2 = PortNumber.uint32(2);
+    private final PortNumber port3 = PortNumber.uint32(3);
+    private final OutputAction action1 = new OutputAction(port1);
+    private final OutputAction action2 = new OutputAction(port2);
+    private final OutputAction action3 = new OutputAction(port3);
+    private final PacketMatch match = new PacketMatchBuilder().build();
+
+    @Override
+    protected SingleSrcTreeFlowIntent createOne() {
+        Set<Pair<Dpid, OutputAction>> actions = new HashSet<>(Arrays.asList(
+                new Pair<>(dpid2, action2),
+                new Pair<>(dpid3, action3)
+        ));
+        SingleSrcTreeFlow tree = new SingleSrcTreeFlow(flowId1, match,
+                new SwitchPort(dpid1, port3), createTree(), actions
+        );
+        return new SingleSrcTreeFlowIntent(intentId1, tree);
+    }
+
+    @Override
+    protected SingleSrcTreeFlowIntent createAnother() {
+        Set<Pair<Dpid, OutputAction>> actions = new HashSet<>(Arrays.asList(
+                new Pair<>(dpid1, action1),
+                new Pair<>(dpid3, action3)
+        ));
+        SingleSrcTreeFlow tree = new SingleSrcTreeFlow(flowId2, match,
+                new SwitchPort(dpid2, port3), createTree(), actions
+        );
+        return new SingleSrcTreeFlowIntent(intentId2, tree);
+    }
+
+    private Tree createTree() {
+        Tree tree = new Tree();
+        tree.add(new FlowLink(dpid1, port1, dpid2, port2));
+        tree.add(new FlowLink(dpid1, port2, dpid3, port3));
+
+        return tree;
+    }
+}