Add a negative test for Host REST API
Change-Id: I84b2645f6a2521bb66a46f09793765956dfc5d04
Showing
1 changed file
with
23 additions
and
0 deletions
... | @@ -42,6 +42,7 @@ import org.onosproject.net.provider.ProviderId; | ... | @@ -42,6 +42,7 @@ import org.onosproject.net.provider.ProviderId; |
42 | import com.eclipsesource.json.JsonArray; | 42 | import com.eclipsesource.json.JsonArray; |
43 | import com.eclipsesource.json.JsonObject; | 43 | import com.eclipsesource.json.JsonObject; |
44 | import com.google.common.collect.ImmutableSet; | 44 | import com.google.common.collect.ImmutableSet; |
45 | +import com.sun.jersey.api.client.UniformInterfaceException; | ||
45 | import com.sun.jersey.api.client.WebResource; | 46 | import com.sun.jersey.api.client.WebResource; |
46 | import com.sun.jersey.test.framework.JerseyTest; | 47 | import com.sun.jersey.test.framework.JerseyTest; |
47 | 48 | ||
... | @@ -54,6 +55,7 @@ import static org.hamcrest.Matchers.hasSize; | ... | @@ -54,6 +55,7 @@ import static org.hamcrest.Matchers.hasSize; |
54 | import static org.hamcrest.Matchers.is; | 55 | import static org.hamcrest.Matchers.is; |
55 | import static org.hamcrest.Matchers.notNullValue; | 56 | import static org.hamcrest.Matchers.notNullValue; |
56 | import static org.junit.Assert.assertThat; | 57 | import static org.junit.Assert.assertThat; |
58 | +import static org.junit.Assert.fail; | ||
57 | import static org.onlab.packet.MacAddress.valueOf; | 59 | import static org.onlab.packet.MacAddress.valueOf; |
58 | import static org.onlab.packet.VlanId.vlanId; | 60 | import static org.onlab.packet.VlanId.vlanId; |
59 | import static org.onosproject.net.PortNumber.portNumber; | 61 | import static org.onosproject.net.PortNumber.portNumber; |
... | @@ -329,5 +331,26 @@ public class HostResourceTest extends JerseyTest { | ... | @@ -329,5 +331,26 @@ public class HostResourceTest extends JerseyTest { |
329 | assertThat(result, matchesHost(host1)); | 331 | assertThat(result, matchesHost(host1)); |
330 | } | 332 | } |
331 | 333 | ||
334 | + /** | ||
335 | + * Tests that a fetch of a non-existent object throws an exception. | ||
336 | + */ | ||
337 | + @Test | ||
338 | + public void testBadGet() { | ||
339 | + | ||
340 | + expect(mockHostService.getHost(HostId.hostId("00:00:11:00:00:01/1"))) | ||
341 | + .andReturn(null) | ||
342 | + .anyTimes(); | ||
343 | + replay(mockHostService); | ||
344 | + | ||
345 | + WebResource rs = resource(); | ||
346 | + try { | ||
347 | + rs.path("hosts/00:00:11:00:00:01/1").get(String.class); | ||
348 | + fail("Fetch of non-existent host did not throw an exception"); | ||
349 | + } catch (UniformInterfaceException ex) { | ||
350 | + assertThat(ex.getMessage(), | ||
351 | + containsString("returned a response status of")); | ||
352 | + } | ||
353 | + } | ||
354 | + | ||
332 | } | 355 | } |
333 | 356 | ... | ... |
-
Please register or login to post a comment