Merge "Add test for generated code checking list of dependencies."
[controller.git] / opendaylight / northbound / commons / src / test / java / org / opendaylight / controller / northbound / commons / exception / CommonsNorthboundExceptionTest.java
1 package org.opendaylight.controller.northbound.commons.exception;
2
3 import javax.ws.rs.core.Response;
4
5 import org.junit.Assert;
6 import org.junit.Test;
7
8 import junit.framework.TestCase;
9
10 public class CommonsNorthboundExceptionTest extends TestCase {
11
12     @Test
13     public void testMethodNotAllowed() {
14         MethodNotAllowed mna = new MethodNotAllowed();
15         Assert.assertTrue(mna.getStatusCode() == 405);
16         Assert.assertTrue(mna.getReasonPhrase().equals("Method Not Allowed"));
17         Assert.assertTrue(mna.getFamily().equals(
18                 Response.Status.Family.CLIENT_ERROR));
19     }
20
21     @Test
22     public void testInternalServerErrorException() {
23         try {
24             throw new InternalServerErrorException("Internal Server Exception");
25         } catch (InternalServerErrorException e) {
26             Assert.assertTrue(e.getResponse().getEntity()
27                     .equals("Internal Server Exception"));
28         }
29     }
30
31     @Test
32     public void testMethodNotAllowedException() {
33         try {
34             throw new MethodNotAllowedException("Method Not Allowed Exception");
35         } catch (MethodNotAllowedException e) {
36             Assert.assertTrue(e.getResponse().getEntity()
37                     .equals("Method Not Allowed Exception"));
38         }
39     }
40
41     @Test
42     public void testNotAcceptableException() {
43         try {
44             throw new NotAcceptableException("Not Acceptable Exception");
45         } catch (NotAcceptableException e) {
46             Assert.assertTrue(e.getResponse().getEntity()
47                     .equals("Not Acceptable Exception"));
48         }
49     }
50
51     @Test
52     public void testResourceConflictException() {
53         try {
54             throw new ResourceConflictException("Resource Conflict Exception");
55         } catch (ResourceConflictException e) {
56             Assert.assertTrue(e.getResponse().getEntity()
57                     .equals("Resource Conflict Exception"));
58         }
59     }
60
61     @Test
62     public void testResourceForbiddenException() {
63         try {
64             throw new ResourceForbiddenException("Resource Forbidden Exception");
65         } catch (ResourceForbiddenException e) {
66             Assert.assertTrue(e.getResponse().getEntity()
67                     .equals("Resource Forbidden Exception"));
68         }
69     }
70
71     @Test
72     public void testResourceGoneException() {
73         try {
74             throw new ResourceGoneException("Resource Gone Exception");
75         } catch (ResourceGoneException e) {
76             Assert.assertTrue(e.getResponse().getEntity()
77                     .equals("Resource Gone Exception"));
78         }
79     }
80
81     @Test
82     public void testResourceNotFoundException() {
83         try {
84             throw new ResourceNotFoundException("Resource Not Found Exception");
85         } catch (ResourceNotFoundException e) {
86             Assert.assertTrue(e.getResponse().getEntity()
87                     .equals("Resource Not Found Exception"));
88         }
89     }
90
91     @Test
92     public void testServiceUnavailableException() {
93         try {
94             throw new ServiceUnavailableException(
95                     "Service Unavailable Exception");
96         } catch (ServiceUnavailableException e) {
97             Assert.assertTrue(e.getResponse().getEntity()
98                     .equals("Service Unavailable Exception"));
99         }
100     }
101
102     @Test
103     public void testUnauthorizedException() {
104         try {
105             throw new UnauthorizedException("Unauthorized Exception");
106         } catch (UnauthorizedException e) {
107             Assert.assertTrue(e.getResponse().getEntity()
108                     .equals("Unauthorized Exception"));
109         }
110     }
111
112     @Test
113     public void testUnsupportedMediaTypeException() {
114         try {
115             throw new UnsupportedMediaTypeException(
116                     "Unsupported Media Type Exception");
117         } catch (UnsupportedMediaTypeException e) {
118             Assert.assertTrue(e.getResponse().getEntity()
119                     .equals("Unsupported Media Type Exception"));
120         }
121     }
122
123 }