Enable Intents REST DELETE tests

Enable the Intents REST API delete tests.  Added code to the tests that will
trigger the backend deletion of the intents.

Change-Id: Ifca2dd06ecd24de9ed9483ad33159c7a989c03b5
diff --git a/src/test/java/net/onrc/onos/api/rest/TestRestIntent.java b/src/test/java/net/onrc/onos/api/rest/TestRestIntent.java
index b229121..8d6dafd 100644
--- a/src/test/java/net/onrc/onos/api/rest/TestRestIntent.java
+++ b/src/test/java/net/onrc/onos/api/rest/TestRestIntent.java
@@ -2,7 +2,9 @@
 
 import net.floodlightcontroller.core.module.FloodlightModuleContext;
 import net.floodlightcontroller.core.module.FloodlightModuleException;
+import net.onrc.onos.core.intent.Intent;
 import net.onrc.onos.core.intent.runtime.IPathCalcRuntimeService;
+import net.onrc.onos.core.intent.runtime.IntentStateList;
 import net.onrc.onos.core.intent.runtime.IntentTestMocks;
 import net.onrc.onos.core.intent.runtime.PathCalcRuntimeModule;
 import net.onrc.onos.core.intent.runtime.web.IntentWebRoutable;
@@ -163,4 +165,19 @@
     Map<String, String> getIntent(final ClientResource client) {
         return client.get(Map.class);
     }
+
+    /**
+     * Modify the state of an intent by directly calling the Intent state
+     * machine.  Needed in unit tests because of mocking of back end
+     * components.
+     *
+     * @param intentId id of the intent to modify
+     * @param newState assign this state to the intent
+     */
+    public void modifyIntentState(final String intentId,
+                                  final Intent.IntentState newState) {
+        final IntentStateList intentStateList = new IntentStateList();
+        intentStateList.put(intentId, newState);
+        getRuntime().entryUpdated(intentStateList);
+    }
 }
diff --git a/src/test/java/net/onrc/onos/api/rest/TestRestIntentHighDelete.java b/src/test/java/net/onrc/onos/api/rest/TestRestIntentHighDelete.java
index fbfe471..89ab771 100644
--- a/src/test/java/net/onrc/onos/api/rest/TestRestIntentHighDelete.java
+++ b/src/test/java/net/onrc/onos/api/rest/TestRestIntentHighDelete.java
@@ -1,5 +1,6 @@
 package net.onrc.onos.api.rest;
 
+import net.onrc.onos.core.intent.Intent;
 import net.onrc.onos.core.intent.IntentOperation;
 import net.onrc.onos.core.intent.IntentOperationList;
 import net.onrc.onos.core.intent.ShortestPathIntent;
@@ -86,7 +87,7 @@
      * Once the Intents are removed, an empty list should be
      * returned by the fetch of all high level Intents.
      */
-    // @Test The delete API does not currently work properly.
+    @Test
     public void testDeleteOfAllIntents() {
 
         makeDefaultIntents();
@@ -97,6 +98,10 @@
         // HTTP status should be NO CONTENT
         assertThat(deleteClient, hasStatusOf(Status.SUCCESS_NO_CONTENT));
 
+        // trigger the back end deletion of the Intents
+        modifyIntentState("1:2___0", Intent.IntentState.DEL_ACK);
+        modifyIntentState("1:3___0", Intent.IntentState.DEL_ACK);
+
         //  Now query the intents to make sure they all got deleted
         final ClientResource client = new ClientResource(getHighRestIntentUrl());
         final Collection<Map<String, String>> intents = getIntentsCollection(client);
@@ -115,7 +120,7 @@
      * Once the Intent is removed, an empty list should be
      * returned by the fetch of the Intent.
      */
-    // @Test Intent delete currently does not work
+    @Test
     public void testDeleteOfSingleExistingIntent() {
 
         makeDefaultIntents();
@@ -127,6 +132,9 @@
         // HTTP status should be NO CONTENT
         assertThat(deleteClient, hasStatusOf(Status.SUCCESS_NO_CONTENT));
 
+        // trigger the back end deletion of the Intent.
+        modifyIntentState("1:2___0", Intent.IntentState.DEL_ACK);
+
         ClientResource client = new ClientResource(intentUrl);
         try {
             //  Now query the intent to make sure it got deleted