Merge "Prevent ConfigPusher from killing its thread"
[controller.git] / opendaylight / northbound / commons / src / test / java / org / opendaylight / controller / northbound / commons / exception / CommonsNorthboundExceptionTest.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.northbound.commons.exception;
9
10 import javax.ws.rs.core.Response;
11
12 import org.junit.Assert;
13 import org.junit.Test;
14
15 public class CommonsNorthboundExceptionTest {
16
17     @Test
18     public void testMethodNotAllowed() {
19         MethodNotAllowed mna = new MethodNotAllowed();
20         Assert.assertTrue(mna.getStatusCode() == 405);
21         Assert.assertTrue(mna.getReasonPhrase().equals("Method Not Allowed"));
22         Assert.assertTrue(mna.getFamily().equals(
23                 Response.Status.Family.CLIENT_ERROR));
24     }
25
26     @Test
27     public void testInternalServerErrorException() {
28         try {
29             throw new InternalServerErrorException("Internal Server Exception");
30         } catch (InternalServerErrorException e) {
31             Assert.assertTrue(e.getResponse().getEntity()
32                     .equals("Internal Server Exception"));
33         }
34     }
35
36     @Test
37     public void testMethodNotAllowedException() {
38         try {
39             throw new MethodNotAllowedException("Method Not Allowed Exception");
40         } catch (MethodNotAllowedException e) {
41             Assert.assertTrue(e.getResponse().getEntity()
42                     .equals("Method Not Allowed Exception"));
43         }
44     }
45
46     @Test
47     public void testNotAcceptableException() {
48         try {
49             throw new NotAcceptableException("Not Acceptable Exception");
50         } catch (NotAcceptableException e) {
51             Assert.assertTrue(e.getResponse().getEntity()
52                     .equals("Not Acceptable Exception"));
53         }
54     }
55
56     @Test
57     public void testResourceConflictException() {
58         try {
59             throw new ResourceConflictException("Resource Conflict Exception");
60         } catch (ResourceConflictException e) {
61             Assert.assertTrue(e.getResponse().getEntity()
62                     .equals("Resource Conflict Exception"));
63         }
64     }
65
66     @Test
67     public void testResourceForbiddenException() {
68         try {
69             throw new ResourceForbiddenException("Resource Forbidden Exception");
70         } catch (ResourceForbiddenException e) {
71             Assert.assertTrue(e.getResponse().getEntity()
72                     .equals("Resource Forbidden Exception"));
73         }
74     }
75
76     @Test
77     public void testResourceGoneException() {
78         try {
79             throw new ResourceGoneException("Resource Gone Exception");
80         } catch (ResourceGoneException e) {
81             Assert.assertTrue(e.getResponse().getEntity()
82                     .equals("Resource Gone Exception"));
83         }
84     }
85
86     @Test
87     public void testResourceNotFoundException() {
88         try {
89             throw new ResourceNotFoundException("Resource Not Found Exception");
90         } catch (ResourceNotFoundException e) {
91             Assert.assertTrue(e.getResponse().getEntity()
92                     .equals("Resource Not Found Exception"));
93         }
94     }
95
96     @Test
97     public void testServiceUnavailableException() {
98         try {
99             throw new ServiceUnavailableException(
100                     "Service Unavailable Exception");
101         } catch (ServiceUnavailableException e) {
102             Assert.assertTrue(e.getResponse().getEntity()
103                     .equals("Service Unavailable Exception"));
104         }
105     }
106
107     @Test
108     public void testUnauthorizedException() {
109         try {
110             throw new UnauthorizedException("Unauthorized Exception");
111         } catch (UnauthorizedException e) {
112             Assert.assertTrue(e.getResponse().getEntity()
113                     .equals("Unauthorized Exception"));
114         }
115     }
116
117     @Test
118     public void testUnsupportedMediaTypeException() {
119         try {
120             throw new UnsupportedMediaTypeException(
121                     "Unsupported Media Type Exception");
122         } catch (UnsupportedMediaTypeException e) {
123             Assert.assertTrue(e.getResponse().getEntity()
124                     .equals("Unsupported Media Type Exception"));
125         }
126     }
127
128 }