Fix the SDN-IP unit tests after changing the Intent IDs to use
explicit ID assignment.

Change-Id: I50bc20188922193cfa47bf0ec324a69929744745
diff --git a/apps/sdnip/src/test/java/org/onlab/onos/sdnip/IntentSyncTest.java b/apps/sdnip/src/test/java/org/onlab/onos/sdnip/IntentSyncTest.java
index ef7955d..2ab2f68 100644
--- a/apps/sdnip/src/test/java/org/onlab/onos/sdnip/IntentSyncTest.java
+++ b/apps/sdnip/src/test/java/org/onlab/onos/sdnip/IntentSyncTest.java
@@ -36,12 +36,12 @@
 import org.onlab.onos.net.host.HostListener;
 import org.onlab.onos.net.host.HostService;
 import org.onlab.onos.net.host.InterfaceIpAddress;
+import org.onlab.onos.net.intent.AbstractIntentTest;
 import org.onlab.onos.net.intent.Intent;
 import org.onlab.onos.net.intent.IntentOperations;
 import org.onlab.onos.net.intent.IntentService;
 import org.onlab.onos.net.intent.IntentState;
 import org.onlab.onos.net.intent.MultiPointToSinglePointIntent;
-import org.onlab.onos.net.intent.AbstractIntentTest;
 import org.onlab.onos.net.provider.ProviderId;
 import org.onlab.onos.sdnip.config.Interface;
 import org.onlab.packet.Ethernet;
diff --git a/apps/sdnip/src/test/java/org/onlab/onos/sdnip/PeerConnectivityManagerTest.java b/apps/sdnip/src/test/java/org/onlab/onos/sdnip/PeerConnectivityManagerTest.java
index 265a3c0..bd50cce 100644
--- a/apps/sdnip/src/test/java/org/onlab/onos/sdnip/PeerConnectivityManagerTest.java
+++ b/apps/sdnip/src/test/java/org/onlab/onos/sdnip/PeerConnectivityManagerTest.java
@@ -30,11 +30,11 @@
 import org.onlab.onos.net.flow.TrafficSelector;
 import org.onlab.onos.net.flow.TrafficTreatment;
 import org.onlab.onos.net.host.InterfaceIpAddress;
+import org.onlab.onos.net.intent.AbstractIntentTest;
 import org.onlab.onos.net.intent.Intent;
 import org.onlab.onos.net.intent.IntentOperations;
 import org.onlab.onos.net.intent.IntentService;
 import org.onlab.onos.net.intent.PointToPointIntent;
-import org.onlab.onos.net.intent.AbstractIntentTest;
 import org.onlab.onos.sdnip.bgp.BgpConstants;
 import org.onlab.onos.sdnip.config.BgpPeer;
 import org.onlab.onos.sdnip.config.BgpSpeaker;
diff --git a/apps/sdnip/src/test/java/org/onlab/onos/sdnip/RouterTest.java b/apps/sdnip/src/test/java/org/onlab/onos/sdnip/RouterTest.java
index 12fc6cb..f15d50f 100644
--- a/apps/sdnip/src/test/java/org/onlab/onos/sdnip/RouterTest.java
+++ b/apps/sdnip/src/test/java/org/onlab/onos/sdnip/RouterTest.java
@@ -31,7 +31,6 @@
 import java.util.Set;
 
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.onlab.junit.TestUtils;
 import org.onlab.junit.TestUtils.TestUtilsException;
@@ -50,10 +49,12 @@
 import org.onlab.onos.net.host.HostListener;
 import org.onlab.onos.net.host.HostService;
 import org.onlab.onos.net.host.InterfaceIpAddress;
+import org.onlab.onos.net.intent.Intent;
 import org.onlab.onos.net.intent.IntentService;
 import org.onlab.onos.net.intent.MultiPointToSinglePointIntent;
 import org.onlab.onos.net.intent.AbstractIntentTest;
 import org.onlab.onos.net.provider.ProviderId;
+import org.onlab.onos.sdnip.IntentSynchronizer.IntentKey;
 import org.onlab.onos.sdnip.config.BgpPeer;
 import org.onlab.onos.sdnip.config.Interface;
 import org.onlab.onos.sdnip.config.SdnIpConfigService;
@@ -232,7 +233,7 @@
     /**
      * This method tests adding a route entry.
      */
-    @Test @Ignore("needs fix from intents")
+    @Test
     public void testProcessRouteAdd() throws TestUtilsException {
         // Construct a route entry
         RouteEntry routeEntry = new RouteEntry(
@@ -260,7 +261,7 @@
 
         // Set up test expectation
         reset(intentService);
-        intentService.submit(intent);
+        intentService.submit(TestIntentServiceHelper.eqExceptId(intent));
         replay(intentService);
 
         // Call the processRouteAdd() method in Router class
@@ -272,8 +273,11 @@
         assertEquals(router.getRoutes().size(), 1);
         assertTrue(router.getRoutes().contains(routeEntry));
         assertEquals(intentSynchronizer.getRouteIntents().size(), 1);
-        assertEquals(intentSynchronizer.getRouteIntents().iterator().next(),
-                intent);
+        Intent firstIntent =
+            intentSynchronizer.getRouteIntents().iterator().next();
+        IntentKey firstIntentKey = new IntentKey(firstIntent);
+        IntentKey intentKey = new IntentKey(intent);
+        assertTrue(firstIntentKey.equals(intentKey));
         verify(intentService);
     }
 
@@ -282,7 +286,7 @@
      *
      * @throws TestUtilsException
      */
-    @Test @Ignore("needs fix from intents")
+    @Test
     public void testRouteUpdate() throws TestUtilsException {
         // Firstly add a route
         testProcessRouteAdd();
@@ -339,8 +343,8 @@
 
         // Set up test expectation
         reset(intentService);
-        intentService.withdraw(intent);
-        intentService.submit(intentNew);
+        intentService.withdraw(TestIntentServiceHelper.eqExceptId(intent));
+        intentService.submit(TestIntentServiceHelper.eqExceptId(intentNew));
         replay(intentService);
 
         // Call the processRouteAdd() method in Router class
@@ -352,15 +356,18 @@
         assertEquals(router.getRoutes().size(), 1);
         assertTrue(router.getRoutes().contains(routeEntryUpdate));
         assertEquals(intentSynchronizer.getRouteIntents().size(), 1);
-        assertEquals(intentSynchronizer.getRouteIntents().iterator().next(),
-                intentNew);
+        Intent firstIntent =
+            intentSynchronizer.getRouteIntents().iterator().next();
+        IntentKey firstIntentKey = new IntentKey(firstIntent);
+        IntentKey intentNewKey = new IntentKey(intentNew);
+        assertTrue(firstIntentKey.equals(intentNewKey));
         verify(intentService);
     }
 
     /**
      * This method tests deleting a route entry.
      */
-    @Test @Ignore("needs fix from intents")
+    @Test
     public void testProcessRouteDelete() throws TestUtilsException {
         // Firstly add a route
         testProcessRouteAdd();
@@ -391,7 +398,7 @@
 
         // Set up expectation
         reset(intentService);
-        intentService.withdraw(intent);
+        intentService.withdraw(TestIntentServiceHelper.eqExceptId(intent));
         replay(intentService);
 
         // Call route deleting method in Router class
diff --git a/apps/sdnip/src/test/java/org/onlab/onos/sdnip/RouterTestWithAsyncArp.java b/apps/sdnip/src/test/java/org/onlab/onos/sdnip/RouterTestWithAsyncArp.java
index 4000158..0e1226e 100644
--- a/apps/sdnip/src/test/java/org/onlab/onos/sdnip/RouterTestWithAsyncArp.java
+++ b/apps/sdnip/src/test/java/org/onlab/onos/sdnip/RouterTestWithAsyncArp.java
@@ -31,7 +31,6 @@
 import java.util.concurrent.ConcurrentHashMap;
 
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.onlab.junit.TestUtils;
 import org.onlab.junit.TestUtils.TestUtilsException;
@@ -50,10 +49,12 @@
 import org.onlab.onos.net.host.HostEvent;
 import org.onlab.onos.net.host.HostService;
 import org.onlab.onos.net.host.InterfaceIpAddress;
+import org.onlab.onos.net.intent.Intent;
 import org.onlab.onos.net.intent.IntentService;
 import org.onlab.onos.net.intent.MultiPointToSinglePointIntent;
 import org.onlab.onos.net.intent.AbstractIntentTest;
 import org.onlab.onos.net.provider.ProviderId;
+import org.onlab.onos.sdnip.IntentSynchronizer.IntentKey;
 import org.onlab.onos.sdnip.Router.InternalHostListener;
 import org.onlab.onos.sdnip.config.BgpPeer;
 import org.onlab.onos.sdnip.config.Interface;
@@ -194,7 +195,7 @@
     /**
      * This method tests adding a route entry.
      */
-    @Test @Ignore("needs fix from intents")
+    @Test
     public void testProcessRouteAdd() throws TestUtilsException {
 
         // Construct a route entry
@@ -213,7 +214,7 @@
         replay(hostService);
 
         reset(intentService);
-        intentService.submit(intent);
+        intentService.submit(TestIntentServiceHelper.eqExceptId(intent));
         replay(intentService);
 
         // Call the processRouteAdd() method in Router class
@@ -234,8 +235,11 @@
         assertEquals(router.getRoutes().size(), 1);
         assertTrue(router.getRoutes().contains(routeEntry));
         assertEquals(intentSynchronizer.getRouteIntents().size(), 1);
-        assertEquals(intentSynchronizer.getRouteIntents().iterator().next(),
-                     intent);
+        Intent firstIntent =
+            intentSynchronizer.getRouteIntents().iterator().next();
+        IntentKey firstIntentKey = new IntentKey(firstIntent);
+        IntentKey intentKey = new IntentKey(intent);
+        assertTrue(firstIntentKey.equals(intentKey));
         verify(intentService);
         verify(hostService);
 
@@ -246,7 +250,7 @@
      *
      * @throws TestUtilsException
      */
-    @Test @Ignore("needs fix from intents")
+    @Test
     public void testRouteUpdate() throws TestUtilsException {
 
         // Construct the existing route entry
@@ -295,8 +299,8 @@
         replay(hostService);
 
         reset(intentService);
-        intentService.withdraw(intent);
-        intentService.submit(intentNew);
+        intentService.withdraw(TestIntentServiceHelper.eqExceptId(intent));
+        intentService.submit(TestIntentServiceHelper.eqExceptId(intentNew));
         replay(intentService);
 
         // Call the processRouteAdd() method in Router class
@@ -317,8 +321,11 @@
         assertEquals(router.getRoutes().size(), 1);
         assertTrue(router.getRoutes().contains(routeEntryUpdate));
         assertEquals(intentSynchronizer.getRouteIntents().size(), 1);
-        assertEquals(intentSynchronizer.getRouteIntents().iterator().next(),
-                intentNew);
+        Intent firstIntent =
+            intentSynchronizer.getRouteIntents().iterator().next();
+        IntentKey firstIntentKey = new IntentKey(firstIntent);
+        IntentKey intentNewKey = new IntentKey(intentNew);
+        assertTrue(firstIntentKey.equals(intentNewKey));
         verify(intentService);
         verify(hostService);
     }
@@ -344,7 +351,7 @@
 
         // Set up expectation
         reset(intentService);
-        intentService.withdraw(intent);
+        intentService.withdraw(TestIntentServiceHelper.eqExceptId(intent));
         replay(intentService);
 
         // Call route deleting method in Router class
diff --git a/apps/sdnip/src/test/java/org/onlab/onos/sdnip/SdnIpTest.java b/apps/sdnip/src/test/java/org/onlab/onos/sdnip/SdnIpTest.java
index 0078650..ab26766 100644
--- a/apps/sdnip/src/test/java/org/onlab/onos/sdnip/SdnIpTest.java
+++ b/apps/sdnip/src/test/java/org/onlab/onos/sdnip/SdnIpTest.java
@@ -22,7 +22,6 @@
 
 import org.easymock.IAnswer;
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 import org.onlab.junit.IntegrationTest;
@@ -200,7 +199,7 @@
      * @throws InterruptedException if interrupted while waiting on a latch
      * @throws TestUtilsException if exceptions when using TestUtils
      */
-    @Test @Ignore("needs fix from intents")
+    @Test
     public void testAddRoutes() throws InterruptedException, TestUtilsException {
         int numRoutes = 100;
 
@@ -220,7 +219,7 @@
             MultiPointToSinglePointIntent intent = getIntentForUpdate(update,
                     generateMacAddress(nextHopAddress),
                     egressConnectPoint);
-            intentService.submit(intent);
+            intentService.submit(TestIntentServiceHelper.eqExceptId(intent));
 
             expectLastCall().andAnswer(new IAnswer<Object>() {
                 @Override
@@ -262,7 +261,7 @@
      * @throws InterruptedException if interrupted while waiting on a latch
      * @throws TestUtilsException exceptions when using TestUtils
      */
-    @Test @Ignore("needs fix from intents")
+    @Test
     public void testDeleteRoutes() throws InterruptedException, TestUtilsException {
         int numRoutes = 100;
         List<RouteUpdate> routeUpdates = generateRouteUpdates(numRoutes);
@@ -281,7 +280,7 @@
             MultiPointToSinglePointIntent intent = getIntentForUpdate(update,
                     generateMacAddress(nextHopAddress),
                     egressConnectPoint);
-            intentService.submit(intent);
+            intentService.submit(TestIntentServiceHelper.eqExceptId(intent));
             expectLastCall().andAnswer(new IAnswer<Object>() {
                 @Override
                 public Object answer() throws Throwable {
@@ -289,7 +288,7 @@
                     return null;
                 }
             }).once();
-            intentService.withdraw(intent);
+            intentService.withdraw(TestIntentServiceHelper.eqExceptId(intent));
             expectLastCall().andAnswer(new IAnswer<Object>() {
                 @Override
                 public Object answer() throws Throwable {
diff --git a/apps/sdnip/src/test/java/org/onlab/onos/sdnip/TestIntentServiceHelper.java b/apps/sdnip/src/test/java/org/onlab/onos/sdnip/TestIntentServiceHelper.java
index 4cc9053..3ea8b02 100644
--- a/apps/sdnip/src/test/java/org/onlab/onos/sdnip/TestIntentServiceHelper.java
+++ b/apps/sdnip/src/test/java/org/onlab/onos/sdnip/TestIntentServiceHelper.java
@@ -5,10 +5,10 @@
 
 import org.apache.commons.collections4.CollectionUtils;
 import org.easymock.IArgumentMatcher;
+import org.onlab.onos.net.intent.Intent;
 import org.onlab.onos.net.intent.IntentId;
 import org.onlab.onos.net.intent.IntentOperation;
 import org.onlab.onos.net.intent.IntentOperations;
-import org.onlab.onos.net.intent.PointToPointIntent;
 import org.onlab.onos.sdnip.IntentSynchronizer.IntentKey;
 
 import static org.easymock.EasyMock.reportMatcher;
@@ -24,6 +24,18 @@
     }
 
     /**
+     * Matcher method to set the expected intent to match against
+     * (ignoring the intent ID for the intent).
+     *
+     * @param intent the expected Intent
+     * @return the submitted Intent
+     */
+    static Intent eqExceptId(Intent intent) {
+        reportMatcher(new IdAgnosticIntentMatcher(intent));
+        return intent;
+    }
+
+    /**
      * Matcher method to set the expected intent operations to match against
      * (ignoring the intent ID for each intent).
      *
@@ -35,18 +47,51 @@
         return intentOperations;
     }
 
-
-    /**
-     * Matcher method to set an expected point-to-point intent to match
-     * against (ignoring the intent ID).
-     *
-     * @param intent the expected point-to-point intent
-     * @return the submitted point-to-point intent
+    /*
+     * EasyMock matcher that matches {@link Inten} but
+     * ignores the {@link IntentId} when matching.
+     * <p/>
+     * The normal intent equals method tests that the intent IDs are equal,
+     * however in these tests we can't know what the intent IDs will be in
+     * advance, so we can't set up expected intents with the correct IDs. Thus,
+     * the solution is to use an EasyMock matcher that verifies that all the
+     * value properties of the provided intent match the expected values, but
+     * ignores the intent ID when testing equality.
      */
-    private static PointToPointIntent eqExceptId(
-            PointToPointIntent intent) {
-        reportMatcher(new IdAgnosticPointToPointIntentMatcher(intent));
-        return intent;
+    private static final class IdAgnosticIntentMatcher implements
+                IArgumentMatcher {
+
+        private final Intent intent;
+        private String providedString;
+
+        /**
+         * Constructor taking the expected intent to match against.
+         *
+         * @param intent the expected intent
+         */
+        public IdAgnosticIntentMatcher(Intent intent) {
+            this.intent = intent;
+        }
+
+        @Override
+        public void appendTo(StringBuffer strBuffer) {
+            strBuffer.append("IntentMatcher unable to match: "
+                    + providedString);
+        }
+
+        @Override
+        public boolean matches(Object object) {
+            if (!(object instanceof Intent)) {
+                return false;
+            }
+
+            Intent providedIntent = (Intent) object;
+            providedString = providedIntent.toString();
+
+            IntentKey thisIntentKey = new IntentKey(intent);
+            IntentKey providedIntentKey = new IntentKey(providedIntent);
+            return thisIntentKey.equals(providedIntentKey);
+        }
     }
 
     /*
@@ -160,54 +205,4 @@
             }
         }
     }
-
-    /*
-     * EasyMock matcher that matches {@link PointToPointIntent}s but
-     * ignores the {@link IntentId} when matching.
-     * <p/>
-     * The normal intent equals method tests that the intent IDs are equal,
-     * however in these tests we can't know what the intent IDs will be in
-     * advance, so we can't set up expected intents with the correct IDs. Thus,
-     * the solution is to use an EasyMock matcher that verifies that all the
-     * value properties of the provided intent match the expected values, but
-     * ignores the intent ID when testing equality.
-     */
-    private static final class IdAgnosticPointToPointIntentMatcher implements
-                IArgumentMatcher {
-
-        private final PointToPointIntent intent;
-        private String providedIntentString;
-
-        /**
-         * Constructor taking the expected intent to match against.
-         *
-         * @param intent the expected intent
-         */
-        public IdAgnosticPointToPointIntentMatcher(PointToPointIntent intent) {
-            this.intent = intent;
-        }
-
-        @Override
-        public void appendTo(StringBuffer strBuffer) {
-            strBuffer.append("PointToPointIntentMatcher unable to match: "
-                    + providedIntentString);
-        }
-
-        @Override
-        public boolean matches(Object object) {
-            if (!(object instanceof PointToPointIntent)) {
-                return false;
-            }
-
-            PointToPointIntent providedIntent = (PointToPointIntent) object;
-            providedIntentString = providedIntent.toString();
-
-            PointToPointIntent matchIntent =
-                    new PointToPointIntent(providedIntent.appId(),
-                            intent.selector(), intent.treatment(),
-                            intent.ingressPoint(), intent.egressPoint());
-
-            return matchIntent.equals(providedIntent);
-        }
-    }
 }