Ray Milkey | 4f5de00 | 2014-12-17 19:26:11 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onosproject.rest; |
| 17 | |
| 18 | import java.util.HashMap; |
| 19 | import java.util.HashSet; |
| 20 | import java.util.Set; |
| 21 | |
| 22 | import org.hamcrest.Description; |
| 23 | import org.hamcrest.TypeSafeMatcher; |
| 24 | import org.junit.After; |
| 25 | import org.junit.Before; |
| 26 | import org.junit.Test; |
| 27 | import org.onlab.osgi.ServiceDirectory; |
| 28 | import org.onlab.osgi.TestServiceDirectory; |
| 29 | import org.onlab.packet.MacAddress; |
| 30 | import org.onlab.rest.BaseResource; |
| 31 | import org.onosproject.codec.CodecService; |
| 32 | import org.onosproject.codec.impl.CodecManager; |
| 33 | import org.onosproject.core.DefaultGroupId; |
| 34 | import org.onosproject.core.GroupId; |
| 35 | import org.onosproject.net.DefaultDevice; |
| 36 | import org.onosproject.net.Device; |
| 37 | import org.onosproject.net.DeviceId; |
| 38 | import org.onosproject.net.device.DeviceService; |
| 39 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 40 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 41 | import org.onosproject.net.flow.FlowEntry; |
| 42 | import org.onosproject.net.flow.FlowId; |
| 43 | import org.onosproject.net.flow.FlowRuleService; |
| 44 | import org.onosproject.net.flow.TrafficSelector; |
| 45 | import org.onosproject.net.flow.TrafficTreatment; |
| 46 | import org.onosproject.net.flow.criteria.Criterion; |
| 47 | import org.onosproject.net.flow.instructions.Instruction; |
| 48 | import org.onosproject.net.flow.instructions.L0ModificationInstruction; |
| 49 | |
| 50 | import com.eclipsesource.json.JsonArray; |
| 51 | import com.eclipsesource.json.JsonObject; |
Ray Milkey | 4f5de00 | 2014-12-17 19:26:11 -0800 | [diff] [blame] | 52 | import com.google.common.collect.ImmutableSet; |
| 53 | import com.sun.jersey.api.client.UniformInterfaceException; |
| 54 | import com.sun.jersey.api.client.WebResource; |
| 55 | import com.sun.jersey.test.framework.JerseyTest; |
| 56 | |
| 57 | import static org.easymock.EasyMock.anyObject; |
| 58 | import static org.easymock.EasyMock.createMock; |
| 59 | import static org.easymock.EasyMock.expect; |
| 60 | import static org.easymock.EasyMock.replay; |
| 61 | import static org.easymock.EasyMock.verify; |
| 62 | import static org.hamcrest.Matchers.containsString; |
| 63 | import static org.hamcrest.Matchers.hasSize; |
| 64 | import static org.hamcrest.Matchers.is; |
| 65 | import static org.hamcrest.Matchers.not; |
| 66 | import static org.hamcrest.Matchers.notNullValue; |
| 67 | import static org.junit.Assert.assertThat; |
| 68 | import static org.junit.Assert.fail; |
| 69 | |
| 70 | /** |
| 71 | * Unit tests for Flows REST APIs. |
| 72 | */ |
| 73 | public class FlowsResourceTest extends JerseyTest { |
| 74 | final FlowRuleService mockFlowService = createMock(FlowRuleService.class); |
| 75 | final HashMap<DeviceId, Set<FlowEntry>> rules = new HashMap<>(); |
| 76 | |
| 77 | final DeviceService mockDeviceService = createMock(DeviceService.class); |
| 78 | |
| 79 | final DeviceId deviceId1 = DeviceId.deviceId("1"); |
| 80 | final DeviceId deviceId2 = DeviceId.deviceId("2"); |
| 81 | final DeviceId deviceId3 = DeviceId.deviceId("3"); |
| 82 | final Device device1 = new DefaultDevice(null, deviceId1, Device.Type.OTHER, |
| 83 | "", "", "", "", null); |
| 84 | final Device device2 = new DefaultDevice(null, deviceId2, Device.Type.OTHER, |
| 85 | "", "", "", "", null); |
| 86 | |
| 87 | final MockFlowEntry flow1 = new MockFlowEntry(deviceId1, 1); |
| 88 | final MockFlowEntry flow2 = new MockFlowEntry(deviceId1, 2); |
| 89 | |
| 90 | final MockFlowEntry flow3 = new MockFlowEntry(deviceId2, 3); |
| 91 | final MockFlowEntry flow4 = new MockFlowEntry(deviceId2, 4); |
| 92 | |
| 93 | final MockFlowEntry flow5 = new MockFlowEntry(deviceId2, 5); |
| 94 | final MockFlowEntry flow6 = new MockFlowEntry(deviceId2, 6); |
| 95 | |
| 96 | /** |
| 97 | * Mock class for a flow entry. |
| 98 | */ |
| 99 | private static class MockFlowEntry implements FlowEntry { |
| 100 | final DeviceId deviceId; |
| 101 | final long baseValue; |
| 102 | TrafficTreatment treatment; |
| 103 | TrafficSelector selector; |
| 104 | |
| 105 | public MockFlowEntry(DeviceId deviceId, long id) { |
| 106 | this.deviceId = deviceId; |
| 107 | this.baseValue = id * 100; |
| 108 | } |
| 109 | |
| 110 | @Override |
| 111 | public FlowEntryState state() { |
| 112 | return FlowEntryState.ADDED; |
| 113 | } |
| 114 | |
| 115 | @Override |
| 116 | public long life() { |
| 117 | return baseValue + 11; |
| 118 | } |
| 119 | |
| 120 | @Override |
| 121 | public long packets() { |
| 122 | return baseValue + 22; |
| 123 | } |
| 124 | |
| 125 | @Override |
| 126 | public long bytes() { |
| 127 | return baseValue + 33; |
| 128 | } |
| 129 | |
| 130 | @Override |
| 131 | public long lastSeen() { |
| 132 | return baseValue + 44; |
| 133 | } |
| 134 | |
| 135 | @Override |
| 136 | public int errType() { |
| 137 | return 0; |
| 138 | } |
| 139 | |
| 140 | @Override |
| 141 | public int errCode() { |
| 142 | return 0; |
| 143 | } |
| 144 | |
| 145 | @Override |
| 146 | public FlowId id() { |
| 147 | final long id = baseValue + 55; |
| 148 | return FlowId.valueOf(id); |
| 149 | } |
| 150 | |
| 151 | @Override |
| 152 | public short appId() { |
| 153 | return 2; |
| 154 | } |
| 155 | |
| 156 | @Override |
| 157 | public GroupId groupId() { |
| 158 | return new DefaultGroupId(3); |
| 159 | } |
| 160 | |
| 161 | @Override |
| 162 | public int priority() { |
| 163 | return (int) (baseValue + 66); |
| 164 | } |
| 165 | |
| 166 | @Override |
| 167 | public DeviceId deviceId() { |
| 168 | return deviceId; |
| 169 | } |
| 170 | |
| 171 | @Override |
| 172 | public TrafficSelector selector() { |
| 173 | return selector; |
| 174 | } |
| 175 | |
| 176 | @Override |
| 177 | public TrafficTreatment treatment() { |
| 178 | return treatment; |
| 179 | } |
| 180 | |
| 181 | @Override |
| 182 | public int timeout() { |
| 183 | return (int) (baseValue + 77); |
| 184 | } |
| 185 | |
| 186 | @Override |
| 187 | public boolean isPermanent() { |
| 188 | return false; |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | public FlowsResourceTest() { |
| 193 | super("org.onosproject.rest"); |
| 194 | } |
| 195 | |
| 196 | /** |
| 197 | * Populates some flows used as testing data. |
| 198 | */ |
| 199 | private void setupMockFlows() { |
| 200 | flow2.treatment = DefaultTrafficTreatment.builder() |
| 201 | .add(new L0ModificationInstruction.ModLambdaInstruction( |
| 202 | L0ModificationInstruction.L0SubType.LAMBDA, (short) 4)) |
| 203 | .add(new L0ModificationInstruction.ModLambdaInstruction( |
| 204 | L0ModificationInstruction.L0SubType.LAMBDA, (short) 5)) |
| 205 | .setEthDst(MacAddress.BROADCAST) |
| 206 | .build(); |
| 207 | flow2.selector = DefaultTrafficSelector.builder() |
| 208 | .matchEthType((short) 3) |
| 209 | .matchIPProtocol((byte) 9) |
| 210 | .build(); |
| 211 | flow4.treatment = DefaultTrafficTreatment.builder() |
| 212 | .add(new L0ModificationInstruction.ModLambdaInstruction( |
| 213 | L0ModificationInstruction.L0SubType.LAMBDA, (short) 6)) |
| 214 | .build(); |
| 215 | final Set<FlowEntry> flows1 = new HashSet<>(); |
| 216 | flows1.add(flow1); |
| 217 | flows1.add(flow2); |
| 218 | |
| 219 | final Set<FlowEntry> flows2 = new HashSet<>(); |
| 220 | flows1.add(flow3); |
| 221 | flows1.add(flow4); |
| 222 | |
| 223 | rules.put(deviceId1, flows1); |
| 224 | rules.put(deviceId2, flows2); |
| 225 | |
| 226 | expect(mockFlowService.getFlowEntries(deviceId1)) |
| 227 | .andReturn(rules.get(deviceId1)).anyTimes(); |
| 228 | expect(mockFlowService.getFlowEntries(deviceId2)) |
| 229 | .andReturn(rules.get(deviceId2)).anyTimes(); |
| 230 | } |
| 231 | |
| 232 | /** |
| 233 | * Sets up the global values for all the tests. |
| 234 | */ |
| 235 | @Before |
| 236 | public void setUp() { |
| 237 | // Mock device service |
| 238 | expect(mockDeviceService.getDevice(deviceId1)) |
| 239 | .andReturn(device1); |
| 240 | expect(mockDeviceService.getDevice(deviceId2)) |
| 241 | .andReturn(device2); |
| 242 | expect(mockDeviceService.getDevices()) |
| 243 | .andReturn(ImmutableSet.of(device1, device2)); |
| 244 | |
| 245 | // Register the services needed for the test |
| 246 | final CodecManager codecService = new CodecManager(); |
| 247 | codecService.activate(); |
| 248 | ServiceDirectory testDirectory = |
| 249 | new TestServiceDirectory() |
| 250 | .add(FlowRuleService.class, mockFlowService) |
| 251 | .add(DeviceService.class, mockDeviceService) |
| 252 | .add(CodecService.class, codecService); |
| 253 | |
| 254 | BaseResource.setServiceDirectory(testDirectory); |
| 255 | } |
| 256 | |
| 257 | /** |
| 258 | * Cleans up and verifies the mocks. |
| 259 | * |
| 260 | * @throws Exception if the super teardown fails. |
| 261 | */ |
| 262 | @After |
| 263 | public void tearDown() throws Exception { |
| 264 | super.tearDown(); |
| 265 | verify(mockFlowService); |
| 266 | } |
| 267 | |
| 268 | /** |
| 269 | * Hamcrest matcher to check that a flow representation in JSON matches |
| 270 | * the actual flow entry. |
| 271 | */ |
| 272 | public static class FlowJsonMatcher extends TypeSafeMatcher<JsonObject> { |
| 273 | private final FlowEntry flow; |
| 274 | private String reason = ""; |
| 275 | |
| 276 | public FlowJsonMatcher(FlowEntry flowValue) { |
| 277 | flow = flowValue; |
| 278 | } |
| 279 | |
| 280 | @Override |
| 281 | public boolean matchesSafely(JsonObject jsonFlow) { |
| 282 | // check id |
| 283 | final String jsonId = jsonFlow.get("id").asString(); |
| 284 | final String flowId = Long.toString(flow.id().value()); |
| 285 | if (!jsonId.equals(flowId)) { |
| 286 | reason = "id " + flow.id().toString(); |
| 287 | return false; |
| 288 | } |
| 289 | |
| 290 | // check application id |
| 291 | final int jsonAppId = jsonFlow.get("appId").asInt(); |
| 292 | if (jsonAppId != flow.appId()) { |
| 293 | reason = "appId " + Short.toString(flow.appId()); |
| 294 | return false; |
| 295 | } |
| 296 | |
| 297 | // check device id |
| 298 | final String jsonDeviceId = jsonFlow.get("deviceId").asString(); |
| 299 | if (!jsonDeviceId.equals(flow.deviceId().toString())) { |
| 300 | reason = "deviceId " + flow.deviceId(); |
| 301 | return false; |
| 302 | } |
| 303 | |
| 304 | // check treatment and instructions array |
| 305 | if (flow.treatment() != null) { |
| 306 | final JsonObject jsonTreatment = jsonFlow.get("treatment").asObject(); |
| 307 | final JsonArray jsonInstructions = jsonTreatment.get("instructions").asArray(); |
| 308 | if (flow.treatment().instructions().size() != jsonInstructions.size()) { |
| 309 | reason = "instructions array size of " + |
| 310 | Integer.toString(flow.treatment().instructions().size()); |
| 311 | return false; |
| 312 | } |
| 313 | for (final Instruction instruction : flow.treatment().instructions()) { |
| 314 | boolean instructionFound = false; |
Ray Milkey | 4f5de00 | 2014-12-17 19:26:11 -0800 | [diff] [blame] | 315 | for (int instructionIndex = 0; instructionIndex < jsonInstructions.size(); instructionIndex++) { |
Ray Milkey | c95bb9d | 2015-01-06 10:28:24 -0800 | [diff] [blame] | 316 | final String jsonType = |
| 317 | jsonInstructions.get(instructionIndex) |
| 318 | .asObject().get("type").asString(); |
| 319 | final String instructionType = instruction.type().name(); |
| 320 | if (jsonType.equals(instructionType)) { |
Ray Milkey | 4f5de00 | 2014-12-17 19:26:11 -0800 | [diff] [blame] | 321 | instructionFound = true; |
| 322 | } |
| 323 | } |
| 324 | if (!instructionFound) { |
Ray Milkey | c95bb9d | 2015-01-06 10:28:24 -0800 | [diff] [blame] | 325 | reason = "instruction " + instruction.toString(); |
Ray Milkey | 4f5de00 | 2014-12-17 19:26:11 -0800 | [diff] [blame] | 326 | return false; |
| 327 | } |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | // check selector and criteria array |
| 332 | if (flow.selector() != null) { |
| 333 | final JsonObject jsonTreatment = jsonFlow.get("selector").asObject(); |
| 334 | final JsonArray jsonCriteria = jsonTreatment.get("criteria").asArray(); |
| 335 | if (flow.selector().criteria().size() != jsonCriteria.size()) { |
| 336 | reason = "criteria array size of " + |
| 337 | Integer.toString(flow.selector().criteria().size()); |
| 338 | return false; |
| 339 | } |
| 340 | for (final Criterion criterion : flow.selector().criteria()) { |
| 341 | boolean criterionFound = false; |
Ray Milkey | c95bb9d | 2015-01-06 10:28:24 -0800 | [diff] [blame] | 342 | |
Ray Milkey | 4f5de00 | 2014-12-17 19:26:11 -0800 | [diff] [blame] | 343 | for (int criterionIndex = 0; criterionIndex < jsonCriteria.size(); criterionIndex++) { |
Ray Milkey | c95bb9d | 2015-01-06 10:28:24 -0800 | [diff] [blame] | 344 | final String jsonType = |
| 345 | jsonCriteria.get(criterionIndex) |
| 346 | .asObject().get("type").asString(); |
| 347 | final String criterionType = criterion.type().name(); |
| 348 | if (jsonType.equals(criterionType)) { |
Ray Milkey | 4f5de00 | 2014-12-17 19:26:11 -0800 | [diff] [blame] | 349 | criterionFound = true; |
| 350 | } |
| 351 | } |
| 352 | if (!criterionFound) { |
Ray Milkey | c95bb9d | 2015-01-06 10:28:24 -0800 | [diff] [blame] | 353 | reason = "criterion " + criterion.toString(); |
Ray Milkey | 4f5de00 | 2014-12-17 19:26:11 -0800 | [diff] [blame] | 354 | return false; |
| 355 | } |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | return true; |
| 360 | } |
| 361 | |
| 362 | @Override |
| 363 | public void describeTo(Description description) { |
| 364 | description.appendText(reason); |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | /** |
| 369 | * Factory to allocate a flow matcher. |
| 370 | * |
| 371 | * @param flow flow object we are looking for |
| 372 | * @return matcher |
| 373 | */ |
| 374 | private static FlowJsonMatcher matchesFlow(FlowEntry flow) { |
| 375 | return new FlowJsonMatcher(flow); |
| 376 | } |
| 377 | |
| 378 | /** |
| 379 | * Hamcrest matcher to check that a flow is represented properly in a JSON |
| 380 | * array of flows. |
| 381 | */ |
| 382 | public static class FlowJsonArrayMatcher extends TypeSafeMatcher<JsonArray> { |
| 383 | private final FlowEntry flow; |
| 384 | private String reason = ""; |
| 385 | |
| 386 | public FlowJsonArrayMatcher(FlowEntry flowValue) { |
| 387 | flow = flowValue; |
| 388 | } |
| 389 | |
| 390 | @Override |
| 391 | public boolean matchesSafely(JsonArray json) { |
| 392 | boolean flowFound = false; |
| 393 | |
| 394 | for (int jsonFlowIndex = 0; jsonFlowIndex < json.size(); |
| 395 | jsonFlowIndex++) { |
| 396 | |
| 397 | final JsonObject jsonFlow = json.get(jsonFlowIndex).asObject(); |
| 398 | |
| 399 | final String flowId = Long.toString(flow.id().value()); |
| 400 | final String jsonFlowId = jsonFlow.get("id").asString(); |
| 401 | if (jsonFlowId.equals(flowId)) { |
| 402 | flowFound = true; |
| 403 | |
| 404 | // We found the correct flow, check attribute values |
| 405 | assertThat(jsonFlow, matchesFlow(flow)); |
| 406 | } |
| 407 | } |
| 408 | if (!flowFound) { |
| 409 | reason = "Flow with id " + flow.id().toString() + " not found"; |
| 410 | return false; |
| 411 | } else { |
| 412 | return true; |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | @Override |
| 417 | public void describeTo(Description description) { |
| 418 | description.appendText(reason); |
| 419 | } |
| 420 | } |
| 421 | |
| 422 | /** |
| 423 | * Factory to allocate a flow array matcher. |
| 424 | * |
| 425 | * @param flow flow object we are looking for |
| 426 | * @return matcher |
| 427 | */ |
| 428 | private static FlowJsonArrayMatcher hasFlow(FlowEntry flow) { |
| 429 | return new FlowJsonArrayMatcher(flow); |
| 430 | } |
| 431 | |
| 432 | /** |
| 433 | * Tests the result of the rest api GET when there are no flows. |
| 434 | */ |
| 435 | @Test |
| 436 | public void testFlowsEmptyArray() { |
| 437 | expect(mockFlowService.getFlowEntries(deviceId1)) |
| 438 | .andReturn(null).anyTimes(); |
| 439 | expect(mockFlowService.getFlowEntries(deviceId2)) |
| 440 | .andReturn(null).anyTimes(); |
| 441 | replay(mockFlowService); |
| 442 | replay(mockDeviceService); |
| 443 | final WebResource rs = resource(); |
| 444 | final String response = rs.path("flows").get(String.class); |
| 445 | assertThat(response, is("{\"flows\":[]}")); |
| 446 | } |
| 447 | |
| 448 | /** |
| 449 | * Tests the result of the rest api GET when there are active flows. |
| 450 | */ |
| 451 | @Test |
| 452 | public void testFlowsPopulatedArray() { |
| 453 | setupMockFlows(); |
| 454 | replay(mockFlowService); |
| 455 | replay(mockDeviceService); |
| 456 | final WebResource rs = resource(); |
| 457 | final String response = rs.path("flows").get(String.class); |
| 458 | final JsonObject result = JsonObject.readFrom(response); |
| 459 | assertThat(result, notNullValue()); |
| 460 | |
| 461 | assertThat(result.names(), hasSize(1)); |
| 462 | assertThat(result.names().get(0), is("flows")); |
| 463 | final JsonArray jsonFlows = result.get("flows").asArray(); |
| 464 | assertThat(jsonFlows, notNullValue()); |
| 465 | assertThat(jsonFlows, hasFlow(flow1)); |
| 466 | assertThat(jsonFlows, hasFlow(flow2)); |
| 467 | assertThat(jsonFlows, hasFlow(flow3)); |
| 468 | assertThat(jsonFlows, hasFlow(flow4)); |
| 469 | } |
| 470 | |
| 471 | /** |
| 472 | * Tests the result of a rest api GET for a device. |
| 473 | */ |
| 474 | @Test |
| 475 | public void testFlowsSingleDevice() { |
| 476 | setupMockFlows(); |
| 477 | final Set<FlowEntry> flows = new HashSet<>(); |
| 478 | flows.add(flow5); |
| 479 | flows.add(flow6); |
| 480 | expect(mockFlowService.getFlowEntries(anyObject())) |
| 481 | .andReturn(flows).anyTimes(); |
| 482 | replay(mockFlowService); |
| 483 | replay(mockDeviceService); |
| 484 | final WebResource rs = resource(); |
| 485 | final String response = rs.path("flows/" + deviceId3).get(String.class); |
| 486 | final JsonObject result = JsonObject.readFrom(response); |
| 487 | assertThat(result, notNullValue()); |
| 488 | |
| 489 | assertThat(result.names(), hasSize(1)); |
| 490 | assertThat(result.names().get(0), is("flows")); |
| 491 | final JsonArray jsonFlows = result.get("flows").asArray(); |
| 492 | assertThat(jsonFlows, notNullValue()); |
| 493 | assertThat(jsonFlows, hasFlow(flow5)); |
| 494 | assertThat(jsonFlows, hasFlow(flow6)); |
| 495 | } |
| 496 | |
| 497 | /** |
| 498 | * Tests the result of a rest api GET for a device. |
| 499 | */ |
| 500 | @Test |
| 501 | public void testFlowsSingleDeviceWithFlowId() { |
| 502 | setupMockFlows(); |
| 503 | final Set<FlowEntry> flows = new HashSet<>(); |
| 504 | flows.add(flow5); |
| 505 | flows.add(flow6); |
| 506 | expect(mockFlowService.getFlowEntries(anyObject())) |
| 507 | .andReturn(flows).anyTimes(); |
| 508 | replay(mockFlowService); |
| 509 | replay(mockDeviceService); |
| 510 | final WebResource rs = resource(); |
| 511 | final String response = rs.path("flows/" + deviceId3 + "/" |
| 512 | + Long.toString(flow5.id().value())).get(String.class); |
| 513 | final JsonObject result = JsonObject.readFrom(response); |
| 514 | assertThat(result, notNullValue()); |
| 515 | |
| 516 | assertThat(result.names(), hasSize(1)); |
| 517 | assertThat(result.names().get(0), is("flows")); |
| 518 | final JsonArray jsonFlows = result.get("flows").asArray(); |
| 519 | assertThat(jsonFlows, notNullValue()); |
| 520 | assertThat(jsonFlows, hasFlow(flow5)); |
| 521 | assertThat(jsonFlows, not(hasFlow(flow6))); |
| 522 | } |
| 523 | |
| 524 | /** |
| 525 | * Tests that a fetch of a non-existent device object throws an exception. |
| 526 | */ |
| 527 | @Test |
| 528 | public void testBadGet() { |
| 529 | expect(mockFlowService.getFlowEntries(deviceId1)) |
| 530 | .andReturn(null).anyTimes(); |
| 531 | expect(mockFlowService.getFlowEntries(deviceId2)) |
| 532 | .andReturn(null).anyTimes(); |
| 533 | replay(mockFlowService); |
| 534 | replay(mockDeviceService); |
| 535 | |
| 536 | WebResource rs = resource(); |
| 537 | try { |
| 538 | rs.path("flows/0").get(String.class); |
| 539 | fail("Fetch of non-existent device did not throw an exception"); |
| 540 | } catch (UniformInterfaceException ex) { |
| 541 | assertThat(ex.getMessage(), |
| 542 | containsString("returned a response status of")); |
| 543 | } |
| 544 | } |
| 545 | } |