blob: 1b462f6ec8d5b7d73d0508d3a37222d9322385d9 [file] [log] [blame]
Ray Milkey2287d882015-01-30 10:15:20 -08001/*
2 * Copyright 2015 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 */
16package org.onosproject.rest;
17
18import org.junit.Test;
19
20import com.sun.jersey.api.client.UniformInterfaceException;
21import com.sun.jersey.api.client.WebResource;
22
23import static org.hamcrest.Matchers.containsString;
24import static org.junit.Assert.assertThat;
25import static org.junit.Assert.fail;
26
27/**
28 * Unit tests for bad REST requests.
29 */
30public class BadRequestTest extends ResourceTest {
Ray Milkeya0cecdc2015-04-09 09:51:52 -070031
32 /**
33 * Tests the response for an invalid URL.
34 */
Ray Milkey2287d882015-01-30 10:15:20 -080035 @Test
36 public void badUrl() {
37 WebResource rs = resource();
38 try {
39 rs.path("ThisIsABadURL").get(String.class);
40 fail("Fetch of non-existent URL did not throw an exception");
41 } catch (UniformInterfaceException ex) {
42 assertThat(ex.getMessage(),
43 containsString("returned a response status of 404 Not Found"));
44 }
45 }
Ray Milkeya0cecdc2015-04-09 09:51:52 -070046
47 /**
48 * Tests the response for a request with a bad method.
49 */
50 @Test
51 public void badMethod() {
52 WebResource rs = resource();
53 try {
54 rs.path("hosts").delete();
55 fail("Fetch of non-existent URL did not throw an exception");
56 } catch (UniformInterfaceException ex) {
57 assertThat(ex.getMessage(),
58 containsString("returned a response status of 405 Method Not Allowed"));
59 }
60 }
Ray Milkey2287d882015-01-30 10:15:20 -080061}