Committed by
Gerrit Code Review
Fix for ONOS-4940
Change-Id: Id4e5913cb69e913190a0b32cd41bac0dbe786729
Showing
2 changed files
with
33 additions
and
6 deletions
... | @@ -22,6 +22,7 @@ import org.onosproject.net.ConnectPoint; | ... | @@ -22,6 +22,7 @@ import org.onosproject.net.ConnectPoint; |
22 | import org.onosproject.net.DeviceId; | 22 | import org.onosproject.net.DeviceId; |
23 | import org.onosproject.net.Link; | 23 | import org.onosproject.net.Link; |
24 | import org.onosproject.net.PortNumber; | 24 | import org.onosproject.net.PortNumber; |
25 | +import org.onosproject.net.device.DeviceService; | ||
25 | import org.onosproject.net.topology.ClusterId; | 26 | import org.onosproject.net.topology.ClusterId; |
26 | import org.onosproject.net.topology.Topology; | 27 | import org.onosproject.net.topology.Topology; |
27 | import org.onosproject.net.topology.TopologyCluster; | 28 | import org.onosproject.net.topology.TopologyCluster; |
... | @@ -35,7 +36,6 @@ import javax.ws.rs.Produces; | ... | @@ -35,7 +36,6 @@ import javax.ws.rs.Produces; |
35 | import javax.ws.rs.core.MediaType; | 36 | import javax.ws.rs.core.MediaType; |
36 | import javax.ws.rs.core.Response; | 37 | import javax.ws.rs.core.Response; |
37 | import java.util.List; | 38 | import java.util.List; |
38 | - | ||
39 | import static org.onlab.util.Tools.nullIsNotFound; | 39 | import static org.onlab.util.Tools.nullIsNotFound; |
40 | 40 | ||
41 | /** | 41 | /** |
... | @@ -187,9 +187,10 @@ public class TopologyWebResource extends AbstractWebResource { | ... | @@ -187,9 +187,10 @@ public class TopologyWebResource extends AbstractWebResource { |
187 | @Path("broadcast/{connectPoint}") | 187 | @Path("broadcast/{connectPoint}") |
188 | public Response getConnectPointBroadcast(@PathParam("connectPoint") String connectPointString) { | 188 | public Response getConnectPointBroadcast(@PathParam("connectPoint") String connectPointString) { |
189 | Topology topology = get(TopologyService.class).currentTopology(); | 189 | Topology topology = get(TopologyService.class).currentTopology(); |
190 | - | ||
191 | DeviceId deviceId = DeviceId.deviceId(getDeviceId(connectPointString)); | 190 | DeviceId deviceId = DeviceId.deviceId(getDeviceId(connectPointString)); |
191 | + nullIsNotFound(get(DeviceService.class).getDevice(deviceId), "Device not found " + connectPointString); | ||
192 | PortNumber portNumber = PortNumber.portNumber(getPortNumber(connectPointString)); | 192 | PortNumber portNumber = PortNumber.portNumber(getPortNumber(connectPointString)); |
193 | + nullIsNotFound(get(DeviceService.class).getPort(deviceId, portNumber), "Port not found " + connectPointString); | ||
193 | ConnectPoint connectPoint = new ConnectPoint(deviceId, portNumber); | 194 | ConnectPoint connectPoint = new ConnectPoint(deviceId, portNumber); |
194 | boolean isBroadcast = get(TopologyService.class).isBroadcastPoint(topology, connectPoint); | 195 | boolean isBroadcast = get(TopologyService.class).isBroadcastPoint(topology, connectPoint); |
195 | 196 | ||
... | @@ -211,9 +212,10 @@ public class TopologyWebResource extends AbstractWebResource { | ... | @@ -211,9 +212,10 @@ public class TopologyWebResource extends AbstractWebResource { |
211 | @Path("infrastructure/{connectPoint}") | 212 | @Path("infrastructure/{connectPoint}") |
212 | public Response getConnectPointInfrastructure(@PathParam("connectPoint") String connectPointString) { | 213 | public Response getConnectPointInfrastructure(@PathParam("connectPoint") String connectPointString) { |
213 | Topology topology = get(TopologyService.class).currentTopology(); | 214 | Topology topology = get(TopologyService.class).currentTopology(); |
214 | - | ||
215 | DeviceId deviceId = DeviceId.deviceId(getDeviceId(connectPointString)); | 215 | DeviceId deviceId = DeviceId.deviceId(getDeviceId(connectPointString)); |
216 | + nullIsNotFound(get(DeviceService.class).getDevice(deviceId), "Device not found " + connectPointString); | ||
216 | PortNumber portNumber = PortNumber.portNumber(getPortNumber(connectPointString)); | 217 | PortNumber portNumber = PortNumber.portNumber(getPortNumber(connectPointString)); |
218 | + nullIsNotFound(get(DeviceService.class).getPort(deviceId, portNumber), "Port not found " + connectPointString); | ||
217 | ConnectPoint connectPoint = new ConnectPoint(deviceId, portNumber); | 219 | ConnectPoint connectPoint = new ConnectPoint(deviceId, portNumber); |
218 | boolean isInfrastructure = get(TopologyService.class).isInfrastructure(topology, connectPoint); | 220 | boolean isInfrastructure = get(TopologyService.class).isInfrastructure(topology, connectPoint); |
219 | 221 | ... | ... |
... | @@ -29,6 +29,12 @@ import org.onosproject.codec.impl.CodecManager; | ... | @@ -29,6 +29,12 @@ import org.onosproject.codec.impl.CodecManager; |
29 | import org.onosproject.net.ConnectPoint; | 29 | import org.onosproject.net.ConnectPoint; |
30 | import org.onosproject.net.DeviceId; | 30 | import org.onosproject.net.DeviceId; |
31 | import org.onosproject.net.Link; | 31 | import org.onosproject.net.Link; |
32 | +import org.onosproject.net.Device; | ||
33 | +import org.onosproject.net.PortNumber; | ||
34 | +import org.onosproject.net.DefaultPort; | ||
35 | +import org.onosproject.net.Port; | ||
36 | +import org.onosproject.net.device.DeviceService; | ||
37 | +import org.onosproject.net.device.DeviceServiceAdapter; | ||
32 | import org.onosproject.net.provider.ProviderId; | 38 | import org.onosproject.net.provider.ProviderId; |
33 | import org.onosproject.net.topology.ClusterId; | 39 | import org.onosproject.net.topology.ClusterId; |
34 | import org.onosproject.net.topology.DefaultTopologyCluster; | 40 | import org.onosproject.net.topology.DefaultTopologyCluster; |
... | @@ -37,17 +43,17 @@ import org.onosproject.net.topology.Topology; | ... | @@ -37,17 +43,17 @@ import org.onosproject.net.topology.Topology; |
37 | import org.onosproject.net.topology.TopologyCluster; | 43 | import org.onosproject.net.topology.TopologyCluster; |
38 | import org.onosproject.net.topology.TopologyService; | 44 | import org.onosproject.net.topology.TopologyService; |
39 | import org.onosproject.net.topology.TopologyServiceAdapter; | 45 | import org.onosproject.net.topology.TopologyServiceAdapter; |
40 | - | ||
41 | import javax.ws.rs.client.WebTarget; | 46 | import javax.ws.rs.client.WebTarget; |
42 | import java.util.Set; | 47 | import java.util.Set; |
43 | - | ||
44 | import static org.hamcrest.Matchers.containsString; | 48 | import static org.hamcrest.Matchers.containsString; |
45 | import static org.hamcrest.Matchers.hasSize; | 49 | import static org.hamcrest.Matchers.hasSize; |
46 | import static org.hamcrest.Matchers.is; | 50 | import static org.hamcrest.Matchers.is; |
47 | import static org.hamcrest.Matchers.notNullValue; | 51 | import static org.hamcrest.Matchers.notNullValue; |
48 | import static org.junit.Assert.assertThat; | 52 | import static org.junit.Assert.assertThat; |
53 | +import static org.onosproject.net.NetTestTools.device; | ||
49 | import static org.onosproject.net.NetTestTools.did; | 54 | import static org.onosproject.net.NetTestTools.did; |
50 | import static org.onosproject.net.NetTestTools.link; | 55 | import static org.onosproject.net.NetTestTools.link; |
56 | +import static org.onosproject.net.PortNumber.portNumber; | ||
51 | 57 | ||
52 | /** | 58 | /** |
53 | * Unit tests for Topology REST APIs. | 59 | * Unit tests for Topology REST APIs. |
... | @@ -144,17 +150,37 @@ public class TopologyResourceTest extends ResourceTest { | ... | @@ -144,17 +150,37 @@ public class TopologyResourceTest extends ResourceTest { |
144 | 150 | ||
145 | } | 151 | } |
146 | 152 | ||
153 | + private static class MockDeviceService extends DeviceServiceAdapter { | ||
154 | + | ||
155 | + @Override | ||
156 | + public Device getDevice(DeviceId deviceId) { | ||
157 | + String deviceId1 = "dev2"; | ||
158 | + Device device = device(deviceId1); | ||
159 | + return device; | ||
160 | + } | ||
161 | + | ||
162 | + @Override | ||
163 | + public Port getPort(DeviceId deviceId, PortNumber portNumber) { | ||
164 | + String deviceIdString = "dev2"; | ||
165 | + Device device = device(deviceIdString); | ||
166 | + Port port = new DefaultPort(device, portNumber(1), true); | ||
167 | + return port; | ||
168 | + } | ||
169 | + } | ||
170 | + | ||
147 | /** | 171 | /** |
148 | * Initializes the test harness. | 172 | * Initializes the test harness. |
149 | */ | 173 | */ |
150 | @Before | 174 | @Before |
151 | public void setUpTest() { | 175 | public void setUpTest() { |
152 | TopologyService topologyService = new MockTopologyService(); | 176 | TopologyService topologyService = new MockTopologyService(); |
177 | + DeviceService mockDeviceService = new MockDeviceService(); | ||
153 | CodecManager codecService = new CodecManager(); | 178 | CodecManager codecService = new CodecManager(); |
154 | codecService.activate(); | 179 | codecService.activate(); |
155 | 180 | ||
156 | ServiceDirectory testDirectory = | 181 | ServiceDirectory testDirectory = |
157 | new TestServiceDirectory() | 182 | new TestServiceDirectory() |
183 | + .add(DeviceService.class, mockDeviceService) | ||
158 | .add(TopologyService.class, topologyService) | 184 | .add(TopologyService.class, topologyService) |
159 | .add(CodecService.class, codecService); | 185 | .add(CodecService.class, codecService); |
160 | BaseResource.setServiceDirectory(testDirectory); | 186 | BaseResource.setServiceDirectory(testDirectory); |
... | @@ -275,7 +301,6 @@ public class TopologyResourceTest extends ResourceTest { | ... | @@ -275,7 +301,6 @@ public class TopologyResourceTest extends ResourceTest { |
275 | String response = wt.path("topology/infrastructure/dev2:1").request().get(String.class); | 301 | String response = wt.path("topology/infrastructure/dev2:1").request().get(String.class); |
276 | JsonObject result = Json.parse(response).asObject(); | 302 | JsonObject result = Json.parse(response).asObject(); |
277 | assertThat(result, notNullValue()); | 303 | assertThat(result, notNullValue()); |
278 | - | ||
279 | assertThat(result.get("infrastructure").asBoolean(), is(true)); | 304 | assertThat(result.get("infrastructure").asBoolean(), is(true)); |
280 | } | 305 | } |
281 | } | 306 | } | ... | ... |
-
Please register or login to post a comment