Remove dependency on LinkResourceService from MplsPathIntentCompiler

In addition, revise test to make the situation more realistic

Change-Id: If23648b77f2eddbe27873711dab3b196a4a2729d
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MockResourceService.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MockResourceService.java
new file mode 100644
index 0000000..06b2c81
--- /dev/null
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MockResourceService.java
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.intent.impl.compiler;
+
+import com.google.common.collect.ImmutableList;
+import org.onlab.packet.MplsLabel;
+import org.onosproject.net.newresource.ResourceAllocation;
+import org.onosproject.net.newresource.ResourceConsumer;
+import org.onosproject.net.newresource.ResourcePath;
+import org.onosproject.net.newresource.ResourceService;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+class MockResourceService implements ResourceService {
+
+    private final Map<ResourcePath, ResourceConsumer> assignment = new HashMap<>();
+
+    @Override
+    public List<ResourceAllocation> allocate(ResourceConsumer consumer, List<ResourcePath> resources) {
+        assignment.putAll(
+                resources.stream().collect(Collectors.toMap(x -> x, x -> consumer))
+        );
+
+        return resources.stream()
+                .map(x -> new ResourceAllocation(x, consumer))
+                .collect(Collectors.toList());
+    }
+
+    @Override
+    public boolean release(List<ResourceAllocation> allocations) {
+        allocations.forEach(x -> assignment.remove(x.resource()));
+
+        return true;
+    }
+
+    @Override
+    public boolean release(ResourceConsumer consumer) {
+        List<ResourcePath> resources = assignment.entrySet().stream()
+                .filter(x -> x.getValue().equals(consumer))
+                .map(Map.Entry::getKey)
+                .collect(Collectors.toList());
+        List<ResourceAllocation> allocations = resources.stream()
+                .map(x -> new ResourceAllocation(x, consumer))
+                .collect(Collectors.toList());
+
+        return release(allocations);
+    }
+
+    @Override
+    public Optional<ResourceAllocation> getResourceAllocation(ResourcePath resource) {
+        return Optional.ofNullable(assignment.get(resource))
+                .map(x -> new ResourceAllocation(resource, x));
+    }
+
+    @Override
+    public <T> Collection<ResourceAllocation> getResourceAllocations(ResourcePath parent, Class<T> cls) {
+        return assignment.entrySet().stream()
+                .filter(x -> x.getKey().parent().isPresent())
+                .filter(x -> x.getKey().parent().get().equals(parent))
+                .map(x -> new ResourceAllocation(x.getKey(), x.getValue()))
+                .collect(Collectors.toList());
+    }
+
+    @Override
+    public Collection<ResourceAllocation> getResourceAllocations(ResourceConsumer consumer) {
+        return assignment.entrySet().stream()
+                .filter(x -> x.getValue().equals(consumer))
+                .map(x -> new ResourceAllocation(x.getKey(), x.getValue()))
+                .collect(Collectors.toList());
+    }
+
+    @Override
+    public Collection<ResourcePath> getAvailableResources(ResourcePath parent) {
+        ResourcePath resource = ResourcePath.child(parent, MplsLabel.mplsLabel(10));
+        return ImmutableList.of(resource);
+    }
+
+    @Override
+    public boolean isAvailable(ResourcePath resource) {
+        return true;
+    }
+}
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MplsPathIntentCompilerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MplsPathIntentCompilerTest.java
index 771a988..6cceee1 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MplsPathIntentCompilerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MplsPathIntentCompilerTest.java
@@ -41,10 +41,8 @@
 import org.onosproject.net.intent.FlowRuleIntent;
 import org.onosproject.net.intent.Intent;
 import org.onosproject.net.intent.IntentExtensionService;
-import org.onosproject.net.intent.IntentTestsMocks;
 import org.onosproject.net.intent.MockIdGenerator;
 import org.onosproject.net.intent.MplsPathIntent;
-import org.onosproject.store.trivial.SimpleLinkStore;
 
 import static org.easymock.EasyMock.createMock;
 import static org.easymock.EasyMock.expect;
@@ -52,6 +50,7 @@
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.hasSize;
 import static org.hamcrest.Matchers.is;
+import static org.onosproject.net.DefaultEdgeLink.createEdgeLink;
 import static org.onosproject.net.Link.Type.DIRECT;
 import static org.onosproject.net.NetTestTools.APP_ID;
 import static org.onosproject.net.NetTestTools.PID;
@@ -61,10 +60,12 @@
 
     private final ApplicationId appId = new TestApplicationId("test");
 
+    private final ConnectPoint d1pi = connectPoint("s1", 100);
     private final ConnectPoint d1p1 = connectPoint("s1", 0);
     private final ConnectPoint d2p0 = connectPoint("s2", 0);
     private final ConnectPoint d2p1 = connectPoint("s2", 1);
     private final ConnectPoint d3p1 = connectPoint("s3", 1);
+    private final ConnectPoint d3pe = connectPoint("s3", 100);
 
     private final TrafficSelector selector = DefaultTrafficSelector.builder().build();
     private final TrafficTreatment treatment = DefaultTrafficTreatment.builder().build();
@@ -75,8 +76,10 @@
             Optional.of(MplsLabel.mplsLabel(20));
 
     private final List<Link> links = Arrays.asList(
+            createEdgeLink(d1pi, true),
             new DefaultLink(PID, d1p1, d2p0, DIRECT),
-            new DefaultLink(PID, d2p1, d3p1, DIRECT)
+            new DefaultLink(PID, d2p1, d3p1, DIRECT),
+            createEdgeLink(d3pe, false)
     );
 
     private IdGenerator idGenerator = new MockIdGenerator();
@@ -92,8 +95,7 @@
         expect(coreService.registerApplication("org.onosproject.net.intent"))
                 .andReturn(appId);
         sut.coreService = coreService;
-        sut.linkStore = new SimpleLinkStore();
-        sut.resourceService = new IntentTestsMocks.MockResourceService();
+        sut.resourceService = new MockResourceService();
 
         Intent.bindIdGenerator(idGenerator);
 
@@ -128,7 +130,7 @@
         assertThat(compiled, hasSize(1));
 
         Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
-        assertThat(rules, hasSize(1));
+        assertThat(rules, hasSize(3));
 
         FlowRule rule = rules.stream()
                 .filter(x -> x.deviceId().equals(d2p0.deviceId()))
@@ -139,4 +141,5 @@
         sut.deactivate();
 
     }
+
 }