ONOS-5808: Allocate BW from ConnectivityIntentCompiler and unit tests for partial failure

Change-Id: I2eb3c16efbce619db6d0d2ba415a35752a61ece4
diff --git a/core/api/src/test/java/org/onosproject/net/resource/MockResourceService.java b/core/api/src/test/java/org/onosproject/net/resource/MockResourceService.java
index 436a763..3a8b4e4 100644
--- a/core/api/src/test/java/org/onosproject/net/resource/MockResourceService.java
+++ b/core/api/src/test/java/org/onosproject/net/resource/MockResourceService.java
@@ -20,6 +20,7 @@
 
 import org.onlab.packet.MplsLabel;
 import org.onlab.packet.VlanId;
+import org.onlab.util.Bandwidth;
 import org.onlab.util.Tools;
 import org.onosproject.net.TributarySlot;
 
@@ -35,10 +36,22 @@
 
 public class MockResourceService implements ResourceService {
 
+    private double bandwidth = 1000.0;
     private final Map<Resource, ResourceConsumer> assignment = new HashMap<>();
     public Set<Short> availableVlanLabels = new HashSet<>();
     public Set<Integer> availableMplsLabels = new HashSet<>();
 
+    public MockResourceService(){}
+
+    // To express a custom bandwidth available (in bps)
+    public static ResourceService makeCustomBandwidthResourceService(double bandwidth) {
+        return new MockResourceService(bandwidth);
+    }
+
+    private MockResourceService(double bandwidth) {
+        this.bandwidth = bandwidth;
+    }
+
     @Override
     public List<ResourceAllocation> allocate(ResourceConsumer consumer, List<? extends Resource> resources) {
         assignment.putAll(
@@ -181,6 +194,11 @@
 
     @Override
     public boolean isAvailable(Resource resource) {
+        if (resource.isTypeOf(Bandwidth.class)) {
+            // If there's is enough bandwidth available return true; false otherwise
+            Optional<Double> value = resource.valueAs(Double.class);
+            return value.filter(requested -> requested <= bandwidth).isPresent();
+        }
         return true;
     }