Thomas Vachuska

Fixing an issue with unit test mocks.

Change-Id: I5a081cc737d8c7ea9a4e0cc136f69ed9dc2ba618
...@@ -93,6 +93,21 @@ public final class NetTestTools { ...@@ -93,6 +93,21 @@ public final class NetTestTools {
93 return new DefaultPath(PID, links, ids.length); 93 return new DefaultPath(PID, links, ids.length);
94 } 94 }
95 95
96 + // Creates a path that leads through the given devices.
97 + public static Path createPath(boolean srcIsEdge, boolean dstIsEdge, String... ids) {
98 + List<Link> links = new ArrayList<>();
99 + for (int i = 0; i < ids.length - 1; i++) {
100 + if (i == 0 && srcIsEdge) {
101 + links.add(DefaultEdgeLink.createEdgeLink(host(ids[i], ids[i + 1]), true));
102 + } else if (i == ids.length - 2 && dstIsEdge) {
103 + links.add(DefaultEdgeLink.createEdgeLink(host(ids[i + 1], ids[i]), false));
104 + } else {
105 + links.add(link(ids[i], i, ids[i + 1], i));
106 + }
107 + }
108 + return new DefaultPath(PID, links, ids.length);
109 + }
110 +
96 // Creates OCh signal 111 // Creates OCh signal
97 public static OchSignal createLambda() { 112 public static OchSignal createLambda() {
98 return new OchSignal(GridType.DWDM, ChannelSpacing.CHL_6P25GHZ, 8, 4); 113 return new OchSignal(GridType.DWDM, ChannelSpacing.CHL_6P25GHZ, 8, 4);
......
...@@ -21,6 +21,7 @@ import org.onosproject.core.DefaultGroupId; ...@@ -21,6 +21,7 @@ import org.onosproject.core.DefaultGroupId;
21 import org.onosproject.core.GroupId; 21 import org.onosproject.core.GroupId;
22 import org.onosproject.net.DeviceId; 22 import org.onosproject.net.DeviceId;
23 import org.onosproject.net.ElementId; 23 import org.onosproject.net.ElementId;
24 +import org.onosproject.net.HostId;
24 import org.onosproject.net.Link; 25 import org.onosproject.net.Link;
25 import org.onosproject.net.NetTestTools; 26 import org.onosproject.net.NetTestTools;
26 import org.onosproject.net.NetworkResource; 27 import org.onosproject.net.NetworkResource;
...@@ -152,7 +153,7 @@ public class IntentTestsMocks { ...@@ -152,7 +153,7 @@ public class IntentTestsMocks {
152 System.arraycopy(reversePathHops, 0, allHops, 0, pathHops.length); 153 System.arraycopy(reversePathHops, 0, allHops, 0, pathHops.length);
153 } 154 }
154 155
155 - result.add(createPath(allHops)); 156 + result.add(createPath(src instanceof HostId, dst instanceof HostId, allHops));
156 return result; 157 return result;
157 } 158 }
158 159
...@@ -161,15 +162,17 @@ public class IntentTestsMocks { ...@@ -161,15 +162,17 @@ public class IntentTestsMocks {
161 final Set<Path> paths = getPaths(src, dst); 162 final Set<Path> paths = getPaths(src, dst);
162 163
163 for (Path path : paths) { 164 for (Path path : paths) {
164 - final DeviceId srcDevice = path.src().deviceId(); 165 + final DeviceId srcDevice = path.src().elementId() instanceof DeviceId ? path.src().deviceId() : null;
165 - final DeviceId dstDevice = path.dst().deviceId(); 166 + final DeviceId dstDevice = path.dst().elementId() instanceof DeviceId ? path.dst().deviceId() : null;
166 - final TopologyVertex srcVertex = new DefaultTopologyVertex(srcDevice); 167 + if (srcDevice != null && dstDevice != null) {
167 - final TopologyVertex dstVertex = new DefaultTopologyVertex(dstDevice); 168 + final TopologyVertex srcVertex = new DefaultTopologyVertex(srcDevice);
168 - final Link link = link(src.toString(), 1, dst.toString(), 1); 169 + final TopologyVertex dstVertex = new DefaultTopologyVertex(dstDevice);
169 - 170 + final Link link = link(src.toString(), 1, dst.toString(), 1);
170 - final double weightValue = weight.weight(new DefaultTopologyEdge(srcVertex, dstVertex, link)); 171 +
171 - if (weightValue < 0) { 172 + final double weightValue = weight.weight(new DefaultTopologyEdge(srcVertex, dstVertex, link));
172 - return new HashSet<>(); 173 + if (weightValue < 0) {
174 + return new HashSet<>();
175 + }
173 } 176 }
174 } 177 }
175 return paths; 178 return paths;
......