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/api/newintent/ConnectivityIntentTest.java b/src/test/java/net/onrc/onos/api/newintent/ConnectivityIntentTest.java
index 602ae0e..be84f25 100644
--- a/src/test/java/net/onrc/onos/api/newintent/ConnectivityIntentTest.java
+++ b/src/test/java/net/onrc/onos/api/newintent/ConnectivityIntentTest.java
@@ -5,18 +5,12 @@
import net.onrc.onos.core.matchaction.match.PacketMatchBuilder;
import net.onrc.onos.core.util.SwitchPort;
-import org.junit.Test;
-
-import java.util.Arrays;
-import java.util.HashSet;
import java.util.Set;
-import static org.junit.Assert.*;
-
/**
* Base facilities to test various connectivity tests.
*/
-public abstract class ConnectivityIntentTest {
+public abstract class ConnectivityIntentTest extends IntentTest {
public static final IntentId IID = new IntentId(123);
public static final Match MATCH = (new PacketMatchBuilder()).build();
@@ -28,59 +22,4 @@
public static final Set<SwitchPort> PS1 = itemSet(new SwitchPort[]{P1, P3});
public static final Set<SwitchPort> PS2 = itemSet(new SwitchPort[]{P2, P3});
-
-
- @Test
- public void equalsAndHashCode() {
- Intent one = createOne();
- Intent like = createOne();
- Intent another = createAnother();
-
- assertTrue("should be equal", one.equals(like));
- assertEquals("incorrect hashCode", one.hashCode(), like.hashCode());
-
- assertFalse("should not be equal", one.equals(another));
-
- assertFalse("should not be equal", one.equals(null));
- assertFalse("should not be equal", one.equals("foo"));
- }
-
- @Test
- public void testToString() {
- Intent one = createOne();
- Intent like = createOne();
- assertEquals("incorrect toString", one.toString(), like.toString());
- }
-
- /**
- * Creates a new intent, but always a like intent, i.e. all instances will
- * be equal, but should not be the same.
- *
- * @return intent
- */
- protected abstract Intent createOne();
-
- /**
- * Creates another intent, not equals to the one created by
- * {@link #createOne()} and with a different hash code.
- *
- * @return another intent
- */
- protected abstract Intent createAnother();
-
-
- /**
- * Produces a set of items from the supplied items.
- *
- * @param items items to be placed in set
- * @param <T> item type
- * @return set of items
- */
- private static <T> Set<T> itemSet(T[] items) {
- return new HashSet<>(Arrays.asList(items));
- }
-
- // TODO: move to the match-action related package
- private static class NoAction implements Action {
- }
}
diff --git a/src/test/java/net/onrc/onos/api/newintent/IntentTest.java b/src/test/java/net/onrc/onos/api/newintent/IntentTest.java
new file mode 100644
index 0000000..dd83194
--- /dev/null
+++ b/src/test/java/net/onrc/onos/api/newintent/IntentTest.java
@@ -0,0 +1,70 @@
+package net.onrc.onos.api.newintent;
+
+import net.onrc.onos.core.matchaction.action.Action;
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Base facilities to test various intent tests.
+ */
+public abstract class IntentTest {
+ /**
+ * Produces a set of items from the supplied items.
+ *
+ * @param items items to be placed in set
+ * @param <T> item type
+ * @return set of items
+ */
+ protected static <T> Set<T> itemSet(T[] items) {
+ return new HashSet<>(Arrays.asList(items));
+ }
+
+ @Test
+ public void equalsAndHashCode() {
+ Intent one = createOne();
+ Intent like = createOne();
+ Intent another = createAnother();
+
+ assertTrue("should be equal", one.equals(like));
+ assertEquals("incorrect hashCode", one.hashCode(), like.hashCode());
+
+ assertFalse("should not be equal", one.equals(another));
+
+ assertFalse("should not be equal", one.equals(null));
+ assertFalse("should not be equal", one.equals("foo"));
+ }
+
+ @Test
+ public void testToString() {
+ Intent one = createOne();
+ Intent like = createOne();
+ assertEquals("incorrect toString", one.toString(), like.toString());
+ }
+
+ /**
+ * Creates a new intent, but always a like intent, i.e. all instances will
+ * be equal, but should not be the same.
+ *
+ * @return intent
+ */
+ protected abstract Intent createOne();
+
+ /**
+ * Creates another intent, not equals to the one created by
+ * {@link #createOne()} and with a different hash code.
+ *
+ * @return another intent
+ */
+ protected abstract Intent createAnother();
+
+ // TODO: move to the match-action related package
+ protected static class NoAction implements Action {
+ }
+}