Updating MockFlowRuleService with new semantics

Change-Id: I0a373e6cb25728ca48736902feedc3ed8869fa44
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/IntentManagerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/IntentManagerTest.java
index 897d292..c55c3e8 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/IntentManagerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/IntentManagerTest.java
@@ -396,14 +396,14 @@
     @Test
     public void errorIntentInstallFromFlows() {
         final Long id = MockIntent.nextId();
-        flowRuleService.setFuture(false, 1);
+        flowRuleService.setFuture(false);
         MockIntent intent = new MockIntent(id);
         listener.setLatch(1, Type.FAILED);
         listener.setLatch(1, Type.INSTALL_REQ);
         service.submit(intent);
         listener.await(Type.INSTALL_REQ);
         delay(10); // need to make sure we have some failed futures returned first
-        flowRuleService.setFuture(true, 0);
+        flowRuleService.setFuture(true);
         listener.await(Type.FAILED);
     }
 
@@ -429,7 +429,7 @@
     @Test
     public void errorIntentInstallNeverTrue() {
         final Long id = MockIntent.nextId();
-        flowRuleService.setFuture(false, 1);
+        flowRuleService.setFuture(false);
         MockIntent intent = new MockIntent(id);
         listener.setLatch(1, Type.WITHDRAWN);
         listener.setLatch(1, Type.INSTALL_REQ);
@@ -437,7 +437,7 @@
         listener.await(Type.INSTALL_REQ);
         // The delay here forces the retry loop in the intent manager to time out
         delay(100);
-        flowRuleService.setFuture(false, 1);
+        flowRuleService.setFuture(false);
         service.withdraw(intent);
         listener.await(Type.WITHDRAWN);
     }
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/MockFlowRuleService.java b/core/net/src/test/java/org/onosproject/net/intent/impl/MockFlowRuleService.java
index 72de4f0..f2f4edb 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/MockFlowRuleService.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/MockFlowRuleService.java
@@ -15,68 +15,67 @@
  */
 package org.onosproject.net.intent.impl;
 
-import java.util.Collections;
-import java.util.Set;
-import java.util.concurrent.Future;
-
+import com.google.common.collect.Sets;
 import org.onosproject.core.ApplicationId;
 import org.onosproject.net.DeviceId;
 import org.onosproject.net.flow.CompletedBatchOperation;
+import org.onosproject.net.flow.DefaultFlowEntry;
 import org.onosproject.net.flow.FlowEntry;
 import org.onosproject.net.flow.FlowRule;
-import org.onosproject.net.flow.FlowRuleBatchEntry;
 import org.onosproject.net.flow.FlowRuleBatchOperation;
 import org.onosproject.net.flow.FlowRuleListener;
 import org.onosproject.net.flow.FlowRuleOperations;
 import org.onosproject.net.flow.FlowRuleService;
 
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Sets;
-import com.google.common.util.concurrent.Futures;
+import java.util.Set;
+import java.util.concurrent.Future;
+import java.util.stream.Collectors;
 
 
 public class MockFlowRuleService implements FlowRuleService {
 
-    private Future<CompletedBatchOperation> future;
     final Set<FlowRule> flows = Sets.newHashSet();
+    boolean success;
 
     public void setFuture(boolean success) {
-        setFuture(success, 0);
-    }
-
-    public void setFuture(boolean success, long intentId) {
-        if (success) {
-            future = Futures.immediateFuture(new CompletedBatchOperation(true, Collections.emptySet(), null));
-        } else {
-            final Set<Long> failedIds = ImmutableSet.of(intentId);
-            future = Futures.immediateFuture(
-                    new CompletedBatchOperation(false, flows, failedIds, null));
-        }
+        this.success = success;
     }
 
     @Override
     public Future<CompletedBatchOperation> applyBatch(FlowRuleBatchOperation batch) {
-        for (FlowRuleBatchEntry fbe : batch.getOperations()) {
-            FlowRule fr = fbe.target();
-            switch (fbe.operator()) {
-                case ADD:
-                    flows.add(fr);
-                    break;
-                case REMOVE:
-                    flows.remove(fr);
-                    break;
-                case MODIFY:
-                    break;
-                default:
-                    break;
-            }
-        }
-        return future;
+        throw new UnsupportedOperationException("deprecated");
     }
 
     @Override
     public void apply(FlowRuleOperations ops) {
+        ops.stages().forEach(stage -> stage.forEach(flow -> {
+            switch (flow.type()) {
+                case ADD:
+                case MODIFY: //TODO is this the right behavior for modify?
+                    flows.add(flow.rule());
+                    break;
+                case REMOVE:
+                    flows.remove(flow.rule());
+                    break;
+                default:
+                    break;
+            }
+        }));
+        if (success) {
+            ops.callback().onSuccess(ops);
+        } else {
+            ops.callback().onError(ops);
+        }
+    }
 
+    @Override
+    public void addListener(FlowRuleListener listener) {
+        //TODO not implemented
+    }
+
+    @Override
+    public void removeListener(FlowRuleListener listener) {
+        //TODO not implemented
     }
 
     @Override
@@ -86,39 +85,43 @@
 
     @Override
     public Iterable<FlowEntry> getFlowEntries(DeviceId deviceId) {
-        return null;
+        return flows.stream()
+                    .filter(flow -> flow.deviceId().equals(deviceId))
+                    .map(DefaultFlowEntry::new)
+                    .collect(Collectors.toList());
     }
 
     @Override
     public void applyFlowRules(FlowRule... flowRules) {
+        for (FlowRule flow : flowRules) {
+            flows.add(flow);
+        }
     }
 
     @Override
     public void removeFlowRules(FlowRule... flowRules) {
+        for (FlowRule flow : flowRules) {
+            flows.remove(flow);
+        }
     }
 
     @Override
     public void removeFlowRulesById(ApplicationId appId) {
+        //TODO not implemented
     }
 
     @Override
     public Iterable<FlowRule> getFlowRulesById(ApplicationId id) {
-        return null;
+        return flows.stream()
+                    .filter(flow -> flow.appId() == id.id())
+                    .collect(Collectors.toList());
     }
 
     @Override
     public Iterable<FlowRule> getFlowRulesByGroupId(ApplicationId appId, short groupId) {
-        return null;
-    }
-
-    @Override
-    public void addListener(FlowRuleListener listener) {
-
-    }
-
-    @Override
-    public void removeListener(FlowRuleListener listener) {
-
+        return flows.stream()
+                .filter(flow -> flow.appId() == appId.id() && flow.groupId().id() == groupId)
+                .collect(Collectors.toList());
     }
 }